Skip to content

Commit

Permalink
docs(search): use unsorted grouping for search results
Browse files Browse the repository at this point in the history
closes #13922
  • Loading branch information
KaelWD committed Dec 20, 2022
1 parent bdbecc1 commit 2a4a322
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions packages/docs/src/layouts/default/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
<script>
// Utilities
import { get } from 'vuex-pathify'
import { groupItems, sortItems } from 'vuetify/lib/util/helpers'
import algoliasearch from 'algoliasearch'
import SearchResults from './SearchResults'
Expand Down Expand Up @@ -139,25 +138,42 @@
helper.state.query && helper.search()
},
transformItems (items) {
const sorted = sortItems([...items], ['hierarchy.lvl0', 'hierarchy.lvl1'], [false, false], this.locale)
.map(item => {
const url = new URL(item.url)
items = items.map(item => {
const url = new URL(item.url)
return {
...item,
url: url.href.split(url.origin).pop(),
}
})
const groups = groupItems(sorted, ['hierarchy.lvl0'])
return {
...item,
url: url.href.split(url.origin).pop(),
}
})
const groups = this.groupItems(items, 'lvl0')
groups.forEach(group => {
group.items = groupItems(group.items, ['hierarchy.lvl1'])
group.items = this.groupItems(group.items, 'lvl1')
})
const uiIndex = groups.findIndex(val => val.name === 'UI Components')
if (uiIndex > 0) {
groups.unshift(groups.splice(uiIndex, 1)[0])
}
// const uiIndex = groups.findIndex(val => val.name === 'UI Components')
// if (uiIndex > 0) {
// groups.unshift(groups.splice(uiIndex, 1)[0])
// }
return groups
},
groupItems (items, attribute) {
const groups = []
items.forEach(item => {
const group = groups.find(val => val.name === item.hierarchy[attribute])
if (group) {
group.items.push(item)
} else {
groups.push({
name: item.hierarchy[attribute],
items: [item],
})
}
})
return groups
},
Expand Down

0 comments on commit 2a4a322

Please sign in to comment.