From b36e8693b5602f7b732ccec12ae4522a86d145fe Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Sun, 26 Jul 2020 01:01:31 +0300 Subject: [PATCH] Remove partial update check --- src/store/modules/normalizers.js | 26 ---------- src/store/modules/settings.js | 7 ++- .../normalizers/checkPartialUpdate.test.js | 48 ------------------- 3 files changed, 3 insertions(+), 78 deletions(-) delete mode 100644 test/modules/normalizers/checkPartialUpdate.test.js diff --git a/src/store/modules/normalizers.js b/src/store/modules/normalizers.js index c146d60e..8991353a 100644 --- a/src/store/modules/normalizers.js +++ b/src/store/modules/normalizers.js @@ -9,28 +9,6 @@ export const getBooleanValue = value => { return value } -export const checkPartialUpdate = (settings, updatedSettings, description) => { - return Object.keys(updatedSettings).reduce((acc, group) => { - acc[group] = Object.keys(updatedSettings[group]).reduce((acc, key) => { - 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 = (type, value, path) => { if (type === 'state') { return _.get(value, path) @@ -154,10 +132,6 @@ const parseProxyUrl = value => { return { socks5: false, host: null, port: null } } -const partialUpdate = (group, key) => { - return !(group === ':auto_linker' && key === ':opts') -} - export const processNested = (valueForState, valueForUpdatedSettings, group, parentKey, parents, settings, updatedSettings) => { const [{ key, type }, ...otherParents] = parents const path = [group, parentKey, ...parents.reverse().map(parent => parent.key).slice(0, -1)] diff --git a/src/store/modules/settings.js b/src/store/modules/settings.js index 6053ec2d..6c193e57 100644 --- a/src/store/modules/settings.js +++ b/src/store/modules/settings.js @@ -1,5 +1,5 @@ import { fetchDescription, fetchSettings, removeSettings, updateSettings } from '@/api/settings' -import { checkPartialUpdate, formSearchObject, parseNonTuples, parseTuples, valueHasTuples, wrapUpdatedSettings } from './normalizers' +import { formSearchObject, parseNonTuples, parseTuples, valueHasTuples, wrapUpdatedSettings } from './normalizers' import _ from 'lodash' const settings = { @@ -101,9 +101,8 @@ const settings = { commit('SET_ACTIVE_TAB', tab) }, async SubmitChanges({ getters, commit, state }) { - 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 configs = Object.keys(state.updatedSettings).reduce((acc, group) => { + return [...acc, ...wrapUpdatedSettings(group, state.updatedSettings[group], state.settings)] }, []) await updateSettings(configs, getters.authHost, getters.token) diff --git a/test/modules/normalizers/checkPartialUpdate.test.js b/test/modules/normalizers/checkPartialUpdate.test.js deleted file mode 100644 index 87e6f104..00000000 --- a/test/modules/normalizers/checkPartialUpdate.test.js +++ /dev/null @@ -1,48 +0,0 @@ -import { checkPartialUpdate } from '@/store/modules/normalizers' -import _ from 'lodash' - -describe('Partial update', () => { - it('partial update for settings that do not allow partial update', () => { - const settings = { ':auto_linker': { ':opts': - { ':strip_prefix': true, ':new_window': false, ':rel': 'ugc', ':truncate': 3 } - }} - const updatedSettings = { ':auto_linker': { ':opts': { ':new_window': false }}} - const description = [{ - children: [ - { key: ':strip_prefix', type: 'boolean' }, - { key: ':truncate', type: ['integer', false] }, - { key: ':new_window', type: 'boolean' }], - description: 'Configuration for the auto_linker library', - group: ':auto_linker', - key: ':opts', - label: 'Opts', - type: 'group' - }] - - const expectedData = { ':auto_linker': { ':opts': { - ':strip_prefix': ['boolean', true], - ':new_window': ['boolean', false], - ':rel': ['', 'ugc'], - ':truncate': [['integer', false], 3] - }}} - const updatedData = checkPartialUpdate(settings, updatedSettings, description) - expect(_.isEqual(updatedData, expectedData)).toBeTruthy() - }) - - it('partial update for settings that allow partial update', () => { - const settings = { ':pleroma': { 'Pleroma.Captcha': { ':enabled': true, ':seconds_valid': 70, ':method': 'Pleroma.Captcha.Kocaptcha' }}} - const updatedSettings = { ':pleroma': { 'Pleroma.Captcha': { ':seconds_valid': ['integer', 70] }}} - const description = [{ - children: [], - description: 'Captcha-related settings', - group: ':pleroma', - key: 'Pleroma.Captcha', - label: 'Pleroma.Captcha', - type: 'group' - }] - - const expectedData = { ':pleroma': { 'Pleroma.Captcha': { ':seconds_valid': ['integer', 70] }}} - const updatedData = checkPartialUpdate(settings, updatedSettings, description) - expect(_.isEqual(updatedData, expectedData)).toBeTruthy() - }) -})