mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 02:44:55 +00:00
Global single request
This commit is contained in:
parent
6e559170f7
commit
e1b0f07655
@ -4,7 +4,7 @@ import { request } from 'strapi-helper-plugin';
|
||||
|
||||
import { getInitDataSucceeded, getSecuredDataSucceeded } from './actions';
|
||||
import { EMIT_EVENT, GET_INIT_DATA, GET_SECURED_DATA } from './constants';
|
||||
import { makeSelectUuid } from './selectors';
|
||||
import { makeSelectUuid } from '../App/selectors';
|
||||
|
||||
export function* emitter(action) {
|
||||
try {
|
||||
|
||||
@ -36,10 +36,11 @@ export function freezeApp(data) {
|
||||
};
|
||||
}
|
||||
|
||||
export function getDataSucceeded(hasAdminUser) {
|
||||
export function getDataSucceeded(hasAdminUser, data) {
|
||||
return {
|
||||
type: GET_DATA_SUCCEEDED,
|
||||
hasAdminUser,
|
||||
data,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -37,7 +37,9 @@ function App(props) {
|
||||
const requestURL = '/users-permissions/init';
|
||||
|
||||
const { hasAdmin } = await request(requestURL, { method: 'GET' });
|
||||
getDataRef.current(hasAdmin);
|
||||
const { data } = await request('/admin/init', { method: 'GET' });
|
||||
|
||||
getDataRef.current(hasAdmin, data);
|
||||
} catch (err) {
|
||||
strapi.notification.error('app.containers.App.notification.error.init');
|
||||
}
|
||||
|
||||
@ -14,13 +14,17 @@ import {
|
||||
} from './constants';
|
||||
|
||||
const initialState = fromJS({
|
||||
autoReload: false,
|
||||
blockApp: false,
|
||||
overlayBlockerData: null,
|
||||
hasUserPlugin: true,
|
||||
currentEnvironment: 'development',
|
||||
hasAdminUser: false,
|
||||
hasUserPlugin: true,
|
||||
isLoading: true,
|
||||
overlayBlockerData: null,
|
||||
plugins: {},
|
||||
showGlobalAppBlocker: true,
|
||||
strapiVersion: '3',
|
||||
uuid: false,
|
||||
});
|
||||
|
||||
function appReducer(state = initialState, action) {
|
||||
@ -37,10 +41,20 @@ function appReducer(state = initialState, action) {
|
||||
|
||||
return null;
|
||||
});
|
||||
case GET_DATA_SUCCEEDED:
|
||||
case GET_DATA_SUCCEEDED: {
|
||||
const {
|
||||
hasAdminUser,
|
||||
data: { uuid, currentEnvironment, autoReload, strapiVersion },
|
||||
} = action;
|
||||
|
||||
return state
|
||||
.update('isLoading', () => false)
|
||||
.update('hasAdminUser', () => action.hasAdminUser);
|
||||
.update('hasAdminUser', () => hasAdminUser)
|
||||
.update('uuid', () => uuid)
|
||||
.update('autoReload', () => autoReload)
|
||||
.update('currentEnvironment', () => currentEnvironment)
|
||||
.update('strapiVersion', () => strapiVersion);
|
||||
}
|
||||
case PLUGIN_LOADED:
|
||||
return state.setIn(['plugins', action.plugin.id], fromJS(action.plugin));
|
||||
case UPDATE_PLUGIN:
|
||||
|
||||
@ -45,6 +45,12 @@ const makeSelectOverlayBlockerProps = () =>
|
||||
appState => appState.get('overlayBlockerData')
|
||||
);
|
||||
|
||||
const makeSelectUuid = () =>
|
||||
createSelector(
|
||||
selectApp(),
|
||||
appState => appState.get('uuid')
|
||||
);
|
||||
|
||||
export default makeSelectApp;
|
||||
export {
|
||||
selectApp,
|
||||
@ -53,4 +59,5 @@ export {
|
||||
makeSelectBlockApp,
|
||||
makeSelectOverlayBlockerProps,
|
||||
makeSelectShowGlobalAppBlocker,
|
||||
makeSelectUuid,
|
||||
};
|
||||
|
||||
@ -16,13 +16,17 @@ describe('<App /> reducer', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
state = fromJS({
|
||||
autoReload: false,
|
||||
blockApp: false,
|
||||
overlayBlockerData: null,
|
||||
hasUserPlugin: true,
|
||||
currentEnvironment: 'development',
|
||||
hasAdminUser: false,
|
||||
hasUserPlugin: true,
|
||||
isLoading: true,
|
||||
overlayBlockerData: null,
|
||||
plugins: {},
|
||||
showGlobalAppBlocker: true,
|
||||
strapiVersion: '3',
|
||||
uuid: false,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@ import makeSelectApp, {
|
||||
makeSelectBlockApp,
|
||||
makeSelectOverlayBlockerProps,
|
||||
makeSelectShowGlobalAppBlocker,
|
||||
makeSelectUuid,
|
||||
} from '../selectors';
|
||||
|
||||
describe('<App /> selectors', () => {
|
||||
@ -96,4 +97,16 @@ describe('<App /> selectors', () => {
|
||||
expect(makeSelectShowGlobalAppBlocker()(mockedState)).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('makeSelectUuid', () => {
|
||||
it('should select the showGlobalAppBlocker', () => {
|
||||
const mockedState = fromJS({
|
||||
app: {
|
||||
uuid: 'getstarted',
|
||||
},
|
||||
});
|
||||
|
||||
expect(makeSelectUuid()(mockedState)).toEqual('getstarted');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -32,6 +32,12 @@
|
||||
"handler": "Admin.getLayout",
|
||||
"policies": []
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"path": "/init",
|
||||
"handler": "Admin.init",
|
||||
"policies": []
|
||||
},
|
||||
{
|
||||
"method": "POST",
|
||||
"path": "/plugins/install",
|
||||
|
||||
@ -8,6 +8,17 @@ const _ = require('lodash');
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
async init(ctx) {
|
||||
const uuid = _.get(strapi, ['config', 'uuid'], false);
|
||||
const currentEnvironment = strapi.app.env;
|
||||
const autoReload = _.get(strapi, ['config', 'autoReload'], false);
|
||||
const strapiVersion = _.get(strapi.config, 'info.strapi', null);
|
||||
|
||||
return ctx.send({
|
||||
data: { uuid, currentEnvironment, autoReload, strapiVersion },
|
||||
});
|
||||
},
|
||||
|
||||
async getCurrentEnvironment(ctx) {
|
||||
try {
|
||||
const autoReload = strapi.config.autoReload;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user