From 218608e73ca028300e0670eeed14f7f0ffe19649 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Fri, 3 Jan 2020 14:30:41 +0700 Subject: [PATCH] Fix processing nested data for mime types setting --- src/store/modules/normalizers.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/store/modules/normalizers.js b/src/store/modules/normalizers.js index 984062ff..120c3874 100644 --- a/src/store/modules/normalizers.js +++ b/src/store/modules/normalizers.js @@ -136,25 +136,26 @@ export const processNested = (valueForState, valueForUpdatedSettings, group, par const [{ key, type }, ...otherParents] = parents const path = [group, parentKey, ...parents.reverse().map(parent => parent.key).slice(0, -1)] - const updatedValueForState = valueExists(settings, path) + let updatedValueForState = valueExists(settings, path) ? { ...getCurrentValue(settings[group][parentKey], parents.map(el => el.key).slice(0, -1)), ...{ [key]: valueForState }} : { [key]: valueForState } - const updatedValueForUpdatedSettings = valueExists(updatedSettings, path) + let updatedValueForUpdatedSettings = valueExists(updatedSettings, path) ? { ...getCurrentValue(updatedSettings[group][parentKey], parents.map(el => el.key).slice(0, -1))[1], ...{ [key]: [type, valueForUpdatedSettings] }} : { [key]: [type, valueForUpdatedSettings] } - // if (group === ':mime' && key === ':types') { - // updatedValueForState = { ...settings[group][key].value, ...updatedValueForState } - // updatedValueForUpdatedSettings = { - // ...Object.keys(settings[group][key].value) - // .reduce((acc, el) => { - // return { ...acc, [el]: [['list', 'string'], settings[group][key].value[el]] } - // }, {}), - // ...updatedValueForUpdatedSettings - // } - // } + if (group === ':mime' && parents[0].key === ':types') { + updatedValueForState = { ...settings[group][parents[0].key].value, ...updatedValueForState } + updatedValueForUpdatedSettings = { + ...Object.keys(settings[group][parents[0].key].value) + .reduce((acc, el) => { + return { ...acc, [el]: [type, settings[group][parents[0].key].value[el]] } + }, {}), + ...updatedValueForUpdatedSettings + } + } + return otherParents.length === 1 ? { valueForState: updatedValueForState, valueForUpdatedSettings: updatedValueForUpdatedSettings, setting: otherParents[0] } : processNested(updatedValueForState, updatedValueForUpdatedSettings, group, parentKey, otherParents, settings, updatedSettings)