Use data from state for settings that cannot be partially updated
This commit is contained in:
parent
864b8a1492
commit
37cdff3745
2 changed files with 32 additions and 6 deletions
|
@ -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)] }
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue