Skip to content

Commit 6fc9267

Browse files
authored
Direct users to setup webview from warning popups (#2990)
* direct to setup webview from all CLI unavailable popups * fix show setup underneath show plots button
1 parent 16a79dc commit 6fc9267

File tree

12 files changed

+96
-80
lines changed

12 files changed

+96
-80
lines changed

extension/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,7 @@
13551355
},
13561356
{
13571357
"view": "dvc.views.webviews",
1358-
"contents": "[Show Experiments](command:dvc.showSetupWebview)\n[Show Plots](command:dvc.showSetupdWebview)\n[Show Experiments and Plots](command:dvc.showSetupWebview)",
1358+
"contents": "[Show Experiments](command:dvc.showSetup)\n[Show Plots](command:dvc.showSetup)\n[Show Experiments and Plots](command:dvc.showSetup)",
13591359
"when": "!dvc.commands.available || !dvc.project.available || !dvc.project.hasData"
13601360
},
13611361
{

extension/src/cli/dvc/discovery.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ const warnUserCLIInaccessible = async (
4646

4747
const response = await Toast.warnWithOptions(
4848
warningText,
49-
Response.SETUP_WORKSPACE,
49+
Response.SHOW_SETUP,
5050
Response.NEVER
5151
)
5252

5353
switch (response) {
54-
case Response.SETUP_WORKSPACE:
55-
return extension.setupWorkspace()
54+
case Response.SHOW_SETUP:
55+
return extension.showSetup()
5656
case Response.NEVER:
5757
return setUserConfigValue(ConfigKey.DO_NOT_SHOW_CLI_UNAVAILABLE, true)
5858
}
@@ -77,7 +77,7 @@ const warnUser = (
7777
cliCompatible: CliCompatible,
7878
version: string | undefined
7979
): void => {
80-
if (!extension.hasRoots()) {
80+
if (!extension.shouldWarnUserIfCLIUnavailable()) {
8181
return
8282
}
8383
switch (cliCompatible) {
@@ -154,11 +154,11 @@ const tryGlobalFallbackVersion = async (
154154
const tryGlobal = await getVersionDetails(extension, cwd, true)
155155
const { cliCompatible, isAvailable, isCompatible, version } = tryGlobal
156156

157-
if (extension.hasRoots() && !isCompatible) {
157+
if (extension.shouldWarnUserIfCLIUnavailable() && !isCompatible) {
158158
warnUserCLIInaccessibleAnywhere(extension, version)
159159
}
160160
if (
161-
extension.hasRoots() &&
161+
extension.shouldWarnUserIfCLIUnavailable() &&
162162
cliCompatible === CliCompatible.YES_MINOR_VERSION_AHEAD_OF_TESTED
163163
) {
164164
warnAheadOfLatestTested()

extension/src/commands/external.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,5 @@ export enum RegisteredCommands {
9292
TRACKED_EXPLORER_OPEN_TO_THE_SIDE = 'dvc.openToTheSide',
9393
TRACKED_EXPLORER_SELECT_FOR_COMPARE = 'dvc.selectForCompare',
9494

95-
SETUP_WEBVIEW_SHOW = 'dvc.showSetupWebview'
95+
SETUP_SHOW = 'dvc.showSetup'
9696
}

extension/src/extension.ts

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ export class Extension extends Disposable implements IExtension {
274274
)
275275

276276
this.internalCommands.registerExternalCommand(
277-
RegisteredCommands.SETUP_WEBVIEW_SHOW,
277+
RegisteredCommands.SETUP_SHOW,
278278
async () => {
279279
await this.setup.showWebview()
280280
}
@@ -341,39 +341,12 @@ export class Extension extends Disposable implements IExtension {
341341
this.watchForVenvChanges()
342342
}
343343

344-
public async setupWorkspace() {
345-
const stopWatch = new StopWatch()
346-
try {
347-
const previousCliPath = this.config.getCliPath()
348-
const previousPythonPath = this.config.getPythonBinPath()
349-
350-
const completed = await setupWorkspace(() =>
351-
this.config.setPythonAndNotifyIfChanged()
352-
)
353-
sendTelemetryEvent(
354-
RegisteredCommands.EXTENSION_SETUP_WORKSPACE,
355-
{ completed },
356-
{
357-
duration: stopWatch.getElapsedTime()
358-
}
359-
)
360-
361-
const executionDetailsUnchanged =
362-
this.config.getCliPath() === previousPythonPath &&
363-
this.config.getPythonBinPath() === previousCliPath
364-
365-
if (completed && !this.cliAccessible && executionDetailsUnchanged) {
366-
this.workspaceChanged.fire()
367-
}
344+
public async showSetup() {
345+
return await this.setup.showWebview()
346+
}
368347

369-
return completed
370-
} catch (error: unknown) {
371-
return sendTelemetryEventAndThrow(
372-
RegisteredCommands.EXTENSION_SETUP_WORKSPACE,
373-
error as Error,
374-
stopWatch.getElapsedTime()
375-
)
376-
}
348+
public shouldWarnUserIfCLIUnavailable() {
349+
return this.hasRoots() && !this.setup.isFocused()
377350
}
378351

379352
public async isPythonExtensionUsed() {
@@ -479,6 +452,41 @@ export class Extension extends Disposable implements IExtension {
479452
setContextValue('dvc.commands.available', available)
480453
}
481454

455+
private async setupWorkspace() {
456+
const stopWatch = new StopWatch()
457+
try {
458+
const previousCliPath = this.config.getCliPath()
459+
const previousPythonPath = this.config.getPythonBinPath()
460+
461+
const completed = await setupWorkspace(() =>
462+
this.config.setPythonAndNotifyIfChanged()
463+
)
464+
sendTelemetryEvent(
465+
RegisteredCommands.EXTENSION_SETUP_WORKSPACE,
466+
{ completed },
467+
{
468+
duration: stopWatch.getElapsedTime()
469+
}
470+
)
471+
472+
const executionDetailsUnchanged =
473+
this.config.getCliPath() === previousPythonPath &&
474+
this.config.getPythonBinPath() === previousCliPath
475+
476+
if (completed && !this.cliAccessible && executionDetailsUnchanged) {
477+
this.workspaceChanged.fire()
478+
}
479+
480+
return completed
481+
} catch (error: unknown) {
482+
return sendTelemetryEventAndThrow(
483+
RegisteredCommands.EXTENSION_SETUP_WORKSPACE,
484+
error as Error,
485+
stopWatch.getElapsedTime()
486+
)
487+
}
488+
}
489+
482490
private setProjectAvailability() {
483491
const available = this.hasRoots()
484492
setContextValue('dvc.project.available', available)

extension/src/interfaces.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export interface IExtension {
77
hasRoots: () => boolean
88
isPythonExtensionUsed: () => Promise<boolean>
99

10-
setupWorkspace: () => void
10+
showSetup: () => void
11+
shouldWarnUserIfCLIUnavailable: () => boolean
1112

1213
initialize: () => Promise<void[]>
1314
resetMembers: () => void

0 commit comments

Comments
 (0)