Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kxi 35687-2 #239

Merged
merged 3 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions src/services/resultsPanelProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,41 +102,64 @@ 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) {
return Object.keys(results.meta).map((key: string) => {
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 {
return Object.keys(results.rows[0]).map((key: string) => {
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 {
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 };
});
}
}
Expand Down Expand Up @@ -178,7 +201,6 @@ export class KdbResultsViewProvider implements WebviewViewProvider {
domLayout: "autoHeight",
pagination: true,
paginationPageSize: 100,
cacheBlockSize: 100,
enableCellTextSelection: true,
ensureDomOrder: true,
suppressContextMenu: true,
Expand Down Expand Up @@ -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();
}
});
Expand Down
108 changes: 104 additions & 4 deletions test/suite/panels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand All @@ -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,
Expand All @@ -217,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", () => {
Expand Down
Loading