Skip to content

Commit

Permalink
Merge branch 'main' into only-disable-for-workspace-runs
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon authored May 8, 2023
2 parents fca9961 + 59ae23d commit 2f63386
Show file tree
Hide file tree
Showing 13 changed files with 387 additions and 84 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"svgr": "yarn workspace dvc-vscode-webview svgr"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "5.59.1",
"@typescript-eslint/parser": "5.59.1",
"@typescript-eslint/eslint-plugin": "5.59.2",
"@typescript-eslint/parser": "5.59.2",
"@vscode/codicons": "0.0.32",
"eslint": "8.39.0",
"eslint-config-prettier": "8.8.0",
Expand Down
209 changes: 209 additions & 0 deletions webview/src/setup/components/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React from 'react'
import { SetupSection, SetupData } from 'dvc/src/setup/webview/contract'
import { App } from './App'
import { vsCodeApi } from '../../shared/api'
import { TooltipIconType } from '../../shared/components/sectionContainer/InfoTooltip'

jest.mock('../../shared/api')
jest.mock('../../shared/components/codeSlider/CodeSlider')
Expand Down Expand Up @@ -629,6 +630,58 @@ describe('App', () => {
type: MessageFromWebviewType.SELECT_PYTHON_INTERPRETER
})
})

it('should show an error icon if DVC is not setup', () => {
renderApp({
canGitInitialize: false,
cliCompatible: true,
dvcCliDetails: {
command: 'python -m dvc',
version: '1.0.0'
},
hasData: false,
isPythonExtensionUsed: false,
isStudioConnected: false,
needsGitCommit: false,
needsGitInitialized: undefined,
projectInitialized: false,
pythonBinPath: undefined,
sectionCollapsed: undefined,
shareLiveToStudio: false
})

const iconWrapper = screen.getAllByTestId('info-tooltip-toggle')[0]

expect(
within(iconWrapper).getByTestId(TooltipIconType.ERROR)
).toBeInTheDocument()
})

it('should show a passed icon if DVC CLI is compatible and project is initialized', () => {
renderApp({
canGitInitialize: false,
cliCompatible: true,
dvcCliDetails: {
command: 'python -m dvc',
version: '1.0.0'
},
hasData: true,
isPythonExtensionUsed: true,
isStudioConnected: true,
needsGitCommit: false,
needsGitInitialized: false,
projectInitialized: true,
pythonBinPath: 'python',
sectionCollapsed: undefined,
shareLiveToStudio: false
})

const iconWrapper = screen.getAllByTestId('info-tooltip-toggle')[0]

expect(
within(iconWrapper).getByTestId(TooltipIconType.PASSED)
).toBeInTheDocument()
})
})

describe('Experiments', () => {
Expand Down Expand Up @@ -823,6 +876,84 @@ describe('App', () => {
type: MessageFromWebviewType.OPEN_EXPERIMENTS_WEBVIEW
})
})

it('should show an error icon if experiments are not setup', () => {
renderApp({
canGitInitialize: false,
cliCompatible: true,
dvcCliDetails: {
command: 'python -m dvc',
version: '1.0.0'
},
hasData: false,
isPythonExtensionUsed: false,
isStudioConnected: false,
needsGitCommit: false,
needsGitInitialized: undefined,
projectInitialized: true,
pythonBinPath: undefined,
sectionCollapsed: undefined,
shareLiveToStudio: false
})

const iconWrapper = screen.getAllByTestId('info-tooltip-toggle')[1]

expect(
within(iconWrapper).getByTestId(TooltipIconType.ERROR)
).toBeInTheDocument()
})

it('should show an error icon if dvc is not setup', () => {
renderApp({
canGitInitialize: false,
cliCompatible: false,
dvcCliDetails: {
command: 'dvc',
version: '1.0.0'
},
hasData: false,
isPythonExtensionUsed: false,
isStudioConnected: false,
needsGitCommit: false,
needsGitInitialized: undefined,
projectInitialized: false,
pythonBinPath: undefined,
sectionCollapsed: undefined,
shareLiveToStudio: false
})

const iconWrapper = screen.getAllByTestId('info-tooltip-toggle')[1]

expect(
within(iconWrapper).getByTestId(TooltipIconType.ERROR)
).toBeInTheDocument()
})

it('should show a passed icon if experiments are setup', () => {
renderApp({
canGitInitialize: false,
cliCompatible: true,
dvcCliDetails: {
command: 'python -m dvc',
version: '1.0.0'
},
hasData: true,
isPythonExtensionUsed: true,
isStudioConnected: true,
needsGitCommit: false,
needsGitInitialized: false,
projectInitialized: true,
pythonBinPath: 'python',
sectionCollapsed: undefined,
shareLiveToStudio: false
})

const iconWrapper = screen.getAllByTestId('info-tooltip-toggle')[1]

expect(
within(iconWrapper).getByTestId(TooltipIconType.PASSED)
).toBeInTheDocument()
})
})

describe('Studio not connected', () => {
Expand Down Expand Up @@ -933,6 +1064,58 @@ describe('App', () => {
type: MessageFromWebviewType.SAVE_STUDIO_TOKEN
})
})

