Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /var/www/html/wincloud_gateway/node_modules/strapi-admin/admin/src/containers/LeftMenu/ drwxr-xr-x | |
| Viewing file: Select action/file-type: import { useEffect, useRef } from 'react';
import { useUser } from 'strapi-helper-plugin';
import { useSelector, useDispatch } from 'react-redux';
import getCtOrStLinks from './utils/getCtOrStLinks';
import getPluginSectionLinks from './utils/getPluginSectionLinks';
import getGeneralLinks from './utils/getGeneralLinks';
import { setCtOrStLinks, setSectionLinks, toggleIsLoading, unsetIsLoading } from './actions';
import useSettingsMenu from '../../hooks/useSettingsMenu';
import toPluginLinks from './utils/toPluginLinks';
import selectMenuLinks from './selectors';
const useMenuSections = (plugins, shouldUpdateStrapi) => {
const state = useSelector(selectMenuLinks);
const dispatch = useDispatch();
const { userPermissions } = useUser();
const { menu: settingsMenu } = useSettingsMenu(true);
// We are using a ref because we don't want our effect to have this in its dependencies array
const generalSectionLinksRef = useRef(state.generalSectionLinks);
const shouldUpdateStrapiRef = useRef(shouldUpdateStrapi);
// Since the settingsMenu is not managing any state because of the true argument we can use a ref here
// so we don't need to add it to the effect dependencies array
const settingsMenuRef = useRef(settingsMenu);
// Once in the app lifecycle the plugins should not be added into any dependencies array, in order to prevent
// the effect to be run when another plugin is using one plugins internal api for instance
// so it's definitely ok to use a ref here
const pluginsRef = useRef(plugins);
const toggleLoading = () => dispatch(toggleIsLoading());
const resolvePermissions = async (permissions = userPermissions) => {
const pluginsSectionLinks = toPluginLinks(pluginsRef.current);
const { authorizedCtLinks, authorizedStLinks, contentTypes } = await getCtOrStLinks(
permissions
);
const authorizedPluginSectionLinks = await getPluginSectionLinks(
permissions,
pluginsSectionLinks
);
const authorizedGeneralSectionLinks = await getGeneralLinks(
permissions,
generalSectionLinksRef.current,
settingsMenuRef.current,
shouldUpdateStrapiRef.current
);
dispatch(setCtOrStLinks(authorizedCtLinks, authorizedStLinks, contentTypes));
dispatch(setSectionLinks(authorizedGeneralSectionLinks, authorizedPluginSectionLinks));
dispatch(unsetIsLoading());
};
const resolvePermissionsRef = useRef(resolvePermissions);
useEffect(() => {
resolvePermissionsRef.current(userPermissions);
}, [userPermissions, dispatch]);
return { state, generateMenu: resolvePermissionsRef.current, toggleLoading };
};
export default useMenuSections;
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0054 ]-- |