From af103d423d7a79b59ed2af254d17c595268df791 Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Tue, 30 Jan 2024 12:15:00 +0000 Subject: [PATCH 1/3] add fix for ag-grid --- src/services/resultsPanelProvider.ts | 30 ++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/services/resultsPanelProvider.ts b/src/services/resultsPanelProvider.ts index 4013f291..022fd991 100644 --- a/src/services/resultsPanelProvider.ts +++ b/src/services/resultsPanelProvider.ts @@ -102,6 +102,19 @@ export class KdbResultsViewProvider implements WebviewViewProvider { utils.exportToCsv(workspaceUri); } + defineDataType(type: string): string { + const typeMapping: { [key: string]: string } = { + short: "number", + int: "number", + long: "number", + float: "number", + real: "number", + boolean: "boolean", + }; + + return typeMapping[type] || "text"; + } + generateCoumnDefs(results: any, isInsights: boolean): any { if (isInsights) { if (results.rows.length === 0) { @@ -109,10 +122,12 @@ export class KdbResultsViewProvider implements WebviewViewProvider { const sanitizedKey = this.sanitizeString(key); const type = results.meta[key]; const headerTooltip = type; + const cellDataType = this.defineDataType(type); return { field: sanitizedKey, headerName: sanitizedKey, headerTooltip, + cellDataType, }; }); } else { @@ -120,10 +135,12 @@ export class KdbResultsViewProvider implements WebviewViewProvider { const sanitizedKey = this.sanitizeString(key); const type = results.meta[key]; const headerTooltip = type; + const cellDataType = this.defineDataType(type); return { field: sanitizedKey, headerName: sanitizedKey, headerTooltip, + cellDataType, }; }); } @@ -131,12 +148,18 @@ export class KdbResultsViewProvider implements WebviewViewProvider { if (typeof results[0] === "string") { return results.map((key: string) => { const sanitizedKey = this.sanitizeString(key); - return { field: sanitizedKey, headerName: sanitizedKey }; + const cellDataType = "text"; + return { + field: sanitizedKey, + headerName: sanitizedKey, + cellDataType, + }; }); } return Object.keys(results[0]).map((key: string) => { const sanitizedKey = this.sanitizeString(key); - return { field: sanitizedKey, headerName: sanitizedKey }; + const cellDataType = "text"; + return { field: sanitizedKey, headerName: sanitizedKey, cellDataType }; }); } } @@ -178,7 +201,6 @@ export class KdbResultsViewProvider implements WebviewViewProvider { domLayout: "autoHeight", pagination: true, paginationPageSize: 100, - cacheBlockSize: 100, enableCellTextSelection: true, ensureDomOrder: true, suppressContextMenu: true, @@ -281,7 +303,7 @@ export class KdbResultsViewProvider implements WebviewViewProvider { if(${isGrid}){ const gridDiv = document.getElementById('grid'); const obj = JSON.parse('${gridOptionsString}'); - const gridApi = new agGrid.Grid(gridDiv, obj); + const gridApi = agGrid.createGrid(gridDiv, obj); document.getElementById("results").scrollIntoView(); } }); From 8ef4314e77e1ece8606faf664bb8c988fd4f992e Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Tue, 30 Jan 2024 12:32:41 +0000 Subject: [PATCH 2/3] fix tests --- test/suite/panels.test.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/test/suite/panels.test.ts b/test/suite/panels.test.ts index 5695ee09..89c23ff2 100644 --- a/test/suite/panels.test.ts +++ b/test/suite/panels.test.ts @@ -193,13 +193,22 @@ describe("WebPanels", () => { { prop1: "value3", prop2: "value4" }, ], columnDefs: [ - { field: "prop1", headerName: "prop1", headerTooltip: "type1" }, - { field: "prop2", headerName: "prop2", headerTooltip: "type2" }, + { + field: "prop1", + headerName: "prop1", + headerTooltip: "type1", + cellDataType: "text", + }, + { + field: "prop2", + headerName: "prop2", + headerTooltip: "type2", + cellDataType: "text", + }, ], domLayout: "autoHeight", pagination: true, paginationPageSize: 100, - cacheBlockSize: 100, enableCellTextSelection: true, ensureDomOrder: true, suppressContextMenu: true, From 25746953f4eb5df5ccd9d715165fbd31335b5bf5 Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Tue, 30 Jan 2024 14:19:42 +0000 Subject: [PATCH 3/3] add more tests --- test/suite/panels.test.ts | 93 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 92 insertions(+), 1 deletion(-) diff --git a/test/suite/panels.test.ts b/test/suite/panels.test.ts index 89c23ff2..f3508dbf 100644 --- a/test/suite/panels.test.ts +++ b/test/suite/panels.test.ts @@ -171,7 +171,7 @@ describe("WebPanels", () => { }); describe("convertToGrid()", () => { - it("should convert results to grid format", () => { + it("should convert results to grid format for inisights", () => { const results = { rows: [ { prop1: "value1", prop2: "value2" }, @@ -226,6 +226,97 @@ describe("WebPanels", () => { // Restore the stub stub.restore(); }); + + it("should convert results to grid format with empty rows ", () => { + const results = { + rows: [], + meta: { prop1: "type1", prop2: "type2" }, + }; + + const expectedOutput = JSON.stringify({ + defaultColDef: { + sortable: true, + resizable: true, + filter: true, + flex: 1, + minWidth: 100, + }, + rowData: [], + columnDefs: [ + { + field: "prop1", + headerName: "prop1", + headerTooltip: "type1", + cellDataType: "text", + }, + { + field: "prop2", + headerName: "prop2", + headerTooltip: "type2", + cellDataType: "text", + }, + ], + domLayout: "autoHeight", + pagination: true, + paginationPageSize: 100, + enableCellTextSelection: true, + ensureDomOrder: true, + suppressContextMenu: true, + suppressDragLeaveHidesColumns: true, + tooltipShowDelay: 200, + }); + + // Mock ext.connectionNode + const stub = sinon.stub(ext, "connectionNode"); + stub.get(() => insightsNode); + + const output = resultsPanel.convertToGrid(results); + assert.equal(output, expectedOutput); + + // Restore the stub + stub.restore(); + }); + }); + + describe("generateColumnDefs", () => { + it("should return an array of column definitions if the results are not empty", () => { + const input = [ + { prop1: "value1", prop2: "value2" }, + { prop1: "value3", prop2: "value4" }, + ]; + const expectedOutput = [ + { + field: "prop1", + headerName: "prop1", + cellDataType: "text", + }, + { + field: "prop2", + headerName: "prop2", + cellDataType: "text", + }, + ]; + const actualOutput = resultsPanel.generateCoumnDefs(input, false); + assert.deepStrictEqual(actualOutput, expectedOutput); + }); + + it("should return the results if the results are array of strings", () => { + const input = ["value1", "value2"]; + const expectedOutput = [ + { + field: "value1", + headerName: "value1", + cellDataType: "text", + }, + { + field: "value2", + headerName: "value2", + cellDataType: "text", + }, + ]; + const actualOutput = resultsPanel.generateCoumnDefs(input, false); + assert.deepStrictEqual(actualOutput, expectedOutput); + }); }); describe("removeEndCommaFromStrings", () => {