fix: Production warning in admin

pull/31/head
Boaz Poolman 2021-12-08 16:05:45 +01:00
parent 7b9b664cdf
commit 14eddc5459
9 changed files with 53 additions and 7 deletions

View File

@ -6,7 +6,7 @@ import { useNotification } from '@strapi/helper-plugin';
import { Alert } from '@strapi/design-system/Alert'; import { Alert } from '@strapi/design-system/Alert';
import { Typography } from '@strapi/design-system/Typography'; import { Typography } from '@strapi/design-system/Typography';
import { getAllConfigDiff } from '../../state/actions/Config'; import { getAllConfigDiff, getAppEnv } from '../../state/actions/Config';
import ConfigList from '../../components/ConfigList'; import ConfigList from '../../components/ConfigList';
import ActionButtons from '../../components/ActionButtons'; import ActionButtons from '../../components/ActionButtons';
@ -15,14 +15,16 @@ const ConfigPage = () => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const isLoading = useSelector((state) => state.getIn(['config', 'isLoading'], Map({}))); const isLoading = useSelector((state) => state.getIn(['config', 'isLoading'], Map({})));
const configDiff = useSelector((state) => state.getIn(['config', 'configDiff'], Map({}))); const configDiff = useSelector((state) => state.getIn(['config', 'configDiff'], Map({})));
const appEnv = useSelector((state) => state.getIn(['config', 'appEnv']));
useEffect(() => { useEffect(() => {
dispatch(getAllConfigDiff(toggleNotification)); dispatch(getAllConfigDiff(toggleNotification));
dispatch(getAppEnv(toggleNotification));
}, []); }, []);
return ( return (
<Box paddingLeft={8} paddingRight={8} paddingBottom={8}> <Box paddingLeft={8} paddingRight={8} paddingBottom={8}>
{process.env.NODE_ENV === 'production' && ( {appEnv === 'production' && (
<Box paddingBottom={4}> <Box paddingBottom={4}>
<Alert variant="danger"> <Alert variant="danger">
<Typography variant="omega" fontWeight="bold">You&apos;re in the production environment</Typography><br /> <Typography variant="omega" fontWeight="bold">You&apos;re in the production environment</Typography><br />

View File

@ -30,7 +30,7 @@ const configureStore = () => {
const composedEnhancers = devtools || compose; const composedEnhancers = devtools || compose;
const storeEnhancers = composedEnhancers( const storeEnhancers = composedEnhancers(
applyMiddleware(...middlewares), applyMiddleware(...middlewares),
...enhancers ...enhancers,
); );
const store = createStore( const store = createStore(

View File

@ -2,7 +2,7 @@ const pluginPkg = require('../../../package.json');
const pluginId = pluginPkg.name.replace( const pluginId = pluginPkg.name.replace(
/^strapi-plugin-/i, /^strapi-plugin-/i,
'' '',
); );
module.exports = pluginId; module.exports = pluginId;

View File

@ -54,7 +54,7 @@ export default {
locale, locale,
}; };
}); });
}) }),
); );
return Promise.resolve(importedTrads); return Promise.resolve(importedTrads);

View File

@ -80,3 +80,24 @@ export function setLoadingState(value) {
value, value,
}; };
} }
export function getAppEnv(toggleNotification) {
return async function(dispatch) {
try {
const env = await request('/config-sync/app-env', {
method: 'GET',
});
dispatch(setAppEnvInState(env));
} catch (err) {
toggleNotification({ type: 'warning', message: { id: 'notification.error' } });
}
};
}
export const SET_APP_ENV_IN_STATE = 'SET_APP_ENV_IN_STATE';
export function setAppEnvInState(value) {
return {
type: SET_APP_ENV_IN_STATE,
value,
};
}

View File

@ -5,12 +5,18 @@
*/ */
import { fromJS, Map, List } from 'immutable'; import { fromJS, Map, List } from 'immutable';
import { SET_CONFIG_DIFF_IN_STATE, SET_CONFIG_PARTIAL_DIFF_IN_STATE, SET_LOADING_STATE } from '../../actions/Config'; import {
SET_CONFIG_DIFF_IN_STATE,
SET_CONFIG_PARTIAL_DIFF_IN_STATE,
SET_LOADING_STATE,
SET_APP_ENV_IN_STATE,
} from '../../actions/Config';
const initialState = fromJS({ const initialState = fromJS({
configDiff: Map({}), configDiff: Map({}),
partialDiff: List([]), partialDiff: List([]),
isLoading: false, isLoading: false,
appEnv: 'development',
}); });
export default function configReducer(state = initialState, action) { export default function configReducer(state = initialState, action) {
@ -24,6 +30,9 @@ export default function configReducer(state = initialState, action) {
case SET_LOADING_STATE: case SET_LOADING_STATE:
return state return state
.update('isLoading', () => fromJS(action.value)); .update('isLoading', () => fromJS(action.value));
case SET_APP_ENV_IN_STATE:
return state
.update('appEnv', () => fromJS(action.value));
default: default:
return state; return state;
} }

View File

@ -83,4 +83,10 @@ module.exports = {
return strapi.plugin('config-sync').service('main').getFormattedDiff(); return strapi.plugin('config-sync').service('main').getFormattedDiff();
}, },
/**
* Get the current Strapi env.
* @returns {string} The current Strapi environment.
*/
getAppEnv: async () => strapi.server.app.env,
}; };

View File

@ -27,5 +27,13 @@ module.exports = {
policies: [], policies: [],
}, },
}, },
{
method: "GET",
path: "/app-env",
handler: "config.getAppEnv",
config: {
policies: [],
},
},
], ],
}; };

View File

@ -15,7 +15,7 @@ const sortByKeys = (unordered) => {
obj[key] = unordered[key]; obj[key] = unordered[key];
return obj; return obj;
}, },
{} {},
); );
}; };