Add info about group and setting key into search object

This commit is contained in:
Angelina Filippova 2020-03-09 22:09:32 +03:00
parent ab5a7158b5
commit 26889c28e3
2 changed files with 17 additions and 7 deletions

View file

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

View file

@ -226,9 +226,10 @@ export default {
handleSearchSelect() {
},
querySearch(queryString, cb) {
const results = Object.keys(this.searchData)
.filter(key => this.searchData[key].find(el => el.includes(queryString.toLowerCase())))
.map(key => { return { value: this.searchData[key][1] } })
const results = this.searchData.filter(searchObj => searchObj.search.find(el => el.includes(queryString.toLowerCase())))
.map(searchObj => {
return { value: `${searchObj.key} in ${searchObj.group}` }
})
cb(results)
}
}