Skip to content

Commit b853df6

Browse files
Add a view for DABs resource viewer (#1002)
## Changes * Add a view for DABs resource viewer. * The view only appears when the user has selected a valid target * Fix some callbacks so target is updated properly when bundle file changes. ## Tests * manual
1 parent cac9604 commit b853df6

File tree

8 files changed

+52
-34
lines changed

8 files changed

+52
-34
lines changed

packages/databricks-vscode/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,12 @@
247247
"id": "configurationView",
248248
"name": "Configuration"
249249
},
250+
{
251+
"id": "dabsResourceExplorerView",
252+
"name": "DABs Resource Explorer",
253+
"visibility": "visible",
254+
"when": "databricks.context.bundle.isTargetSet"
255+
},
250256
{
251257
"id": "workspaceFsView",
252258
"name": "Workspace explorer",

packages/databricks-vscode/src/bundle/models/BundlePreValidateModel.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import {BundleFileSet, BundleWatcher} from "..";
33
import {BundleTarget} from "../types";
44
import {BaseModelWithStateCache} from "../../configuration/models/BaseModelWithStateCache";
55
import {UrlUtils} from "../../utils";
6-
import {onError} from "../../utils/onErrorDecorator";
76
import {Mutex} from "../../locking";
7+
import {onError} from "../../utils/onErrorDecorator";
88

99
export type BundlePreValidateState = {
1010
host?: URL;
@@ -56,14 +56,16 @@ export class BundlePreValidateModel extends BaseModelWithStateCache<BundlePreVal
5656
}
5757

5858
protected readStateFromTarget(
59-
target: BundleTarget
60-
): BundlePreValidateState {
61-
return {
62-
...target,
63-
host: UrlUtils.normalizeHost(target?.workspace?.host ?? ""),
64-
mode: target?.mode as BundlePreValidateState["mode"],
65-
authParams: undefined,
66-
};
59+
target?: BundleTarget
60+
): BundlePreValidateState | undefined {
61+
return target
62+
? {
63+
...target,
64+
host: UrlUtils.normalizeHost(target?.workspace?.host ?? ""),
65+
mode: target?.mode as BundlePreValidateState["mode"],
66+
authParams: undefined,
67+
}
68+
: undefined;
6769
}
6870

6971
@onError({popup: {prefix: "Failed to parse bundle yaml"}})
@@ -76,7 +78,7 @@ export class BundlePreValidateModel extends BaseModelWithStateCache<BundlePreVal
7678
const targetObject = (await this.bundleFileSet.bundleDataCache.value)
7779
.targets?.[this.target];
7880

79-
return this.readStateFromTarget(targetObject ?? {});
81+
return this.readStateFromTarget(targetObject) ?? {};
8082
}
8183

