From b60c04c9aac83f0439e28f64658fb8159e47adc3 Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Fri, 16 Aug 2024 09:28:04 +0100 Subject: [PATCH 1/8] fix rename and delete labels --- src/panels/newConnection.ts | 10 ++++++++++ src/utils/connLabel.ts | 5 +++++ 2 files changed, 15 insertions(+) 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/utils/connLabel.ts b/src/utils/connLabel.ts index 61599384..6bd6ebc3 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) { From 9bc01f766f8a5d3e99cdc111272f83716e62a4b8 Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Fri, 16 Aug 2024 09:44:35 +0100 Subject: [PATCH 2/8] select label when create --- .../components/kdbNewConnectionView.ts | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/webview/components/kdbNewConnectionView.ts b/src/webview/components/kdbNewConnectionView.ts index 5d26fbbd..83ec2101 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, @@ -423,10 +423,11 @@ export class KdbNewConnectionView extends LitElement { ${this.renderLblDropdownOptions()} @@ -505,6 +506,7 @@ export class KdbNewConnectionView extends LitElement {
${this.renderPortNumber(true)}
${this.renderConnectionLabelsSection()} + ${this.renderCreateConnectionBtn()} @@ -576,6 +578,7 @@ export class KdbNewConnectionView extends LitElement { ${this.renderConnectionLabelsSection()} + ${this.renderCreateConnectionBtn()} @@ -610,22 +613,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 +659,9 @@ export class KdbNewConnectionView extends LitElement {
${this.renderEditConnFields()}
${this.renderConnectionLabelsSection()}
- -
Edit ConnectionUpdate Connection
@@ -885,6 +889,7 @@ export class KdbNewConnectionView extends LitElement { }, }); setTimeout(() => { + this.labels[0] = this.newLblName; this.closeModal(); }, 500); } From c33fd9c5eee8955fb99d3adb5e368145f77a457a Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Fri, 16 Aug 2024 09:50:07 +0100 Subject: [PATCH 3/8] disable create lbl btn --- src/webview/components/kdbNewConnectionView.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/webview/components/kdbNewConnectionView.ts b/src/webview/components/kdbNewConnectionView.ts index 83ec2101..cc1d551f 100644 --- a/src/webview/components/kdbNewConnectionView.ts +++ b/src/webview/components/kdbNewConnectionView.ts @@ -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 From 6d89692461087bf307ea083a6ed867ec8e94d9ae Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Fri, 16 Aug 2024 10:12:40 +0100 Subject: [PATCH 4/8] add refresh labels to expand label when changed --- src/commands/serverCommand.ts | 8 ++++++++ src/extensionVariables.ts | 1 + src/services/kdbTreeProvider.ts | 5 ++++- src/utils/connLabel.ts | 9 +++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/commands/serverCommand.ts b/src/commands/serverCommand.ts index 6c53cb1b..55cbbc0a 100644 --- a/src/commands/serverCommand.ts +++ b/src/commands/serverCommand.ts @@ -138,6 +138,8 @@ export async function addInsightsConnection( const newInsights = getInsights(); if (newInsights != undefined) { if (labels && labels.length > 0) { + ext.latestLblsChanged.length = 0; + ext.latestLblsChanged.push(...labels); await handleLabelsConnMap(labels, insightsData.alias); } ext.serverProvider.refreshInsights(newInsights); @@ -225,6 +227,8 @@ export async function editInsightsConnection( const newInsights = getInsights(); if (newInsights != undefined) { if (labels && labels.length > 0) { + ext.latestLblsChanged.length = 0; + ext.latestLblsChanged.push(...labels); await handleLabelsConnMap(labels, insightsData.alias); } else { removeConnFromLabels(insightsData.alias); @@ -387,6 +391,8 @@ export async function addKdbConnection( const newServers = getServers(); if (newServers != undefined) { if (labels && labels.length > 0) { + ext.latestLblsChanged.length = 0; + ext.latestLblsChanged.push(...labels); await handleLabelsConnMap(labels, kdbData.serverAlias); } Telemetry.sendEvent("Connection.Created.QProcess"); @@ -490,6 +496,8 @@ export async function editKdbConnection( const newServers = getServers(); if (newServers != undefined) { if (labels && labels.length > 0) { + ext.latestLblsChanged.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/services/kdbTreeProvider.ts b/src/services/kdbTreeProvider.ts index 10cc8b3e..a151b768 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"; @@ -824,7 +825,9 @@ export class LabelNode extends TreeItem { source.name, isLabelEmpty(source.name) ? TreeItemCollapsibleState.None - : TreeItemCollapsibleState.Collapsed, + : isLabelContentChanged(source.name) + ? TreeItemCollapsibleState.Expanded + : TreeItemCollapsibleState.Collapsed, ); this.contextValue = "label"; } diff --git a/src/utils/connLabel.ts b/src/utils/connLabel.ts index 6bd6ebc3..ff869b2c 100644 --- a/src/utils/connLabel.ts +++ b/src/utils/connLabel.ts @@ -183,3 +183,12 @@ export function isLabelEmpty(name: string) { } return true; } + +export function isLabelContentChanged(name: string) { + const found = ext.latestLblsChanged.find((item) => item === name); + if (found) { + ext.latestLblsChanged.length = 0; + return true; + } + return false; +} From a9f951419e641612629619c3de5c999f89881fd6 Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Fri, 16 Aug 2024 11:05:07 +0100 Subject: [PATCH 5/8] improve code quality --- src/commands/serverCommand.ts | 8 ++++---- src/utils/connLabel.ts | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/commands/serverCommand.ts b/src/commands/serverCommand.ts index 55cbbc0a..0837fcca 100644 --- a/src/commands/serverCommand.ts +++ b/src/commands/serverCommand.ts @@ -137,8 +137,8 @@ export async function addInsightsConnection( await updateInsights(insights); const newInsights = getInsights(); if (newInsights != undefined) { + ext.latestLblsChanged.length = 0; if (labels && labels.length > 0) { - ext.latestLblsChanged.length = 0; ext.latestLblsChanged.push(...labels); await handleLabelsConnMap(labels, insightsData.alias); } @@ -226,8 +226,8 @@ export async function editInsightsConnection( const newInsights = getInsights(); if (newInsights != undefined) { + ext.latestLblsChanged.length = 0; if (labels && labels.length > 0) { - ext.latestLblsChanged.length = 0; ext.latestLblsChanged.push(...labels); await handleLabelsConnMap(labels, insightsData.alias); } else { @@ -390,8 +390,8 @@ export async function addKdbConnection( await updateServers(servers); const newServers = getServers(); if (newServers != undefined) { + ext.latestLblsChanged.length = 0; if (labels && labels.length > 0) { - ext.latestLblsChanged.length = 0; ext.latestLblsChanged.push(...labels); await handleLabelsConnMap(labels, kdbData.serverAlias); } @@ -495,8 +495,8 @@ export async function editKdbConnection( } const newServers = getServers(); if (newServers != undefined) { + ext.latestLblsChanged.length = 0; if (labels && labels.length > 0) { - ext.latestLblsChanged.length = 0; ext.latestLblsChanged.push(...labels); await handleLabelsConnMap(labels, kdbData.serverAlias); } else { diff --git a/src/utils/connLabel.ts b/src/utils/connLabel.ts index ff869b2c..f2c9f4c9 100644 --- a/src/utils/connLabel.ts +++ b/src/utils/connLabel.ts @@ -187,7 +187,6 @@ export function isLabelEmpty(name: string) { export function isLabelContentChanged(name: string) { const found = ext.latestLblsChanged.find((item) => item === name); if (found) { - ext.latestLblsChanged.length = 0; return true; } return false; From 31120e8d8151a18902e4bc353ac19c838ea264d9 Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Fri, 16 Aug 2024 11:17:36 +0100 Subject: [PATCH 6/8] add tests --- test/suite/utils.test.ts | 21 +++++++++++++++++++++ test/suite/webview.test.ts | 11 +++++++++++ 2 files changed, 32 insertions(+) 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; From b7ab2255fd3c17b64d4aec017a3f99d85743471b Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Fri, 16 Aug 2024 11:24:09 +0100 Subject: [PATCH 7/8] add more tests --- test/suite/panels.test.ts | 9 +++++++++ 1 file changed, 9 insertions(+) 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", + ); + }); }); }); From f32f58dc1eb737d358527a709381f9b4390acf89 Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Fri, 16 Aug 2024 11:30:39 +0100 Subject: [PATCH 8/8] improve code quality --- src/services/kdbTreeProvider.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/services/kdbTreeProvider.ts b/src/services/kdbTreeProvider.ts index a151b768..15638986 100644 --- a/src/services/kdbTreeProvider.ts +++ b/src/services/kdbTreeProvider.ts @@ -821,14 +821,8 @@ export class LabelNode extends TreeItem { readonly children: TreeItem[] = []; constructor(public readonly source: Labels) { - super( - source.name, - isLabelEmpty(source.name) - ? TreeItemCollapsibleState.None - : isLabelContentChanged(source.name) - ? TreeItemCollapsibleState.Expanded - : TreeItemCollapsibleState.Collapsed, - ); + super(source.name); + this.collapsibleState = this.getCollapsibleState(source.name); this.contextValue = "label"; } @@ -852,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; + } }