refactor(v4): Get config diff in admin

pull/25/head
Boaz Poolman 2021-10-14 17:33:21 +02:00
parent 41a9bfdf6c
commit d5b8b0b719
6 changed files with 29 additions and 18 deletions

View File

@ -24,8 +24,8 @@ const ActionButtons = ({ diff }) => {
return (
<ActionButtonsStyling>
<Button disabled={isEmpty(diff.diff)} label="Import" onClick={() => openModal('import')} />
<Button disabled={isEmpty(diff.diff)} label="Export" onClick={() => openModal('export')} />
<Button disabled={isEmpty(diff.diff)} onClick={() => openModal('import')}>Import</Button>
<Button disabled={isEmpty(diff.diff)} onClick={() => openModal('export')}>Export</Button>
{!isEmpty(diff.diff) && (
<h4 style={{ display: 'inline' }}>{Object.keys(diff.diff).length} {Object.keys(diff.diff).length === 1 ? "config change" : "config changes"}</h4>
)}
@ -33,7 +33,7 @@ const ActionButtons = ({ diff }) => {
isOpen={modalIsOpen}
onClose={closeModal}
type={actionType}
onSubmit={actionType === 'import' ? dispatch(importAllConfig()) : dispatch(exportAllConfig())}
onSubmit={() => actionType === 'import' ? dispatch(importAllConfig()) : dispatch(exportAllConfig())}
/>
</ActionButtonsStyling>
);

View File

@ -102,7 +102,7 @@ const ConfigList = ({ diff, isLoading }) => {
</Thead>
<Tbody>
{rows.map((row) => (
<ConfigListRow key={row.name} {...row} />
<ConfigListRow key={row.name} row={row} />
))}
</Tbody>
</Table>

View File

@ -0,0 +1,8 @@
const config = {
blacklist: [
'REDUX_STORAGE_SAVE',
'REDUX_STORAGE_LOAD',
],
};
export default config;

View File

@ -1,6 +1,7 @@
'use strict';
const fs = require('fs');
const types = require('./types');
/**
* An asynchronous bootstrap function that runs before
@ -13,6 +14,8 @@ const fs = require('fs');
*/
module.exports = async () => {
// console.log(await types['core-store'].exportAll());
if (strapi.plugins['config-sync'].config.importOnBootstrap) {
if (fs.existsSync(strapi.plugins['config-sync'].config.destination)) {
await strapi.plugins['config-sync'].services.main.importAllConfig();

View File

@ -15,10 +15,10 @@ module.exports = {
* @returns {void}
*/
exportAll: async (ctx) => {
await strapi.plugins['config-sync'].services.main.exportAllConfig();
await strapi.plugin('config-sync').service('main').exportAllConfig();
ctx.send({
message: `Config was successfully exported to ${strapi.plugins['config-sync'].config.destination}.`,
message: `Config was successfully exported to ${strapi.config.get('plugin.config-sync.destination')}.`,
});
},
@ -30,7 +30,7 @@ module.exports = {
*/
importAll: async (ctx) => {
// Check for existance of the config file destination dir.
if (!fs.existsSync(strapi.plugins['config-sync'].config.destination)) {
if (!fs.existsSync(strapi.config.get('plugin.config-sync.destination'))) {
ctx.send({
message: 'No config files were found.',
});
@ -38,7 +38,7 @@ module.exports = {
return;
}
await strapi.plugins['config-sync'].services.main.importAllConfig();
await strapi.plugin('config-sync').service('main').importAllConfig();
ctx.send({
message: 'Config was successfully imported.',
@ -56,7 +56,7 @@ module.exports = {
*/
getDiff: async (ctx) => {
// Check for existance of the config file destination dir.
if (!fs.existsSync(strapi.plugins['config-sync'].config.destination)) {
if (!fs.existsSync(strapi.config.get('plugin.config-sync.destination'))) {
ctx.send({
message: 'No config files were found.',
});
@ -70,8 +70,8 @@ module.exports = {
diff: {},
};
const fileConfig = await strapi.plugins['config-sync'].services.main.getAllConfigFromFiles();
const databaseConfig = await strapi.plugins['config-sync'].services.main.getAllConfigFromDatabase();
const fileConfig = await strapi.plugin('config-sync').service('main').getAllConfigFromFiles();
const databaseConfig = await strapi.plugin('config-sync').service('main').getAllConfigFromDatabase();
const diff = difference(databaseConfig, fileConfig);

View File

@ -28,12 +28,12 @@ module.exports = () => ({
? JSON.stringify(fileContents, null, 2)
: JSON.stringify(fileContents);
if (!fs.existsSync(strapi.config.get('plugin.config-sync').destination)) {
fs.mkdirSync(strapi.config.get('plugin.config-sync').destination, { recursive: true });
if (!fs.existsSync(strapi.config.get('plugin.config-sync.destination'))) {
fs.mkdirSync(strapi.config.get('plugin.config-sync.destination'), { recursive: true });
}
const writeFile = util.promisify(fs.writeFile);
await writeFile(`${strapi.config.get('plugin.config-sync').destination}${configType}.${configName}.json`, json)
await writeFile(`${strapi.config.get('plugin.config-sync.destination')}${configType}.${configName}.json`, json)
.then(() => {
// @TODO:
// Add logging for successfull config export.
@ -55,7 +55,7 @@ module.exports = () => ({
const shouldExclude = strapi.config.get('plugin.config-sync.exclude').includes(`${configName}`);
if (shouldExclude) return;
fs.unlinkSync(`${strapi.config.get('plugin.config-sync').destination}${configName}.json`);
fs.unlinkSync(`${strapi.config.get('plugin.config-sync.destination')}${configName}.json`);
},
/**
@ -67,7 +67,7 @@ module.exports = () => ({
*/
readConfigFile: async (configType, configName) => {
const readFile = util.promisify(fs.readFile);
return readFile(`${strapi.config.get('plugin.config-sync').destination}${configType}.${configName}.json`)
return readFile(`${strapi.config.get('plugin.config-sync.destination')}${configType}.${configName}.json`)
.then((data) => {
return JSON.parse(data);
})
@ -84,11 +84,11 @@ module.exports = () => ({
* @returns {object} Object with key value pairs of configs.
*/
getAllConfigFromFiles: async (configType = null) => {
if (!fs.existsSync(strapi.config.get('plugin.config-sync').destination)) {
if (!fs.existsSync(strapi.config.get('plugin.config-sync.destination'))) {
return {};
}
const configFiles = fs.readdirSync(strapi.config.get('plugin.config-sync').destination);
const configFiles = fs.readdirSync(strapi.config.get('plugin.config-sync.destination'));
const getConfigs = async () => {
const fileConfigs = {};