Add global tools section & export data generator

This commit is contained in:
MattIPv4
2020-05-04 20:55:23 +01:00
parent 431cbf53e2
commit e7e9cbcfa2
5 changed files with 264 additions and 1 deletions

View File

@@ -0,0 +1,42 @@
const categoriesExport = (categories) => {
const categoriesData = {};
// Work through each category
for (const category in categories) {
const categoryData = {};
// Go over each property in the category
for (const property in categories[category]) {
// If the user input differs from the default, they changed it, so we save it
const propertyData = categories[category][property];
if (propertyData.value !== propertyData.default) {
categoryData[property] = propertyData.value;
}
}
// If there were any property changes, save the category
if (Object.keys(categoryData).length) {
categoriesData[category] = categoryData;
}
}
return categoriesData;
};
export default (domains, global) => {
const exportData = {};
// Handle domains
// Always save changes, even if none, so we can replicate the correct number of domains
exportData.domains = domains.map(domain => categoriesExport(domain[0]));
// Handle global
// If there were any category changes, save global changes
const globalData = categoriesExport(global);
if (Object.keys(globalData).length) {
exportData.global = globalData;
}
return exportData;
};