Skip to content

Commit a656fb2

Browse files
authored
Simply welcome view inside view container (#3023)
1 parent e547b52 commit a656fb2

File tree

8 files changed

+64
-44
lines changed

8 files changed

+64
-44
lines changed

extension/package.json

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,24 +1360,9 @@
13601360
},
13611361
{
13621362
"view": "dvc.views.welcome",
1363-
"contents": "New to the extension?\n[Show Walkthrough](command:dvc.getStarted)\n\n",
1363+
"contents": "New to the extension?\n[Show Walkthrough](command:dvc.getStarted)\n\nThe extension is currently unable to initialize.\n[Show Setup](command:dvc.showSetup)",
13641364
"when": "true"
13651365
},
1366-
{
1367-
"view": "dvc.views.welcome",
1368-
"contents": "DVC is currently unavailable, [learn more](https://dvc.org/doc).\n[Setup the Workspace](command:dvc.setupWorkspace)",
1369-
"when": "!dvc.commands.available && !dvc.cli.incompatible"
1370-
},
1371-
{
1372-
"view": "dvc.views.welcome",
1373-
"contents": "The located version of DVC is incompatible with the extension.\n[Find Another](command:dvc.setupWorkspace)\nUpgrade DVC then...\n[Check Compatibility](command:dvc.checkCLICompatible)",
1374-
"when": "dvc.cli.incompatible"
1375-
},
1376-
{
1377-
"view": "dvc.views.welcome",
1378-
"contents": "The current workspace does not contain a DVC project. You can initialize a project which will enable features powered by DVC.\n[Initialize Project](command:dvc.init)\nTo learn more about how to use DVC please read [our docs](https://dvc.org/doc).",
1379-
"when": "dvc.commands.available && !dvc.cli.incompatible && !dvc.project.available"
1380-
},
13811366
{
13821367
"view": "dvc.views.trackedExplorerTree",
13831368
"contents": "No Tracked Data to Display."

extension/src/setup/webview/messages.ts

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,26 @@ export class WebviewMessages {
4848
}
4949

5050
public handleMessageFromWebview(message: MessageFromWebview) {
51-
if (message.type === MessageFromWebviewType.INITIALIZE_DVC) {
52-
return this.initializeDvc()
51+
switch (message.type) {
52+
case MessageFromWebviewType.CHECK_CLI_COMPATIBLE:
53+
return commands.executeCommand(
54+
RegisteredCommands.EXTENSION_CHECK_CLI_COMPATIBLE
55+
)
56+
case MessageFromWebviewType.INITIALIZE_DVC:
57+
return this.initializeDvc()
58+
case MessageFromWebviewType.INITIALIZE_GIT:
59+
return this.initializeGit()
60+
case MessageFromWebviewType.SELECT_PYTHON_INTERPRETER:
61+
return this.selectPythonInterpreter()
62+
case MessageFromWebviewType.INSTALL_DVC:
63+
return this.installDvc()
64+
case MessageFromWebviewType.SETUP_WORKSPACE:
65+
return commands.executeCommand(
66+
RegisteredCommands.EXTENSION_SETUP_WORKSPACE
67+
)
68+
default:
69+
Logger.error(`Unexpected message: ${JSON.stringify(message)}`)
5370
}
54-
55-
if (message.type === MessageFromWebviewType.INITIALIZE_GIT) {
56-
return this.initializeGit()
57-
}
58-
59-
if (message.type === MessageFromWebviewType.SELECT_PYTHON_INTERPRETER) {
60-
return this.selectPythonInterpreter()
61-
}
62-
63-
if (message.type === MessageFromWebviewType.INSTALL_DVC) {
64-
return this.installDvc()
65-
}
66-
67-
if (message.type === MessageFromWebviewType.SETUP_WORKSPACE) {
68-
return commands.executeCommand(
69-
RegisteredCommands.EXTENSION_SETUP_WORKSPACE
70-
)
71-
}
72-
73-
Logger.error(`Unexpected message: ${JSON.stringify(message)}`)
7471
}
7572

7673
private selectPythonInterpreter() {

extension/src/test/suite/setup/index.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ suite('Setup Test Suite', () => {
5656
expect(mockInitializeDvc).to.be.calledOnce
5757
}).timeout(WEBVIEW_TEST_TIMEOUT)
5858

59+
it('should handle a check cli compatible message from the webview', async () => {
60+
const { messageSpy, setup, mockExecuteCommand } = buildSetup(disposable)
61+
62+
const webview = await setup.showWebview()
63+
await webview.isReady()
64+
65+
const mockMessageReceived = getMessageReceivedEmitter(webview)
66+
67+
messageSpy.resetHistory()
68+
mockMessageReceived.fire({
69+
type: MessageFromWebviewType.CHECK_CLI_COMPATIBLE
70+
})
71+
72+
expect(mockExecuteCommand).to.be.calledWithExactly(
73+
RegisteredCommands.EXTENSION_CHECK_CLI_COMPATIBLE
74+
)
75+
}).timeout(WEBVIEW_TEST_TIMEOUT)
76+
5977
it('should handle an auto install dvc message from the webview', async () => {
6078
const { messageSpy, setup, mockAutoInstallDvc } = buildSetup(disposable)
6179

extension/src/webview/contract.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export enum MessageFromWebviewType {
4848
MODIFY_EXPERIMENT_PARAMS_AND_RUN = 'modify-experiment-params-and-run',
4949
MODIFY_EXPERIMENT_PARAMS_RESET_AND_RUN = 'modify-experiment-params-reset-and-run',
5050
SET_EXPERIMENTS_HEADER_HEIGHT = 'update-experiments-header-height',
51+
CHECK_CLI_COMPATIBLE = 'check-cli-compatible',
5152
INITIALIZE_DVC = 'initialize-dvc',
5253
INITIALIZE_GIT = 'initialize-git',
5354
INSTALL_DVC = 'install-dvc',
@@ -183,6 +184,7 @@ export type MessageFromWebview =
183184
payload: string
184185
}
185186
| { type: MessageFromWebviewType.SET_EXPERIMENTS_HEADER_HEIGHT }
187+
| { type: MessageFromWebviewType.CHECK_CLI_COMPATIBLE }
186188
| { type: MessageFromWebviewType.INITIALIZE_DVC }
187189
| { type: MessageFromWebviewType.INITIALIZE_GIT }
188190
| { type: MessageFromWebviewType.INSTALL_DVC }

webview/src/setup/components/App.test.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ describe('App', () => {
7272
})
7373

7474
expect(screen.getByText('DVC is incompatible')).toBeInTheDocument()
75+
76+
const button = screen.getByText('Check Compatibility')
77+
expect(button).toBeInTheDocument()
78+
79+
fireEvent.click(button)
80+
expect(mockPostMessage).toHaveBeenCalledWith({
81+
type: MessageFromWebviewType.CHECK_CLI_COMPATIBLE
82+
})
7583
})
7684

7785
it('should show a screen saying that DVC is not installed if the cli is unavailable', () => {

webview/src/setup/components/App.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ export const App: React.FC = () => {
5454
)
5555
)
5656

57+
const checkCompatibility = () => {
58+
sendMessage({ type: MessageFromWebviewType.CHECK_CLI_COMPATIBLE })
59+
}
60+
5761
const initializeGit = () => {
5862
sendMessage({
5963
type: MessageFromWebviewType.INITIALIZE_GIT
@@ -79,7 +83,7 @@ export const App: React.FC = () => {
7983
}
8084

8185
if (cliCompatible === false) {
82-
return <CliIncompatible />
86+
return <CliIncompatible checkCompatibility={checkCompatibility} />
8387
}
8488

8589
if (cliCompatible === undefined) {
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import React from 'react'
22
import { MIN_CLI_VERSION } from 'dvc/src/cli/dvc/contract'
33
import { EmptyState } from '../../shared/components/emptyState/EmptyState'
4+
import { Button } from '../../shared/components/button/Button'
45

5-
export const CliIncompatible: React.FC = () => (
6+
type CliIncompatibleProps = { checkCompatibility: () => void }
7+
8+
export const CliIncompatible: React.FC<CliIncompatibleProps> = ({
9+
checkCompatibility
10+
}) => (
611
<EmptyState>
712
<div>
813
<h1>DVC is incompatible</h1>
9-
<p>The located CLI is incompatible with the extension</p>
10-
<p>The minimum version is {MIN_CLI_VERSION}</p>
11-
<p>Please update your install and try again</p>
14+
<p>The located CLI is incompatible with the extension.</p>
15+
<p>The minimum version is {MIN_CLI_VERSION}.</p>
16+
<p>Please update your install and try again.</p>
17+
<Button text="Check Compatibility" onClick={checkCompatibility} />
1218
</div>
1319
</EmptyState>
1420
)

webview/src/stories/CliIncompatible.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default {
1414
} as Meta
1515

1616
const Template: Story = () => {
17-
return <CliIncompatible />
17+
return <CliIncompatible checkCompatibility={() => undefined} />
1818
}
1919

2020
export const CliFoundButNotCompatible = Template.bind({})

0 commit comments

Comments
 (0)