Skip to content

Commit 927ea42

Browse files
Hide context buttons during deployment (#1062)
## Changes * Hide buttons such as "open external url", "start cluster", "run resource" etc when deploying because these might be in inconsistent state. * Throw a better error from openExternal command when url is not found. ## Tests <!-- How is this tested? -->
1 parent af29a83 commit 927ea42

File tree

5 files changed

+49
-29
lines changed

5 files changed

+49
-29
lines changed

packages/databricks-vscode/package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,12 @@
367367
},
368368
{
369369
"command": "databricks.bundle.refreshRemoteState",
370-
"when": "view == dabsResourceExplorerView",
370+
"when": "view == dabsResourceExplorerView && databricks.context.bundle.deploymentState == idle",
371371
"group": "navigation@1"
372372
},
373373
{
374374
"command": "databricks.bundle.deploy",
375-
"when": "view == dabsResourceExplorerView",
375+
"when": "view == dabsResourceExplorerView && databricks.context.bundle.deploymentState == idle",
376376
"group": "navigation@1"
377377
}
378378
],
@@ -390,47 +390,47 @@
390390
"view/item/context": [
391391
{
392392
"command": "databricks.utils.openExternal",
393-
"when": "viewItem =~ /^databricks.*\\.(has-url).*$/",
393+
"when": "viewItem =~ /^databricks.*\\.(has-url).*$/ && databricks.context.bundle.deploymentState == idle",
394394
"group": "inline@1"
395395
},
396396
{
397397
"command": "databricks.connection.attachCluster",
398-
"when": "view == clusterView",
398+
"when": "view == clusterView && databricks.context.bundle.deploymentState == idle",
399399
"group": "inline@2"
400400
},
401401
{
402402
"command": "databricks.connection.bundle.selectTarget",
403-
"when": "view == configurationView && viewItem =~ /^databricks.configuration.target.*$/",
403+
"when": "view == configurationView && viewItem =~ /^databricks.configuration.target.*$/ && databricks.context.bundle.deploymentState == idle",
404404
"group": "inline@2"
405405
},
406406
{
407407
"command": "databricks.connection.configureLogin",
408-
"when": "view == configurationView && viewItem =~ /^databricks.configuration.authType.*$/",
408+
"when": "view == configurationView && viewItem =~ /^databricks.configuration.authType.*$/ && databricks.context.bundle.deploymentState == idle",
409409
"group": "inline@2"
410410
},
411411
{
412412
"command": "databricks.connection.attachClusterQuickPick",
413-
"when": "view == configurationView && viewItem =~ /^databricks.configuration.cluster.*$/",
413+
"when": "view == configurationView && viewItem =~ /^databricks.configuration.cluster.*$/ && databricks.context.bundle.deploymentState == idle",
414414
"group": "inline@2"
415415
},
416416
{
417417
"command": "databricks.cluster.stop",
418-
"when": "view == configurationView && viewItem =~ /^databricks.configuration.cluster.*\\.(running|pending).*$/",
418+
"when": "view == configurationView && viewItem =~ /^databricks.configuration.cluster.*\\.(running|pending).*$/ && databricks.context.bundle.deploymentState == idle",
419419
"group": "inline@0"
420420
},
421421
{
422422
"command": "databricks.cluster.start",
423-
"when": "view == configurationView && viewItem =~ /databricks.configuration.cluster.*\\.terminated.*/",
423+
"when": "view == configurationView && viewItem =~ /databricks.configuration.cluster.*\\.terminated.*/ && databricks.context.bundle.deploymentState == idle",
424424
"group": "inline@0"
425425
},
426426
{
427427
"command": "databricks.bundle.deployAndRun",
428-
"when": "view == dabsResourceExplorerView && viewItem =~ /^databricks.bundle.*.runnable.*$/",
428+
"when": "view == dabsResourceExplorerView && viewItem =~ /^databricks.bundle.*.runnable.*$/ && databricks.context.bundle.deploymentState == idle",
429429
"group": "inline@0"
430430
},
431431
{
432432
"command": "databricks.bundle.cancelRun",
433-
"when": "view == dabsResourceExplorerView && viewItem =~ /^databricks.bundle.*.cancellable.*$/",
433+
"when": "view == dabsResourceExplorerView && viewItem =~ /^databricks.bundle.*.cancellable.*$/ && databricks.context.bundle.deploymentState == running",
434434
"group": "inline@0"
435435
}
436436
],

