Skip to content

Commit

Permalink
Merge pull request #458 from KxSystems/fix-insights-results2
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip-Carneiro-KX authored Nov 14, 2024
2 parents 808d78f + 184a058 commit 50beb02
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 24 deletions.
10 changes: 7 additions & 3 deletions src/classes/insightsConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class InsightsConnection {
if (token) {
await this.getConfig();
await this.getMeta();
await this.getScratchpadQuery("");
await this.getScratchpadQuery("", undefined, false, true);
}
});
return this.connected;
Expand Down Expand Up @@ -398,9 +398,13 @@ export class InsightsConnection {
query: string,
context?: string,
isPython?: boolean,
isStarting?: boolean,
): Promise<any | undefined> {
if (this.connected && this.connEndpoints) {
const isTableView = ext.isResultsTabVisible;
const queryMsg = isStarting
? "Starting scratchpad..."
: "Query is executing...";
const scratchpadURL = new url.URL(
this.connEndpoints.scratchpad.scratchpad,
this.node.details.server,
Expand Down Expand Up @@ -451,7 +455,7 @@ export class InsightsConnection {
kdbOutputLog(`User cancelled the Scrathpad execution.`, "WARNING");
});

progress.report({ message: "Query is executing..." });
progress.report({ message: queryMsg });
const spRes = await axios
.post(scratchpadURL.toString(), body, {
headers,
Expand All @@ -472,7 +476,7 @@ export class InsightsConnection {
kdbOutputLog(`[SCRATCHPAD] Status: ${response.status}`, "INFO");
if (!response.data.error) {
if (isTableView) {
if (this.insightsVersion && this.insightsVersion >= 1.11) {
if (this.insightsVersion && this.insightsVersion >= 1.12) {
response.data = JSON.parse(
response.data.data,
) as StructuredTextResults;
Expand Down
23 changes: 17 additions & 6 deletions src/services/resultsPanelProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class KdbResultsViewProvider implements WebviewViewProvider {
char: "text",
symbol: "text",
string: "text",
date: "date",
date: "text",
time: "time",
timestamp: "datetime",
timespan: "text",
Expand Down Expand Up @@ -159,7 +159,8 @@ export class KdbResultsViewProvider implements WebviewViewProvider {
const sanitizedKey = this.sanitizeString(key);
const type = results.meta[key];
const headerTooltip = type;
const cellDataType = this.kdbToAgGridCellType(type);
const cellDataType =
type != undefined ? this.kdbToAgGridCellType(type) : undefined;
return {
field: sanitizedKey,
headerName: sanitizedKey,
Expand Down Expand Up @@ -229,6 +230,7 @@ export class KdbResultsViewProvider implements WebviewViewProvider {
rowData = this.updatedExtractRowData(results);
columnDefs = this.updatedExtractColumnDefs(results);
} else {
results = isInsights ? results.data : results;
const queryResult = isInsights ? results.rows : results;
if (Array.isArray(queryResult[0])) {
if (typeof queryResult[0][0] === "object") {
Expand All @@ -246,12 +248,21 @@ export class KdbResultsViewProvider implements WebviewViewProvider {
rowData = queryResult;
}

rowData = rowData.map((row: any) => {
const newRow = { ...row };
Object.keys(newRow).forEach((key) => {
if (typeof newRow[key] === "object" && newRow[key] !== null) {
newRow[key] = newRow[key].toString();
}
});
return newRow;
});

if (isInsights) {
results.rows = rowData;
columnDefs = this.generateCoumnDefs(results, isInsights);
} else {
columnDefs = this.generateCoumnDefs(rowData, isInsights);
}

columnDefs = this.generateCoumnDefs(results, isInsights);
}

if (
Expand Down Expand Up @@ -406,7 +417,7 @@ export class KdbResultsViewProvider implements WebviewViewProvider {
function restoreColumnWidths(columnWidths) {
if (!gridApi || !columnWidths) return;
gridApi.applyColumnState({state: columnWidths, applyOrder: true,});
gridApi.applyColumnState({state: columnWidths, });
}
window.addEventListener('message', event => {
Expand Down
35 changes: 20 additions & 15 deletions test/suite/panels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,13 @@ describe("WebPanels", () => {
describe("convertToGrid()", () => {
it("should convert results to grid format for insights", () => {
const results = {
rows: [
{ prop1: "value1", prop2: "value2" },
{ prop1: "value3", prop2: "value4" },
],
meta: { prop1: "type1", prop2: "type2" },
data: {
rows: [
{ prop1: "value1", prop2: "value2" },
{ prop1: "value3", prop2: "value4" },
],
meta: { prop1: "type1", prop2: "type2" },
},
};

const expectedOutput = JSON.stringify({
Expand Down Expand Up @@ -244,8 +246,10 @@ describe("WebPanels", () => {

it("should convert results to grid format with empty rows", () => {
const results = {
rows: [],
meta: { prop1: "type1", prop2: "type2" },
data: {
rows: [],
meta: { prop1: "type1", prop2: "type2" },
},
};

const expectedOutput = JSON.stringify({
Expand Down Expand Up @@ -296,11 +300,13 @@ describe("WebPanels", () => {

it("should convert results to grid format when queryResult[0] is an array of objects", () => {
const results = {
rows: [
[{ sym: "a" }, { sym: "b" }, { sym: "c" }],
[{ val: 1 }, { val: 2 }, { val: 3 }],
],
meta: { sym: "type1", val: "type2" },
data: {
rows: [
[{ sym: "a" }, { sym: "b" }, { sym: "c" }],
[{ val: 1 }, { val: 2 }, { val: 3 }],
],
meta: { sym: "type1", val: "type2" },
},
};

const expectedOutput = JSON.stringify({
Expand Down Expand Up @@ -355,8 +361,7 @@ describe("WebPanels", () => {

it("should convert results to grid format when queryResult[0] is an array of non-objects", () => {
const results = {
rows: [[1, 2, 3]],
meta: { value: "type1" },
data: { rows: [[1, 2, 3]], meta: { value: "type1" } },
};

const expectedOutput = JSON.stringify({
Expand All @@ -367,7 +372,7 @@ describe("WebPanels", () => {
flex: 1,
minWidth: 100,
},
rowData: [{ index: 1, value: [1, 2, 3] }],
rowData: [{ index: 1, value: "1,2,3" }],
columnDefs: [
{ field: "index", headerName: "Index", cellDataType: "number" },
{
Expand Down

0 comments on commit 50beb02

Please sign in to comment.