Cleanup frontend
parent
29a9ff70c5
commit
e981aa7920
|
@ -1,6 +1,7 @@
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import { useDispatch } from 'react-redux';
|
import { useDispatch } from 'react-redux';
|
||||||
|
import { isEmpty } from 'lodash';
|
||||||
import { Button } from '@buffetjs/core';
|
import { Button } from '@buffetjs/core';
|
||||||
import ConfirmModal from '../ConfirmModal';
|
import ConfirmModal from '../ConfirmModal';
|
||||||
import { exportAllConfig, importAllConfig } from '../../state/actions/Config';
|
import { exportAllConfig, importAllConfig } from '../../state/actions/Config';
|
||||||
|
@ -22,8 +23,8 @@ const ActionButtons = ({ diff }) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ActionButtonsStyling>
|
<ActionButtonsStyling>
|
||||||
<Button disabled={!diff} color="primary" label="Import" onClick={() => openModal('import')} />
|
<Button disabled={isEmpty(diff)} color="primary" label="Import" onClick={() => openModal('import')} />
|
||||||
<Button disabled={!diff} color="primary" label="Export" onClick={() => openModal('export')} />
|
<Button disabled={isEmpty(diff)} color="primary" label="Export" onClick={() => openModal('export')} />
|
||||||
<ConfirmModal
|
<ConfirmModal
|
||||||
isOpen={modalIsOpen}
|
isOpen={modalIsOpen}
|
||||||
onClose={closeModal}
|
onClose={closeModal}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { useState } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { Table } from '@buffetjs/core';
|
import { Table } from '@buffetjs/core';
|
||||||
import ConfigDiff from '../ConfigDiff';
|
import ConfigDiff from '../ConfigDiff';
|
||||||
|
|
||||||
|
@ -17,22 +17,26 @@ const headers = [
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const ConfigList = ({ fileConfig, databaseConfig, isLoading, diff }) => {
|
const ConfigList = ({ fileConfig, databaseConfig, diff, isLoading }) => {
|
||||||
const [openModal, setOpenModal] = useState(false);
|
const [openModal, setOpenModal] = useState(false);
|
||||||
const [originalConfig, setOriginalConfig] = useState({});
|
const [originalConfig, setOriginalConfig] = useState({});
|
||||||
const [newConfig, setNewConfig] = useState({});
|
const [newConfig, setNewConfig] = useState({});
|
||||||
const [configName, setConfigName] = useState('');
|
const [configName, setConfigName] = useState('');
|
||||||
let rows = [];
|
const [rows, setRows] = useState([]);
|
||||||
|
|
||||||
Object.keys(diff).map((config) => {
|
useEffect(() => {
|
||||||
// @TODO implement different config types, roles/permissions e.g.
|
let formattedRows = [];
|
||||||
rows.push({
|
Object.keys(diff).map((config) => {
|
||||||
config_name: config,
|
// @TODO implement different config types, roles/permissions e.g.
|
||||||
table_name: 'core_store',
|
formattedRows.push({
|
||||||
change_type: ''
|
config_name: config,
|
||||||
|
table_name: 'core_store',
|
||||||
|
change_type: ''
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
setRows(formattedRows);
|
||||||
|
}, [diff]);
|
||||||
|
|
||||||
const closeModal = () => {
|
const closeModal = () => {
|
||||||
setOriginalConfig({});
|
setOriginalConfig({});
|
||||||
setNewConfig({});
|
setNewConfig({});
|
||||||
|
@ -59,8 +63,8 @@ const ConfigList = ({ fileConfig, databaseConfig, isLoading, diff }) => {
|
||||||
setOpenModal(true);
|
setOpenModal(true);
|
||||||
}}
|
}}
|
||||||
rows={!isLoading ? rows : []}
|
rows={!isLoading ? rows : []}
|
||||||
tableEmptyText="No config changes. You are up to date!"
|
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
|
tableEmptyText="No config changes. You are up to date!"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -6,6 +6,8 @@ import {
|
||||||
import getTrad from '../../helpers/getTrad';
|
import getTrad from '../../helpers/getTrad';
|
||||||
|
|
||||||
const ConfirmModal = ({ isOpen, onClose, onSubmit, type }) => {
|
const ConfirmModal = ({ isOpen, onClose, onSubmit, type }) => {
|
||||||
|
if (!isOpen) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ModalConfirm
|
<ModalConfirm
|
||||||
confirmButtonLabel={{
|
confirmButtonLabel={{
|
||||||
|
@ -25,9 +27,7 @@ const ConfirmModal = ({ isOpen, onClose, onSubmit, type }) => {
|
||||||
br: () => <br />,
|
br: () => <br />,
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
>
|
/>
|
||||||
<div>Zeker?</div>
|
|
||||||
</ModalConfirm>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,20 @@
|
||||||
import React, { useEffect, useState } from 'react';
|
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 { getAllDatabaseConfig, getAllFileConfig } from '../../state/actions/Config';
|
import { getAllConfig } from '../../state/actions/Config';
|
||||||
import ConfigList from '../../components/ConfigList';
|
import ConfigList from '../../components/ConfigList';
|
||||||
import ActionButtons from '../../components/ActionButtons';
|
import ActionButtons from '../../components/ActionButtons';
|
||||||
import difference from '../../helpers/getObjectDiff';
|
import difference from '../../helpers/getObjectDiff';
|
||||||
|
|
||||||
const ConfigPage = () => {
|
const ConfigPage = () => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const isLoading = useSelector((state) => state.getIn(['config', 'isLoading']), Map());
|
||||||
const fileConfig = useSelector((state) => state.getIn(['config', 'fileConfig']), Map());
|
const fileConfig = useSelector((state) => state.getIn(['config', 'fileConfig']), Map());
|
||||||
const databaseConfig = useSelector((state) => state.getIn(['config', 'databaseConfig']), Map());
|
const databaseConfig = useSelector((state) => state.getIn(['config', 'databaseConfig']), Map());
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(getAllDatabaseConfig());
|
dispatch(getAllConfig());
|
||||||
dispatch(getAllFileConfig());
|
|
||||||
setIsLoading(false);
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const diff = difference(fileConfig.toJS(), databaseConfig.toJS());
|
const diff = difference(fileConfig.toJS(), databaseConfig.toJS());
|
||||||
|
|
|
@ -7,30 +7,18 @@
|
||||||
import { request } from 'strapi-helper-plugin';
|
import { request } from 'strapi-helper-plugin';
|
||||||
import { Map } from 'immutable';
|
import { Map } from 'immutable';
|
||||||
|
|
||||||
export function getAllDatabaseConfig() {
|
export function getAllConfig() {
|
||||||
return async function(dispatch) {
|
return async function(dispatch) {
|
||||||
|
dispatch(setLoadingState(true));
|
||||||
try {
|
try {
|
||||||
const data = await request('/config/all/from-database', { method: 'GET' });
|
const databaseConfig = await request('/config/all/from-database', { method: 'GET' });
|
||||||
dispatch(setDatabaseConfigInState(data));
|
const fileConfig = await request('/config/all/from-files', { method: 'GET' });
|
||||||
|
dispatch(setFileConfigInState(fileConfig));
|
||||||
strapi.notification.success('woop!');
|
dispatch(setDatabaseConfigInState(databaseConfig));
|
||||||
|
dispatch(setLoadingState(false));
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.log(err);
|
|
||||||
strapi.notification.error('notification.error');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getAllFileConfig() {
|
|
||||||
return async function(dispatch) {
|
|
||||||
try {
|
|
||||||
const data = await request('/config/all/from-files', { method: 'GET' });
|
|
||||||
dispatch(setFileConfigInState(data));
|
|
||||||
|
|
||||||
strapi.notification.success('woop!');
|
|
||||||
} catch(err) {
|
|
||||||
console.log(err);
|
|
||||||
strapi.notification.error('notification.error');
|
strapi.notification.error('notification.error');
|
||||||
|
dispatch(setLoadingState(false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,30 +41,42 @@ export function setFileConfigInState(config) {
|
||||||
|
|
||||||
export function exportAllConfig() {
|
export function exportAllConfig() {
|
||||||
return async function(dispatch) {
|
return async function(dispatch) {
|
||||||
|
dispatch(setLoadingState(true));
|
||||||
try {
|
try {
|
||||||
const { message } = await request('/config/export', { method: 'GET' });
|
const { message } = await request('/config/export', { method: 'GET' });
|
||||||
dispatch(getAllFileConfig());
|
dispatch(setFileConfigInState(Map({})));
|
||||||
dispatch(getAllDatabaseConfig());
|
dispatch(setDatabaseConfigInState(Map({})));
|
||||||
|
|
||||||
strapi.notification.success(message);
|
strapi.notification.success(message);
|
||||||
|
dispatch(setLoadingState(false));
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.log(err);
|
|
||||||
strapi.notification.error('notification.error');
|
strapi.notification.error('notification.error');
|
||||||
|
dispatch(setLoadingState(false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function importAllConfig() {
|
export function importAllConfig() {
|
||||||
return async function(dispatch) {
|
return async function(dispatch) {
|
||||||
|
dispatch(setLoadingState(true));
|
||||||
try {
|
try {
|
||||||
const { message } = await request('/config/import', { method: 'GET' });
|
const { message } = await request('/config/import', { method: 'GET' });
|
||||||
dispatch(getAllFileConfig());
|
dispatch(setFileConfigInState(Map({})));
|
||||||
dispatch(getAllDatabaseConfig());
|
dispatch(setDatabaseConfigInState(Map({})));
|
||||||
|
|
||||||
strapi.notification.success(message);
|
strapi.notification.success(message);
|
||||||
|
dispatch(setLoadingState(false));
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.log(err);
|
|
||||||
strapi.notification.error('notification.error');
|
strapi.notification.error('notification.error');
|
||||||
|
dispatch(setLoadingState(false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const SET_LOADING_STATE = 'SET_LOADING_STATE';
|
||||||
|
export function setLoadingState(value) {
|
||||||
|
return {
|
||||||
|
type: SET_LOADING_STATE,
|
||||||
|
value,
|
||||||
|
};
|
||||||
}
|
}
|
|
@ -5,11 +5,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { fromJS, Map } from 'immutable';
|
import { fromJS, Map } from 'immutable';
|
||||||
import { SET_DATABASE_CONFIG_IN_STATE, SET_FILE_CONFIG_IN_STATE } from '../../actions/Config';
|
import { SET_DATABASE_CONFIG_IN_STATE, SET_FILE_CONFIG_IN_STATE, SET_LOADING_STATE } from '../../actions/Config';
|
||||||
|
|
||||||
const initialState = fromJS({
|
const initialState = fromJS({
|
||||||
databaseConfig: Map({}),
|
databaseConfig: Map({}),
|
||||||
fileConfig: Map({})
|
fileConfig: Map({}),
|
||||||
|
isLoading: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default function configReducer(state = initialState, action) {
|
export default function configReducer(state = initialState, action) {
|
||||||
|
@ -20,6 +21,9 @@ export default function configReducer(state = initialState, action) {
|
||||||
case SET_FILE_CONFIG_IN_STATE:
|
case SET_FILE_CONFIG_IN_STATE:
|
||||||
return state
|
return state
|
||||||
.update('fileConfig', () => fromJS(action.config))
|
.update('fileConfig', () => fromJS(action.config))
|
||||||
|
case SET_LOADING_STATE:
|
||||||
|
return state
|
||||||
|
.update('isLoading', () => fromJS(action.value))
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
"popUpWarning.button.export": "Yes, export",
|
"popUpWarning.button.export": "Yes, export",
|
||||||
|
|
||||||
"Header.Title": "Config Sync",
|
"Header.Title": "Config Sync",
|
||||||
"Header.Description": "Manage your database config acros environments.",
|
"Header.Description": "Manage your database config across environments.",
|
||||||
|
|
||||||
"plugin.name": "Config Sync"
|
"plugin.name": "Config Sync"
|
||||||
}
|
}
|
Loading…
Reference in New Issue