diff --git a/src/commands/serverCommand.ts b/src/commands/serverCommand.ts index 6c53cb1b..0837fcca 100644 --- a/src/commands/serverCommand.ts +++ b/src/commands/serverCommand.ts @@ -137,7 +137,9 @@ export async function addInsightsConnection( await updateInsights(insights); const newInsights = getInsights(); if (newInsights != undefined) { + ext.latestLblsChanged.length = 0; if (labels && labels.length > 0) { + ext.latestLblsChanged.push(...labels); await handleLabelsConnMap(labels, insightsData.alias); } ext.serverProvider.refreshInsights(newInsights); @@ -224,7 +226,9 @@ export async function editInsightsConnection( const newInsights = getInsights(); if (newInsights != undefined) { + ext.latestLblsChanged.length = 0; if (labels && labels.length > 0) { + ext.latestLblsChanged.push(...labels); await handleLabelsConnMap(labels, insightsData.alias); } else { removeConnFromLabels(insightsData.alias); @@ -386,7 +390,9 @@ export async function addKdbConnection( await updateServers(servers); const newServers = getServers(); if (newServers != undefined) { + ext.latestLblsChanged.length = 0; if (labels && labels.length > 0) { + ext.latestLblsChanged.push(...labels); await handleLabelsConnMap(labels, kdbData.serverAlias); } Telemetry.sendEvent("Connection.Created.QProcess"); @@ -489,7 +495,9 @@ export async function editKdbConnection( } const newServers = getServers(); if (newServers != undefined) { + ext.latestLblsChanged.length = 0; if (labels && labels.length > 0) { + ext.latestLblsChanged.push(...labels); await handleLabelsConnMap(labels, kdbData.serverAlias); } else { removeConnFromLabels(kdbData.serverAlias); diff --git a/src/extensionVariables.ts b/src/extensionVariables.ts index 3a923739..bac7d95e 100644 --- a/src/extensionVariables.ts +++ b/src/extensionVariables.ts @@ -87,6 +87,7 @@ export namespace ext { export const kdbConnectionAliasList: string[] = []; export const connLabelList: Labels[] = []; export const labelConnMapList: ConnectionLabel[] = []; + export const latestLblsChanged: string[] = []; export const maxRetryCount = 5; export let secretSettings: AuthSettings; diff --git a/src/panels/newConnection.ts b/src/panels/newConnection.ts index b6df569f..b20fb989 100644 --- a/src/panels/newConnection.ts +++ b/src/panels/newConnection.ts @@ -72,6 +72,16 @@ export class NewConnectionPannel { } } + public static refreshLabels() { + if (NewConnectionPannel.currentPanel) { + NewConnectionPannel.currentPanel._panel.webview.postMessage({ + command: "refreshLabels", + data: ext.connLabelList, + colors: ext.labelColors, + }); + } + } + private constructor(panel: vscode.WebviewPanel, extensionUri: vscode.Uri) { this._extensionUri = extensionUri; this._panel = panel; diff --git a/src/services/kdbTreeProvider.ts b/src/services/kdbTreeProvider.ts index 10cc8b3e..15638986 100644 --- a/src/services/kdbTreeProvider.ts +++ b/src/services/kdbTreeProvider.ts @@ -44,6 +44,7 @@ import { InsightsConnection } from "../classes/insightsConnection"; import { getWorkspaceLabels, getWorkspaceLabelsConnMap, + isLabelContentChanged, isLabelEmpty, retrieveConnLabelsNames, } from "../utils/connLabel"; @@ -820,12 +821,8 @@ export class LabelNode extends TreeItem { readonly children: TreeItem[] = []; constructor(public readonly source: Labels) { - super( - source.name, - isLabelEmpty(source.name) - ? TreeItemCollapsibleState.None - : TreeItemCollapsibleState.Collapsed, - ); + super(source.name); + this.collapsibleState = this.getCollapsibleState(source.name); this.contextValue = "label"; } @@ -849,4 +846,14 @@ export class LabelNode extends TreeItem { `label-${this.source.color.name.toLowerCase()}.svg`, ), }; + + getCollapsibleState(labelName: string): TreeItemCollapsibleState { + if (isLabelEmpty(labelName)) { + return TreeItemCollapsibleState.None; + } + if (isLabelContentChanged(labelName)) { + return TreeItemCollapsibleState.Expanded; + } + return TreeItemCollapsibleState.Collapsed; + } } diff --git a/src/utils/connLabel.ts b/src/utils/connLabel.ts index 61599384..f2c9f4c9 100644 --- a/src/utils/connLabel.ts +++ b/src/utils/connLabel.ts @@ -16,6 +16,7 @@ import { workspace } from "vscode"; import { ext } from "../extensionVariables"; import { kdbOutputLog } from "./core"; import { InsightsNode, KdbNode } from "../services/kdbTreeProvider"; +import { NewConnectionPannel } from "../panels/newConnection"; export function getWorkspaceLabels() { const existingConnLbls = workspace @@ -144,6 +145,7 @@ export function renameLabel(name: string, newName: string) { .getConfiguration() .update("kdb.connectionLabels", ext.connLabelList, true), ); + NewConnectionPannel.refreshLabels(); } export function setLabelColor(name: string, color: string) { @@ -158,6 +160,7 @@ export function setLabelColor(name: string, color: string) { workspace .getConfiguration() .update("kdb.connectionLabels", ext.connLabelList, true); + NewConnectionPannel.refreshLabels(); } export function deleteLabel(name: string) { @@ -169,6 +172,8 @@ export function deleteLabel(name: string) { workspace .getConfiguration() .update("kdb.connectionLabels", ext.connLabelList, true); + + NewConnectionPannel.refreshLabels(); } export function isLabelEmpty(name: string) { @@ -178,3 +183,11 @@ export function isLabelEmpty(name: string) { } return true; } + +export function isLabelContentChanged(name: string) { + const found = ext.latestLblsChanged.find((item) => item === name); + if (found) { + return true; + } + return false; +} diff --git a/src/webview/components/kdbNewConnectionView.ts b/src/webview/components/kdbNewConnectionView.ts index 5d26fbbd..cc1d551f 100644 --- a/src/webview/components/kdbNewConnectionView.ts +++ b/src/webview/components/kdbNewConnectionView.ts @@ -330,7 +330,7 @@ export class KdbNewConnectionView extends LitElement { renderLblDropdownOptions() { return html` - No Label Selected + No Label Selected ${repeat( this.lblNamesList, (lbl) => lbl.name, @@ -362,6 +362,7 @@ export class KdbNewConnectionView extends LitElement { value="${this.newLblName}" @change="${(event: Event) => { this.newLblName = (event.target as HTMLInputElement).value; + this.requestUpdate(); }}" id="label-name" >Label name @@ -392,7 +394,9 @@ export class KdbNewConnectionView extends LitElement { + @click="${this.createLabel}" + ?disabled="${this.newLblName === "" || + this.newLblColorName === ""}"> Create @@ -423,10 +427,11 @@ export class KdbNewConnectionView extends LitElement { ${this.renderLblDropdownOptions()} @@ -505,6 +510,7 @@ export class KdbNewConnectionView extends LitElement {
${this.renderPortNumber(true)}
${this.renderConnectionLabelsSection()} + ${this.renderCreateConnectionBtn()} @@ -576,6 +582,7 @@ export class KdbNewConnectionView extends LitElement { ${this.renderConnectionLabelsSection()} + ${this.renderCreateConnectionBtn()} @@ -610,22 +617,25 @@ export class KdbNewConnectionView extends LitElement { ${this.renderConnectionLabelsSection()} + ${this.renderCreateConnectionBtn()} -
-
- Create Connection -
-
+
`; } + renderCreateConnectionBtn() { + return html`
+ Create Connection +
`; + } + renderEditConnectionForm() { if (!this.connectionData) { return html`
No connection found to be edited
`; @@ -653,11 +663,9 @@ export class KdbNewConnectionView extends LitElement {
${this.renderEditConnFields()}
${this.renderConnectionLabelsSection()}
- -
Edit ConnectionUpdate Connection
@@ -885,6 +893,7 @@ export class KdbNewConnectionView extends LitElement { }, }); setTimeout(() => { + this.labels[0] = this.newLblName; this.closeModal(); }, 500); } diff --git a/test/suite/panels.test.ts b/test/suite/panels.test.ts index 836b1370..71570fc8 100644 --- a/test/suite/panels.test.ts +++ b/test/suite/panels.test.ts @@ -555,5 +555,14 @@ describe("WebPanels", () => { "Panel HTML should include expected web component", ); }); + + it("should refreshLabels", () => { + NewConnectionPannel.render(uriTest); + NewConnectionPannel.refreshLabels(); + assert.ok( + NewConnectionPannel.currentPanel, + "NewConnectionPannel.currentPanel should be truthy", + ); + }); }); }); diff --git a/test/suite/utils.test.ts b/test/suite/utils.test.ts index d7dcc39f..5e55684a 100644 --- a/test/suite/utils.test.ts +++ b/test/suite/utils.test.ts @@ -1813,4 +1813,25 @@ describe("Utils", () => { assert.strictEqual(result, true); }); }); + + describe("isLabelContentChanged", () => { + beforeEach(() => { + ext.latestLblsChanged.length = 0; + }); + + afterEach(() => { + ext.latestLblsChanged.length = 0; + }); + + it("should return true if label content is changed", () => { + ext.latestLblsChanged.push("label1"); + const result = LabelsUtils.isLabelContentChanged("label1"); + assert.strictEqual(result, true); + }); + + it("should return false if label content is not changed", () => { + const result = LabelsUtils.isLabelContentChanged("label1"); + assert.strictEqual(result, false); + }); + }); }); diff --git a/test/suite/webview.test.ts b/test/suite/webview.test.ts index d5fd1bc8..e239b6dd 100644 --- a/test/suite/webview.test.ts +++ b/test/suite/webview.test.ts @@ -585,6 +585,17 @@ describe("KdbNewConnectionView", () => { }); }); + describe("renderCreateConnectionBtn", () => { + it("should render create connection button", () => { + const result = view.renderCreateConnectionBtn(); + + assert.strictEqual( + JSON.stringify(result).includes("Create Connection"), + true, + ); + }); + }); + describe("renderEditConnectionForm", () => { it('should return "No connection found to be edited" when connectionData is null', () => { view.connectionData = null;