Skip to content

Commit 6f6fd6f

Browse files
authored
Improve in-progress auth UI (#1038)
- Configuration view shows "connecting" message when relevant - Connection manager now jump into the "connecting" state earlier - `ConnectionManager.login` is now `connect`, since we don't actually login there - Remove unnecessary auth provider `check` call inside the `connect` - Show progress UI during `connect` (and we already have another progress during login, which happens earlier)
1 parent 385d1fc commit 6f6fd6f

File tree

2 files changed

+58
-56
lines changed

2 files changed

+58
-56
lines changed

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

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,19 @@ export class ConnectionManager implements Disposable {
174174
return this._workspaceClient?.apiClient;
175175
}
176176

177-
async resolveAuth() {
177+
private async loginWithSavedAuth() {
178+
const authProvider = await this.resolveAuth();
179+
if (authProvider === undefined) {
180+
await this.logout();
181+
return;
182+
}
183+
await this.connect(authProvider);
184+
}
185+
186+
@onError({popup: {prefix: "Failed to login."}})
187+
@Mutex.synchronise("loginLogoutMutex")
188+
private async resolveAuth() {
189+
this.updateState("CONNECTING");
178190
const host = await this.configModel.get("host");
179191
const target = this.configModel.target;
180192
if (host === undefined || target === undefined) {
@@ -211,63 +223,52 @@ export class ConnectionManager implements Disposable {
211223
}
212224
}
213225

214-
@onError({
215-
popup: {prefix: "Can't login with saved auth."},
216-
})
217-
private async loginWithSavedAuth() {
218-
const authProvider = await this.resolveAuth();
219-
if (authProvider === undefined) {
220-
await this.logout();
221-
return;
222-
}
223-
await this.login(authProvider);
224-
}
225-
226-
private async login(authProvider: AuthProvider): Promise<void> {
227-
if (!(await authProvider.check())) {
228-
// We return without any state changes. This ensures that
229-
// if users move from a working auth type to an invalid
230-
// auth, the old auth will continue working and they will not
231-
// have to re authenticate even the old one.
232-
return;
233-
}
234-
226+
private async connect(authProvider: AuthProvider): Promise<void> {
235227
try {
236-
await this.loginLogoutMutex.synchronise(async () => {
237-
this.updateState("CONNECTING");
238-
239-
const databricksWorkspace = await DatabricksWorkspace.load(
240-
authProvider.getWorkspaceClient(),
241-
authProvider
242-
);
243-
this._databricksWorkspace = databricksWorkspace;
244-
this._workspaceClient = authProvider.getWorkspaceClient();
245-
246-
await this._databricksWorkspace.optionalEnableFilesInReposPopup(
247-
this._workspaceClient
248-
);
249-
await this.configModel.set(
250-
"authProfile",
251-
authProvider.toJSON().profile as string | undefined
252-
);
253-
await this.configModel.setAuthProvider(authProvider);
254-
await this.updateSyncDestinationMapper();
255-
await this.updateClusterManager();
256-
await this._metadataService.setApiClient(this.apiClient);
257-
this.updateState("CONNECTED");
258-
});
228+
await window.withProgress(
229+
{
230+
location: {viewId: "configurationView"},
231+
title: "Connecting to the workspace",
232+
},
233+
() => this._connect(authProvider)
234+
);
259235
} catch (e) {
260-
NamedLogger.getOrCreate("Extension").error(`Login failed`, e);
236+
NamedLogger.getOrCreate("Extension").error(
237+
`Can't connect to the workspace`,
238+
e
239+
);
261240
if (e instanceof Error) {
262241
await window.showWarningMessage(
263-
`Login failed with error: "${e.message}"."`
242+
`Can't connect to the workspace: "${e.message}"."`
264243
);
265244
}
266245
await this.logout();
267246
}
268247
}
269248

270-
@onError({popup: {prefix: "Can't logout"}})
249+
@Mutex.synchronise("loginLogoutMutex")
250+
private async _connect(authProvider: AuthProvider) {
251+
this.updateState("CONNECTING");
252+
this._databricksWorkspace = await DatabricksWorkspace.load(
253+
authProvider.getWorkspaceClient(),
254+
authProvider
255+
);
256+
this._workspaceClient = authProvider.getWorkspaceClient();
257+
await this._databricksWorkspace.optionalEnableFilesInReposPopup(
258+
this._workspaceClient
259+
);
260+
await this.configModel.set(
261+
"authProfile",
262+
authProvider.toJSON().profile as string | undefined
263+
);
264+
await this.configModel.setAuthProvider(authProvider);
265+
await this.updateSyncDestinationMapper();
266+
await this.updateClusterManager();
267+
await this._metadataService.setApiClient(this.apiClient);
268+
this.updateState("CONNECTED");
269+
}
270+
271+
@onError({popup: {prefix: "Can't logout."}})
271272
@Mutex.synchronise("loginLogoutMutex")
272273
async logout() {
273274
this._workspaceClient = undefined;
@@ -288,8 +289,7 @@ export class ConnectionManager implements Disposable {
288289
if (!authProvider) {
289290
return;
290291
}
291-
292-
await this.login(authProvider);
292+
await this.connect(authProvider);
293293
}
294294

295295
@onError({

packages/databricks-vscode/src/configuration/ui/AuthTypeComponent.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,20 @@ export class AuthTypeComponent extends BaseComponent {
2828
const authProvider =
2929
this.connectionManager.databricksWorkspace?.authProvider;
3030

31-
if (this.configModel.target === undefined) {
32-
return [];
31+
if (this.connectionManager.state === "CONNECTING") {
32+
return [
33+
{
34+
label: "Connecting to the workspace",
35+
iconPath: new ThemeIcon("sync~spin"),
36+
},
37+
];
3338
}
3439

3540
if (authProvider === undefined) {
3641
const label = "Login to Databricks";
3742
return [
3843
{
39-
label: {
40-
label: label,
41-
highlights: [[0, label.length]],
42-
},
44+
label: {label},
4345
iconPath: new ThemeIcon(
4446
"account",
4547
new ThemeColor("notificationsErrorIcon.foreground")

0 commit comments

Comments
 (0)