Skip to content

Commit ef2a987

Browse files
authored
Add webview for when dvc is not available or not initialized (#2861)
* Add webview for get started * Allow incompatible dvc to show webviews * Fix tests and lint errors * Make sure webviews load after initialization * Change order of sidebar views * Register open get started webview to simplify code paths * Remove useless changes
1 parent ae18530 commit ef2a987

File tree

12 files changed

+93
-14
lines changed

12 files changed

+93
-14
lines changed

extension/package.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,11 +1306,6 @@
13061306
}
13071307
],
13081308
"dvc-views": [
1309-
{
1310-
"id": "dvc.views.webviews",
1311-
"name": "Views",
1312-
"when": "dvc.commands.available && dvc.project.available"
1313-
},
13141309
{
13151310
"id": "dvc.views.experimentsColumnsTree",
13161311
"name": "Columns",
@@ -1321,6 +1316,11 @@
13211316
"name": "Welcome",
13221317
"when": "!dvc.commands.available || dvc.cli.incompatible || !dvc.project.available"
13231318
},
1319+
{
1320+
"id": "dvc.views.webviews",
1321+
"name": "Views",
1322+
"when": "true"
1323+
},
13241324
{
13251325
"id": "dvc.views.experimentsTree",
13261326
"name": "Experiments",
@@ -1353,6 +1353,11 @@
13531353
"contents": "[Show Experiments](command:dvc.showExperiments)\n[Show Plots](command:dvc.showPlots)\n[Show Experiments and Plots](command:dvc.showExperimentsAndPlots)",
13541354
"when": "dvc.commands.available && dvc.project.available"
13551355
},
1356+
{
1357+
"view": "dvc.views.webviews",
1358+
"contents": "[Show Experiments](command:dvc.showGetStartedWebview)\n[Show Plots](command:dvc.showGetStartedWebview)\n[Show Experiments and Plots](command:dvc.showGetStartedWebview)",
1359+
"when": "!dvc.commands.available || !dvc.project.available"
1360+
},
13561361
{
13571362
"view": "dvc.views.welcome",
13581363
"contents": "New to the extension?\n[Show Walkthrough](command:dvc.getStarted)\n\n",

extension/src/commands/external.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,7 @@ export enum RegisteredCommands {
9090
TRACKED_EXPLORER_COPY_REL_FILE_PATH = 'dvc.copyRelativeFilePath',
9191
TRACKED_EXPLORER_FIND_IN_FOLDER = 'dvc.findInFolder',
9292
TRACKED_EXPLORER_OPEN_TO_THE_SIDE = 'dvc.openToTheSide',
93-
TRACKED_EXPLORER_SELECT_FOR_COMPARE = 'dvc.selectForCompare'
93+
TRACKED_EXPLORER_SELECT_FOR_COMPARE = 'dvc.selectForCompare',
94+
95+
GET_STARTED_WEBVIEW_SHOW = 'dvc.showGetStartedWebview'
9496
}

extension/src/extension.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ import { collectWorkspaceScale } from './telemetry/collect'
6161
import { createFileSystemWatcher } from './fileSystem/watcher'
6262
import { GitExecutor } from './cli/git/executor'
6363
import { GitReader } from './cli/git/reader'
64+
import { createWebview } from './webview/factory'
65+
import { ViewKey } from './webview/constants'
6466

6567
export class Extension extends Disposable implements IExtension {
6668
protected readonly internalCommands: InternalCommands
@@ -252,6 +254,19 @@ export class Extension extends Disposable implements IExtension {
252254
}
253255
)
254256

257+
this.internalCommands.registerExternalCommand(
258+
RegisteredCommands.GET_STARTED_WEBVIEW_SHOW,
259+
async () => {
260+
await createWebview(
261+
ViewKey.GET_STARTED,
262+
'',
263+
this.resourceLocator.dvcIcon,
264+
ViewColumn.Active,
265+
true
266+
)
267+
}
268+
)
269+
255270
this.dispose.track(
256271
commands.registerCommand(RegisteredCommands.STOP_EXPERIMENT, async () => {
257272
const stopWatch = new StopWatch()

extension/src/telemetry/constants.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ export const EventName = Object.assign(
5858
VIEWS_EXPERIMENTS_TABLE_SORT_COLUMN:
5959
'views.experimentsTable.columnSortAdded',
6060

61+
VIEWS_GET_STARTED_CLOSE: 'view.GET_STARTED.closed',
62+
VIEWS_GET_STARTED_CREATED: 'view.GET_STARTED.created',
63+
VIEWS_GET_STARTED_FOCUS_CHANGED: 'views.GET_STARTED.focusChanged',
64+
6165
VIEWS_PLOTS_CLOSED: 'views.plots.closed',
6266
VIEWS_PLOTS_COMPARISON_ROWS_REORDERED:
6367
'views.plots.comparisonRowsReordered',
@@ -252,4 +256,10 @@ export interface IEventNamePropertyMapping {
252256
[EventName.VIEWS_TERMINAL_CREATED]: undefined
253257

254258
[EventName.VIEWS_TRACKED_EXPLORER_TREE_OPENED]: DvcRootCount
259+
260+
[EventName.VIEWS_GET_STARTED_CLOSE]: undefined
261+
[EventName.VIEWS_GET_STARTED_CREATED]: undefined
262+
[EventName.VIEWS_GET_STARTED_FOCUS_CHANGED]: undefined
263+
264+
[EventName.GET_STARTED_WEBVIEW_SHOW]: undefined
255265
}

extension/src/webview/constants.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
import { distPath, react, experiments, plots } from 'dvc-vscode-webview'
1+
import {
2+
distPath,
3+
react,
4+
experiments,
5+
plots,
6+
getStarted
7+
} from 'dvc-vscode-webview'
28
import { EventName, IEventNamePropertyMapping } from '../telemetry/constants'
39

410
export enum ViewKey {
511
EXPERIMENTS = 'dvc-experiments',
6-
PLOTS = 'dvc-plots'
12+
PLOTS = 'dvc-plots',
13+
GET_STARTED = 'dvc-getStarted'
714
}
815

916
type Name = keyof IEventNamePropertyMapping
@@ -46,5 +53,17 @@ export const WebviewDetails: {
4653
scripts: [react, plots],
4754
title: 'Plots',
4855
viewKey: ViewKey.PLOTS
56+
},
57+
[ViewKey.GET_STARTED]: {
58+
contextKey: 'dvc.getStarted.webviewActive',
59+
distPath,
60+
eventNames: {
61+
closedEvent: EventName.VIEWS_GET_STARTED_CLOSE,
62+
createdEvent: EventName.VIEWS_GET_STARTED_CREATED,
63+
focusChangedEvent: EventName.VIEWS_GET_STARTED_FOCUS_CHANGED
64+
},
65+
scripts: [react, getStarted],
66+
title: 'DVC is not initialized',
67+
viewKey: ViewKey.GET_STARTED
4968
}
5069
} as const

extension/src/webview/factory.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ export const isValidDvcRoot = (dvcRoot?: string): dvcRoot is string => !!dvcRoot
1010
const create = (
1111
viewKey: ViewKey,
1212
webviewPanel: WebviewPanel,
13-
dvcRoot: string
13+
dvcRoot: string,
14+
bypassDvcRoot?: boolean
1415
) => {
15-
if (!isValidDvcRoot(dvcRoot)) {
16+
if (!bypassDvcRoot && !isValidDvcRoot(dvcRoot)) {
1617
throw new Error(`trying to set invalid state into ${viewKey}`)
1718
}
1819

@@ -25,7 +26,8 @@ export const createWebview = async (
2526
viewKey: ViewKey,
2627
dvcRoot: string,
2728
iconPath: Resource,
28-
viewColumn?: ViewColumn
29+
viewColumn?: ViewColumn,
30+
bypassDvcRoot?: boolean
2931
) => {
3032
const { title, distPath } = WebviewDetails[viewKey]
3133

@@ -42,7 +44,7 @@ export const createWebview = async (
4244

4345
webviewPanel.iconPath = iconPath
4446

45-
const view = create(viewKey, webviewPanel, dvcRoot)
47+
const view = create(viewKey, webviewPanel, dvcRoot, bypassDvcRoot)
4648
await view.isReady()
4749
return view
4850
}

webview/.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ module.exports = {
1616
files: [
1717
'src/experiments/index.tsx',
1818
'src/plots/index.tsx',
19-
'src/shared/components/icons/index.ts'
19+
'src/shared/components/icons/index.ts',
20+
'src/getStarted/index.tsx'
2021
],
2122
rules: {
2223
'check-file/no-index': 'off'

webview/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export const distPath: string
22
export const experiments: string
33
export const plots: string
4+
export const getStarted: string
45
export const react: string

webview/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ const path = require('path')
88
module.exports.distPath = path.join(__dirname, 'dist')
99
module.exports.experiments = path.join(__dirname, 'dist/experiments.js')
1010
module.exports.plots = path.join(__dirname, 'dist/plots.js')
11+
module.exports.getStarted = path.join(__dirname, 'dist/getStarted.js')
1112
module.exports.react = path.join(__dirname, 'dist/react.js')
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react'
2+
import { EmptyState } from '../../shared/components/emptyState/EmptyState'
3+
4+
export const App: React.FC = () => {
5+
return (
6+
<EmptyState>
7+
<div>
8+
<h1>DVC is not available or not initialized</h1>
9+
</div>
10+
</EmptyState>
11+
)
12+
}

0 commit comments

Comments
 (0)