Skip to content

Commit

Permalink
Merge pull request #473 from KxSystems/main-1.9.1-to-dev
Browse files Browse the repository at this point in the history
Main 1.9.1 to dev
  • Loading branch information
ecmel authored Dec 5, 2024
2 parents a7adcf6 + 9e9a9d8 commit 0c99b4c
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
10 changes: 7 additions & 3 deletions src/classes/insightsConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/services/connectionManagerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Telemetry } from "../utils/telemetryClient";
import { InsightsConnection } from "../classes/insightsConnection";
import { sanitizeQuery } from "../utils/queryUtils";
import {
compareVersions,
getInsights,
getKeyForServerName,
getServerName,
Expand Down Expand Up @@ -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(
Expand Down
5 changes: 3 additions & 2 deletions src/services/resultsPanelProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
}
70 changes: 70 additions & 0 deletions test/suite/panels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 0c99b4c

Please sign in to comment.