From 01c9da9ec56b03d025e7ea748228d43752e18ec3 Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Wed, 14 Aug 2024 13:55:38 +0100 Subject: [PATCH] fix labels collapse at conn tree --- src/services/kdbTreeProvider.ts | 8 +++++++- src/utils/connLabel.ts | 8 ++++++++ test/suite/utils.test.ts | 29 +++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/services/kdbTreeProvider.ts b/src/services/kdbTreeProvider.ts index 2eb52bbd..10cc8b3e 100644 --- a/src/services/kdbTreeProvider.ts +++ b/src/services/kdbTreeProvider.ts @@ -44,6 +44,7 @@ import { InsightsConnection } from "../classes/insightsConnection"; import { getWorkspaceLabels, getWorkspaceLabelsConnMap, + isLabelEmpty, retrieveConnLabelsNames, } from "../utils/connLabel"; import { Labels } from "../models/labels"; @@ -819,7 +820,12 @@ export class LabelNode extends TreeItem { readonly children: TreeItem[] = []; constructor(public readonly source: Labels) { - super(source.name, TreeItemCollapsibleState.Collapsed); + super( + source.name, + isLabelEmpty(source.name) + ? TreeItemCollapsibleState.None + : TreeItemCollapsibleState.Collapsed, + ); this.contextValue = "label"; } diff --git a/src/utils/connLabel.ts b/src/utils/connLabel.ts index aca981e4..61599384 100644 --- a/src/utils/connLabel.ts +++ b/src/utils/connLabel.ts @@ -170,3 +170,11 @@ export function deleteLabel(name: string) { .getConfiguration() .update("kdb.connectionLabels", ext.connLabelList, true); } + +export function isLabelEmpty(name: string) { + const found = ext.labelConnMapList.find((item) => item.labelName === name); + if (found) { + return found.connections.length === 0; + } + return true; +} diff --git a/test/suite/utils.test.ts b/test/suite/utils.test.ts index 0a57a533..d7dcc39f 100644 --- a/test/suite/utils.test.ts +++ b/test/suite/utils.test.ts @@ -1784,4 +1784,33 @@ describe("Utils", () => { assert.strictEqual(ext.connLabelList.length, 0); }); }); + + describe("isLabelEmpty", () => { + beforeEach(() => { + ext.labelConnMapList.length = 0; + }); + + afterEach(() => { + ext.labelConnMapList.length = 0; + }); + it("should return true if label is empty", () => { + ext.labelConnMapList.push({ labelName: "label1", connections: [] }); + const result = LabelsUtils.isLabelEmpty("label1"); + assert.strictEqual(result, true); + }); + + it("should return false if label is not empty", () => { + ext.labelConnMapList.push({ + labelName: "label1", + connections: ["conn1"], + }); + const result = LabelsUtils.isLabelEmpty("label1"); + assert.strictEqual(result, false); + }); + + it("should return false if label is empty if label not on map list", () => { + const result = LabelsUtils.isLabelEmpty("label1"); + assert.strictEqual(result, true); + }); + }); });