From 31510a5ca9f5c2c496c894076940ea1afee12510 Mon Sep 17 00:00:00 2001 From: aswanson-nr Date: Wed, 15 Sep 2021 14:26:04 -0700 Subject: [PATCH] feat: add categories to filter the catalog --- .../instant-observability-categories.json | 89 ++++++++++++++ src/pages/instant-observability.js | 113 +++++++++--------- 2 files changed, 146 insertions(+), 56 deletions(-) create mode 100644 src/data/instant-observability-categories.json diff --git a/src/data/instant-observability-categories.json b/src/data/instant-observability-categories.json new file mode 100644 index 000000000..1bef913c7 --- /dev/null +++ b/src/data/instant-observability-categories.json @@ -0,0 +1,89 @@ +[ + { + "value": "featured", + "displayName": "Featured", + "associatedKeywords": [ + "featured" + ] + }, + { + "value": "apm-application-monitoring", + "displayName": "APM (Application monitoring)", + "associatedKeywords": [ + "language agent" + ] + }, + { + "value": "infrastructure-and-os", + "displayName": "Infrastructure & OS", + "associatedKeywords": [ + "os", + "infrastructure" + ] + }, + { + "value": "browser-and-mobile", + "displayName": "Browser & Mobile", + "associatedKeywords": [ + "browser agent", + "mobile agent" + ] + }, + { + "value": "simulate-traffic", + "displayName": "Simulate traffic", + "associatedKeywords": [ + "synthetics" + ] + }, + { + "value": "logging", + "displayName": "Logging", + "associatedKeywords": [ + "logs" + ] + }, + { + "value": "kubernetes-and-containers", + "displayName": "Kubernetes & Containers", + "associatedKeywords": [ + "kubernetes", + "containers" + ] + }, + { + "value": "aws-amazon-web-services", + "displayName": "AWS (Amazon Web Services)", + "associatedKeywords": [ + "aws" + ] + }, + { + "value": "azure", + "displayName": "Azure", + "associatedKeywords": [ + "azure" + ] + }, + { + "value": "gcp-google-cloud-platform", + "displayName": "GCP (Google Cloud Platform)", + "associatedKeywords": [ + "gcp" + ] + }, + { + "value": "open-source-monitoring", + "displayName": "Open source monitoring", + "associatedKeywords": [ + "open source monitoring" + ] + }, + { + "value": "mlops", + "displayName": "MLOps", + "associatedKeywords": [ + "mlops" + ] + } +] diff --git a/src/pages/instant-observability.js b/src/pages/instant-observability.js index fe8342cdf..00577857f 100644 --- a/src/pages/instant-observability.js +++ b/src/pages/instant-observability.js @@ -24,10 +24,7 @@ import { useDebounce } from 'react-use'; import { sortFeaturedQuickstarts } from '../utils/sortFeaturedQuickstarts'; const { QUICKSTARTS_REPO } = require('../data/constants'); - -const CATEGORIES = [ - { name: 'Featured', type: 'featured', icon: 'nr-relicans' }, -]; +const CATEGORIES = require('../data/instant-observability-categories'); const FILTERS = [ { name: 'All', type: '', icon: 'nr-all-entities' }, @@ -65,11 +62,19 @@ const filterByContentType = (type) => (quickstart) => { /** * Filters a quickstart based on a category. - * @param {String} type The category type (e.g. 'featured'). + * @param {String} category The category type (e.g. 'featured'). * @returns {(Object) => Boolean} Callback function to be used by filter. */ -const filterByCategory = (type) => (quickstart) => { - return !type || (quickstart.keywords && quickstart.keywords.includes(type)); +const filterByCategory = (category) => { + const associatedKeywords = CATEGORIES.find((cat) => cat.value === category) + ?.associatedKeywords; + const isValidCategory = category && associatedKeywords; + return (quickstart) => { + return ( + !isValidCategory || + (quickstart.keywords && quickstart.keywords.includes(category)) + ); + }; }; const QuickstartsPage = ({ data, location }) => { @@ -233,56 +238,52 @@ const QuickstartsPage = ({ data, location }) => { margin-bottom: 1.5rem; `} /> - - - {isMobile ? ( - - ) : ( - CATEGORIES.map(({ name, type, icon }) => ( - + )) + )} + + {isMobile ? (