8284
public async getFileToWrite(key: string) {

packages/databricks-vscode/src/bundle/models/BundleValidateModel.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {AuthProvider} from "../../configuration/auth/AuthProvider";
44
import {Mutex} from "../../locking";
55
import {CliWrapper} from "../../cli/CliWrapper";
66
import {BundleTarget} from "../types";
7-
import {onError} from "../../utils/onErrorDecorator";
87
import lodash from "lodash";
98
import {workspaceConfigs} from "../../vscode-objs/WorkspaceConfigs";
109
import {BaseModelWithStateCache} from "../../configuration/models/BaseModelWithStateCache";

packages/databricks-vscode/src/configuration/ConnectionManager.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ export class ConnectionManager implements Disposable {
107107
constructor(
108108
private cli: CliWrapper,
109109
private readonly configModel: ConfigModel,
110-
private readonly workspaceUri: Uri
110+
private readonly workspaceUri: Uri,
111+
private readonly customWhenContext: CustomWhenContext
111112
) {}
112113

113114
public async init() {
@@ -330,7 +331,7 @@ export class ConnectionManager implements Disposable {
330331
this._state = newState;
331332
this.onDidChangeStateEmitter.fire(this._state);
332333
}
333-
CustomWhenContext.setLoggedIn(this._state === "CONNECTED");
334+
this.customWhenContext.setLoggedIn(this._state === "CONNECTED");
334335
}
335336

336337
async startCluster() {

packages/databricks-vscode/src/configuration/models/ConfigModel.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
BundleValidateModel,
1818
BundleValidateState,
1919
} from "../../bundle/models/BundleValidateModel";
20+
import {CustomWhenContext} from "../../vscode-objs/CustomWhenContext";
2021

2122
const defaults: ConfigState = {
2223
mode: "development",
@@ -119,6 +120,7 @@ export class ConfigModel implements Disposable {
119120
public readonly bundleValidateModel: BundleValidateModel,
120121
public readonly overrideableConfigModel: OverrideableConfigModel,
121122
public readonly bundlePreValidateModel: BundlePreValidateModel,
123+
private readonly vscodeWhenContext: CustomWhenContext,
122124
private readonly stateStorage: StateStorage
123125
) {
124126
this.disposables.push(
@@ -183,15 +185,10 @@ export class ConfigModel implements Disposable {
183185
}
184186

185187
if (
186-
this.target !== undefined &&
187-
!(
188-
this.target in
189-
((await this.bundlePreValidateModel.targets) ?? {})
190-
)
188+
target !== undefined &&
189+
!(target in ((await this.bundlePreValidateModel.targets) ?? {}))
191190
) {
192-
throw new Error(
193-
`Target '${this.target}' doesn't exist in the bundle`
194-
);
191+
throw new Error(`Target '${target}' doesn't exist in the bundle`);
195192
}
196193
await this.configsMutex.synchronise(async () => {
197194
this._target = target;
@@ -207,6 +204,8 @@ export class ConfigModel implements Disposable {
207204
});
208205
this.onDidChangeTargetEmitter.fire();
209206
});
207+
208+
this.vscodeWhenContext.isTargetSet(this._target !== undefined);
210209
}
211210

212211
@onError({popup: {prefix: "Failed to set auth provider."}})

packages/databricks-vscode/src/configuration/models/OverrideableConfigModel.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {StateStorage} from "../../vscode-objs/StateStorage";
22
import {Mutex} from "../../locking";
33
import {BaseModelWithStateCache} from "./BaseModelWithStateCache";
4-
import {onError} from "../../utils/onErrorDecorator";
54

65
export type OverrideableConfigState = {
76
authProfile?: string;

packages/databricks-vscode/src/extension.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ import {ConfigModel} from "./configuration/models/ConfigModel";
5959
import {OverrideableConfigModel} from "./configuration/models/OverrideableConfigModel";
6060
import {BundlePreValidateModel} from "./bundle/models/BundlePreValidateModel";
6161

62+
const customWhenContext = new CustomWhenContext();
63+
6264
export async function activate(
6365
context: ExtensionContext
6466
): Promise<PublicApi | undefined> {
65-
CustomWhenContext.setActivated(false);
67+
customWhenContext.setActivated(false);
6668

6769
if (extensions.getExtension("databricks.databricks-vscode") !== undefined) {
6870
await commands.executeCommand(
@@ -142,8 +144,8 @@ export async function activate(
142144

143145
// manage contexts for experimental features
144146
function updateFeatureContexts() {
145-
CustomWhenContext.updateShowClusterView();
146-
CustomWhenContext.updateShowWorkspaceView();
147+
customWhenContext.updateShowClusterView();
148+
customWhenContext.updateShowWorkspaceView();
147149
}
148150

149151
updateFeatureContexts();
@@ -180,13 +182,15 @@ export async function activate(
180182
bundleValidateModel,
181183
overrideableConfigModel,
182184
bundlePreValidateModel,
185+
customWhenContext,
183186
stateStorage
184187
);
185188

186189
const connectionManager = new ConnectionManager(
187190
cli,
188191
configModel,
189-
workspaceUri
192+
workspaceUri,
193+
customWhenContext
190194
);
191195
context.subscriptions.push(
192196
connectionManager.onDidChangeState(async (state) => {
@@ -607,7 +611,7 @@ export async function activate(
607611
connectionManager.init().catch((e) => {
608612
window.showErrorMessage(e);
609613
});
610-
CustomWhenContext.setActivated(true);
614+
customWhenContext.setActivated(true);
611615
telemetry.recordEvent(Events.EXTENSION_ACTIVATED);
612616

613617
const publicApi: PublicApi = {
@@ -619,5 +623,5 @@ export async function activate(
619623

620624
// this method is called when your extension is deactivated
621625
export function deactivate() {
622-
CustomWhenContext.setActivated(false);
626+
customWhenContext.setActivated(false);
623627
}

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,30 @@ import {commands} from "vscode";
22
import {workspaceConfigs} from "./WorkspaceConfigs";
33

44
// eslint-disable-next-line @typescript-eslint/naming-convention
5-
export const CustomWhenContext = {
5+
export class CustomWhenContext {
66
setLoggedIn(value: boolean) {
77
commands.executeCommand(
88
"setContext",
99
"databricks.context.loggedIn",
1010
value
1111
);
12-
},
12+
}
1313

1414
setActivated(value: boolean) {
1515
commands.executeCommand(
1616
"setContext",
1717
"databricks.context.activated",
1818
value
1919
);
20-
},
20+
}
21+
22+
isTargetSet(value: boolean) {
23+
commands.executeCommand(
24+
"setContext",
25+
"databricks.context.bundle.isTargetSet",
26+
value
27+
);
28+
}
2129

2230
updateShowClusterView() {
2331
commands.executeCommand(
@@ -27,7 +35,7 @@ export const CustomWhenContext = {
2735
"views.cluster"
2836
)
2937
);
30-
},
38+
}
3139

3240
updateShowWorkspaceView() {
3341
commands.executeCommand(
@@ -37,5 +45,5 @@ export const CustomWhenContext = {
3745
"views.workspace"
3846
)
3947
);
40-
},
41-
};
48+
}
49+
}

0 commit comments

Comments
 (0)