From d7b63f5941c65d80b9b97c53c577bc0b0166bb5a Mon Sep 17 00:00:00 2001 From: Adrian Oprea Date: Tue, 16 Jan 2018 17:23:15 +0200 Subject: [PATCH] feat(massageConfiguration): Add data-transformation function The meta-configuration structure imposes we change the way `react-hijack` parses and pulls its data. Because that work is both error-prone and also time-consuming, we chose to implement a function that would "massage" the data so it fits the current way react-hijack expects it. --- .../componentLoader/massageConfiguration.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 app/javascript/src/componentLoader/massageConfiguration.js diff --git a/app/javascript/src/componentLoader/massageConfiguration.js b/app/javascript/src/componentLoader/massageConfiguration.js new file mode 100644 index 000000000..5a19c0e9c --- /dev/null +++ b/app/javascript/src/componentLoader/massageConfiguration.js @@ -0,0 +1,21 @@ +const massageConfiguration = (config, identifier) => { + const result = { + [identifier]: {} + }; + + Object.keys(config) + .forEach( + addon => Object.keys(config[addon]) + .forEach( + component => { + if (config[addon][component].areas.indexOf(identifier) !== -1) { + result[identifier][component] = config[addon][component]; + } + } + ) + ); + + return result; +}; + +export default massageConfiguration;