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 { 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))}
/>
</ActionButtonsStyling>
);

View File

@ -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]);

View File

@ -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 (
<CheckPagePermissions permissions={pluginPermissions.settings}>
<Provider store={store(toggleNotification)}>
<Provider store={store}>
<Header />
<ConfigPage />
</Provider>

View File

@ -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 (

View File

@ -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();

View File

@ -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' } });