Show correct diff in frontend
parent
b6f1f354ea
commit
f692fa5aaa
|
@ -23,8 +23,8 @@ const ActionButtons = ({ diff }) => {
|
|||
|
||||
return (
|
||||
<ActionButtonsStyling>
|
||||
<Button disabled={isEmpty(diff.fileConfig)} color="primary" label="Import" onClick={() => openModal('import')} />
|
||||
<Button disabled={isEmpty(diff.fileConfig)} color="primary" label="Export" onClick={() => openModal('export')} />
|
||||
<Button disabled={isEmpty(diff.diff)} color="primary" label="Import" onClick={() => openModal('import')} />
|
||||
<Button disabled={isEmpty(diff.diff)} color="primary" label="Export" onClick={() => openModal('export')} />
|
||||
{!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 ConfigList = ({ diff, isLoading }) => {
|
|||
}
|
||||
|
||||
let formattedRows = [];
|
||||
Object.keys(diff.fileConfig).map((configName) => {
|
||||
Object.keys(diff.diff).map((configName) => {
|
||||
const type = configName.split('.')[0]; // Grab the first part of the filename.
|
||||
const name = configName.split(/\.(.+)/)[1]; // Grab the rest of the filename minus the file extension.
|
||||
|
||||
|
|
|
@ -70,7 +70,8 @@ module.exports = {
|
|||
const fileConfig = await strapi.plugins['config-sync'].services.main.getAllConfigFromFiles();
|
||||
const databaseConfig = await strapi.plugins['config-sync'].services.main.getAllConfigFromDatabase();
|
||||
|
||||
const diff = difference(fileConfig, databaseConfig);
|
||||
const diff = difference(databaseConfig, fileConfig);
|
||||
|
||||
formattedDiff.diff = diff;
|
||||
|
||||
Object.keys(diff).map((changedConfigName) => {
|
||||
|
|
|
@ -10,13 +10,23 @@ const { transform, isEqual, isArray, isObject } = require('lodash');
|
|||
const difference = (origObj, newObj) => {
|
||||
function changes(newObj, origObj) {
|
||||
let arrayIndexCounter = 0
|
||||
return transform(newObj, function (result, value, key) {
|
||||
|
||||
const newObjChange = transform(newObj, function (result, value, key) {
|
||||
if (!isEqual(value, origObj[key])) {
|
||||
let resultKey = isArray(origObj) ? arrayIndexCounter++ : key
|
||||
result[resultKey] = (isObject(value) && isObject(origObj[key])) ? changes(value, origObj[key]) : value
|
||||
}
|
||||
});
|
||||
const origObjChange = transform(origObj, function (result, value, key) {
|
||||
if (!isEqual(value, newObj[key])) {
|
||||
let resultKey = isArray(newObj) ? arrayIndexCounter++ : key
|
||||
result[resultKey] = (isObject(value) && isObject(newObj[key])) ? changes(value, newObj[key]) : value
|
||||
}
|
||||
})
|
||||
|
||||
return Object.assign(newObjChange, origObjChange);
|
||||
}
|
||||
|
||||
return changes(newObj, origObj)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue