Change adminReducer to immer

Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
soupette 2020-06-16 11:31:46 +02:00 committed by Alexandre Bodin
parent 8b02624b6b
commit b64af2c309
15 changed files with 332 additions and 178 deletions

View File

@ -4,12 +4,30 @@
* *
*/ */
import { GET_PLUGINS_FROM_MARKETPLACE_SUCCEEDED, SET_APP_ERROR } from './constants'; import {
GET_USER_PERMISSIONS,
GET_USER_PERMISSIONS_ERROR,
GET_USER_PERMISSIONS_SUCCEEDED,
SET_APP_ERROR,
} from './constants';
export function getPluginsFromMarketPlaceSucceeded(plugins) { export function getUserPermissions() {
return { return {
type: GET_PLUGINS_FROM_MARKETPLACE_SUCCEEDED, type: GET_USER_PERMISSIONS,
plugins, };
}
export function getUserPermissionsError(error) {
return {
type: GET_USER_PERMISSIONS_ERROR,
error,
};
}
export function getUserPermissionsSucceeded(data) {
return {
type: GET_USER_PERMISSIONS_SUCCEEDED,
data,
}; };
} }

View File

@ -4,6 +4,7 @@
* *
*/ */
export const GET_PLUGINS_FROM_MARKETPLACE_SUCCEEDED =
'StrapiAdmin/Admin/GET_PLUGINS_FROM_MARKETPLACE_SUCCEEDED';
export const SET_APP_ERROR = 'StrapiAdmin/Admin/SET_APP_ERROR'; export const SET_APP_ERROR = 'StrapiAdmin/Admin/SET_APP_ERROR';
export const GET_USER_PERMISSIONS = 'StrapiAdmin/Admin/GET_USER_PERMISSIONS';
export const GET_USER_PERMISSIONS_ERROR = 'StrapiAdmin/Admin/GET_USER_PERMISSIONS_ERROR';
export const GET_USER_PERMISSIONS_SUCCEEDED = 'StrapiAdmin/Admin/GET_USER_PERMISSIONS_SUCCEEDED';

View File

