Skip to content

Commit

Permalink
add meta to tree object
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip-Carneiro-KX committed Jun 10, 2024
1 parent 1b07e9c commit 19a27a0
Showing 1 changed file with 194 additions and 13 deletions.
207 changes: 194 additions & 13 deletions src/services/kdbTreeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import {
getServerName,
getStatus,
} from "../utils/core";
import { ConnectionManagementService } from "./connectionManagerService";
import { InsightsConnection } from "../classes/insightsConnection";

export class KdbTreeProvider implements TreeDataProvider<TreeItem> {
private _onDidChangeTreeData: EventEmitter<
Expand Down Expand Up @@ -94,13 +96,23 @@ export class KdbTreeProvider implements TreeDataProvider<TreeItem> {
ext.kdbrootNodes.indexOf(element.contextValue) !== -1
) {
return Promise.resolve(await this.getNamespaces());
} else if (
element.contextValue !== undefined &&
ext.kdbinsightsNodes.indexOf(element.contextValue) !== -1
) {
return Promise.resolve(await this.getMetas(element.contextValue));
} else if (element.contextValue === "ns") {
return Promise.resolve(
this.getCategories(
(element as QNamespaceNode).details?.toString(),
ext.qObjectCategories,
),
);
} else if (
element.contextValue === "meta" &&
element instanceof InsightsMetaNode
) {
return Promise.resolve(this.getMetaObjects(element.connLabel));
} else {
return Promise.resolve(this.getServerObjects(element));
}
Expand All @@ -127,6 +139,24 @@ export class KdbTreeProvider implements TreeDataProvider<TreeItem> {
return this.createInsightLeafItems(this.insightsList);
}

private async getMetas(connLabel: string): Promise<InsightsMetaNode[]> {
const connMng = new ConnectionManagementService();
const conn = connMng.retrieveConnectedConnection(connLabel);
if (conn) {
return [
new InsightsMetaNode(
[],
"meta",
"",
TreeItemCollapsibleState.Collapsed,
connLabel,
),
];
} else {
return new Array<InsightsMetaNode>();
}
}

private async getNamespaces(): Promise<QNamespaceNode[]> {
const ns = await loadNamespaces();
const result = ns.map(
Expand Down Expand Up @@ -289,6 +319,85 @@ export class KdbTreeProvider implements TreeDataProvider<TreeItem> {
return new Array<QServerNode>();
}

private async getMetaObjects(
connLabel: string,
): Promise<MetaObjectPayloadNode[]> {
const connMng = new ConnectionManagementService();
const conn = connMng.retrieveConnectedConnection(connLabel);
const isInsights = conn instanceof InsightsConnection;
if (conn && isInsights) {
const meta = conn.meta;
if (!meta) {
return new Array<MetaObjectPayloadNode>();
}
const objects: MetaObjectPayloadNode[] = [];
if (meta.payload.schema) {
objects.push(
new MetaObjectPayloadNode(
[],
"schema",
"",
TreeItemCollapsibleState.None,
"schemaicon",
connLabel,
),
);
}
if (meta.payload.api) {
objects.push(
new MetaObjectPayloadNode(
[],
"api",
"",
TreeItemCollapsibleState.None,
"apiicon",
connLabel,
),
);
}
if (meta.payload.dap) {
objects.push(
new MetaObjectPayloadNode(
[],
"dap",
"",
TreeItemCollapsibleState.None,
"dapicon",
connLabel,
),
);
}
if (meta.payload.rc) {
objects.push(
new MetaObjectPayloadNode(
[],
"rc",
"",
TreeItemCollapsibleState.None,
"rcicon",
connLabel,
),
);
}
if (meta.payload.agg) {
objects.push(
new MetaObjectPayloadNode(
[],
"agg",
"",
TreeItemCollapsibleState.None,
"aggicon",
connLabel,
),
);
}

return objects;
} else {
return new Array<MetaObjectPayloadNode>();
}
}

private createLeafItems(servers: Server): KdbNode[] {
const keys: string[] = Object.keys(servers);
return keys.map(
Expand All @@ -305,16 +414,21 @@ export class KdbTreeProvider implements TreeDataProvider<TreeItem> {
}

private createInsightLeafItems(insights: Insights): InsightsNode[] {
const connMng = new ConnectionManagementService();
const keys: string[] = Object.keys(insights);
return keys.map(
(x) =>
new InsightsNode(
[],
insights[x].alias,
insights[x],
TreeItemCollapsibleState.None,
),
);
return keys.map((x) => {
const isConnected = connMng.retrieveConnectedConnection(
insights[x].alias,
);
return new InsightsNode(
[],
insights[x].alias,
insights[x],
isConnected
? TreeItemCollapsibleState.Collapsed
: TreeItemCollapsibleState.None,
);
});
}
}

Expand All @@ -329,10 +443,6 @@ export class KdbNode extends TreeItem {
label = label + ` [${details.serverAlias}]`;
}

// if (ext.connectionNode != undefined && label === ext.connectionNode.label) {
// label = label + " (connected)";
// }

// set context for root nodes
if (ext.kdbrootNodes.indexOf(label) === -1) {
ext.kdbrootNodes.push(label);
Expand Down Expand Up @@ -488,6 +598,44 @@ export class InsightsNode extends TreeItem {
contextValue = this.label; // "root";
}

export class InsightsMetaNode extends TreeItem {
constructor(
public readonly children: string[],
public readonly label: string,
public readonly details: string,
public readonly collapsibleState: TreeItemCollapsibleState,
public readonly connLabel: string,
) {
details = connLabel;
super(label, collapsibleState);
this.description = this.getDescription();
}

getDescription(): string {
return "";
}

iconPath = {
light: path.join(
__filename,
"..",
"..",
"resources",
"metaIcons",
"metaicon.svg",
),
dark: path.join(
__filename,
"..",
"..",
"resources",
"metaIcons",
"metaicon.svg",
),
};
contextValue = "meta";
}

export class QNamespaceNode extends TreeItem {
constructor(
public readonly children: string[],
Expand Down Expand Up @@ -557,6 +705,39 @@ export class QCategoryNode extends TreeItem {
contextValue = this.ns; // "category";
}

export class MetaObjectPayloadNode extends TreeItem {
constructor(
public readonly children: string[],
public readonly label: string,
public readonly details: string,
public readonly collapsibleState: TreeItemCollapsibleState,
public readonly coreIcon: string,
public readonly connLabel: string,
) {
details = connLabel;
super(label, collapsibleState);
this.description = "";
}
iconPath = {
light: path.join(
__filename,
"..",
"..",
"resources",
"metaIcons",
`${this.coreIcon}.svg`,
),
dark: path.join(
__filename,
"..",
"..",
"resources",
"metaIcons",
`${this.coreIcon}.svg`,
),
};
}

export class QServerNode extends TreeItem {
constructor(
public readonly children: string[],
Expand Down

0 comments on commit 19a27a0

Please sign in to comment.