From 51f6ed61d996541f860506be5ff1eab601ee0640 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Fri, 20 Dec 2019 23:17:39 +0300 Subject: [PATCH] Update parsing and processing data for Metadata and MRF tabs --- src/store/modules/normalizers.js | 17 +++++++++++++---- .../inputComponents/EditableKeywordInput.vue | 10 +++++++--- src/views/settings/index.vue | 19 ++++++++----------- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/store/modules/normalizers.js b/src/store/modules/normalizers.js index 73e39f73..059d03a3 100644 --- a/src/store/modules/normalizers.js +++ b/src/store/modules/normalizers.js @@ -12,10 +12,14 @@ export const parseTuples = (tuples, key) => { accum[item.tuple[0]] = item.tuple[1].reduce((acc, mascot) => { return [...acc, { [mascot.tuple[0]]: { ...mascot.tuple[1], id: `f${(~~(Math.random() * 1e8)).toString(16)}` }}] }, []) - } else if (item.tuple[0] === ':groups') { + } else if (item.tuple[0] === ':groups' || item.tuple[0] === ':replace') { accum[item.tuple[0]] = item.tuple[1].reduce((acc, group) => { return [...acc, { [group.tuple[0]]: { value: group.tuple[1], id: `f${(~~(Math.random() * 1e8)).toString(16)}` }}] }, []) + } else if (item.tuple[0] === ':match_actor') { + accum[item.tuple[0]] = Object.keys(item.tuple[1]).reduce((acc, regex) => { + return [...acc, { [regex]: { value: item.tuple[1][regex], id: `f${(~~(Math.random() * 1e8)).toString(16)}` }}] + }, []) } else if (item.tuple[0] === ':icons') { accum[item.tuple[0]] = item.tuple[1].map(icon => { return Object.keys(icon).map(name => { @@ -122,7 +126,7 @@ export const wrapUpdatedSettings = (group, settings, currentState) => { const wrapValues = (settings, currentState) => { return Object.keys(settings).map(setting => { const [type, value] = Array.isArray(settings[setting]) ? settings[setting] : ['', settings[setting]] - if (type === 'keyword' || type.includes('keyword')) { + if (type === 'keyword' || type.includes('keyword') || setting === ':replace') { return { 'tuple': [setting, wrapValues(value)] } } else if (type === 'atom' && value.length > 0) { return { 'tuple': [setting, `:${value}`] } @@ -130,10 +134,15 @@ const wrapValues = (settings, currentState) => { return { 'tuple': [setting, { 'tuple': value }] } } else if (type === 'map') { const mapValue = Object.keys(value).reduce((acc, key) => { - acc[key] = value[key][1] + acc[key] = setting === ':match_actor' ? value[key] : value[key][1] return acc }, {}) - return { 'tuple': [setting, { ...currentState[setting], ...mapValue }] } + const mapCurrentState = setting === ':match_actor' + ? currentState[setting].reduce((acc, element) => { + return { ...acc, ...{ [Object.keys(element)[0]]: Object.values(element)[0].value }} + }, {}) + : currentState[setting] + return { 'tuple': [setting, { ...mapCurrentState, ...mapValue }] } } else if (setting === ':ip') { const ip = value.split('.').map(s => parseInt(s, 10)) return { 'tuple': [setting, { 'tuple': ip }] } diff --git a/src/views/settings/components/inputComponents/EditableKeywordInput.vue b/src/views/settings/components/inputComponents/EditableKeywordInput.vue index 52354614..a85104f4 100644 --- a/src/views/settings/components/inputComponents/EditableKeywordInput.vue +++ b/src/views/settings/components/inputComponents/EditableKeywordInput.vue @@ -93,9 +93,13 @@ export default { this.updateSetting(updatedValue, this.settingGroup.group, this.settingGroup.key, this.setting.key, this.setting.type) }, updateSetting(value, group, key, input, type) { - const updatedSettings = value.reduce((acc, element) => { - return { ...acc, [Object.keys(element)[0]]: [['list', 'string'], Object.values(element)[0].value] } - }, {}) + const updatedSettings = type !== 'map' + ? value.reduce((acc, element) => { + return { ...acc, [Object.keys(element)[0]]: [['list', 'string'], Object.values(element)[0].value] } + }, {}) + : value.reduce((acc, element) => { + return { ...acc, [Object.keys(element)[0]]: Object.values(element)[0].value } + }, {}) this.$store.dispatch('UpdateSettings', { group, key, input, value: updatedSettings, type }) this.$store.dispatch('UpdateState', { group, key, input, value }) } diff --git a/src/views/settings/index.vue b/src/views/settings/index.vue index f905fd31..199ec97c 100644 --- a/src/views/settings/index.vue +++ b/src/views/settings/index.vue @@ -44,23 +44,20 @@ - +