From a518cc492fb28f7ee2c114c5366215c5003c63b2 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Tue, 24 Dec 2019 02:12:41 +0300 Subject: [PATCH] Fix processing backends setting in logger group --- src/store/modules/normalizers.js | 8 ++++++++ src/store/modules/settings.js | 6 ++++-- .../inputComponents/BackendsLoggerInput.vue | 11 ++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/store/modules/normalizers.js b/src/store/modules/normalizers.js index 88e92b8c..cd1670b3 100644 --- a/src/store/modules/normalizers.js +++ b/src/store/modules/normalizers.js @@ -3,6 +3,14 @@ const nonAtomsObjects = ['match_actor', ':match_actor'] const objects = ['digest', 'pleroma_fe', 'masto_fe', 'poll_limits', 'styling'] const objectParents = ['mascots'] +export const parseNonTuples = (key, value) => { + if (key === ':backends') { + const index = value.findIndex(el => Array.isArray(el) && el.includes(':ex_syslogger')) + const updated = value.map((el, i) => i === index ? ':ex_syslogger' : el) + return { value: updated } + } + return { value } +} // REFACTOR export const parseTuples = (tuples, key) => { return tuples.reduce((accum, item) => { diff --git a/src/store/modules/settings.js b/src/store/modules/settings.js index bea87939..68bed86c 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, partialUpdate, valueHasTuples, wrapUpdatedSettings } from './normalizers' +import { parseNonTuples, parseTuples, partialUpdate, valueHasTuples, wrapUpdatedSettings } from './normalizers' const settings = { state: { @@ -38,7 +38,9 @@ const settings = { }, SET_SETTINGS: (state, data) => { const newSettings = data.reduce((acc, { group, key, value }) => { - const parsedValue = valueHasTuples(key, value) ? { value } : parseTuples(value, key) + const parsedValue = valueHasTuples(key, value) + ? parseNonTuples(key, value) + : parseTuples(value, key) acc[group][key] = { ...acc[group][key], ...parsedValue } return acc }, state.settings) diff --git a/src/views/settings/components/inputComponents/BackendsLoggerInput.vue b/src/views/settings/components/inputComponents/BackendsLoggerInput.vue index da6af188..7206617a 100644 --- a/src/views/settings/components/inputComponents/BackendsLoggerInput.vue +++ b/src/views/settings/components/inputComponents/BackendsLoggerInput.vue @@ -36,7 +36,16 @@ export default { }, methods: { updateSetting(value, group, key, input, type) { - this.$store.dispatch('UpdateSettings', { group, key, input, value, type }) + const updatedValue = () => { + const index = value.findIndex(el => el === ':ex_syslogger') + const updatedArray = value.slice() + if (index !== -1) { + updatedArray[index] = ['ExSyslogger', ':ex_syslogger'] + } + return updatedArray + } + + this.$store.dispatch('UpdateSettings', { group, key, input, value: updatedValue(), type }) this.$store.dispatch('UpdateState', { group, key, input, value }) } }