mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 00:39:49 +00:00
Fix menu links that were missing when updating a content type
Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
parent
9378dc5428
commit
009c995736
@ -1,4 +1,4 @@
|
|||||||
import { useEffect } from 'react';
|
import { useEffect, useRef } from 'react';
|
||||||
import { useUser } from 'strapi-helper-plugin';
|
import { useUser } from 'strapi-helper-plugin';
|
||||||
import { useSelector, useDispatch } from 'react-redux';
|
import { useSelector, useDispatch } from 'react-redux';
|
||||||
import getCtOrStLinks from './utils/getCtOrStLinks';
|
import getCtOrStLinks from './utils/getCtOrStLinks';
|
||||||
@ -14,10 +14,20 @@ const useMenuSections = (plugins, shouldUpdateStrapi) => {
|
|||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const { userPermissions } = useUser();
|
const { userPermissions } = useUser();
|
||||||
const { menu: settingsMenu } = useSettingsMenu(true);
|
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);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const resolvePermissions = async () => {
|
const resolvePermissions = async () => {
|
||||||
const pluginsSectionLinks = toPluginLinks(plugins);
|
const pluginsSectionLinks = toPluginLinks(pluginsRef.current);
|
||||||
const { authorizedCtLinks, authorizedStLinks, contentTypes } = await getCtOrStLinks(
|
const { authorizedCtLinks, authorizedStLinks, contentTypes } = await getCtOrStLinks(
|
||||||
userPermissions
|
userPermissions
|
||||||
);
|
);
|
||||||
@ -29,9 +39,9 @@ const useMenuSections = (plugins, shouldUpdateStrapi) => {
|
|||||||
|
|
||||||
const authorizedGeneralSectionLinks = await getGeneralLinks(
|
const authorizedGeneralSectionLinks = await getGeneralLinks(
|
||||||
userPermissions,
|
userPermissions,
|
||||||
state.generalSectionLinks,
|
generalSectionLinksRef.current,
|
||||||
settingsMenu,
|
settingsMenuRef.current,
|
||||||
shouldUpdateStrapi
|
shouldUpdateStrapiRef.current
|
||||||
);
|
);
|
||||||
|
|
||||||
dispatch(setCtOrStLinks(authorizedCtLinks, authorizedStLinks, contentTypes));
|
dispatch(setCtOrStLinks(authorizedCtLinks, authorizedStLinks, contentTypes));
|
||||||
@ -40,8 +50,7 @@ const useMenuSections = (plugins, shouldUpdateStrapi) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
resolvePermissions();
|
resolvePermissions();
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
}, [userPermissions, dispatch]);
|
||||||
}, [plugins, userPermissions, dispatch]);
|
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user