From 15adeb7cfa3ed5010a630e5a22dce102faf02fa1 Mon Sep 17 00:00:00 2001 From: Andrey Pokhilko Date: Thu, 24 Nov 2022 11:21:20 +0000 Subject: [PATCH] Only display NS that has charts (#113) --- pkg/dashboard/static/list-view.js | 15 +++++++++++++-- pkg/dashboard/static/scripts.js | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pkg/dashboard/static/list-view.js b/pkg/dashboard/static/list-view.js index 5280bc7f..28d98321 100644 --- a/pkg/dashboard/static/list-view.js +++ b/pkg/dashboard/static/list-view.js @@ -9,12 +9,24 @@ function loadChartsList() { }).done(function (data) { chartsCards.empty().hide() $("#installedList .header h2 span").text(data.length) + const usedNS = {} data.forEach(function (elm) { let card = buildChartCard(elm); chartsCards.append(card) + usedNS[elm.namespace] = usedNS[elm.namespace] ? usedNS[elm.namespace] + 1 : 1 }) sendStats('Get releases', {'status': 'success', length:data.length}); filterInstalledList(chartsCards.find(".row")) + $("#namespace li").each(function (ix, obj) { + obj = $(obj) + const objNS = obj.find("input").val(); + if (usedNS[objNS]) { + obj.find("label .text-muted").text('['+usedNS[objNS]+']') + obj.show() + } else { + obj.hide() + } + }) chartsCards.show() if (!data.length) { $("#installedList .no-charts").show() @@ -22,7 +34,6 @@ function loadChartsList() { }) } - function buildChartCard(elm) { const card = $(``) - + // semver2 regex , add optional v prefix const chartNameRegex = 'v?(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?' const chartName = elm.chart.substring(0, elm.chart.match(chartNameRegex).index - 1) diff --git a/pkg/dashboard/static/scripts.js b/pkg/dashboard/static/scripts.js index 8e773587..e86b0736 100644 --- a/pkg/dashboard/static/scripts.js +++ b/pkg/dashboard/static/scripts.js @@ -212,7 +212,7 @@ function fillNamespaceList(data) { } Array.from(data).forEach(function (elm) { const filteredNamespace = getHashParam("filteredNamespace") - let opt = $('
  • '); + let opt = $(''); opt.attr('title', elm.metadata.name) opt.find("input").val(elm.metadata.name).text(elm.metadata.name) opt.find("span").text(elm.metadata.name)