Add ability to select a setting and go to the tab of the selected setting

This commit is contained in:
Angelina Filippova 2020-03-10 00:43:32 +03:00
parent 26889c28e3
commit 584401a3d7
3 changed files with 14 additions and 9 deletions

View file

@ -256,21 +256,21 @@ const wrapValues = (settings, currentState) => {
} }
export const formSearchObject = description => { export const formSearchObject = description => {
const parseNestedSettings = (description, key) => description.reduce((acc, setting) => { const parseNestedSettings = (description, label, key) => description.reduce((acc, setting) => {
const searchArray = _.compact([setting.key, setting.label, setting.description]).map(el => el.toLowerCase()) const searchArray = _.compact([setting.key, setting.label, setting.description]).map(el => el.toLowerCase())
if (setting.children) { if (setting.children) {
const updatedAcc = [...acc, { key: setting.label, group: key, search: searchArray }] const updatedAcc = [...acc, { label: setting.label, key: setting.key, groupKey: key, groupLabel: label, search: searchArray }]
return [...updatedAcc, ...parseNestedSettings(setting.children, setting.label)] return [...updatedAcc, ...parseNestedSettings(setting.children, setting.label, setting.key)]
} }
return [...acc, { key: [setting.label], group: key, search: searchArray }] return [...acc, { label: setting.label, key: setting.label, groupKey: key, groupLabel: label, search: searchArray }]
}, []) }, [])
return description.reduce((acc, setting) => { return description.reduce((acc, setting) => {
const searchArray = _.compact([setting.key, setting.label, setting.description]).map(el => el.toLowerCase()) const searchArray = _.compact([setting.key, setting.label, setting.description]).map(el => el.toLowerCase())
if (setting.children) { if (setting.children) {
const updatedAcc = [...acc, { key: setting.label, group: setting.label, search: searchArray }] const updatedAcc = [...acc, { label: setting.label, key: setting.key, groupKey: setting.key, groupLabel: setting.label, search: searchArray }]
return [...updatedAcc, ...parseNestedSettings(setting.children, setting.label)] return [...updatedAcc, ...parseNestedSettings(setting.children, setting.label, setting.key)]
} }
return [...acc, { key: setting.label, group: setting.label, search: searchArray }] return [...acc, { label: setting.label, key: setting.label, groupKey: setting.key, groupLabel: setting.label, search: searchArray }]
}, []) }, [])
} }

View file

@ -3,6 +3,7 @@ import _ from 'lodash'
export const tabs = { export const tabs = {
'activity-pub': { 'activity-pub': {
label: 'settings.activityPub', label: 'settings.activityPub',
settings: [':activitypub', ':user'],
activitypub: () => this.settings.description.find(setting => setting.key === ':activitypub'), activitypub: () => this.settings.description.find(setting => setting.key === ':activitypub'),
activitypubData: () => _.get(this.settings.settings, [':pleroma', ':activitypub']) || {}, activitypubData: () => _.get(this.settings.settings, [':pleroma', ':activitypub']) || {},
user: () => this.settings.description.find(setting => setting.key === ':user'), user: () => this.settings.description.find(setting => setting.key === ':user'),

View file

@ -223,12 +223,16 @@ export default {
message: i18n.t('settings.restartSuccess') message: i18n.t('settings.restartSuccess')
}) })
}, },
handleSearchSelect() { handleSearchSelect(selectedValue) {
const tab = Object.keys(this.tabs).find(tab => {
return this.tabs[tab].settings.includes(selectedValue.group)
})
this.$store.dispatch('SetActiveTab', tab)
}, },
querySearch(queryString, cb) { querySearch(queryString, cb) {
const results = this.searchData.filter(searchObj => searchObj.search.find(el => el.includes(queryString.toLowerCase()))) const results = this.searchData.filter(searchObj => searchObj.search.find(el => el.includes(queryString.toLowerCase())))
.map(searchObj => { .map(searchObj => {
return { value: `${searchObj.key} in ${searchObj.group}` } return { value: `${searchObj.label} in ${searchObj.groupLabel}`, group: searchObj.groupKey }
}) })
cb(results) cb(results)
} }