it('should show an error icon if dvc is not compatible', () => {
renderApp({
canGitInitialize: false,
cliCompatible: false,
dvcCliDetails: {
command: 'python -m dvc',
version: '1.0.0'
},
hasData: false,
isPythonExtensionUsed: false,
isStudioConnected: false,
needsGitCommit: false,
needsGitInitialized: undefined,
projectInitialized: true,
pythonBinPath: undefined,
sectionCollapsed: undefined,
shareLiveToStudio: false
})

const iconWrapper = screen.getAllByTestId('info-tooltip-toggle')[2]

expect(
within(iconWrapper).getByTestId(TooltipIconType.ERROR)
).toBeInTheDocument()
})

it('should show an info icon if dvc is compatible but studio is not connected', () => {
renderApp({
canGitInitialize: false,
cliCompatible: true,
dvcCliDetails: {
command: 'python -m dvc',
version: '1.0.0'
},
hasData: true,
isPythonExtensionUsed: true,
isStudioConnected: false,
needsGitCommit: false,
needsGitInitialized: false,
projectInitialized: true,
pythonBinPath: 'python',
sectionCollapsed: undefined,
shareLiveToStudio: false
})

const iconWrapper = screen.getAllByTestId('info-tooltip-toggle')[2]

expect(
within(iconWrapper).getByTestId(TooltipIconType.INFO)
).toBeInTheDocument()
})
})

describe('Studio connected', () => {
Expand Down Expand Up @@ -990,6 +1173,32 @@ describe('App', () => {
type: MessageFromWebviewType.SAVE_STUDIO_TOKEN
})
})

it('should show a passed icon if connected', () => {
renderApp({
canGitInitialize: false,
cliCompatible: true,
dvcCliDetails: {
command: 'python -m dvc',
version: '1.0.0'
},
hasData: false,
isPythonExtensionUsed: false,
isStudioConnected: true,
needsGitCommit: true,
needsGitInitialized: false,
projectInitialized: true,
pythonBinPath: undefined,
sectionCollapsed: undefined,
shareLiveToStudio: false
})

const iconWrapper = screen.getAllByTestId('info-tooltip-toggle')[2]

expect(
within(iconWrapper).getByTestId(TooltipIconType.PASSED)
).toBeInTheDocument()
})
})

describe('focused section', () => {
Expand Down
6 changes: 6 additions & 0 deletions webview/src/setup/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,16 @@ export const App: React.FC = () => {
})
}

const isDvcSetup = !!cliCompatible && projectInitialized

return (
<>
<SetupContainer
sectionKey={SetupSection.DVC}
title="DVC"
sectionCollapsed={sectionCollapsed}
setSectionCollapsed={setSectionCollapsed}
isSetup={isDvcSetup}
>
<Dvc
canGitInitialize={canGitInitialize}
Expand All @@ -115,6 +118,7 @@ export const App: React.FC = () => {
title="Experiments"
sectionCollapsed={sectionCollapsed}
setSectionCollapsed={setSectionCollapsed}
isSetup={isDvcSetup && !!hasData}
>
<Experiments
needsGitCommit={needsGitCommit}
Expand All @@ -128,6 +132,8 @@ export const App: React.FC = () => {
title="Studio"
sectionCollapsed={sectionCollapsed}
setSectionCollapsed={setSectionCollapsed}
isSetup={!!cliCompatible}
isConnected={isStudioConnected}
>
<Studio
isStudioConnected={isStudioConnected}
Expand Down
16 changes: 15 additions & 1 deletion webview/src/setup/components/SetupContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,38 @@ import {
} from 'dvc/src/setup/webview/contract'
import React from 'react'
import { SectionContainer } from '../../shared/components/sectionContainer/SectionContainer'
import { TooltipIconType } from '../../shared/components/sectionContainer/InfoTooltip'

const getTooltipIconType = (isSetup: boolean, isConnected = true) => {
if (!isSetup) {
return TooltipIconType.ERROR
}

return isConnected ? TooltipIconType.PASSED : TooltipIconType.INFO
}

export const SetupContainer: React.FC<{
children: React.ReactNode
sectionCollapsed: typeof DEFAULT_SECTION_COLLAPSED
sectionKey: SetupSection
setSectionCollapsed: (value: typeof DEFAULT_SECTION_COLLAPSED) => void
title: string
isSetup: boolean
isConnected?: boolean
}> = ({
children,
sectionCollapsed,
sectionKey,
setSectionCollapsed,
title
title,
isSetup,
isConnected
}) => (
<SectionContainer
sectionCollapsed={sectionCollapsed[sectionKey]}
sectionKey={sectionKey}
title={title}
icon={getTooltipIconType(isSetup, isConnected)}
onToggleSection={() =>
setSectionCollapsed({
...sectionCollapsed,
Expand Down
22 changes: 22 additions & 0 deletions webview/src/shared/components/icons/PassFilled.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react'

function PassFilled(props: React.SVGProps<SVGSVGElement>) {
return (
<svg
width="16"
height="16"
viewBox="0 0 16 16"
xmlns="http://www.w3.org/2000/svg"
fill="currentColor"
{...props}
>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14zm-1.02-4.13h-.71L4 8.6l.71-.71 1.92 1.92 4.2-4.21.71.71-4.56 4.56z"
/>
</svg>
)
}

export default PassFilled
1 change: 1 addition & 0 deletions webview/src/shared/components/icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export { default as GraphLine } from './GraphLine'
export { default as Gripper } from './Gripper'
export { default as Info } from './Info'
export { default as Lines } from './Lines'
export { default as PassFilled } from './PassFilled'
export { default as Pin } from './Pin'
export { default as Refresh } from './Refresh'
export { default as UpArrow } from './UpArrow'
Expand Down
Loading

0 comments on commit 2f63386

Please sign in to comment.