From ae143d508f62401b5d57c3ce24ee8a8a29baa498 Mon Sep 17 00:00:00 2001 From: aswanson-nr Date: Wed, 15 Sep 2021 16:03:34 -0700 Subject: [PATCH] feat: search by keywords and 'All' category --- .../instant-observability-categories.json | 9 ++++++-- src/pages/instant-observability.js | 23 ++++++++++++++----- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/data/instant-observability-categories.json b/src/data/instant-observability-categories.json index 1bef913c7..d16d63942 100644 --- a/src/data/instant-observability-categories.json +++ b/src/data/instant-observability-categories.json @@ -1,4 +1,9 @@ [ + { + "value": "", + "displayName": "All", + "associatedKeywords": [] + }, { "value": "featured", "displayName": "Featured", @@ -23,7 +28,7 @@ }, { "value": "browser-and-mobile", - "displayName": "Browser & Mobile", + "displayName": "Browser & mobile", "associatedKeywords": [ "browser agent", "mobile agent" @@ -45,7 +50,7 @@ }, { "value": "kubernetes-and-containers", - "displayName": "Kubernetes & Containers", + "displayName": "Kubernetes & containers", "associatedKeywords": [ "kubernetes", "containers" diff --git a/src/pages/instant-observability.js b/src/pages/instant-observability.js index 56366560d..fb638f7d3 100644 --- a/src/pages/instant-observability.js +++ b/src/pages/instant-observability.js @@ -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) ); }; @@ -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)) ); }; };