Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLI incompatible screen to Studio section #3763

Merged
merged 3 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions webview/src/setup/components/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ describe('App', () => {
shareLiveToStudio: false
})

expect(
screen.getByText('DVC is currently unavailable')
).toBeInTheDocument()
expect(screen.getAllByText('DVC is currently unavailable')).toHaveLength(
2
)
})

it('should tell the user they cannot install DVC without a Python interpreter', () => {
Expand Down
7 changes: 6 additions & 1 deletion webview/src/setup/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import React, { useCallback, useState } from 'react'
import { Dvc } from './Dvc'
import { Experiments } from './Experiments'
import { Studio } from './Studio'
import { Studio } from './studio/Studio'
import { SetupContainer } from './SetupContainer'
import { useVsCodeMessaging } from '../../shared/hooks/useVsCodeMessaging'
import { sendMessage } from '../../shared/vscode'
Expand Down Expand Up @@ -44,6 +44,9 @@ export const App: React.FC = () => {
useVsCodeMessaging(
useCallback(
({ data }: { data: MessageToWebview<SetupData> }) => {
if (!data?.data) {
return
}
setCanGitInitialized(data.data.canGitInitialize)
setCliCompatible(data.data.cliCompatible)
setHasData(data.data.hasData)
Expand Down Expand Up @@ -123,7 +126,9 @@ export const App: React.FC = () => {
<Studio
isStudioConnected={isStudioConnected}
shareLiveToStudio={shareLiveToStudio}
setSectionCollapsed={setSectionCollapsed}
setShareLiveToStudio={setShareLiveToStudio}
cliCompatible={!!cliCompatible}
/>
</SetupContainer>
</>
Expand Down
111 changes: 0 additions & 111 deletions webview/src/setup/components/Studio.tsx

This file was deleted.

25 changes: 25 additions & 0 deletions webview/src/setup/components/studio/CliIncompatible.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like we're trying to head in the direction of splitting out components. LMK if I got this wrong.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to help greatly in keeping styles simple and easy to clean out. It'll also help with Codeclimate issues and even tests.

import { STUDIO_URL, SectionCollapsed } from 'dvc/src/setup/webview/contract'
import { EmptyState } from '../../../shared/components/emptyState/EmptyState'
import { Button } from '../../../shared/components/button/Button'

export const CliIncompatible: React.FC<{
setSectionCollapsed: (sectionCollapsed: SectionCollapsed) => void
}> = ({ setSectionCollapsed }) => (
<EmptyState isFullScreen={false}>
<h1>DVC is currently unavailable</h1>
<p>
Locate DVC to connect to <a href={STUDIO_URL}>Studio</a>
</p>
<Button
text="Setup DVC"
onClick={() =>
setSectionCollapsed({
dvc: false,
experiments: true,
studio: true
})
}
/>
</EmptyState>
)
48 changes: 48 additions & 0 deletions webview/src/setup/components/studio/Connect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react'
import { STUDIO_URL } from 'dvc/src/setup/webview/contract'
import { openStudio, openStudioProfile, saveStudioToken } from '../messages'
import { EmptyState } from '../../../shared/components/emptyState/EmptyState'
import { Button } from '../../../shared/components/button/Button'

export const Connect: React.FC = () => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Connect has 41 lines of code (exceeds 40 allowed). Consider refactoring.

return (
<EmptyState isFullScreen={false}>
<div data-testid="setup-studio-content">
<h1>
Connect to <a href={STUDIO_URL}>Studio</a>
</h1>
<p>
Share experiments and plots with collaborators directly from your IDE.
</p>
<p>
An{' '}
<a href="https://dvc.org/doc/studio/user-guide/projects-and-experiments/live-metrics-and-plots#set-up-an-access-token">
access token
</a>{' '}
can be generated from your Studio profile page.
</p>
<Button
appearance="primary"
isNested={false}
text="Sign In"
onClick={openStudio}
/>
<Button
appearance="secondary"
isNested={true}
text="Get Token"
onClick={openStudioProfile}
/>
<Button
appearance="secondary"
isNested={true}
text="Save"
onClick={saveStudioToken}
/>
<p>
Don&apos;t Have an account? <a href={STUDIO_URL}>Get Started</a>
</p>
</div>
</EmptyState>
)
}
46 changes: 46 additions & 0 deletions webview/src/setup/components/studio/Settings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from 'react'
import { VSCodeCheckbox } from '@vscode/webview-ui-toolkit/react'
import { saveStudioToken, removeStudioToken } from '../messages'
import { EmptyState } from '../../../shared/components/emptyState/EmptyState'
import { Button } from '../../../shared/components/button/Button'

export const Settings: React.FC<{
shareLiveToStudio: boolean
setShareLiveToStudio: (shareLiveToStudio: boolean) => void
}> = ({ shareLiveToStudio, setShareLiveToStudio }) => {
return (
<EmptyState isFullScreen={false}>
<div>
<h1>Studio Settings</h1>
<p>
Experiment metrics and plots logged with DVCLive <br />
can be{' '}
<a href="https://dvc.org/doc/studio/user-guide/projects-and-experiments/live-metrics-and-plots#send-and-view-live-metrics-and-plots">
automatically shared to Studio
</a>
.
</p>
<p>
<VSCodeCheckbox
onClick={() => setShareLiveToStudio(!shareLiveToStudio)}
checked={shareLiveToStudio}
>
Share New Experiments Live
</VSCodeCheckbox>
</p>
<Button
appearance="primary"
isNested={false}
text="Update Token"
onClick={saveStudioToken}
/>
<Button
appearance="secondary"
isNested={true}
text="Disconnect"
onClick={removeStudioToken}
/>
</div>
</EmptyState>
)
}
32 changes: 32 additions & 0 deletions webview/src/setup/components/studio/Studio.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react'
import { SectionCollapsed } from 'dvc/src/setup/webview/contract'
import { Connect } from './Connect'
import { Settings } from './Settings'
import { CliIncompatible } from './CliIncompatible'

export const Studio: React.FC<{
isStudioConnected: boolean
shareLiveToStudio: boolean
cliCompatible: boolean
setSectionCollapsed: (sectionCollapsed: SectionCollapsed) => void
setShareLiveToStudio: (shareLiveToStudio: boolean) => void
}> = ({
cliCompatible,
isStudioConnected,
shareLiveToStudio,
setSectionCollapsed,
setShareLiveToStudio
}) => {
if (!cliCompatible) {
return <CliIncompatible setSectionCollapsed={setSectionCollapsed} />
}

return isStudioConnected ? (
<Settings
shareLiveToStudio={shareLiveToStudio}
setShareLiveToStudio={setShareLiveToStudio}
/>
) : (
<Connect />
)
}