@ -45,7 +45,12 @@ import {
updatePlugin, updatePlugin,
} from '../App/actions'; } from '../App/actions';
import makeSelecApp from '../App/selectors'; import makeSelecApp from '../App/selectors';
import { setAppError } from './actions'; import {
getUserPermissions,
getUserPermissionsError,
getUserPermissionsSucceeded,
setAppError,
} from './actions';
import makeSelectAdmin from './selectors'; import makeSelectAdmin from './selectors';
import Wrapper from './Wrapper'; import Wrapper from './Wrapper';
import Content from './Content'; import Content from './Content';
@ -62,6 +67,9 @@ export class Admin extends React.Component {
componentDidMount() { componentDidMount() {
this.emitEvent('didAccessAuthenticatedAdministration'); this.emitEvent('didAccessAuthenticatedAdministration');
// TODO: remove the user1 it is just for testing until
// Api is ready
this.fetchUserPermissions('user1', true);
} }
shouldComponentUpdate(prevProps) { shouldComponentUpdate(prevProps) {
@ -100,6 +108,28 @@ export class Admin extends React.Component {
} }
}; };
fetchUserPermissions = async (user = 'user1', resetState = false) => {
const { getUserPermissions, getUserPermissionsError, getUserPermissionsSucceeded } = this.props;
if (resetState) {
// Show a loader
getUserPermissions();
}
try {
const data = await new Promise(resolve =>
setTimeout(() => {
resolve(fakePermissionsData[user]);
}, 2000)
);
getUserPermissionsSucceeded(data);
} catch (err) {
console.error(err);
getUserPermissionsError(err);
}
};
hasApluginNotReady = props => { hasApluginNotReady = props => {
const { const {
global: { plugins }, global: { plugins },
@ -144,6 +174,7 @@ export class Admin extends React.Component {
render() { render() {
const { const {
admin: { isLoading, userPermissions },
global: { global: {
autoReload, autoReload,
blockApp, blockApp,
@ -169,6 +200,13 @@ export class Admin extends React.Component {
); );
} }
// Show a loader while permissions are being fetched
// TODO: we might need to improve this behavior for the ctb
// since we will need to update the permissions
if (isLoading) {
return <LoadingIndicatorPage />;
}
return ( return (
<GlobalContextProvider <GlobalContextProvider
autoReload={autoReload} autoReload={autoReload}
@ -177,13 +215,14 @@ export class Admin extends React.Component {
currentLocale={locale} currentLocale={locale}
disableGlobalOverlayBlocker={disableGlobalOverlayBlocker} disableGlobalOverlayBlocker={disableGlobalOverlayBlocker}
enableGlobalOverlayBlocker={enableGlobalOverlayBlocker} enableGlobalOverlayBlocker={enableGlobalOverlayBlocker}
fetchUserPermissions={this.fetchUserPermissions}
formatMessage={formatMessage} formatMessage={formatMessage}
menu={this.menuRef.current}
plugins={plugins} plugins={plugins}
settingsBaseURL={SETTINGS_BASE_URL || '/settings'} settingsBaseURL={SETTINGS_BASE_URL || '/settings'}
menu={this.menuRef.current}
updatePlugin={updatePlugin} updatePlugin={updatePlugin}
> >
<UserProvider value={fakePermissionsData.user2}> <UserProvider value={userPermissions}>
<Wrapper> <Wrapper>
<LeftMenu version={strapiVersion} plugins={plugins} ref={this.menuRef} /> <LeftMenu version={strapiVersion} plugins={plugins} ref={this.menuRef} />
<NavTopRightWrapper> <NavTopRightWrapper>
@ -243,9 +282,14 @@ Admin.defaultProps = {
Admin.propTypes = { Admin.propTypes = {
admin: PropTypes.shape({ admin: PropTypes.shape({
appError: PropTypes.bool, appError: PropTypes.bool,
isLoading: PropTypes.bool,
userPermissions: PropTypes.array,
}).isRequired, }).isRequired,
disableGlobalOverlayBlocker: PropTypes.func.isRequired, disableGlobalOverlayBlocker: PropTypes.func.isRequired,
enableGlobalOverlayBlocker: PropTypes.func.isRequired, enableGlobalOverlayBlocker: PropTypes.func.isRequired,
getUserPermissions: PropTypes.func.isRequired,
getUserPermissionsError: PropTypes.func.isRequired,
getUserPermissionsSucceeded: PropTypes.func.isRequired,
global: PropTypes.shape({ global: PropTypes.shape({
autoReload: PropTypes.bool, autoReload: PropTypes.bool,
blockApp: PropTypes.bool, blockApp: PropTypes.bool,
@ -275,6 +319,9 @@ export function mapDispatchToProps(dispatch) {
{ {
disableGlobalOverlayBlocker, disableGlobalOverlayBlocker,
enableGlobalOverlayBlocker, enableGlobalOverlayBlocker,
getUserPermissions,
getUserPermissionsError,
getUserPermissionsSucceeded,
setAppError, setAppError,
updatePlugin, updatePlugin,
}, },

View File

@ -4,23 +4,48 @@
* *
*/ */
import { fromJS } from 'immutable'; import produce from 'immer';
import { GET_PLUGINS_FROM_MARKETPLACE_SUCCEEDED, SET_APP_ERROR } from './constants';
const initialState = fromJS({ import {
GET_USER_PERMISSIONS,
GET_USER_PERMISSIONS_ERROR,
GET_USER_PERMISSIONS_SUCCEEDED,
SET_APP_ERROR,
} from './constants';
const initialState = {
appError: false, appError: false,
pluginsFromMarketplace: [], isLoading: true,
}); userPermissions: [],
};
function adminReducer(state = initialState, action) { const reducer = (state = initialState, action) =>
switch (action.type) { // eslint-disable-next-line consistent-return
case GET_PLUGINS_FROM_MARKETPLACE_SUCCEEDED: produce(state, draftState => {
return state.update('pluginsFromMarketplace', () => fromJS(action.plugins)); switch (action.type) {
case SET_APP_ERROR: case GET_USER_PERMISSIONS: {
return state.update('appError', () => true); draftState.isLoading = true;
default: break;
return state; }
}
}
export default adminReducer; case GET_USER_PERMISSIONS_ERROR: {
draftState.error = action.error;
draftState.isLoading = false;
break;
}
case GET_USER_PERMISSIONS_SUCCEEDED: {
draftState.isLoading = false;
draftState.userPermissions = action.data;
break;
}
case SET_APP_ERROR: {
draftState.appError = true;
break;
}
default:
return state;
}
});
export default reducer;
export { initialState };

View File

@ -1,9 +1,12 @@
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import { initialState } from './reducer';
/** /**
* Direct selector to the admin state domain * Direct selector to the admin state domain
*/ */
const selectAdminDomain = () => state => state.get('admin'); const selectAdminDomain = () => state => {
return state.get('admin') || initialState;
};
/** /**
* Other specific selectors * Other specific selectors
@ -13,12 +16,7 @@ const selectAdminDomain = () => state => state.get('admin');
* Default selector used by Admin * Default selector used by Admin
*/ */
const makeSelectAdmin = () => createSelector(selectAdminDomain(), substate => substate.toJS()); const makeSelectAdmin = () => createSelector(selectAdminDomain(), substate => substate);
const makeSelectPluginsFromMarketplace = () =>
createSelector(selectAdminDomain(), substate => substate.get('pluginsFromMarketplace').toJS());
const makeSelectUuid = () => createSelector(selectAdminDomain(), substate => substate.get('uuid'));
export default makeSelectAdmin; export default makeSelectAdmin;
export { makeSelectUuid, selectAdminDomain, makeSelectPluginsFromMarketplace }; export { selectAdminDomain };

View File

@ -22,6 +22,9 @@ describe('<Admin />', () => {
disableGlobalOverlayBlocker: jest.fn(), disableGlobalOverlayBlocker: jest.fn(),
emitEvent: jest.fn(), emitEvent: jest.fn(),
enableGlobalOverlayBlocker: jest.fn(), enableGlobalOverlayBlocker: jest.fn(),
getUserPermissions: jest.fn(),
getUserPermissionsError: jest.fn(),
getUserPermissionsSucceeded: jest.fn(),
global: { global: {
autoReload: false, autoReload: false,
blockApp: false, blockApp: false,

View File

@ -1,16 +1,21 @@
import { fromJS } from 'immutable'; import produce from 'immer';
import {
import { setAppError } from '../actions'; setAppError,
getUserPermissions,
getUserPermissionsError,
getUserPermissionsSucceeded,
} from '../actions';
import adminReducer from '../reducer'; import adminReducer from '../reducer';
describe('adminReducer', () => { describe('adminReducer', () => {
let state; let state;
beforeEach(() => { beforeEach(() => {
state = fromJS({ state = {
appError: false, appError: false,
pluginsFromMarketplace: [], isLoading: true,
}); userPermissions: [],
};
}); });
it('returns the initial state', () => { it('returns the initial state', () => {
@ -19,9 +24,39 @@ describe('adminReducer', () => {
expect(adminReducer(undefined, {})).toEqual(expected); expect(adminReducer(undefined, {})).toEqual(expected);
}); });
it('should handle the setaAppError action correctly', () => { it('should handle the setAppError action correctly', () => {
const expected = state.set('appError', true); const expected = produce(state, draft => {
draft.appError = true;
});
expect(adminReducer(state, setAppError())).toEqual(expected); expect(adminReducer(state, setAppError())).toEqual(expected);
}); });
it('should handle the getUserPermissions action correctly', () => {
const expected = produce(state, draft => {
draft.isLoading = true;
});
expect(adminReducer(state, getUserPermissions())).toEqual(expected);
});
it('should handle the getUserPermissionsError action correctly', () => {
const error = 'Error';
const expected = produce(state, draft => {
draft.isLoading = false;
draft.error = error;
});
expect(adminReducer(state, getUserPermissionsError(error))).toEqual(expected);
});
it('should handle the getUserPermissionsSucceeded action correctly', () => {
const data = ['permission 1', 'permission 2'];
const expected = produce(state, draft => {
draft.isLoading = false;
draft.userPermissions = data;
});
expect(adminReducer(state, getUserPermissionsSucceeded(data))).toEqual(expected);
});
}); });

View File

@ -1,45 +0,0 @@
import { fromJS, Map } from 'immutable';
import makeSelectAdminDomain, { selectAdminDomain } from '../selectors';
describe('<Admin /> selectors', () => {
describe('selectAdminDomain selector', () => {
it('should select the global state', () => {
const state = fromJS({
autoReload: false,
appError: false,
currentEnvironment: 'development',
isLoading: true,
layout: Map({}),
showLeftMenu: true,
strapiVersion: '3',
uuid: false,
});
const mockedState = fromJS({
admin: state,
});
expect(selectAdminDomain()(mockedState)).toEqual(state);
});
});
describe('makeSelectAdminDomain', () => {
it('should select the global state (.toJS())', () => {
const state = fromJS({
autoReload: false,
appError: false,
currentEnvironment: 'development',
isLoading: true,
layout: Map({}),
showLeftMenu: true,
strapiVersion: '3',
uuid: false,
});
const mockedState = fromJS({
admin: state,
});
expect(makeSelectAdminDomain()(mockedState)).toEqual(state.toJS());
});
});
});

View File

@ -141,7 +141,7 @@ const LeftMenu = forwardRef(({ version, plugins }, ref) => {
getLinksPermissions(); getLinksPermissions();
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, []); }, [permissions]);
return ( return (
<Wrapper> <Wrapper>

View File

@ -56,7 +56,7 @@ const reducer = (state, action) =>
break; break;
} }
case 'TOGGLE_IS_LOADING': { case 'TOGGLE_IS_LOADING': {
draftState.isLoading = !state.isLoading; draftState.isLoading = false;
break; break;
} }
default: default:

View File

@ -14,6 +14,7 @@ const reducer = (state, action) =>
case 'GET_MODELS': { case 'GET_MODELS': {
draftState.collectionTypes = initialState.collectionTypes; draftState.collectionTypes = initialState.collectionTypes;
draftState.singleTypes = initialState.singleTypes; draftState.singleTypes = initialState.singleTypes;
draftState.components = initialState.components;
draftState.isLoading = true; draftState.isLoading = true;
break; break;
} }

View File

@ -1,6 +1,6 @@
import reducer from '../reducer'; import reducer from '../reducer';
describe('ADMIN | HOOKS | useContentTypes | reducer', () => { describe('ADMIN | HOOKS | useModels | reducer', () => {
describe('DEFAULT_ACTION', () => { describe('DEFAULT_ACTION', () => {
it('should return the initialState', () => { it('should return the initialState', () => {
const state = { const state = {
@ -11,13 +11,14 @@ describe('ADMIN | HOOKS | useContentTypes | reducer', () => {
}); });
}); });
describe('GET_DATA_ERROR', () => { describe('GET_MODELS_ERROR', () => {
it('should set isLoading to false is an error occured', () => { it('should set isLoading to false is an error occured', () => {
const action = { const action = {
type: 'GET_MODELS_ERROR', type: 'GET_MODELS_ERROR',
}; };
const initialState = { const initialState = {
collectionTypes: [], collectionTypes: [],
components: [],
singleTypes: [ singleTypes: [
{ {
uid: 'app.homepage', uid: 'app.homepage',
@ -31,6 +32,7 @@ describe('ADMIN | HOOKS | useContentTypes | reducer', () => {
}; };
const expected = { const expected = {
collectionTypes: [], collectionTypes: [],
components: [],
singleTypes: [], singleTypes: [],
isLoading: false, isLoading: false,
}; };
@ -45,12 +47,37 @@ describe('ADMIN | HOOKS | useContentTypes | reducer', () => {
type: 'GET_MODELS', type: 'GET_MODELS',
}; };
const initialState = { const initialState = {
collectionTypes: [], collectionTypes: [
singleTypes: [], {
isLoading: true, uid: 'app.category',
isDisplayed: true,
schema: {
kind: 'collectionType',
},
},
{
uid: 'app.category',
isDisplayed: true,
schema: {
kind: 'collectionType',
},
},
],
singleTypes: [
{
uid: 'app.homepage',
isDisplayed: true,
schema: {
kind: 'singleType',
},
},
],
components: [{}],
isLoading: false,
}; };
const expected = { const expected = {
collectionTypes: [], collectionTypes: [],
components: [],
singleTypes: [], singleTypes: [],
isLoading: true, isLoading: true,
}; };
@ -63,7 +90,7 @@ describe('ADMIN | HOOKS | useContentTypes | reducer', () => {
it('should return the state with the collectionTypes and singleTypes', () => { it('should return the state with the collectionTypes and singleTypes', () => {
const action = { const action = {
type: 'GET_MODELS_SUCCEDED', type: 'GET_MODELS_SUCCEDED',
data: [ contentTypes: [
{ {
uid: 'app.homepage', uid: 'app.homepage',
isDisplayed: true, isDisplayed: true,
@ -86,9 +113,11 @@ describe('ADMIN | HOOKS | useContentTypes | reducer', () => {
}, },
}, },
], ],
components: [],
}; };
const initialState = { const initialState = {
collectionTypes: [], collectionTypes: [],
components: [],
singleTypes: [], singleTypes: [],
isLoading: true, isLoading: true,
}; };
@ -111,6 +140,7 @@ describe('ADMIN | HOOKS | useContentTypes | reducer', () => {
}, },
}, },
], ],
components: [],
isLoading: false, isLoading: false,
}; };

View File

@ -21,82 +21,82 @@ const data = {
}, },
// Admin webhooks // Admin webhooks
{ // {
action: 'admin::webhooks.create', // action: 'admin::webhooks.create',
subject: null, // subject: null,
fields: null, // fields: null,
conditions: [], // conditions: [],
}, // },
{ // {
action: 'admin::webhooks.read', // action: 'admin::webhooks.read',
subject: null, // subject: null,
fields: null, // fields: null,
conditions: [], // conditions: [],
}, // },
{ // {
action: 'admin::webhooks.update', // action: 'admin::webhooks.update',
subject: null, // subject: null,
fields: null, // fields: null,
conditions: [], // conditions: [],
}, // },
{ // {
action: 'admin::webhooks.delete', // action: 'admin::webhooks.delete',
subject: null, // subject: null,
fields: null, // fields: null,
conditions: [], // conditions: [],
}, // },
// Admin users // Admin users
{ // {
action: 'admin::users.create', // action: 'admin::users.create',
subject: null, // subject: null,
fields: null, // fields: null,
conditions: [], // conditions: [],
}, // },
{ // {
action: 'admin::users.read', // action: 'admin::users.read',
subject: null, // subject: null,
fields: null, // fields: null,
conditions: [], // conditions: [],
}, // },
{ // {
action: 'admin::users.update', // action: 'admin::users.update',
subject: null, // subject: null,
fields: null, // fields: null,
conditions: [], // conditions: [],
}, // },
{ // {
action: 'admin::users.delete', // action: 'admin::users.delete',
subject: null, // subject: null,
fields: null, // fields: null,
conditions: [], // conditions: [],
}, // },
// Admin roles // Admin roles
{ // {
action: 'admin::roles.create', // action: 'admin::roles.create',
subject: null, // subject: null,
fields: null, // fields: null,
conditions: [], // conditions: [],
}, // },
{ // {
action: 'admin::roles.read', // action: 'admin::roles.read',
subject: null, // subject: null,
fields: null, // fields: null,
conditions: [], // conditions: [],
}, // },
{ // {
action: 'admin::roles.update', // action: 'admin::roles.update',
subject: null, // subject: null,
fields: null, // fields: null,
conditions: [], // conditions: [],
}, // },
{ // {
action: 'admin::roles.delete', // action: 'admin::roles.delete',
subject: null, // subject: null,
fields: null, // fields: null,
conditions: [], // conditions: [],
}, // },
// Content type builder // Content type builder
{ {
@ -157,12 +157,12 @@ const data = {
fields: null, fields: null,
conditions: null, conditions: null,
}, },
{ // {
action: 'plugins::upload.settings.read', // action: 'plugins::upload.settings.read',
subject: null, // subject: null,
fields: null, // fields: null,
conditions: null, // conditions: null,
}, // },
// Users-permissions // Users-permissions
{ {
@ -331,6 +331,11 @@ const data = {
subject: 'application::address.address', subject: 'application::address.address',
conditions: [], conditions: [],
}, },
{
action: 'plugins::content-manager.explorer.create',
subject: 'application::vegetable.vegetable',
conditions: [],
},
{ {
action: 'plugins::content-manager.explorer.create', action: 'plugins::content-manager.explorer.create',
subject: 'application::restaurant.restaurant', subject: 'application::restaurant.restaurant',

View File

@ -77,8 +77,7 @@ function serverRestartWatcher(response) {
if (res.status >= 400) { if (res.status >= 400) {
throw new Error('not available'); throw new Error('not available');
} }
// Hide the global OverlayBlocker
strapi.unlockApp();
resolve(response); resolve(response);
}) })
.catch(() => { .catch(() => {
@ -146,9 +145,6 @@ export default function request(...args) {
.then(parseJSON) .then(parseJSON)
.then(response => { .then(response => {
if (shouldWatchServerRestart) { if (shouldWatchServerRestart) {
// Display the global OverlayBlocker
strapi.lockApp(shouldWatchServerRestart);
return serverRestartWatcher(response); return serverRestartWatcher(response);
} }

View File

@ -33,7 +33,14 @@ import {
const DataManagerProvider = ({ allIcons, children }) => { const DataManagerProvider = ({ allIcons, children }) => {
const [reducerState, dispatch] = useReducer(reducer, initialState, init); const [reducerState, dispatch] = useReducer(reducer, initialState, init);
const [infoModals, toggleInfoModal] = useState({ cancel: false }); const [infoModals, toggleInfoModal] = useState({ cancel: false });
const { autoReload, currentEnvironment, emitEvent, formatMessage, menu } = useGlobalContext(); const {
autoReload,
currentEnvironment,
emitEvent,
fetchUserPermissions,
formatMessage,
menu,
} = useGlobalContext();
const { const {
components, components,
contentTypes, contentTypes,
@ -214,11 +221,18 @@ const DataManagerProvider = ({ allIcons, children }) => {
push({ search: '' }); push({ search: '' });
if (userConfirm) { if (userConfirm) {
strapi.lockApp();
await request(requestURL, { method: 'DELETE' }, true); await request(requestURL, { method: 'DELETE' }, true);
await updatePermissions();
// Reload the plugin so the cycle is new again // Reload the plugin so the cycle is new again
dispatch({ type: 'RELOAD_PLUGIN' }); dispatch({ type: 'RELOAD_PLUGIN' });
// Refetch all the data // Refetch all the data
getDataRef.current(); getDataRef.current();
strapi.unlockApp();
} }
} catch (err) { } catch (err) {
console.error({ err }); console.error({ err });
@ -252,15 +266,22 @@ const DataManagerProvider = ({ allIcons, children }) => {
return; return;
} }
strapi.lockApp();
await request(requestURL, { method: 'DELETE' }, true); await request(requestURL, { method: 'DELETE' }, true);
// Reload the plugin so the cycle is new again // Reload the plugin so the cycle is new again
dispatch({ type: 'RELOAD_PLUGIN' }); dispatch({ type: 'RELOAD_PLUGIN' });
// Refetch the permissions
await updatePermissions();
// Update the app menu // Update the app menu
await updateAppMenu(); await updateAppMenu();
// Refetch all the data // Refetch all the data
getDataRef.current(); getDataRef.current();
strapi.unlockApp();
} }
} catch (err) { } catch (err) {
console.error({ err }); console.error({ err });
@ -275,13 +296,20 @@ const DataManagerProvider = ({ allIcons, children }) => {
// Close the modal // Close the modal
push({ search: '' }); push({ search: '' });
// Lock the app
strapi.lockApp();
// Update the category // Update the category
await request(requestURL, { method: 'PUT', body }, true); await request(requestURL, { method: 'PUT', body }, true);
await updatePermissions();
// Reload the plugin so the cycle is new again // Reload the plugin so the cycle is new again
dispatch({ type: 'RELOAD_PLUGIN' }); dispatch({ type: 'RELOAD_PLUGIN' });
// Refetch all the data // Refetch all the data
getDataRef.current(); getDataRef.current();
strapi.unlockApp();
} catch (err) { } catch (err) {
console.error({ err }); console.error({ err });
strapi.notification.error('notification.error'); strapi.notification.error('notification.error');
@ -394,7 +422,13 @@ const DataManagerProvider = ({ allIcons, children }) => {
const baseURL = `/${pluginId}/${endPoint}`; const baseURL = `/${pluginId}/${endPoint}`;
const requestURL = isCreating ? baseURL : `${baseURL}/${currentUid}`; const requestURL = isCreating ? baseURL : `${baseURL}/${currentUid}`;
// Lock the app
strapi.lockApp();
await request(requestURL, { method, body }, true); await request(requestURL, { method, body }, true);
await updatePermissions();
// Update the app menu // Update the app menu
await updateAppMenu(); await updateAppMenu();
@ -416,6 +450,8 @@ const DataManagerProvider = ({ allIcons, children }) => {
dispatch({ type: 'RELOAD_PLUGIN' }); dispatch({ type: 'RELOAD_PLUGIN' });
// Refetch all the data // Refetch all the data
getDataRef.current(); getDataRef.current();
strapi.unlockApp();
} catch (err) { } catch (err) {
if (!isInContentTypeView) { if (!isInContentTypeView) {
emitEvent('didNotSaveComponent'); emitEvent('didNotSaveComponent');
@ -437,6 +473,10 @@ const DataManagerProvider = ({ allIcons, children }) => {
} }
}; };
const updatePermissions = async () => {
await fetchUserPermissions('user2');
};
const updateSchema = (data, schemaType, componentUID) => { const updateSchema = (data, schemaType, componentUID) => {
dispatch({ dispatch({
type: 'UPDATE_SCHEMA', type: 'UPDATE_SCHEMA',