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); + }); + }); });