From d75bb7542766f1f1d1964a65303075a7c6cd23a5 Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Thu, 2 May 2024 09:42:14 +0100 Subject: [PATCH] add ds icons --- resources/datasource-active.svg | 6 +++ resources/datasource-connected.svg | 6 +++ resources/datasource.svg | 6 +++ src/extensionVariables.ts | 3 ++ src/utils/core.ts | 10 ++++ test/suite/utils.test.ts | 86 ++++++++++++++++++++++++------ 6 files changed, 101 insertions(+), 16 deletions(-) create mode 100644 resources/datasource-active.svg create mode 100644 resources/datasource-connected.svg create mode 100644 resources/datasource.svg diff --git a/resources/datasource-active.svg b/resources/datasource-active.svg new file mode 100644 index 00000000..8f0e696d --- /dev/null +++ b/resources/datasource-active.svg @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/resources/datasource-connected.svg b/resources/datasource-connected.svg new file mode 100644 index 00000000..8e535452 --- /dev/null +++ b/resources/datasource-connected.svg @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/resources/datasource.svg b/resources/datasource.svg new file mode 100644 index 00000000..e8b46bf6 --- /dev/null +++ b/resources/datasource.svg @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/src/extensionVariables.ts b/src/extensionVariables.ts index 19238a2f..09fa6855 100644 --- a/src/extensionVariables.ts +++ b/src/extensionVariables.ts @@ -37,6 +37,7 @@ import { WorkspaceTreeProvider } from "./services/workspaceTreeProvider"; import { ScratchpadFile } from "./models/scratchpad"; import { LocalConnection } from "./classes/localConnection"; import { InsightsConnection } from "./classes/insightsConnection"; +import { DataSourceFiles } from "./models/dataSource"; // eslint-disable-next-line @typescript-eslint/no-namespace export namespace ext { @@ -53,6 +54,8 @@ export namespace ext { export let runScratchpadItem: StatusBarItem; export const activeScratchPadList: Array = []; export const connectedScratchPadList: Array = []; + export const activeDatasourceList: Array = []; + export const connectedDatasourceList: Array = []; export let serverObjects: ServerObject; export let openSslVersion: string | null; export let resultPanelCSV: string; diff --git a/src/utils/core.ts b/src/utils/core.ts index 64d7423d..6a2f013b 100644 --- a/src/utils/core.ts +++ b/src/utils/core.ts @@ -295,6 +295,16 @@ export function getScratchpadStatusIcon(label: string) { } } +export function getDatasourceStatusIcon(label: string) { + if (ext.activeDatasourceList?.some((ds) => ds.name === label)) { + return "-active"; + } else if (ext.connectedDatasourceList?.some((ds) => ds.name === label)) { + return "-connected"; + } else { + return ""; + } +} + export async function checkLocalInstall(): Promise { const QHOME = workspace.getConfiguration().get("kdb.qHomeDirectory"); if (QHOME || env.QHOME) { diff --git a/test/suite/utils.test.ts b/test/suite/utils.test.ts index 0b5bd9f2..9e12059c 100644 --- a/test/suite/utils.test.ts +++ b/test/suite/utils.test.ts @@ -46,7 +46,7 @@ import { DDateTimeClass, DTimestampClass, } from "../../src/ipc/cClasses"; -import { DataSourceTypes } from "../../src/models/dataSource"; +import { DataSourceFiles, DataSourceTypes } from "../../src/models/dataSource"; import { InsightDetails } from "../../src/models/insights"; import { LocalConnection } from "../../src/classes/localConnection"; import { ScratchpadFile } from "../../src/models/scratchpad"; @@ -101,7 +101,7 @@ describe("Utils", () => { beforeEach(() => { getConfigurationStub = sinon.stub( vscode.workspace, - "getConfiguration" + "getConfiguration", ) as sinon.SinonStub; }); @@ -208,6 +208,60 @@ describe("Utils", () => { }); }); + describe("getDatasourceStatusIcon", () => { + const dsFileDummy: DataSourceFiles = { + name: "test", + dataSource: { + selectedType: DataSourceTypes.API, + api: { + selectedApi: "", + table: "", + startTS: "", + endTS: "", + fill: "zero", + temporality: "snapshot", + filter: [], + groupBy: [], + agg: [], + sortCols: [], + slice: [], + labels: [], + }, + qsql: { + query: "", + selectedTarget: "", + }, + sql: { + query: "", + }, + }, + }; + beforeEach(() => { + ext.activeDatasourceList.length = 0; + ext.connectedDatasourceList.length = 0; + }); + afterEach(() => { + ext.activeDatasourceList.length = 0; + ext.connectedDatasourceList.length = 0; + }); + it("should return active if scratchpad label is on the active list", () => { + ext.activeDatasourceList.push(dsFileDummy); + ext.connectedDatasourceList.push(dsFileDummy); + const result = coreUtils.getDatasourceStatusIcon("test"); + assert.strictEqual(result, "-active"); + }); + it("should return connected if scratchpad label is on the connected list", () => { + ext.connectedDatasourceList.push(dsFileDummy); + const result = coreUtils.getDatasourceStatusIcon("test"); + assert.strictEqual(result, "-connected"); + }); + + it("should return empty string if scratchpad label is not on the active or connected list", () => { + const result = coreUtils.getDatasourceStatusIcon("test"); + assert.strictEqual(result, ""); + }); + }); + describe("getServerIconState", () => { const localConn = new LocalConnection("127.0.0.1:5001", "testLabel"); afterEach(() => { @@ -293,12 +347,12 @@ describe("Utils", () => { it("checkIfTimeParamIsCorrect", () => { const result = dataSourceUtils.checkIfTimeParamIsCorrect( "2021-01-01", - "2021-01-02" + "2021-01-02", ); assert.strictEqual(result, true); const result2 = dataSourceUtils.checkIfTimeParamIsCorrect( "2021-01-02", - "2021-01-01" + "2021-01-01", ); assert.strictEqual(result2, false); }); @@ -537,7 +591,7 @@ describe("Utils", () => { auth: false, tls: false, }, - TreeItemCollapsibleState.None + TreeItemCollapsibleState.None, ); const insightsNode = new InsightsNode( @@ -548,7 +602,7 @@ describe("Utils", () => { alias: "insightsserveralias", auth: true, }, - TreeItemCollapsibleState.None + TreeItemCollapsibleState.None, ); beforeEach(() => { @@ -596,7 +650,7 @@ describe("Utils", () => { assert.strictEqual(ext.kdbQueryHistoryList[0].success, true); assert.strictEqual( ext.kdbQueryHistoryList[0].connectionType, - ServerType.KDB + ServerType.KDB, ); getConfigurationStub.restore(); @@ -619,7 +673,7 @@ describe("Utils", () => { assert.strictEqual(ext.kdbQueryHistoryList[0].success, true); assert.strictEqual( ext.kdbQueryHistoryList[0].connectionType, - ServerType.KDB + ServerType.KDB, ); getConfigurationStub.restore(); }); @@ -636,7 +690,7 @@ describe("Utils", () => { assert.strictEqual(ext.kdbQueryHistoryList[0].success, true); assert.strictEqual( ext.kdbQueryHistoryList[0].connectionType, - ServerType.INSIGHTS + ServerType.INSIGHTS, ); }); @@ -652,7 +706,7 @@ describe("Utils", () => { assert.strictEqual(ext.kdbQueryHistoryList[0].success, false); assert.strictEqual( ext.kdbQueryHistoryList[0].connectionType, - ServerType.KDB + ServerType.KDB, ); }); @@ -668,7 +722,7 @@ describe("Utils", () => { assert.strictEqual(ext.kdbQueryHistoryList[0].success, false); assert.strictEqual( ext.kdbQueryHistoryList[0].connectionType, - ServerType.INSIGHTS + ServerType.INSIGHTS, ); }); @@ -684,7 +738,7 @@ describe("Utils", () => { assert.strictEqual(ext.kdbQueryHistoryList[0].success, false); assert.strictEqual( ext.kdbQueryHistoryList[0].connectionType, - ServerType.undefined + ServerType.undefined, ); }); }); @@ -712,7 +766,7 @@ describe("Utils", () => { connectionName, connectionType, true, - true + true, ); assert.strictEqual(ext.kdbQueryHistoryList.length, 1); }); @@ -749,7 +803,7 @@ describe("Utils", () => { "testPanel", "Test Panel", vscode.ViewColumn.One, - {} + {}, ); const webview = panel.webview; const extensionUri = vscode.Uri.parse("file:///path/to/extension"); @@ -763,7 +817,7 @@ describe("Utils", () => { "testPanel", "Test Panel", vscode.ViewColumn.One, - {} + {}, ); const webview = panel.webview; const extensionUri = vscode.Uri.parse("file:///path/to/extension"); @@ -1129,7 +1183,7 @@ describe("Utils", () => { getConfigurationStub = sinon.stub(vscode.workspace, "getConfiguration"); showInformationMessageStub = sinon.stub( vscode.window, - "showInformationMessage" + "showInformationMessage", ) as sinon.SinonStub< [ message: string,