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

Small bugs #279

Merged
merged 3 commits into from
Apr 25, 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
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -559,22 +559,22 @@
{
"command": "kdb.insightsConnect",
"when": "view == kdb-servers && viewItem not in kdb.connected && viewItem in kdb.insightsNodes",
"group": "connection"
"group": "connection@0"
},
{
"command": "kdb.insightsRemove",
"when": "view == kdb-servers && viewItem in kdb.insightsNodes",
"group": "connection"
"group": "connection@5"
},
{
"command": "kdb.disconnect",
"when": "view == kdb-servers && viewItem in kdb.connected && (viewItem in kdb.rootNodes || viewItem in kdb.insightsNodes)",
"group": "connection"
"group": "connection@4"
},
{
"command": "kdb.removeConnection",
"when": "view == kdb-servers && viewItem in kdb.rootNodes",
"group": "connection@2"
"group": "connection@5"
},
{
"command": "kdb.startLocalProcess",
Expand Down
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
30 changes: 17 additions & 13 deletions src/services/connectionManagerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
} from "../utils/core";
import { Insights } from "../models/insights";
import { Server } from "../models/server";
import { refreshDataSourcesPanel } from "../utils/dataSource";

export class ConnectionManagementService {
public retrieveConnection(
Expand Down Expand Up @@ -116,6 +117,7 @@ export class ConnectionManagementService {
} else {
this.isNotConnectedBehaviour(connLabel);
}
refreshDataSourcesPanel();
}
}

Expand All @@ -129,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 All @@ -142,19 +149,7 @@ export class ConnectionManagementService {
/* istanbul ignore next */
if (isLocal && connectionNode) {
connection.getConnection()?.close(() => {
ext.connectedConnectionList.splice(
ext.connectedConnectionList.indexOf(connection),
1,
);
ext.activeConnection = undefined;
ext.connectionNode = undefined;

commands.executeCommand("setContext", "kdb.connected.active", false);
Telemetry.sendEvent("Connection.Disconnected");
ext.outputChannel.appendLine(
`Connection stopped from ${connection.connLabel}`,
);
ext.serverProvider.reload();
this.disconnectBehaviour(connection);
});
} else {
connection.disconnect();
Expand Down Expand Up @@ -240,6 +235,15 @@ export class ConnectionManagementService {
ext.connectedConnectionList.indexOf(connection),
1,
);
ext.connectedContextStrings.splice(
ext.connectedContextStrings.indexOf(connection.connLabel),
1,
);
commands.executeCommand(
"setContext",
"kdb.connected",
ext.connectedContextStrings,
);
if (ext.activeConnection === connection) {
ext.activeConnection = undefined;
ext.connectionNode = undefined;
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;
}
Loading