Skip to content

Commit

Permalink
feat: search by keywords and 'All' category
Browse files Browse the repository at this point in the history
  • Loading branch information
aswanson-nr committed Sep 16, 2021
1 parent 69fca4a commit ae143d5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
9 changes: 7 additions & 2 deletions src/data/instant-observability-categories.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
[
{
"value": "",
"displayName": "All",
"associatedKeywords": []
},
{
"value": "featured",
"displayName": "Featured",
Expand All @@ -23,7 +28,7 @@
},
{
"value": "browser-and-mobile",
"displayName": "Browser & Mobile",
"displayName": "Browser & mobile",
"associatedKeywords": [
"browser agent",
"mobile agent"
Expand All @@ -45,7 +50,7 @@
},
{
"value": "kubernetes-and-containers",
"displayName": "Kubernetes & Containers",
"displayName": "Kubernetes & containers",
"associatedKeywords": [
"kubernetes",
"containers"
Expand Down
23 changes: 17 additions & 6 deletions src/pages/instant-observability.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,16 @@ const VIEWS = {
* @param {String} search Search term.
* @returns {(Object) => Boolean} Callback function to be used by filter.
*/
const filterBySearch = (search) => ({ name, description }) => {
const filterBySearch = (search) => ({ name, description, keywords }) => {
if (!search) {
return true;
}

const lowerSearch = search.toLowerCase();
return (
!search ||
name.toLowerCase().includes(search.toLowerCase()) ||
description.toLowerCase().includes(search.toLowerCase())
name.toLowerCase().includes(lowerSearch) ||
description.toLowerCase().includes(lowerSearch) ||
keywords.map((s) => s.toLowerCase()).includes(lowerSearch)
);
};

Expand All @@ -69,10 +74,16 @@ const filterByCategory = (category) => {
const associatedKeywords = CATEGORIES.find((cat) => cat.value === category)
?.associatedKeywords;
const isValidCategory = category && associatedKeywords;

return (quickstart) => {
if (!isValidCategory) {
return true;
}

const catKeywords = new Set([...associatedKeywords]);

return (
!isValidCategory ||
(quickstart.keywords && quickstart.keywords.includes(category))
quickstart.keywords && quickstart.keywords.find((k) => catKeywords.has(k))
);
};
};
Expand Down

0 comments on commit ae143d5

Please sign in to comment.