Skip to content
Snippets Groups Projects
Commit b3c446d6 authored by Angelina Filippova's avatar Angelina Filippova
Browse files

Fix removing settings that have no subkeys

parent a0e01bfd
No related branches found
No related tags found
1 merge request!77Ability to remove settings from db
This commit is part of merge request !77. Comments created here will be created in the context of that merge request.
...@@ -28,9 +28,9 @@ const settings = { ...@@ -28,9 +28,9 @@ const settings = {
CLEAR_UPDATED_SETTINGS: (state) => { CLEAR_UPDATED_SETTINGS: (state) => {
state.updatedSettings = {} state.updatedSettings = {}
}, },
REMOVE_SETTING_FROM_UPDATED: (state, { group, key, subkey }) => { REMOVE_SETTING_FROM_UPDATED: (state, { group, key, subkeys }) => {
if (_.get(state.updatedSettings, [group, key, subkey])) { if (_.get(state.updatedSettings, [group, key, subkeys[0]])) {
const { [subkey]: value, ...updatedSettings } = state.updatedSettings[group][key] const { [subkeys[0]]: value, ...updatedSettings } = state.updatedSettings[group][key]
state.updatedSettings = updatedSettings state.updatedSettings = updatedSettings
} }
}, },
...@@ -56,11 +56,17 @@ const settings = { ...@@ -56,11 +56,17 @@ const settings = {
: { [key]: { ...state.updatedSettings[group][key], ...{ [input]: [type, value] }}} : { [key]: { ...state.updatedSettings[group][key], ...{ [input]: [type, value] }}}
state.updatedSettings[group] = { ...state.updatedSettings[group], ...updatedSetting } state.updatedSettings[group] = { ...state.updatedSettings[group], ...updatedSetting }
}, },
UPDATE_SETTINGS_AFTER_REMOVAL: (state, { group, key, value }) => { UPDATE_SETTINGS_AFTER_REMOVAL: (state, { configs, response }) => {
const parsedValue = valueHasTuples(key, value) if (!response) {
? { value: parseNonTuples(key, value) } const { [configs[0].key]: value, ...updatedSettings } = state.settings[configs[0].group]
: parseTuples(value, key) state.settings[configs[0].group] = updatedSettings
state.settings[group] = { ...state.settings[group], [key]: parsedValue } } else {
const { group, key, value } = response
const parsedValue = valueHasTuples(key, value)
? { value: parseNonTuples(key, value) }
: parseTuples(value, key)
state.settings[group] = { ...state.settings[group], [key]: parsedValue }
}
}, },
UPDATE_STATE: (state, { group, key, input, value }) => { UPDATE_STATE: (state, { group, key, input, value }) => {
const updatedState = key === 'Pleroma.Emails.Mailer' && input === ':adapter' const updatedState = key === 'Pleroma.Emails.Mailer' && input === ':adapter'
...@@ -81,9 +87,9 @@ const settings = { ...@@ -81,9 +87,9 @@ const settings = {
}, },
async RemoveSetting({ commit, getters }, configs) { async RemoveSetting({ commit, getters }, configs) {
const response = await removeSettings(configs, getters.authHost, getters.token) const response = await removeSettings(configs, getters.authHost, getters.token)
const { group, key } = response.data.configs[0] const { group, key, subkeys } = configs[0]
commit('UPDATE_SETTINGS_AFTER_REMOVAL', response.data.configs[0]) commit('UPDATE_SETTINGS_AFTER_REMOVAL', { response: response.data.configs[0], configs })
commit('REMOVE_SETTING_FROM_UPDATED', { group, key, subkey: configs[0].subkeys[0] }) commit('REMOVE_SETTING_FROM_UPDATED', { group, key, subkeys: subkeys || [] })
}, },
async SubmitChanges({ getters, commit, state }) { async SubmitChanges({ getters, commit, state }) {
const updatedData = checkPartialUpdate(state.settings, state.updatedSettings, state.description) const updatedData = checkPartialUpdate(state.settings, state.updatedSettings, state.description)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment