Integration search filter improvements (#16067)

* Integration search filter improvements

* Handle more cases, fix capitalization
This commit is contained in:
Franck Nijhof 2021-01-04 13:09:08 +01:00 committed by GitHub
parent da1063a456
commit 77ffab25f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -118,8 +118,17 @@ allComponents.pop(); // remove placeholder element at the end
function init() { function init() {
// do the lowerCase transformation once // do the lowerCase transformation once
for (i = 0; i < (allComponents.length); i++) { for (i = 0; i < allComponents.length; i++) {
allComponents[i].titleLC = allComponents[i].title.toLowerCase(); title = allComponents[i].title.toLowerCase();
domain = allComponents[i].domain;
title_normalized = title
.normalize("NFD")
.replace(/[\u0300-\u036f]/g, "");
title_dedashed = title.replace(/[-_]/g, " ");
title_normalized_dedashed = title_normalized.replace(/[-_]/g, " ");
allComponents[i].titleLC = title;
allComponents[i].search = `${title} ${title_normalized} ${title_dedashed} ${title_normalized_dedashed} ${domain}`;
} }
// sort the components alphabetically // sort the components alphabetically
@ -175,8 +184,10 @@ allComponents.pop(); // remove placeholder element at the end
// search through title and category // search through title and category
search = decodeURIComponent(hash).substring(8).toLowerCase(); search = decodeURIComponent(hash).substring(8).toLowerCase();
filter = function (comp) { filter = function (comp) {
return (comp.titleLC.indexOf(search) !== -1) || return (
(comp.cat.find(c => c.includes("#")) != undefined); comp.search.indexOf(search) !== -1 ||
comp.cat.find((c) => c.includes("#")) != undefined
);
}; };
} else if (hash === '#featured' || hash === '') { } else if (hash === '#featured' || hash === '') {