();
}
@@ -558,7 +587,7 @@ export class KdbNode extends TreeItem {
: "";
}
- iconPath = getNamedIconPath("p-q-connection", this.label);
+ iconPath = getNamedIconPath("conn-kdb", this.label);
contextValue = this.label; // "root";
}
@@ -606,7 +635,7 @@ export class InsightsNode extends TreeItem {
: "";
}
- iconPath = getNamedIconPath("p-insights", this.label);
+ iconPath = getNamedIconPath("conn-insights", this.label);
contextValue = this.label; // "root";
}
@@ -627,24 +656,7 @@ export class InsightsMetaNode extends TreeItem {
return "";
}
- iconPath = {
- light: path.join(
- __filename,
- "..",
- "..",
- "resources",
- "light",
- "metaicon.svg",
- ),
- dark: path.join(
- __filename,
- "..",
- "..",
- "resources",
- "dark",
- "metaicon.svg",
- ),
- };
+ iconPath = getOtherIconPath("metaicon");
contextValue = "meta";
}
@@ -655,6 +667,7 @@ export class QNamespaceNode extends TreeItem {
public readonly details: string,
public readonly collapsibleState: TreeItemCollapsibleState,
public readonly fullName: string,
+ public readonly connLabel: string,
) {
details = fullName;
super(label, collapsibleState);
@@ -665,24 +678,7 @@ export class QNamespaceNode extends TreeItem {
return "";
}
- iconPath = {
- light: path.join(
- __filename,
- "..",
- "..",
- "resources",
- "light",
- "namespaces.svg",
- ),
- dark: path.join(
- __filename,
- "..",
- "..",
- "resources",
- "dark",
- "namespaces.svg",
- ),
- };
+ iconPath = getOtherIconPath("namespaces");
contextValue = "ns";
}
@@ -693,6 +689,7 @@ export class QCategoryNode extends TreeItem {
public readonly details: string,
public readonly ns: string,
public readonly collapsibleState: TreeItemCollapsibleState,
+ public readonly connLabel: string,
) {
details = "";
super(label, collapsibleState);
@@ -703,24 +700,7 @@ export class QCategoryNode extends TreeItem {
return "";
}
- iconPath = {
- light: path.join(
- __filename,
- "..",
- "..",
- "resources",
- "light",
- `${this.label.toLowerCase()}.svg`,
- ),
- dark: path.join(
- __filename,
- "..",
- "..",
- "resources",
- "dark",
- `${this.label.toLowerCase()}.svg`,
- ),
- };
+ iconPath = getOtherIconPath(this.label.toLowerCase());
contextValue = this.ns; // "category";
}
@@ -736,24 +716,7 @@ export class MetaObjectPayloadNode extends TreeItem {
super(label, collapsibleState);
this.description = "";
}
- iconPath = {
- light: path.join(
- __filename,
- "..",
- "..",
- "resources",
- "light",
- `${this.coreIcon}.svg`,
- ),
- dark: path.join(
- __filename,
- "..",
- "..",
- "resources",
- "dark",
- `${this.coreIcon}.svg`,
- ),
- };
+ iconPath = getOtherIconPath(this.coreIcon);
}
export class QServerNode extends TreeItem {
@@ -763,6 +726,7 @@ export class QServerNode extends TreeItem {
public readonly details: string,
public readonly collapsibleState: TreeItemCollapsibleState,
public readonly coreIcon: string,
+ public readonly connLabel: string,
) {
details = "";
super(label, collapsibleState);
@@ -773,24 +737,7 @@ export class QServerNode extends TreeItem {
return "";
}
- iconPath = {
- light: path.join(
- __filename,
- "..",
- "..",
- "resources",
- "light",
- `${this.coreIcon}.svg`,
- ),
- dark: path.join(
- __filename,
- "..",
- "..",
- "resources",
- "dark",
- `${this.coreIcon}.svg`,
- ),
- };
+ iconPath = getOtherIconPath(this.coreIcon);
contextValue = this.label;
}
@@ -857,3 +804,17 @@ function getNamedIconPath(name: string, label: string) {
),
};
}
+
+function getOtherIconPath(name: string) {
+ return {
+ light: path.join(
+ __filename,
+ "..",
+ "..",
+ "resources",
+ "light",
+ name + ".svg",
+ ),
+ dark: path.join(__filename, "..", "..", "resources", "dark", name + ".svg"),
+ };
+}
diff --git a/src/services/queryHistoryProvider.ts b/src/services/queryHistoryProvider.ts
index 35ff9fe8..05957ba1 100644
--- a/src/services/queryHistoryProvider.ts
+++ b/src/services/queryHistoryProvider.ts
@@ -109,13 +109,35 @@ export class QueryHistoryTreeItem extends TreeItem {
tooltipMd.appendMarkdown(
"- Workbook: " + this.details.executorName + " \n",
);
+ } else if (this.details.isFromConnTree) {
+ tooltipMd.appendMarkdown("- Executiom from: Connection Tree \n");
+ tooltipMd.appendMarkdown(
+ "- Category: " + this.details.executorName + " \n",
+ );
} else {
tooltipMd.appendMarkdown(
"- File: " + this.details.executorName + " \n",
);
}
- tooltipMd.appendMarkdown("- Query: \n");
- tooltipMd.appendCodeblock(this.details.query, codeType);
+ tooltipMd.appendMarkdown("- Query: ");
+ let queryText = this.details.query;
+
+ if (typeof queryText === "string") {
+ const lines = queryText.split("\n");
+ if (lines.length > 1) {
+ queryText =
+ lines[0].slice(0, 77) +
+ (lines[0].length > 77 ? "... " : "") +
+ "\n" +
+ lines[1].slice(0, 77) +
+ (lines[1].length > 77 ? "... " : "");
+ } else {
+ queryText =
+ lines[0].slice(0, 77) + (lines[0].length > 77 ? "... " : "");
+ }
+ }
+
+ tooltipMd.appendCodeblock(queryText, codeType);
} else {
tooltipMd.appendMarkdown(
"- Data Source: **" + this.details.executorName + "** \n",
diff --git a/src/services/resultsPanelProvider.ts b/src/services/resultsPanelProvider.ts
index ab7d1058..31dcf05a 100644
--- a/src/services/resultsPanelProvider.ts
+++ b/src/services/resultsPanelProvider.ts
@@ -23,11 +23,13 @@ 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";
export class KdbResultsViewProvider implements WebviewViewProvider {
public static readonly viewType = "kdb-results";
- private _view?: WebviewView;
+ public isInsights = false;
public _colorTheme: any;
+ private _view?: WebviewView;
private _results: string | string[] = "";
constructor(private readonly _extensionUri: Uri) {
@@ -48,10 +50,11 @@ export class KdbResultsViewProvider implements WebviewViewProvider {
localResourceRoots: [Uri.joinPath(this._extensionUri, "out")],
};
- webviewView.webview.html = this._getWebviewContent("");
+ webviewView.webview.html = this._getWebviewContent();
+ this.updateWebView("");
webviewView.webview.onDidReceiveMessage((data) => {
- webviewView.webview.html = this._getWebviewContent(data);
+ this.updateWebView(data);
});
webviewView.onDidChangeVisibility(() => {
ext.isResultsTabVisible = webviewView.visible;
@@ -62,19 +65,11 @@ export class KdbResultsViewProvider implements WebviewViewProvider {
});
}
- public updateResults(
- queryResults: any,
- isInsights?: boolean,
- dataSourceType?: string,
- ) {
+ public updateResults(queryResults: any, isInsights?: boolean) {
if (this._view) {
this._view.show?.(true);
- this._view.webview.postMessage(queryResults);
- this._view.webview.html = this._getWebviewContent(
- queryResults,
- isInsights,
- dataSourceType,
- );
+ this.isInsights = !!isInsights;
+ this.updateWebView(queryResults);
}
}
@@ -176,7 +171,7 @@ export class KdbResultsViewProvider implements WebviewViewProvider {
}
}
- convertToGrid(results: any, isInsights: boolean): string {
+ convertToGrid(results: any, isInsights: boolean): any {
const queryResult = isInsights ? results.rows : results;
const columnDefs = this.generateCoumnDefs(results, isInsights);
@@ -199,7 +194,7 @@ export class KdbResultsViewProvider implements WebviewViewProvider {
if (rowData.length > 0) {
ext.resultPanelCSV = this.convertToCsv(rowData).join("\n");
}
- return JSON.stringify({
+ return {
defaultColDef: {
sortable: true,
resizable: true,
@@ -217,7 +212,7 @@ export class KdbResultsViewProvider implements WebviewViewProvider {
suppressContextMenu: true,
suppressDragLeaveHidesColumns: true,
tooltipShowDelay: 200,
- });
+ };
}
isVisible(): boolean {
@@ -251,13 +246,39 @@ export class KdbResultsViewProvider implements WebviewViewProvider {
: "";
}
- private _getWebviewContent(
- queryResult: any,
- isInsights?: boolean,
- _dataSourceType?: string,
- ) {
+ public updateWebView(queryResult: any) {
ext.resultPanelCSV = "";
this._results = queryResult;
+ let result = "";
+ let gridOptions = undefined;
+ if (!this._view) {
+ kdbOutputLog("[Results Tab] No view to update", "ERROR");
+ return;
+ }
+ if (typeof queryResult === "string" || typeof queryResult === "number") {
+ result =
+ queryResult !== ""
+ ? `${queryResult
+ .toString()
+ .replace(/\n/g, "
")}
`
+ : "No results to show
";
+ } else if (queryResult) {
+ gridOptions = this.convertToGrid(queryResult, this.isInsights);
+ }
+ if (gridOptions) {
+ this._view.webview.postMessage({
+ command: "setGridOptions",
+ gridOptions: gridOptions,
+ });
+ } else {
+ this._view.webview.postMessage({
+ command: "setResultsContent",
+ results: result,
+ });
+ }
+ }
+
+ private _getWebviewContent() {
const agGridTheme = this.defineAgGridTheme();
if (this._view) {
const webviewUri = getUri(this._view.webview, this._extensionUri, [
@@ -265,70 +286,72 @@ export class KdbResultsViewProvider implements WebviewViewProvider {
"webview.js",
]);
const nonce = getNonce();
- let result = "";
- let gridOptionsString = "";
+ return /*html*/ `
+
+
+
+
+
+
+
+
+
+
+ Q Results
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
- `;
+ function restoreColumnWidths(columnWidths) {
+ if (!gridApi || !columnWidths) return;
+ gridApi.applyColumnState({state: columnWidths});
+ }
+
+ window.addEventListener('message', event => {
+ const message = event.data;
+ if (message.command === 'setGridOptions') {
+ const columnWidths = saveColumnWidths();
+ const gridOptions = message.gridOptions;
+ const gridDiv = document.getElementById('grid');
+ const resultsDiv = document.querySelector('#results .content-wrapper');
+ resultsDiv.innerHTML = '';
+ gridDiv.innerHTML = '';
+ gridApi = agGrid.createGrid(gridDiv, gridOptions);
+ restoreColumnWidths(columnWidths);
+ document.getElementById("results").scrollIntoView();
+ } else if (message.command === 'setResultsContent') {
+ const resultsContent = message.results;
+ const resultsDiv = document.querySelector('#results .content-wrapper');
+ const gridDiv = document.getElementById('grid');
+ gridDiv.innerHTML = '';
+ resultsDiv.innerHTML = '';
+ resultsDiv.innerHTML = resultsContent;
+ }
+ });
+ document.addEventListener('contextmenu', (e) => {
+ e.stopImmediatePropagation();
+ }, true);
+
+