diff --git a/CHANGELOG.md b/CHANGELOG.md index e4e96990..f7da10d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to the **kdb VS Code extension** are documented in this file. +# v1.9.1 + +### Fixes + +- Fixed Insights version validation + # v1.9.0 ### Enhancements diff --git a/package-lock.json b/package-lock.json index 44769652..e6d96686 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "kdb", - "version": "1.9.0", + "version": "1.9.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "kdb", - "version": "1.9.0", + "version": "1.9.1", "license": "MIT", "dependencies": { "@vscode/webview-ui-toolkit": "^1.4.0", diff --git a/package.json b/package.json index 5937e267..06fcc7da 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "displayName": "kdb", "description": "IDE support for kdb product suite including the q programming language", "publisher": "KX", - "version": "1.9.0", + "version": "1.9.1", "engines": { "vscode": "^1.86.0" }, diff --git a/src/classes/insightsConnection.ts b/src/classes/insightsConnection.ts index 6283ba47..c8cfad57 100644 --- a/src/classes/insightsConnection.ts +++ b/src/classes/insightsConnection.ts @@ -29,6 +29,7 @@ import { JwtUser } from "../models/jwt_user"; import { Telemetry } from "../utils/telemetryClient"; import { handleScratchpadTableRes, handleWSResults } from "../utils/queryUtils"; import { + compareVersions, invalidUsernameJWT, kdbOutputLog, tokenUndefinedError, @@ -170,7 +171,7 @@ export class InsightsConnection { }; // uncomment this WHEN the insights version is available // if (this.insightsVersion) { - // if (this.insightsVersion >= 1.12) { + // if (compareVersions(this.insightsVersion, 1.12)) { // this.connEndpoints = { // scratchpad: { // scratchpad: "scratchpad/execute/display", @@ -432,7 +433,7 @@ export class InsightsConnection { }; if (this.insightsVersion) { - if (this.insightsVersion >= 1.12) { + if (compareVersions(this.insightsVersion, 1.12)) { body.returnFormat = isTableView ? "structuredText" : "text"; } else { body.isTableView = isTableView; @@ -476,7 +477,10 @@ export class InsightsConnection { kdbOutputLog(`[SCRATCHPAD] Status: ${response.status}`, "INFO"); if (!response.data.error) { if (isTableView) { - if (this.insightsVersion && this.insightsVersion >= 1.12) { + if ( + this.insightsVersion && + compareVersions(this.insightsVersion, 1.12) + ) { response.data = JSON.parse( response.data.data, ) as StructuredTextResults; diff --git a/src/services/connectionManagerService.ts b/src/services/connectionManagerService.ts index 3f439d8a..baaf9b76 100644 --- a/src/services/connectionManagerService.ts +++ b/src/services/connectionManagerService.ts @@ -19,6 +19,7 @@ import { Telemetry } from "../utils/telemetryClient"; import { InsightsConnection } from "../classes/insightsConnection"; import { sanitizeQuery } from "../utils/queryUtils"; import { + compareVersions, getInsights, getKeyForServerName, getServerName, @@ -353,7 +354,7 @@ export class ConnectionManagementService { if ( ext.activeConnection.insightsVersion && - ext.activeConnection.insightsVersion >= 1.12 + compareVersions(ext.activeConnection.insightsVersion, 1.12) ) { const confirmationPrompt = `Are you sure you want to reset the scratchpad from the connection ${ext.activeConnection.connLabel}?`; const selection = await window.showInformationMessage( diff --git a/src/services/resultsPanelProvider.ts b/src/services/resultsPanelProvider.ts index 3d62c1b3..c2d7b727 100644 --- a/src/services/resultsPanelProvider.ts +++ b/src/services/resultsPanelProvider.ts @@ -23,7 +23,7 @@ import { ext } from "../extensionVariables"; import * as utils from "../utils/execution"; import { getNonce } from "../utils/getNonce"; import { getUri } from "../utils/getUri"; -import { kdbOutputLog } from "../utils/core"; +import { compareVersions, kdbOutputLog } from "../utils/core"; import { StructuredTextResults } from "../models/queryResult"; export class KdbResultsViewProvider implements WebviewViewProvider { @@ -226,7 +226,8 @@ export class KdbResultsViewProvider implements WebviewViewProvider { convertToGrid(results: any, isInsights: boolean, connVersion?: number): any { let rowData = []; let columnDefs = []; - if (connVersion && connVersion >= 1.12) { + + if (connVersion && compareVersions(connVersion, 1.12)) { rowData = this.updatedExtractRowData(results); columnDefs = this.updatedExtractColumnDefs(results); } else { diff --git a/src/utils/core.ts b/src/utils/core.ts index 7584fdb6..1c3c641e 100644 --- a/src/utils/core.ts +++ b/src/utils/core.ts @@ -694,3 +694,7 @@ function map(xs: any, f: any) { res.push(f.call(xs, xs[i], i)); } } + +export function compareVersions(version1: number, version2: number): boolean { + return semver.gte(`${version1}.0`, `${version2}.0`); +} diff --git a/test/suite/panels.test.ts b/test/suite/panels.test.ts index c03b9b99..9b3588da 100644 --- a/test/suite/panels.test.ts +++ b/test/suite/panels.test.ts @@ -244,6 +244,76 @@ describe("WebPanels", () => { stub.restore(); }); + it("should convert results to grid format for insights above 1.12", () => { + const results: StructuredTextResults = { + columns: [ + { + name: "prop1", + type: "type1", + values: ["value1", "value2"], + order: [1, 2], + }, + { + name: "prop2", + type: "type2", + values: ["value3", "value4"], + order: [1, 2], + }, + ], + count: 2, + }; + + const expectedOutput = JSON.stringify({ + defaultColDef: { + sortable: true, + resizable: true, + filter: true, + flex: 1, + minWidth: 100, + }, + rowData: [ + { index: 1, prop1: "value2", prop2: "value4" }, + { index: 2 }, + ], + columnDefs: [ + { field: "index", headerName: "Index", cellDataType: "number" }, + { + field: "prop1", + headerName: "prop1", + cellDataType: "text", + cellRendererParams: { disabled: false }, + headerTooltip: "type1", + }, + { + field: "prop2", + headerName: "prop2", + cellDataType: "text", + cellRendererParams: { disabled: false }, + headerTooltip: "type2", + }, + ], + domLayout: "autoHeight", + pagination: true, + paginationPageSize: 100, + enableCellTextSelection: true, + ensureDomOrder: true, + suppressContextMenu: true, + suppressDragLeaveHidesColumns: true, + tooltipShowDelay: 200, + loading: true, + }); + + // Mock ext.connectionNode + const stub = sinon.stub(ext, "activeConnection"); + stub.get(() => insightsConn); + + const output = resultsPanel.convertToGrid(results, true, 1.12); + assert.equal(JSON.stringify(output), expectedOutput); + + // Restore the stub + stub.restore(); + }); + it("should convert results to grid format with empty rows", () => { const results = { data: {