Fix processing values with type map

This commit is contained in:
Angelina Filippova 2019-12-19 19:21:44 +03:00
parent 529a84691f
commit 961bf8ae0c
2 changed files with 6 additions and 6 deletions

View file

@ -107,7 +107,7 @@ export const valueHasTuples = (key, value) => {
valueIsArrayOfNonObjects
}
export const wrapUpdatedSettings = (group, settings) => {
export const wrapUpdatedSettings = (group, settings, currentState) => {
return Object.keys(settings).map((key) => {
if (settings[key]._value) {
const value = settings[key]._value[0] === 'atom' && settings[key]._value[1].length > 1
@ -115,11 +115,11 @@ export const wrapUpdatedSettings = (group, settings) => {
: settings[key]._value[1]
return { group, key, value }
}
return { group, key, value: wrapValues(settings[key]) }
return { group, key, value: wrapValues(settings[key], currentState[group][key]) }
})
}
const wrapValues = settings => {
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')) {
@ -129,11 +129,11 @@ const wrapValues = settings => {
} else if (type.includes('tuple') && Array.isArray(value)) {
return { 'tuple': [setting, { 'tuple': value }] }
} else if (type === 'map') {
const objectValue = Object.keys(value).reduce((acc, key) => {
const mapValue = Object.keys(value).reduce((acc, key) => {
acc[key] = value[key][1]
return acc
}, {})
return { 'tuple': [setting, objectValue] }
return { 'tuple': [setting, { ...currentState[setting], ...mapValue }] }
} else if (setting === ':ip') {
const ip = value.split('.').map(s => parseInt(s, 10))
return { 'tuple': [setting, { 'tuple': ip }] }

View file

@ -86,7 +86,7 @@ const settings = {
}, {})
const configs = Object.keys(updatedData).reduce((acc, group) => {
return [...acc, ...wrapUpdatedSettings(group, updatedData[group])]
return [...acc, ...wrapUpdatedSettings(group, updatedData[group], state.settings)]
}, [])
const response = await updateSettings(configs, getters.authHost, getters.token)
commit('SET_SETTINGS', response.data.configs)