From d2c9712384ce41d4442be222b14e166c8fc4be03 Mon Sep 17 00:00:00 2001 From: Fabian Rodriguez Date: Wed, 18 Dec 2024 20:38:31 -0300 Subject: [PATCH] WIP: Add hub filters and update categories to use text instead of name for consistency TODO: update url with query params and filters based on the query params --- app/_assets/entrypoints/hub.js | 83 +++++++++++++++++++++++++++++++++ app/_data/plugin_categories.yml | 16 +++---- app/_includes/cards/plugin.html | 10 +++- app/_includes/checkbox.html | 3 ++ app/_layouts/default.html | 4 ++ app/plugins.html | 25 ++++------ 6 files changed, 114 insertions(+), 27 deletions(-) create mode 100644 app/_assets/entrypoints/hub.js create mode 100644 app/_includes/checkbox.html diff --git a/app/_assets/entrypoints/hub.js b/app/_assets/entrypoints/hub.js new file mode 100644 index 00000000..390511ae --- /dev/null +++ b/app/_assets/entrypoints/hub.js @@ -0,0 +1,83 @@ +class Hub { + constructor() { + this.filters = document.getElementById("filters"); + this.plugins = document.querySelectorAll("[data-card='plugin']"); + + this.deploymentTopologies = this.filters.querySelectorAll( + 'input[name="deployment-topology"]' + ); + this.categories = this.filters.querySelectorAll('input[name="category"]'); + + this.deploymentValues = []; + this.categoryValues = []; + + this.addEventListeners(); + } + + addEventListeners() { + const checkboxes = [...this.deploymentTopologies, ...this.categories]; + checkboxes.forEach((checkbox) => { + checkbox.addEventListener("change", () => this.onChange()); + }); + } + + onChange() { + this.deploymentValues = this.getValues(this.deploymentTopologies); + this.categoryValues = this.getValues(this.categories); + + this.filterPlugins(); + } + + getValues(filterGroup) { + return Array.from(filterGroup) + .filter((checkbox) => checkbox.checked) + .map((checkbox) => checkbox.value); + } + + filterPlugins() { + this.plugins.forEach((plugin) => { + const matchesDeploymentTopology = this.filterBy( + plugin, + this.deploymentTopologies, + "deploymentTopology" + ); + const matchesCategory = this.filterBy( + plugin, + this.categories, + "category" + ); + + const showPlugin = matchesDeploymentTopology && matchesCategory; + + plugin.classList.toggle("hidden", !showPlugin); + }); + + this.toggleCategoriesIfEmpty(); + } + + toggleCategoriesIfEmpty() { + this.categories.forEach((cat) => { + const category = document.getElementById(cat.value); + const showCategory = category.querySelectorAll( + '[data-card="plugin"]:not(.hidden)' + ).length; + + category.classList.toggle("hidden", !showCategory); + }); + } + + filterBy(plugin, filterGroup, dataAttribute) { + const checkedValues = Array.from(filterGroup) + .filter((checkbox) => checkbox.checked) + .map((checkbox) => checkbox.value); + + const dataValues = plugin.dataset[dataAttribute]?.split(",") || []; + return ( + checkedValues.length === 0 || + checkedValues.some((value) => dataValues.includes(value)) + ); + } +} + +// Initialize the Hub once the DOM is fully loaded +document.addEventListener("DOMContentLoaded", () => new Hub()); diff --git a/app/_data/plugin_categories.yml b/app/_data/plugin_categories.yml index 533ad18b..6afce132 100644 --- a/app/_data/plugin_categories.yml +++ b/app/_data/plugin_categories.yml @@ -1,24 +1,24 @@ -- name: AI +- text: AI slug: ai desc: Govern, secure, and control AI traffic with multi-LLM AI Gateway plugins -- name: Authentication +- text: Authentication slug: authentication desc: Protect your services with an authentication layer -- name: Security +- text: Security slug: security desc: Protect your services with additional security layer -- name: Traffic Control +- text: Traffic Control slug: traffic-control desc: Manage, throttle and restrict inbound and outbound API traffic -- name: Serverless +- text: Serverless slug: serverless desc: Invoke serverless functions in combination with other plugins -- name: Analytics & Monitoring +- text: Analytics & Monitoring slug: analytics-monitoring desc: Visualize, inspect and monitor APIs and microservices traffic -- name: Transformations +- text: Transformations slug: transformations desc: Transform request and responses on the fly on Kong -- name: Logging +- text: Logging slug: logging desc: Log request and response data using the best transport for your infrastructure \ No newline at end of file diff --git a/app/_includes/cards/plugin.html b/app/_includes/cards/plugin.html index 704cffd2..f1217fb9 100644 --- a/app/_includes/cards/plugin.html +++ b/app/_includes/cards/plugin.html @@ -1,6 +1,12 @@ {% assign plugin = include.plugin %} -
+ {% endif %} -
\ No newline at end of file + diff --git a/app/_includes/checkbox.html b/app/_includes/checkbox.html new file mode 100644 index 00000000..507a07e3 --- /dev/null +++ b/app/_includes/checkbox.html @@ -0,0 +1,3 @@ +
+ +
\ No newline at end of file diff --git a/app/_layouts/default.html b/app/_layouts/default.html index e4103d45..4b196b62 100644 --- a/app/_layouts/default.html +++ b/app/_layouts/default.html @@ -45,6 +45,10 @@ {% if layout.plugin_schema %} {% vite_javascript_tag plugin_schema %} {% endif %} + + {% if page.hub %} + {% vite_javascript_tag hub %} + {% endif %} diff --git a/app/plugins.html b/app/plugins.html index be1ad7dd..54d8b51c 100644 --- a/app/plugins.html +++ b/app/plugins.html @@ -1,5 +1,6 @@ --- title: Plugins +hub: true layout: default --- @@ -49,21 +50,16 @@

Kong Plugins

- {% assign categories = site.data.plugin_categories | sort: "name" %} + {% assign categories = site.data.plugin_categories | sort: "text" %} {% assign kong_plugins = site.data.kong_plugins %}
-
+
Deployment Platforms
{% for deployment_topology in site.data.products.gateway.deployment_topologies %} -
- -
+ {% include checkbox.html value=deployment_topology.slug name="deployment-topology" label=deployment_topology.text %} {% endfor %}
@@ -72,12 +68,7 @@

Kong Plugins

{% for category in categories %} -
- -
+ {% include checkbox.html value=category.slug name="category" label=category.text %} {% endfor %}
@@ -85,10 +76,10 @@

Kong Plugins

{% for cat in categories %} - {% assign plugins_for_category = kong_plugins | where_exp: "plugin", "plugin.categories contains cat.slug" | sort: "name" %} + {% assign plugins_for_category = kong_plugins | where_exp: "plugin", "plugin.categories contains cat.slug" | sort: "text" %} {% if plugins_for_category.size > 0 %} -
-

{{ cat.name }}

+
+

{{ cat.text }}

{% for plugin in plugins_for_category %}