Skip to content

Commit

Permalink
Merge pull request #401 from KxSystems/fix-label-tree
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip-Carneiro-KX authored Aug 14, 2024
2 parents 9bc8ba4 + 01c9da9 commit 8883693
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/services/kdbTreeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { InsightsConnection } from "../classes/insightsConnection";
import {
getWorkspaceLabels,
getWorkspaceLabelsConnMap,
isLabelEmpty,
retrieveConnLabelsNames,
} from "../utils/connLabel";
import { Labels } from "../models/labels";
Expand Down Expand Up @@ -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";
}

Expand Down
8 changes: 8 additions & 0 deletions src/utils/connLabel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
29 changes: 29 additions & 0 deletions test/suite/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

0 comments on commit 8883693

Please sign in to comment.