Skip to content

Commit

Permalink
Merge pull request #403 from KxSystems/larry-new-conn-requests
Browse files Browse the repository at this point in the history
Larry change requests
  • Loading branch information
Philip-Carneiro-KX authored Aug 16, 2024
2 parents db77f14 + f32f58d commit 28ed191
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 21 deletions.
8 changes: 8 additions & 0 deletions src/commands/serverCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/extensionVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/panels/newConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 13 additions & 6 deletions 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,
isLabelContentChanged,
isLabelEmpty,
retrieveConnLabelsNames,
} from "../utils/connLabel";
Expand Down Expand Up @@ -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";
}

Expand All @@ -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;
}
}
13 changes: 13 additions & 0 deletions src/utils/connLabel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -169,6 +172,8 @@ export function deleteLabel(name: string) {
workspace
.getConfiguration()
.update("kdb.connectionLabels", ext.connLabelList, true);

NewConnectionPannel.refreshLabels();
}

export function isLabelEmpty(name: string) {
Expand All @@ -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;
}
39 changes: 24 additions & 15 deletions src/webview/components/kdbNewConnectionView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export class KdbNewConnectionView extends LitElement {

renderLblDropdownOptions() {
return html`
<vscode-option .value="${undefined}"> No Label Selected </vscode-option>
<vscode-option> No Label Selected </vscode-option>
${repeat(
this.lblNamesList,
(lbl) => lbl.name,
Expand Down Expand Up @@ -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</vscode-text-field
Expand All @@ -376,6 +377,7 @@ export class KdbNewConnectionView extends LitElement {
value="${this.newLblColorName}"
@change="${(event: Event) => {
this.newLblColorName = (event.target as HTMLInputElement).value;
this.requestUpdate();
}}"
class="dropdown"
style="width: 18.5em;">
Expand All @@ -392,7 +394,9 @@ export class KdbNewConnectionView extends LitElement {
<vscode-button
aria-label="Create Label"
appearance="primary"
@click="${this.createLabel}">
@click="${this.createLabel}"
?disabled="${this.newLblName === "" ||
this.newLblColorName === ""}">
Create
</vscode-button>
</div>
Expand Down Expand Up @@ -423,10 +427,11 @@ export class KdbNewConnectionView extends LitElement {
<vscode-dropdown
id="selectLabel"
class="dropdown larger"
value="${this.labels.length > 0 ? this.labels[0] : ""}"
value="${this.labels[0]}"
current-value="${this.labels[0]}"
@change="${(event: Event) => {
this.labels.length = 0;
this.labels.push((event.target as HTMLInputElement).value);
this.labels[0] = (event.target as HTMLInputElement).value;
this.requestUpdate();
}}">
${this.renderLblDropdownOptions()}
</vscode-dropdown>
Expand Down Expand Up @@ -505,6 +510,7 @@ export class KdbNewConnectionView extends LitElement {
<div class="col gap-0">${this.renderPortNumber(true)}</div>
</div>
${this.renderConnectionLabelsSection()}
${this.renderCreateConnectionBtn()}
</div>
</vscode-panel-view>
<vscode-panel-view id="view-2" class="panel">
Expand Down Expand Up @@ -576,6 +582,7 @@ export class KdbNewConnectionView extends LitElement {
</div>
</div>
${this.renderConnectionLabelsSection()}
${this.renderCreateConnectionBtn()}
</div>
</vscode-panel-view>
<vscode-panel-view id="view-3" class="panel">
Expand Down Expand Up @@ -610,22 +617,25 @@ export class KdbNewConnectionView extends LitElement {
</div>
</div>
${this.renderConnectionLabelsSection()}
${this.renderCreateConnectionBtn()}
</div>
</vscode-panel-view>
</vscode-panels>
</div>
</div>
<div class="col">
<div class="row">
<vscode-button @click="${() => this.save()}"
>Create Connection</vscode-button
>
</div>
</div>
<div class="col"></div>
</div>
`;
}

renderCreateConnectionBtn() {
return html`<div class="row">
<vscode-button @click="${() => this.save()}"
>Create Connection</vscode-button
>
</div>`;
}

renderEditConnectionForm() {
if (!this.connectionData) {
return html`<div>No connection found to be edited</div>`;
Expand Down Expand Up @@ -653,11 +663,9 @@ export class KdbNewConnectionView extends LitElement {
</div>
<div class="row">${this.renderEditConnFields()}</div>
<div class="row">${this.renderConnectionLabelsSection()}</div>
</div>
<div class="col">
<div class="row">
<vscode-button @click="${() => this.editConnection()}"
>Edit Connection</vscode-button
>Update Connection</vscode-button
>
</div>
</div>
Expand Down Expand Up @@ -885,6 +893,7 @@ export class KdbNewConnectionView extends LitElement {
},
});
setTimeout(() => {
this.labels[0] = this.newLblName;
this.closeModal();
}, 500);
}
Expand Down
9 changes: 9 additions & 0 deletions test/suite/panels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
);
});
});
});
21 changes: 21 additions & 0 deletions test/suite/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
11 changes: 11 additions & 0 deletions test/suite/webview.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 28ed191

Please sign in to comment.