mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
feat(NodeGenerator): better search UX
This commit is contained in:
parent
2fe27057fe
commit
818b720239
1 changed files with 18 additions and 8 deletions
|
|
@ -27,20 +27,30 @@ function getFilterFunc(keyRegex) {
|
|||
}
|
||||
}
|
||||
|
||||
function filterDuplications(arr) {
|
||||
return Array.from(new Set(arr))
|
||||
}
|
||||
|
||||
function search(treeNodes, searchKey) {
|
||||
if (!searchKey) return treeNodes
|
||||
/**
|
||||
* if searchKey is 'abcd'
|
||||
* then keyRegex will be /a.*?b.*?c.*?d/i
|
||||
* then keyRegex will be /abcd/i and /a.*?b.*?c.*?d/i
|
||||
*/
|
||||
const keyRegex = new RegExp(
|
||||
searchKey
|
||||
.replace(/\//, '')
|
||||
.split('')
|
||||
.join('.*?'),
|
||||
'i'
|
||||
const keyRegexes = [
|
||||
new RegExp(searchKey, 'i'),
|
||||
new RegExp(
|
||||
searchKey
|
||||
.replace(/\//, '')
|
||||
.split('')
|
||||
.join('.*?'),
|
||||
'i'
|
||||
),
|
||||
]
|
||||
const searchResults = [].concat(
|
||||
...keyRegexes.map(keyRegex => treeNodes.filter(getFilterFunc(keyRegex)))
|
||||
)
|
||||
return treeNodes.filter(getFilterFunc(keyRegex))
|
||||
return filterDuplications(searchResults)
|
||||
}
|
||||
|
||||
function debounce(func, delay) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue