Skip to content

Commit a0598ce

Browse files
authored
Point users to Python extension in DVC Setup (#4124)
* add link to python extension if users don't use it and disable buttons instead of removing completely
1 parent d5e7c48 commit a0598ce

File tree

6 files changed

+78
-24
lines changed

6 files changed

+78
-24
lines changed

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ describe('App', () => {
147147
/DVC & DVCLive cannot be auto-installed as Python was not located./
148148
)
149149
).toBeInTheDocument()
150-
expect(screen.queryByText('Install')).not.toBeInTheDocument()
151150
})
152151

153152
it('should tell the user they can auto-install DVC with a Python interpreter', () => {
@@ -169,7 +168,7 @@ describe('App', () => {
169168
expect(screen.getByText('Install (pip)')).toBeInTheDocument()
170169
})
171170

172-
it('should let the user find another Python interpreter to install DVC when the Python extension is not installed', () => {
171+
it('should let the user locate DVC when the Python extension is not installed', () => {
173172
renderApp({
174173
cliCompatible: undefined,
175174
dvcCliDetails: {
@@ -187,6 +186,24 @@ describe('App', () => {
187186
})
188187
})
189188

189+
it('should show python extension info when dvc is unavailable and Python extension is not installed', () => {
190+
renderApp({
191+
cliCompatible: undefined,
192+
dvcCliDetails: {
193+
command: 'python -m dvc',
194+
version: undefined
195+
}
196+
})
197+
198+
const infoText = screen.getByText(/detect or create python environments/)
199+
200+
expect(infoText).toBeInTheDocument()
201+
202+
sendSetDataMessage({ ...DEFAULT_DATA, isPythonExtensionUsed: true })
203+
204+
expect(infoText).not.toBeInTheDocument()
205+
})
206+
190207
it('should let the user find or create another Python interpreter to install DVC when the Python extension is installed', () => {
191208
renderApp({
192209
cliCompatible: undefined,

webview/src/setup/components/dvc/CliUnavailable.tsx

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
updatePythonEnvironment
1111
} from '../../util/messages'
1212
import { Warning } from '../../../shared/components/icons'
13+
import { ShowExtension } from '../remotes/ShowExtension'
1314

1415
export const CliUnavailable: React.FC<PropsWithChildren> = ({ children }) => {
1516
const { pythonBinPath, isPythonExtensionUsed, isPythonEnvironmentGlobal } =
@@ -35,21 +36,13 @@ export const CliUnavailable: React.FC<PropsWithChildren> = ({ children }) => {
3536
)}
3637
.
3738
</p>
38-
<div className={styles.sideBySideButtons}>
39-
<Button onClick={installDvc} text="Install (pip)" />
40-
{isPythonExtensionUsed && (
41-
<Button onClick={updatePythonEnvironment} text="Set Env" />
42-
)}
43-
<Button onClick={setupWorkspace} text="Locate DVC" />
44-
</div>
4539
</>
4640
) : (
4741
<>
4842
<p>
4943
{installationSentence} DVC & DVCLive cannot be auto-installed as Python
5044
was not located.
5145
</p>
52-
<Button onClick={setupWorkspace} text="Locate DVC" />
5346
</>
5447
)
5548

@@ -58,6 +51,27 @@ export const CliUnavailable: React.FC<PropsWithChildren> = ({ children }) => {
5851
<h1>DVC is currently unavailable</h1>
5952
{children}
6053
{conditionalContents}
54+
<div className={styles.sideBySideButtons}>
55+
<Button
56+
disabled={!canInstall}
57+
onClick={installDvc}
58+
text="Install (pip)"
59+
/>
60+
<Button
61+
disabled={!isPythonExtensionUsed}
62+
onClick={updatePythonEnvironment}
63+
text="Set Env"
64+
/>
65+
<Button onClick={setupWorkspace} text="Locate DVC" />
66+
</div>
67+
{isPythonExtensionUsed || (
68+
<ShowExtension
69+
className={styles.pythonExtInfo}
70+
id="ms-python.python"
71+
name="Python"
72+
capabilities="detect or create python environments"
73+
/>
74+
)}
6175
</EmptyState>
6276
)
6377
}

webview/src/setup/components/dvc/styles.module.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
font-size: inherit;
4646
}
4747

48-
.sideBySideButtons > *:not(:first-child) {
48+
.sideBySideButtons *:not(:first-child) {
4949
margin-left: 15px;
5050
}
51+
52+
.pythonExtInfo {
53+
max-width: 350px;
54+
margin: 8px auto;
55+
}

webview/src/setup/components/remotes/ShowExtension.tsx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,24 @@ import React from 'react'
22
import styles from './styles.module.scss'
33
import { Icon } from '../../../shared/components/Icon'
44
import { Extensions } from '../../../shared/components/icons'
5+
import { ExtensionLink } from '../shared/ExtensionLink'
56

67
export const ShowExtension: React.FC<{
78
capabilities: string
89
id: string
910
name: string
10-
}> = ({ capabilities, id, name }) => {
11-
const idQuery = `"@id:${id}"`
12-
11+
className?: string
12+
}> = ({ capabilities, id, name, className }) => {
1313
return (
14-
<p>
14+
<p className={className}>
1515
<Icon
1616
icon={Extensions}
1717
width={16}
1818
height={16}
1919
className={styles.infoIcon}
2020
/>{' '}
21-
The{' '}
22-
<a
23-
href={`command:workbench.extensions.search?${encodeURIComponent(
24-
idQuery
25-
)}`}
26-
>
27-
{name}
28-
</a>{' '}
29-
extension can be used to <span>{capabilities}</span>.
21+
The <ExtensionLink extensionId={id}>{name}</ExtensionLink> extension can
22+
be used to <span>{capabilities}</span>.
3023
</p>
3124
)
3225
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React, { PropsWithChildren } from 'react'
2+
import type { HTMLAttributes } from 'react'
3+
4+
interface ExtensionLinkProps extends HTMLAttributes<HTMLAnchorElement> {
5+
extensionId: string
6+
}
7+
8+
export const ExtensionLink: React.FC<PropsWithChildren<ExtensionLinkProps>> = ({
9+
extensionId,
10+
children,
11+
...props
12+
}) => {
13+
const idQuery = `"@id:${extensionId}"`
14+
return (
15+
<a
16+
href={`command:workbench.extensions.search?${encodeURIComponent(
17+
idQuery
18+
)}`}
19+
{...props}
20+
>
21+
{children}
22+
</a>
23+
)
24+
}

webview/src/shared/components/button/Button.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export type ButtonProps = {
99
isNested?: boolean
1010
children?: React.ReactNode
1111
disabled?: boolean
12+
className?: string
1213
}
1314

1415
export const Button: React.FC<ButtonProps> = ({

0 commit comments

Comments
 (0)