2021-03-20 14:42:15 +01:00
|
|
|
import React, { useState } from 'react';
|
|
|
|
import { Table } from '@buffetjs/core';
|
|
|
|
import ConfigDiff from '../ConfigDiff';
|
|
|
|
|
|
|
|
const headers = [
|
|
|
|
{
|
|
|
|
name: 'Config name',
|
2021-03-20 16:51:34 +01:00
|
|
|
value: 'config_name',
|
2021-03-20 14:42:15 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Database table',
|
2021-03-20 16:51:34 +01:00
|
|
|
value: 'table_name',
|
2021-03-20 14:42:15 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Change',
|
|
|
|
value: 'change_type',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2021-03-20 16:51:34 +01:00
|
|
|
const ConfigList = ({ fileConfig, databaseConfig, isLoading, diff }) => {
|
2021-03-20 14:42:15 +01:00
|
|
|
const [openModal, setOpenModal] = useState(false);
|
|
|
|
const [originalConfig, setOriginalConfig] = useState({});
|
|
|
|
const [newConfig, setNewConfig] = useState({});
|
|
|
|
const [configName, setConfigName] = useState('');
|
|
|
|
let rows = [];
|
|
|
|
|
2021-03-20 16:51:34 +01:00
|
|
|
Object.keys(diff).map((config) => {
|
|
|
|
// @TODO implement different config types, roles/permissions e.g.
|
|
|
|
rows.push({
|
|
|
|
config_name: config,
|
|
|
|
table_name: 'core_store',
|
|
|
|
change_type: ''
|
|
|
|
});
|
|
|
|
});
|
2021-03-20 14:42:15 +01:00
|
|
|
|
|
|
|
const closeModal = () => {
|
|
|
|
setOriginalConfig({});
|
|
|
|
setNewConfig({});
|
|
|
|
setConfigName('');
|
|
|
|
setOpenModal(false);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<ConfigDiff
|
|
|
|
isOpen={openModal}
|
|
|
|
oldValue={originalConfig}
|
|
|
|
newValue={newConfig}
|
|
|
|
onClose={closeModal}
|
|
|
|
onToggle={closeModal}
|
|
|
|
configName={configName}
|
|
|
|
/>
|
2021-03-20 16:51:34 +01:00
|
|
|
<Table
|
2021-03-20 14:42:15 +01:00
|
|
|
headers={headers}
|
|
|
|
onClickRow={(e, data) => {
|
2021-03-20 16:51:34 +01:00
|
|
|
setOriginalConfig(fileConfig.get(data.config_name));
|
|
|
|
setNewConfig(databaseConfig.get(data.config_name));
|
|
|
|
setConfigName(data.config_name);
|
2021-03-20 14:42:15 +01:00
|
|
|
setOpenModal(true);
|
|
|
|
}}
|
2021-03-20 16:51:34 +01:00
|
|
|
rows={!isLoading ? rows : []}
|
|
|
|
tableEmptyText="No config changes. You are up to date!"
|
|
|
|
isLoading={isLoading}
|
2021-03-20 14:42:15 +01:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ConfigList;
|