Commit 1b368c77 authored by Angelina Filippova's avatar Angelina Filippova

Move checking partial update to normalizers and fix bugs

parent edc8fe58
export const checkPartialUpdate = (settings, updatedSettings, description) => {
return Object.keys(updatedSettings).reduce((acc, group) => {
acc[group] = Object.keys(updatedSettings[group]).reduce((acc, key) => {
debugger
if (!partialUpdate(group, key)) {
const updated = Object.keys(settings[group][key]).reduce((acc, settingName) => {
const setting = description
.find(element => element.group === group && element.key === key).children
.find(child => child.key === settingName)
const type = setting ? setting.type : ''
acc[settingName] = [type, settings[group][key][settingName]]
return acc
}, {})
acc[key] = updated
return acc
}
acc[key] = updatedSettings[group][key]
return acc
}, {})
return acc
}, {})
}
const getCurrentValue = (object, keys) => {
if (keys.length === 0) {
return object
......@@ -103,7 +126,7 @@ const parseProxyUrl = value => {
return { socks5: false, host: null, port: null }
}
export const partialUpdate = (group, key) => {
const partialUpdate = (group, key) => {
if (group === ':auto_linker' && key === ':opts') {
return false
}
......
import { fetchDescription, fetchSettings, removeSettings, updateSettings, uploadMedia } from '@/api/settings'
import { parseNonTuples, parseTuples, partialUpdate, valueHasTuples, wrapUpdatedSettings } from './normalizers'
import { checkPartialUpdate, parseNonTuples, parseTuples, valueHasTuples, wrapUpdatedSettings } from './normalizers'
const settings = {
state: {
......@@ -70,27 +70,11 @@ const settings = {
await removeSettings(configs, getters.authHost, getters.token)
},
async SubmitChanges({ getters, commit, state }) {
const updatedData = Object.keys(state.updatedSettings).reduce((acc, group) => {
acc[group] = Object.keys(state.updatedSettings[group]).reduce((acc, key) => {
if (!partialUpdate(group, key)) {
const updated = Object.keys(state.settings[group][key]).reduce((acc, settingName) => {
const settingType = state.description
.find(element => element.group === group && element.key === key).children
.find(child => child.key === settingName).type
acc[settingName] = [settingType, state.settings[group][key][settingName]]
return acc
}, {})
acc[key] = updated
return acc
}
acc[key] = state.updatedSettings[group][key]
return acc
}, {})
return acc
}, {})
const updatedData = checkPartialUpdate(state.settings, state.updatedSettings, state.description)
const configs = Object.keys(updatedData).reduce((acc, group) => {
return [...acc, ...wrapUpdatedSettings(group, updatedData[group], state.settings)]
}, [])
const response = await updateSettings(configs, getters.authHost, getters.token)
commit('SET_SETTINGS', response.data.configs)
commit('CLEAR_UPDATED_SETTINGS')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment