From 792a58722d474b41809dd33857da379b625fd703 Mon Sep 17 00:00:00 2001 From: Boaz Poolman Date: Sat, 20 Nov 2021 19:51:03 +0100 Subject: [PATCH] fix: Bugs in admin --- admin/src/components/ActionButtons/index.js | 4 +++- admin/src/components/ConfigList/index.js | 4 +++- admin/src/containers/App/index.js | 8 +++----- admin/src/containers/ConfigPage/index.js | 4 +++- admin/src/helpers/configureStore.js | 6 ++++-- admin/src/state/actions/Config.js | 16 +++++++++------- 6 files changed, 25 insertions(+), 17 deletions(-) diff --git a/admin/src/components/ActionButtons/index.js b/admin/src/components/ActionButtons/index.js index f88f286..b9a0cac 100644 --- a/admin/src/components/ActionButtons/index.js +++ b/admin/src/components/ActionButtons/index.js @@ -4,12 +4,14 @@ import { useDispatch, useSelector } from 'react-redux'; import { isEmpty } from 'lodash'; import { Button } from '@strapi/design-system/Button'; import { Map } from 'immutable'; +import { useNotification } from '@strapi/helper-plugin'; import ConfirmModal from '../ConfirmModal'; import { exportAllConfig, importAllConfig } from '../../state/actions/Config'; const ActionButtons = () => { const dispatch = useDispatch(); + const toggleNotification = useNotification(); const [modalIsOpen, setModalIsOpen] = useState(false); const [actionType, setActionType] = useState(''); const partialDiff = useSelector((state) => state.getIn(['config', 'partialDiff'], Map({}))).toJS(); @@ -35,7 +37,7 @@ const ActionButtons = () => { isOpen={modalIsOpen} onClose={closeModal} type={actionType} - onSubmit={() => actionType === 'import' ? dispatch(importAllConfig(partialDiff)) : dispatch(exportAllConfig(partialDiff))} + onSubmit={() => actionType === 'import' ? dispatch(importAllConfig(partialDiff, toggleNotification)) : dispatch(exportAllConfig(partialDiff, toggleNotification))} /> ); diff --git a/admin/src/components/ConfigList/index.js b/admin/src/components/ConfigList/index.js index 29d9b6a..2569787 100644 --- a/admin/src/components/ConfigList/index.js +++ b/admin/src/components/ConfigList/index.js @@ -47,11 +47,12 @@ const ConfigList = ({ diff, isLoading }) => { } const formattedRows = []; + const newCheckedItems = []; Object.keys(diff.diff).map((name) => { 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. - setCheckedItems(checkedItems.concat(true)); + newCheckedItems.push(true); formattedRows.push({ configName: formattedName, @@ -65,6 +66,7 @@ const ConfigList = ({ diff, isLoading }) => { }, }); }); + setCheckedItems(newCheckedItems); setRows(formattedRows); }, [diff]); diff --git a/admin/src/containers/App/index.js b/admin/src/containers/App/index.js index a8c2fba..26778c7 100644 --- a/admin/src/containers/App/index.js +++ b/admin/src/containers/App/index.js @@ -7,19 +7,17 @@ import React from 'react'; import { Provider } from 'react-redux'; -import { CheckPagePermissions, useNotification } from '@strapi/helper-plugin'; +import { CheckPagePermissions } from '@strapi/helper-plugin'; import pluginPermissions from '../../permissions'; import Header from '../../components/Header'; -import store from "../../helpers/configureStore"; +import { store } from "../../helpers/configureStore"; import ConfigPage from '../ConfigPage'; const App = () => { - const toggleNotification = useNotification(); - return ( - +
diff --git a/admin/src/containers/ConfigPage/index.js b/admin/src/containers/ConfigPage/index.js index 4092b98..e019624 100644 --- a/admin/src/containers/ConfigPage/index.js +++ b/admin/src/containers/ConfigPage/index.js @@ -2,18 +2,20 @@ import React, { useEffect } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { Map } from 'immutable'; import { Box } from '@strapi/design-system/Box'; +import { useNotification } from '@strapi/helper-plugin'; import { getAllConfigDiff } from '../../state/actions/Config'; import ConfigList from '../../components/ConfigList'; import ActionButtons from '../../components/ActionButtons'; const ConfigPage = () => { + const toggleNotification = useNotification(); const dispatch = useDispatch(); const isLoading = useSelector((state) => state.getIn(['config', 'isLoading'], Map({}))); const configDiff = useSelector((state) => state.getIn(['config', 'configDiff'], Map({}))); useEffect(() => { - dispatch(getAllConfigDiff()); + dispatch(getAllConfigDiff(toggleNotification)); }, []); return ( diff --git a/admin/src/helpers/configureStore.js b/admin/src/helpers/configureStore.js index 371f547..7c250cf 100755 --- a/admin/src/helpers/configureStore.js +++ b/admin/src/helpers/configureStore.js @@ -5,12 +5,12 @@ import { Map } from 'immutable'; import rootReducer from '../state/reducers'; import { __DEBUG__ } from '../config/constants'; -const configureStore = (toggleNotification) => { +const configureStore = () => { const initialStoreState = Map(); const enhancers = []; const middlewares = [ - thunkMiddleware.withExtraArgument(toggleNotification), + thunkMiddleware, ]; let devtools; @@ -43,3 +43,5 @@ const configureStore = (toggleNotification) => { }; export default configureStore; + +export const store = configureStore(); diff --git a/admin/src/state/actions/Config.js b/admin/src/state/actions/Config.js index e080fed..d27b16a 100644 --- a/admin/src/state/actions/Config.js +++ b/admin/src/state/actions/Config.js @@ -5,13 +5,13 @@ */ import { request } from '@strapi/helper-plugin'; -import { Map } from 'immutable'; -export function getAllConfigDiff() { - return async function(dispatch, getState, toggleNotification) { +export function getAllConfigDiff(toggleNotification) { + return async function(dispatch) { dispatch(setLoadingState(true)); try { const configDiff = await request('/config-sync/diff', { method: 'GET' }); + dispatch(setConfigPartialDiffInState([])); dispatch(setConfigDiffInState(configDiff)); dispatch(setLoadingState(false)); } catch (err) { @@ -37,8 +37,8 @@ export function setConfigPartialDiffInState(config) { }; } -export function exportAllConfig(partialDiff) { - return async function(dispatch, getState, toggleNotification) { +export function exportAllConfig(partialDiff, toggleNotification) { + return async function(dispatch) { dispatch(setLoadingState(true)); try { const { message } = await request('/config-sync/export', { @@ -46,6 +46,7 @@ export function exportAllConfig(partialDiff) { body: partialDiff, }); toggleNotification({ type: 'success', message }); + dispatch(getAllConfigDiff(toggleNotification)); dispatch(setLoadingState(false)); } catch (err) { toggleNotification({ type: 'warning', message: { id: 'notification.error' } }); @@ -54,8 +55,8 @@ export function exportAllConfig(partialDiff) { }; } -export function importAllConfig(partialDiff) { - return async function(dispatch, getState, toggleNotification) { +export function importAllConfig(partialDiff, toggleNotification) { + return async function(dispatch) { dispatch(setLoadingState(true)); try { const { message } = await request('/config-sync/import', { @@ -63,6 +64,7 @@ export function importAllConfig(partialDiff) { body: partialDiff, }); toggleNotification({ type: 'success', message }); + dispatch(getAllConfigDiff(toggleNotification)); dispatch(setLoadingState(false)); } catch (err) { toggleNotification({ type: 'warning', message: { id: 'notification.error' } });