From c6dcc94626328a9b32c9dbeadd8baed88d7f301f Mon Sep 17 00:00:00 2001 From: kPherox Date: Wed, 21 Aug 2019 17:48:30 +0000 Subject: [PATCH] Fix parsing objects in config --- src/store/modules/normalizers.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/store/modules/normalizers.js b/src/store/modules/normalizers.js index be78a57b..f885df89 100644 --- a/src/store/modules/normalizers.js +++ b/src/store/modules/normalizers.js @@ -107,8 +107,14 @@ export const parseTuples = (tuples, key) => { nonAtomsTuples.includes(item.tuple[0]) ? accum[item.tuple[0].substr(1)] = parseNonAtomTuples(item.tuple[1]) : accum[item.tuple[0].substr(1)] = parseTuples(item.tuple[1]) + } else if (Array.isArray(item.tuple[1])) { + accum[item.tuple[0].substr(1)] = item.tuple[1] } else if (item.tuple[1] && typeof item.tuple[1] === 'object' && 'tuple' in item.tuple[1]) { accum[item.tuple[0].substr(1)] = item.tuple[1]['tuple'].join('.') + } else if (item.tuple[1] && typeof item.tuple[1] === 'object') { + nonAtomsObjects.includes(item.tuple[0]) + ? accum[item.tuple[0].substr(1)] = parseNonAtomObject(item.tuple[1]) + : accum[item.tuple[0].substr(1)] = parseObject(item.tuple[1]) } else { key === 'mrf_user_allowlist' ? accum[item.tuple[0]] = item.tuple[1] @@ -125,6 +131,20 @@ const parseNonAtomTuples = (tuples) => { }, {}) } +const parseNonAtomObject = (object) => { + return Object.keys(object).reduce((acc, item) => { + acc[item] = object[item] + return acc + }, {}) +} + +const parseObject = (object) => { + return Object.keys(object).reduce((acc, item) => { + acc[item.substr(1)] = object[item] + return acc + }, {}) +} + export const valueHasTuples = (key, value) => { const valueIsArrayOfNonObjects = Array.isArray(value) && value.length > 0 && typeof value[0] !== 'object' return key === 'meta' ||