fix: Bugs in admin

pull/28/head
Boaz Poolman 2021-11-20 19:51:03 +01:00
parent 17c68c2c36
commit 792a58722d
6 changed files with 25 additions and 17 deletions

View File

@ -4,12 +4,14 @@ import { useDispatch, useSelector } from 'react-redux';
import { isEmpty } from 'lodash'; import { isEmpty } from 'lodash';
import { Button } from '@strapi/design-system/Button'; import { Button } from '@strapi/design-system/Button';
import { Map } from 'immutable'; import { Map } from 'immutable';
import { useNotification } from '@strapi/helper-plugin';
import ConfirmModal from '../ConfirmModal'; import ConfirmModal from '../ConfirmModal';
import { exportAllConfig, importAllConfig } from '../../state/actions/Config'; import { exportAllConfig, importAllConfig } from '../../state/actions/Config';
const ActionButtons = () => { const ActionButtons = () => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const toggleNotification = useNotification();
const [modalIsOpen, setModalIsOpen] = useState(false); const [modalIsOpen, setModalIsOpen] = useState(false);
const [actionType, setActionType] = useState(''); const [actionType, setActionType] = useState('');
const partialDiff = useSelector((state) => state.getIn(['config', 'partialDiff'], Map({}))).toJS(); const partialDiff = useSelector((state) => state.getIn(['config', 'partialDiff'], Map({}))).toJS();
@ -35,7 +37,7 @@ const ActionButtons = () => {
isOpen={modalIsOpen} isOpen={modalIsOpen}
onClose={closeModal} onClose={closeModal}
type={actionType} type={actionType}
onSubmit={() => actionType === 'import' ? dispatch(importAllConfig(partialDiff)) : dispatch(exportAllConfig(partialDiff))} onSubmit={() => actionType === 'import' ? dispatch(importAllConfig(partialDiff, toggleNotification)) : dispatch(exportAllConfig(partialDiff, toggleNotification))}
/> />
</ActionButtonsStyling> </ActionButtonsStyling>
); );

View File

@ -47,11 +47,12 @@ const ConfigList = ({ diff, isLoading }) => {
} }
const formattedRows = []; const formattedRows = [];
const newCheckedItems = [];
Object.keys(diff.diff).map((name) => { Object.keys(diff.diff).map((name) => {
const type = name.split('.')[0]; // Grab the first part of the filename. const type = name.split('.')[0]; // Grab the first part of the filename.
const formattedName = name.split(/\.(.+)/)[1]; // Grab the rest of the filename minus the file extension. const formattedName = name.split(/\.(.+)/)[1]; // Grab the rest of the filename minus the file extension.
setCheckedItems(checkedItems.concat(true)); newCheckedItems.push(true);
formattedRows.push({ formattedRows.push({
configName: formattedName, configName: formattedName,
@ -65,6 +66,7 @@ const ConfigList = ({ diff, isLoading }) => {
}, },
}); });
}); });
setCheckedItems(newCheckedItems);
setRows(formattedRows); setRows(formattedRows);
}, [diff]); }, [diff]);

View File

