From 4590c8fd6e80770b000eb41a7d6ffe22f27d3593 Mon Sep 17 00:00:00 2001 From: Boaz Poolman Date: Sat, 27 Mar 2021 16:16:14 +0100 Subject: [PATCH] Show config state in admin page --- .../ConfigList/ConfigListRow/index.js | 52 +++++++++++++++++++ admin/src/components/ConfigList/index.js | 39 ++++++++++---- 2 files changed, 82 insertions(+), 9 deletions(-) create mode 100644 admin/src/components/ConfigList/ConfigListRow/index.js diff --git a/admin/src/components/ConfigList/ConfigListRow/index.js b/admin/src/components/ConfigList/ConfigListRow/index.js new file mode 100644 index 0000000..d1863d3 --- /dev/null +++ b/admin/src/components/ConfigList/ConfigListRow/index.js @@ -0,0 +1,52 @@ +import React from 'react'; +import styled from 'styled-components'; + +const CustomRow = ({ row }) => { + const { config_name, config_type, state, onClick } = row; + + + return ( + onClick(config_type, config_name)}> + +

{config_name}

+ + +

{config_type}

+ + +

{state}

+ + + ); +}; + +const stateStyle = (state) => { + let style = { + display: 'inline-flex', + padding: '0 10px', + borderRadius: '12px', + height: '24px', + alignItems: 'center', + fontWeight: '500', + }; + + if (state === 'Only in DB') { + style.backgroundColor = '#cbf2d7'; + style.color = '#1b522b'; + } + + if (state === 'Only in sync dir') { + style.backgroundColor = '#f0cac7'; + style.color = '#3d302f'; + } + + if (state === 'Different') { + style.backgroundColor = '#e8e6b7'; + style.color = '#4a4934'; + } + + return style; +}; + + +export default CustomRow \ No newline at end of file diff --git a/admin/src/components/ConfigList/index.js b/admin/src/components/ConfigList/index.js index 12bb344..ba185a7 100644 --- a/admin/src/components/ConfigList/index.js +++ b/admin/src/components/ConfigList/index.js @@ -3,6 +3,7 @@ import { Table } from '@buffetjs/core'; import { isEmpty } from 'lodash'; import ConfigDiff from '../ConfigDiff'; import FirstExport from '../FirstExport'; +import ConfigListRow from './ConfigListRow'; const headers = [ { @@ -14,8 +15,8 @@ const headers = [ value: 'config_type', }, { - name: 'Change', - value: 'change_type', + name: 'State', + value: 'state', }, ]; @@ -26,6 +27,25 @@ const ConfigList = ({ diff, isLoading }) => { const [configName, setConfigName] = useState(''); const [rows, setRows] = useState([]); + const getConfigState = (configName) => { + if ( + diff.fileConfig[configName] && + diff.databaseConfig[configName] + ) { + return 'Different' + } else if ( + diff.fileConfig[configName] && + !diff.databaseConfig[configName] + ) { + return 'Only in sync dir' + } else if ( + !diff.fileConfig[configName] && + diff.databaseConfig[configName] + ) { + return 'Only in DB' + } + }; + useEffect(() => { if (isEmpty(diff.diff)) { setRows([]); @@ -40,7 +60,13 @@ const ConfigList = ({ diff, isLoading }) => { formattedRows.push({ config_name: name, config_type: type, - change_type: '' + state: getConfigState(configName), + onClick: (config_type, config_name) => { + setOriginalConfig(diff.fileConfig[`${config_type}.${config_name}`]); + setNewConfig(diff.databaseConfig[`${config_type}.${config_name}`]); + setConfigName(`${config_type}.${config_name}`); + setOpenModal(true); + } }); }); @@ -70,12 +96,7 @@ const ConfigList = ({ diff, isLoading }) => { /> { - setOriginalConfig(diff.fileConfig[`${config_type}.${config_name}`]); - setNewConfig(diff.databaseConfig[`${config_type}.${config_name}`]); - setConfigName(`${config_type}.${config_name}`); - setOpenModal(true); - }} + customRow={ConfigListRow} rows={!isLoading ? rows : []} isLoading={isLoading} tableEmptyText="No config changes. You are up to date!"