From b3c446d60c93a65f35fc0eb8bd683d8ef115db19 Mon Sep 17 00:00:00 2001
From: Angelina Filippova <linakirsanova@gmail.com>
Date: Wed, 15 Jan 2020 20:15:09 +0700
Subject: [PATCH] Fix removing settings that have no subkeys

---
 src/store/modules/settings.js | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/src/store/modules/settings.js b/src/store/modules/settings.js
index 0574fc64..0381eca6 100644
--- a/src/store/modules/settings.js
+++ b/src/store/modules/settings.js
@@ -28,9 +28,9 @@ const settings = {
     CLEAR_UPDATED_SETTINGS: (state) => {
       state.updatedSettings = {}
     },
-    REMOVE_SETTING_FROM_UPDATED: (state, { group, key, subkey }) => {
-      if (_.get(state.updatedSettings, [group, key, subkey])) {
-        const { [subkey]: value, ...updatedSettings } = state.updatedSettings[group][key]
+    REMOVE_SETTING_FROM_UPDATED: (state, { group, key, subkeys }) => {
+      if (_.get(state.updatedSettings, [group, key, subkeys[0]])) {
+        const { [subkeys[0]]: value, ...updatedSettings } = state.updatedSettings[group][key]
         state.updatedSettings = updatedSettings
       }
     },
@@ -56,11 +56,17 @@ const settings = {
         : { [key]: { ...state.updatedSettings[group][key], ...{ [input]: [type, value] }}}
       state.updatedSettings[group] = { ...state.updatedSettings[group], ...updatedSetting }
     },
-    UPDATE_SETTINGS_AFTER_REMOVAL: (state, { group, key, value }) => {
-      const parsedValue = valueHasTuples(key, value)
-        ? { value: parseNonTuples(key, value) }
-        : parseTuples(value, key)
-      state.settings[group] = { ...state.settings[group], [key]: parsedValue }
+    UPDATE_SETTINGS_AFTER_REMOVAL: (state, { configs, response }) => {
+      if (!response) {
+        const { [configs[0].key]: value, ...updatedSettings } = state.settings[configs[0].group]
+        state.settings[configs[0].group] = updatedSettings
+      } 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 }) => {
       const updatedState = key === 'Pleroma.Emails.Mailer' && input === ':adapter'
@@ -81,9 +87,9 @@ const settings = {
     },
     async RemoveSetting({ commit, getters }, configs) {
       const response = await removeSettings(configs, getters.authHost, getters.token)
-      const { group, key } = response.data.configs[0]
-      commit('UPDATE_SETTINGS_AFTER_REMOVAL', response.data.configs[0])
-      commit('REMOVE_SETTING_FROM_UPDATED', { group, key, subkey: configs[0].subkeys[0] })
+      const { group, key, subkeys } = configs[0]
+      commit('UPDATE_SETTINGS_AFTER_REMOVAL', { response: response.data.configs[0], configs })
+      commit('REMOVE_SETTING_FROM_UPDATED', { group, key, subkeys: subkeys || [] })
     },
     async SubmitChanges({ getters, commit, state }) {
       const updatedData = checkPartialUpdate(state.settings, state.updatedSettings, state.description)
-- 
GitLab