From 37cdff3745f71b334e01db5d455fd95e0c9c7cc7 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Wed, 11 Dec 2019 00:24:43 +0300 Subject: [PATCH] Use data from state for settings that cannot be partially updated --- src/store/modules/normalizers.js | 14 ++++++++++++-- src/store/modules/settings.js | 24 ++++++++++++++++++++---- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/store/modules/normalizers.js b/src/store/modules/normalizers.js index 7231a476..4fbfecae 100644 --- a/src/store/modules/normalizers.js +++ b/src/store/modules/normalizers.js @@ -58,6 +58,18 @@ const parseObject = object => { }, {}) } +export const partialUpdate = (group, key) => { + if ((group === ':pleroma' && key === ':ecto_repos') || + (group === ':quack' && key === ':meta') || + (group === ':mime' && key === ':types') || + (group === ':auto_linker' && key === ':opts') || + (group === ':swarm' && key === ':node_blacklist') || + (group === ':cors_plug' && [':max_age', ':methods', ':expose', ':headers'].includes(key))) { + return false + } + return true +} + export const valueHasTuples = (key, value) => { const valueIsArrayOfNonObjects = Array.isArray(value) && value.length > 0 && typeof value[0] !== 'object' return key === ':meta' || @@ -72,7 +84,6 @@ export const valueHasTuples = (key, value) => { } export const wrapUpdatedSettings = (group, settings) => { - console.log(group, settings) return Object.keys(settings).map((key) => { const value = groupWithoutKey(settings[key]) || wrapValues(settings[key]) return { group, key, value } @@ -81,7 +92,6 @@ export const wrapUpdatedSettings = (group, settings) => { const wrapValues = settings => { return Object.keys(settings).map(setting => { - console.log(settings[setting]) const [type, value] = Array.isArray(settings[setting]) ? settings[setting] : ['', settings[setting]] if (type === 'keyword' || type.includes('keyword')) { return { 'tuple': [setting, wrapValues(value)] } diff --git a/src/store/modules/settings.js b/src/store/modules/settings.js index adb2a05a..640bc237 100644 --- a/src/store/modules/settings.js +++ b/src/store/modules/settings.js @@ -1,5 +1,5 @@ import { fetchDescription, fetchSettings, updateSettings, uploadMedia } from '@/api/settings' -import { parseTuples, valueHasTuples, wrapUpdatedSettings } from './normalizers' +import { parseTuples, partialUpdate, valueHasTuples, wrapUpdatedSettings } from './normalizers' const settings = { state: { @@ -56,7 +56,7 @@ const settings = { } }, actions: { - async FetchSettings({ commit, dispatch, getters }) { + async FetchSettings({ commit, getters }) { commit('SET_LOADING', true) const response = await fetchSettings(getters.authHost, getters.token) const description = await fetchDescription(getters.authHost, getters.token) @@ -69,8 +69,24 @@ const settings = { commit('REWRITE_CONFIG', { tab, data }) }, async SubmitChanges({ getters, commit, state }) { - const configs = Object.keys(state.updatedSettings).reduce((acc, group) => { - return [...acc, ...wrapUpdatedSettings(group, state.updatedSettings[group])] + 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) => { + acc[settingName] = ['', state.settings[group][key][settingName]] + return acc + }, {}) + acc[key] = updated + return acc + } + acc[key] = state.updatedSettings[group][key] + return acc + }, {}) + return acc + }, {}) + + const configs = Object.keys(updatedData).reduce((acc, group) => { + return [...acc, ...wrapUpdatedSettings(group, updatedData[group])] }, []) const response = await updateSettings(configs, getters.authHost, getters.token) commit('SET_SETTINGS', response.data.configs)