packages/databricks-vscode/src/extension.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export async function activate(
7171
context: ExtensionContext
7272
): Promise<PublicApi | undefined> {
7373
customWhenContext.setActivated(false);
74+
customWhenContext.setDeploymentState("idle");
7475

7576
if (extensions.getExtension("databricks.databricks-vscode") !== undefined) {
7677
await commands.executeCommand(
@@ -548,7 +549,8 @@ export async function activate(
548549
const bundleCommands = new BundleCommands(
549550
bundleRemoteStateModel,
550551
bundleRunStatusManager,
551-
bundleValidateModel
552+
bundleValidateModel,
553+
customWhenContext
552554
);
553555
const decorationProvider = new TreeItemDecorationProvider(
554556
bundleResourceExplorerTreeDataProvider,

packages/databricks-vscode/src/ui/bundle-resource-explorer/BundleCommands.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {Mutex} from "../../locking";
77
import {BundleValidateModel} from "../../bundle/models/BundleValidateModel";
88
import {PipelineTreeNode} from "./PipelineTreeNode";
99
import {JobTreeNode} from "./JobTreeNode";
10+
import {CustomWhenContext} from "../../vscode-objs/CustomWhenContext";
1011

1112
export const RUNNABLE_BUNDLE_RESOURCES = [
1213
"pipelines",
@@ -30,7 +31,8 @@ export class BundleCommands implements Disposable {
3031
constructor(
3132
private readonly bundleRemoteStateModel: BundleRemoteStateModel,
3233
private readonly bundleRunStatusManager: BundleRunStatusManager,
33-
private readonly bundleValidateModel: BundleValidateModel
34+
private readonly bundleValidateModel: BundleValidateModel,
35+
private readonly whenContext: CustomWhenContext
3436
) {
3537
this.disposables.push(
3638
this.outputChannel,
@@ -70,18 +72,23 @@ export class BundleCommands implements Disposable {
7072

7173
@Mutex.synchronise("deployMutex")
7274
async deploy() {
73-
this.prepareOutputChannel();
74-
await window.withProgress(
75-
{location: ProgressLocation.Notification, cancellable: false},
76-
async () => {
77-
await this.bundleRemoteStateModel.deploy(
78-
this.writeToChannel,
79-
this.writeToChannel
80-
);
81-
}
82-
);
75+
try {
76+
this.whenContext.setDeploymentState("deploying");
77+
this.prepareOutputChannel();
78+
await window.withProgress(
79+
{location: ProgressLocation.Notification, cancellable: false},
80+
async () => {
81+
await this.bundleRemoteStateModel.deploy(
82+
this.writeToChannel,
83+
this.writeToChannel
84+
);
85+
}
86+
);
8387

84-
await this.refreshRemoteState();
88+
await this.refreshRemoteState();
89+
} finally {
90+
this.whenContext.setDeploymentState("idle");
91+
}
8592
}
8693

8794
async deployCommand() {

packages/databricks-vscode/src/utils/UtilsCommands.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
import {Disposable} from "vscode";
1+
import {Disposable, window} from "vscode";
22
import {openExternal} from "./urlUtils";
33

44
export class UtilsCommands implements Disposable {
55
private disposables: Disposable[] = [];
66

77
openExternalCommand() {
8-
return async (value: any) => {
8+
return async (value: any | undefined) => {
99
let url: string | undefined;
1010

11-
if (value.url instanceof Promise) {
11+
if (value?.url instanceof Promise) {
1212
url = await value.url;
13-
} else if (value.url !== undefined) {
13+
} else if (value?.url !== undefined) {
1414
url = value.url;
1515
}
1616

17-
if (!url) {
17+
if (url === undefined) {
18+
window.showErrorMessage(
19+
"Databricks: Can't open external link. No URL found."
20+
);
1821
return;
1922
}
2023
await openExternal(url);

packages/databricks-vscode/src/vscode-objs/CustomWhenContext.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ export class CustomWhenContext {
1919
);
2020
}
2121

22+
setDeploymentState(value: "idle" | "deploying") {
23+
commands.executeCommand(
24+
"setContext",
25+
"databricks.context.bundle.deploymentState",
26+
value
27+
);
28+
}
29+
2230
isTargetSet(value: boolean) {
2331
commands.executeCommand(
2432
"setContext",

0 commit comments

Comments
 (0)