Skip to content

Commit

Permalink
fix ds
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip-Carneiro-KX committed Apr 25, 2024
1 parent 87243cc commit 0c238ab
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
1 change: 0 additions & 1 deletion src/commands/serverCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ export async function removeConnection(viewItem: KdbNode | InsightsNode) {
export async function connect(viewItem: KdbNode | InsightsNode): Promise<void> {
const connMngService = new ConnectionManagementService();
commands.executeCommand("kdb-results.focus");
await commands.executeCommand("setContext", "kdb.insightsConnected", false);
ExecutionConsole.start();
// handle cleaning up existing connection
if (ext.activeConnection !== undefined) {
Expand Down
5 changes: 5 additions & 0 deletions src/services/connectionManagerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ export class ConnectionManagementService {
]);
Telemetry.sendEvent("Connection.Connected.Active");
ext.activeConnection = connection;
if (node instanceof InsightsNode) {
commands.executeCommand("setContext", "kdb.insightsConnected", true);
} else {
commands.executeCommand("setContext", "kdb.insightsConnected", false);
}
ext.serverProvider.reload();
}

Expand Down
14 changes: 7 additions & 7 deletions src/services/dataSourceTreeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class KdbDataSourceProvider implements TreeDataProvider<TreeItem> {
this.refresh();
const datasourceFolder = createKdbDataSourcesFolder();
this.watcher = workspace.createFileSystemWatcher(
new RelativePattern(datasourceFolder, ext.kdbDataSourceFileGlob)
new RelativePattern(datasourceFolder, ext.kdbDataSourceFileGlob),
);
// watch updates in the folder
this.watcher.onDidChange(() => this.refresh());
Expand All @@ -59,7 +59,7 @@ export class KdbDataSourceProvider implements TreeDataProvider<TreeItem> {
}

getChildren(
element?: KdbDataSourceTreeItem
element?: KdbDataSourceTreeItem,
): Promise<KdbDataSourceTreeItem[]> {
if (!element) {
return this.getDsFiles();
Expand All @@ -84,7 +84,7 @@ export class KdbDataSourceProvider implements TreeDataProvider<TreeItem> {
const files = fs.readdirSync(kdbDataSourcesFolderPath);
const dsFiles = files.filter((file) => {
const isFromInsightsNode = checkFileFromInsightsNode(
path.join(kdbDataSourcesFolderPath, file)
path.join(kdbDataSourcesFolderPath, file),
);
return (
path.extname(file) === ext.kdbDataSourceFileExtension &&
Expand All @@ -97,9 +97,9 @@ export class KdbDataSourceProvider implements TreeDataProvider<TreeItem> {
return new KdbDataSourceTreeItem(
newLabel,
TreeItemCollapsibleState.None,
[Uri.file(path.join(kdbDataSourcesFolderPath, file))]
[Uri.file(path.join(kdbDataSourcesFolderPath, file))],
);
})
}),
);
} else {
return Promise.resolve([]);
Expand All @@ -111,7 +111,7 @@ export class KdbDataSourceTreeItem extends TreeItem {
constructor(
public readonly label: string,
public readonly collapsibleState: TreeItemCollapsibleState,
public readonly files: Uri[]
public readonly files: Uri[],
) {
super(label, collapsibleState);
this.iconPath = new ThemeIcon("file");
Expand All @@ -125,7 +125,7 @@ export class KdbDataSourceTreeItem extends TreeItem {
commands.executeCommand(
"setContext",
"kdb.dataSourceTreeNodes",
ext.kdbDataSourceRootNodes
ext.kdbDataSourceRootNodes,
);
}
}
Expand Down
24 changes: 10 additions & 14 deletions src/utils/dataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@ import path from "path";
import { ext } from "../extensionVariables";
import { DataSourceFiles } from "../models/dataSource";
import { DataSourcesPanel } from "../panels/datasource";
import { InsightsConnection } from "../classes/insightsConnection";

export function createKdbDataSourcesFolder(): string {
const rootPath = ext.context.globalStorageUri.fsPath;
const kdbDataSourcesFolderPath = path.join(rootPath, ext.kdbDataSourceFolder);
if (!fs.existsSync(rootPath)) {
ext.outputChannel.appendLine(
`Directory created to the extension folder: ${rootPath}`
`Directory created to the extension folder: ${rootPath}`,
);
fs.mkdirSync(rootPath);
}
if (!fs.existsSync(kdbDataSourcesFolderPath)) {
ext.outputChannel.appendLine(
`Directory created to the extension folder: ${kdbDataSourcesFolderPath}`
`Directory created to the extension folder: ${kdbDataSourcesFolderPath}`,
);
fs.mkdirSync(kdbDataSourcesFolderPath);
}
Expand All @@ -45,21 +46,16 @@ export function convertTimeToTimestamp(time: string): string {
return `${datePart}.${timePart}`;
} catch (error) {
console.error(
`The string param is in an incorrect format. Param: ${time} Error: ${error}`
`The string param is in an incorrect format. Param: ${time} Error: ${error}`,
);
return "";
}
}

export function getConnectedInsightsNode(): string {
const connectedNode = ext.kdbinsightsNodes.find((node) =>
node.endsWith(" (connected)")
);
if (connectedNode) {
return connectedNode.replace(" (connected)", "");
} else {
return "";
}
return ext.activeConnection instanceof InsightsConnection
? ext.activeConnection.connLabel
: "";
}

export function checkFileFromInsightsNode(filePath: string): boolean {
Expand All @@ -78,15 +74,15 @@ export function checkFileFromInsightsNode(filePath: string): boolean {

export function checkIfTimeParamIsCorrect(
startTS: string,
endTS: string
endTS: string,
): boolean {
try {
const startDate = new Date(startTS);
const endDate = new Date(endTS);
return startDate < endDate;
} catch (error) {
console.error(
`The string params are in an incorrect format. startTS: ${startTS}, endTS: ${endTS}, Error: ${error}`
`The string params are in an incorrect format. startTS: ${startTS}, endTS: ${endTS}, Error: ${error}`,
);
return false;
}
Expand All @@ -99,7 +95,7 @@ export function refreshDataSourcesPanel(): void {
}

export function convertDataSourceFormToDataSourceFile(
form: any
form: any,
): DataSourceFiles {
return form as DataSourceFiles;
}

0 comments on commit 0c238ab

Please sign in to comment.