@ -7,19 +7,17 @@
import React from 'react'; import React from 'react';
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
import { CheckPagePermissions, useNotification } from '@strapi/helper-plugin'; import { CheckPagePermissions } from '@strapi/helper-plugin';
import pluginPermissions from '../../permissions'; import pluginPermissions from '../../permissions';
import Header from '../../components/Header'; import Header from '../../components/Header';
import store from "../../helpers/configureStore"; import { store } from "../../helpers/configureStore";
import ConfigPage from '../ConfigPage'; import ConfigPage from '../ConfigPage';
const App = () => { const App = () => {
const toggleNotification = useNotification();
return ( return (
<CheckPagePermissions permissions={pluginPermissions.settings}> <CheckPagePermissions permissions={pluginPermissions.settings}>
<Provider store={store(toggleNotification)}> <Provider store={store}>
<Header /> <Header />
<ConfigPage /> <ConfigPage />
</Provider> </Provider>

View File

@ -2,18 +2,20 @@ import React, { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux'; import { useDispatch, useSelector } from 'react-redux';
import { Map } from 'immutable'; import { Map } from 'immutable';
import { Box } from '@strapi/design-system/Box'; import { Box } from '@strapi/design-system/Box';
import { useNotification } from '@strapi/helper-plugin';
import { getAllConfigDiff } from '../../state/actions/Config'; import { getAllConfigDiff } from '../../state/actions/Config';
import ConfigList from '../../components/ConfigList'; import ConfigList from '../../components/ConfigList';
import ActionButtons from '../../components/ActionButtons'; import ActionButtons from '../../components/ActionButtons';
const ConfigPage = () => { const ConfigPage = () => {
const toggleNotification = useNotification();
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({})));
useEffect(() => { useEffect(() => {
dispatch(getAllConfigDiff()); dispatch(getAllConfigDiff(toggleNotification));
}, []); }, []);
return ( return (

View File

@ -5,12 +5,12 @@ import { Map } from 'immutable';
import rootReducer from '../state/reducers'; import rootReducer from '../state/reducers';
import { __DEBUG__ } from '../config/constants'; import { __DEBUG__ } from '../config/constants';
const configureStore = (toggleNotification) => { const configureStore = () => {
const initialStoreState = Map(); const initialStoreState = Map();
const enhancers = []; const enhancers = [];
const middlewares = [ const middlewares = [
thunkMiddleware.withExtraArgument(toggleNotification), thunkMiddleware,
]; ];
let devtools; let devtools;
@ -43,3 +43,5 @@ const configureStore = (toggleNotification) => {
}; };
export default configureStore; export default configureStore;
export const store = configureStore();

View File

@ -5,13 +5,13 @@
*/ */
import { request } from '@strapi/helper-plugin'; import { request } from '@strapi/helper-plugin';
import { Map } from 'immutable';
export function getAllConfigDiff() { export function getAllConfigDiff(toggleNotification) {
return async function(dispatch, getState, toggleNotification) { return async function(dispatch) {
dispatch(setLoadingState(true)); dispatch(setLoadingState(true));
try { try {
const configDiff = await request('/config-sync/diff', { method: 'GET' }); const configDiff = await request('/config-sync/diff', { method: 'GET' });
dispatch(setConfigPartialDiffInState([]));
dispatch(setConfigDiffInState(configDiff)); dispatch(setConfigDiffInState(configDiff));
dispatch(setLoadingState(false)); dispatch(setLoadingState(false));
} catch (err) { } catch (err) {
@ -37,8 +37,8 @@ export function setConfigPartialDiffInState(config) {
}; };
} }
export function exportAllConfig(partialDiff) { export function exportAllConfig(partialDiff, toggleNotification) {
return async function(dispatch, getState, toggleNotification) { return async function(dispatch) {
dispatch(setLoadingState(true)); dispatch(setLoadingState(true));
try { try {
const { message } = await request('/config-sync/export', { const { message } = await request('/config-sync/export', {
@ -46,6 +46,7 @@ export function exportAllConfig(partialDiff) {
body: partialDiff, body: partialDiff,
}); });
toggleNotification({ type: 'success', message }); toggleNotification({ type: 'success', message });
dispatch(getAllConfigDiff(toggleNotification));
dispatch(setLoadingState(false)); dispatch(setLoadingState(false));
} catch (err) { } catch (err) {
toggleNotification({ type: 'warning', message: { id: 'notification.error' } }); toggleNotification({ type: 'warning', message: { id: 'notification.error' } });
@ -54,8 +55,8 @@ export function exportAllConfig(partialDiff) {
}; };
} }
export function importAllConfig(partialDiff) { export function importAllConfig(partialDiff, toggleNotification) {
return async function(dispatch, getState, toggleNotification) { return async function(dispatch) {
dispatch(setLoadingState(true)); dispatch(setLoadingState(true));
try { try {
const { message } = await request('/config-sync/import', { const { message } = await request('/config-sync/import', {
@ -63,6 +64,7 @@ export function importAllConfig(partialDiff) {
body: partialDiff, body: partialDiff,
}); });
toggleNotification({ type: 'success', message }); toggleNotification({ type: 'success', message });
dispatch(getAllConfigDiff(toggleNotification));
dispatch(setLoadingState(false)); dispatch(setLoadingState(false));
} catch (err) { } catch (err) {
toggleNotification({ type: 'warning', message: { id: 'notification.error' } }); toggleNotification({ type: 'warning', message: { id: 'notification.error' } });