Skip to content
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
12 changes: 11 additions & 1 deletion src/commands/dataSourceCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ import { Telemetry } from "../utils/telemetryClient";
import { LocalConnection } from "../classes/localConnection";
import { ConnectionManagementService } from "../services/connectionManagerService";
import { InsightsConnection } from "../classes/insightsConnection";
import { kdbOutputLog, offerConnectAction } from "../utils/core";
import {
kdbOutputLog,
noSelectedConnectionAction,
offerConnectAction,
} from "../utils/core";
import { ServerType } from "../models/connectionsModels";

export async function addDataSource(): Promise<void> {
Expand Down Expand Up @@ -118,6 +122,12 @@ export async function runDataSource(
if (DataSourcesPanel.running) {
return;
}

if (connLabel === "") {
noSelectedConnectionAction();
return;
}

DataSourcesPanel.running = true;
const connMngService = new ConnectionManagementService();
const selectedConnection =
Expand Down
5 changes: 4 additions & 1 deletion src/commands/workspaceCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ export function getServerForUri(uri: Uri) {
"connectionMap",
{},
);
return map[relativePath(uri)];
const server = map[relativePath(uri)];
const servers = getServers();

return server && servers.includes(server) ? server : undefined;
}

/* istanbul ignore next */
Expand Down
6 changes: 6 additions & 0 deletions src/utils/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,12 @@ export function offerConnectAction(connLabel: string): void {
});
}

export function noSelectedConnectionAction(): void {
window.showInformationMessage(
`You didn't selected any existing connection to execute this action, please select a connection and try again.`,
);
}

/* istanbul ignore next */
export function offerReconnectionAfterEdit(connLabel: string): void {
window
Expand Down
18 changes: 13 additions & 5 deletions src/webview/components/kdbDataSourceView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -914,17 +914,25 @@ export class KdbDataSourceView extends LitElement {
}

renderActions() {
const selectedServerExists = this.servers.includes(this.selectedServer);
if (!selectedServerExists) {
this.selectedServer = "";
}
return html`
<sl-select
label="Connection"
.value="${live(this.selectedServer)}"
@sl-change="${this.requestServerChange}"
?disabled="${this.running}">
<sl-option
.value="${live(this.selectedServer)}"
.selected="${live(true)}"
>${this.selectedServer || "(none)"}</sl-option
>
${!selectedServerExists
? html`<sl-option .value="${live("")}" .selected="${live(true)}"
>(none)</sl-option
>`
: html`<sl-option
.value="${live(this.selectedServer)}"
.selected="${live(true)}"
>${this.selectedServer}</sl-option
>`}
<small>Connections</small>
${this.servers.map(
(server) => html`
Expand Down
15 changes: 15 additions & 0 deletions test/suite/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,21 @@ describe("dataSourceCommand2", () => {
ext.isResultsTabVisible = false;
});

it("should not proceed there is no connection selected", async () => {
ext.activeConnection = undefined;
await dataSourceCommand.runDataSource(
{} as DataSourceFiles,
"",
"test-file.kdb.json",
);
windowMock
.expects("showInformationMessage")
.once()
.withArgs(
"You didn't selected any existing connection to execute this action, please select a connection and try again.",
);
});

it("should show an error message if not connected to an Insights server", async () => {
ext.activeConnection = undefined;
getMetaStub.resolves({});
Expand Down
14 changes: 14 additions & 0 deletions test/suite/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,20 @@ describe("Utils", () => {
assert.ok(stub.calledOnce);
});
});

describe("noSelectedConnectionAction", () => {
afterEach(() => {
sinon.restore();
});

it("should call showInformationMessage", () => {
const stub = sinon
.stub(vscode.window, "showInformationMessage")
.resolves();
coreUtils.noSelectedConnectionAction();
assert.ok(stub.calledOnce);
});
});
});

describe("dataSource", () => {
Expand Down