Fix processing backends setting in logger group

This commit is contained in:
Angelina Filippova 2019-12-24 02:12:41 +03:00
parent 222697d048
commit a518cc492f
3 changed files with 22 additions and 3 deletions

View file

@ -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) => {

View file

@ -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)

View file

@ -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 })
}
}