Skip to content

Commit 52093ce

Browse files
authored
Refactor empty state code for experiments and plots (#4075)
1 parent b2f4c75 commit 52093ce

File tree

21 files changed

+261
-220
lines changed

21 files changed

+261
-220
lines changed

webview/src/experiments/components/ErrorState.tsx

Lines changed: 0 additions & 13 deletions
This file was deleted.

webview/src/experiments/components/Experiments.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,15 @@ import {
2424
import { MessageFromWebviewType } from 'dvc/src/webview/contract'
2525
import { Table } from './table/Table'
2626
import styles from './table/styles.module.scss'
27-
import { ErrorState } from './ErrorState'
28-
import { AddColumns, Welcome } from './GetStarted'
27+
import { ErrorState } from './emptyState/ErrorState'
28+
import { GetStarted } from './emptyState/GetStarted'
2929
import { RowSelectionProvider } from './table/RowSelectionContext'
3030
import { CellValue } from './table/content/Cell'
3131
import { AddStage } from './AddStage'
3232
import { ExperimentCell } from './table/content/ExperimentCell'
3333
import { buildColumns, columnHelper } from '../util/buildColumns'
3434
import { sendMessage } from '../../shared/vscode'
3535
import { WebviewWrapper } from '../../shared/components/webviewWrapper/WebviewWrapper'
36-
import { GetStarted } from '../../shared/components/getStarted/GetStarted'
3736
import { EmptyState } from '../../shared/components/emptyState/EmptyState'
3837
import { ExperimentsState } from '../store'
3938
import { EXPERIMENT_COLUMN_ID } from '../util/columns'
@@ -186,13 +185,7 @@ export const ExperimentsTable: React.FC = () => {
186185
const hasOnlyDefaultColumns = columns.length <= 1
187186
const hasOnlyWorkspace = data.length <= 1
188187
if (hasOnlyDefaultColumns || hasOnlyWorkspace) {
189-
return (
190-
<GetStarted
191-
addItems={<AddColumns />}
192-
showEmpty={!hasColumns || hasOnlyWorkspace}
193-
welcome={<Welcome />}
194-
/>
195-
)
188+
return <GetStarted showWelcome={!hasColumns || hasOnlyWorkspace} />
196189
}
197190
return (
198191
<RowSelectionProvider>

webview/src/experiments/components/GetStarted.tsx

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react'
2+
import { StartButton } from '../../../shared/components/button/StartButton'
3+
import { selectColumns } from '../../util/messages'
4+
5+
export const AddColumns: React.FC = () => (
6+
<div>
7+
<p>No Columns Selected.</p>
8+
<StartButton onClick={selectColumns} text="Add Columns" />
9+
</div>
10+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react'
2+
import { EmptyState } from '../../../shared/components/emptyState/EmptyState'
3+
import { ErrorIcon } from '../../../shared/components/errorIcon/ErrorIcon'
4+
import { RefreshButton } from '../../../shared/components/button/RefreshButton'
5+
import { refreshData } from '../../util/messages'
6+
7+
export const ErrorState: React.FC<{ cliError: string }> = ({ cliError }) => (
8+
<EmptyState>
9+
<ErrorIcon error={cliError} size={96} />
10+
<p>No Experiments to Display.</p>
11+
<RefreshButton onClick={refreshData} />
12+
</EmptyState>
13+
)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import React from 'react'
2+
import { Welcome } from './Welcome'
3+
import { AddColumns } from './AddColumns'
4+
import { EmptyState } from '../../../shared/components/emptyState/EmptyState'
5+
6+
export const GetStarted: React.FC<{ showWelcome: boolean }> = ({
7+
showWelcome
8+
}) => <EmptyState>{showWelcome ? <Welcome /> : <AddColumns />}</EmptyState>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react'
2+
3+
export const Welcome: React.FC = () => (
4+
<div>
5+
<p>No Experiments to Display.</p>
6+
<p>
7+
Get started with{' '}
8+
<a href="https://dvc.org/doc/start/experiments">experiments</a>.
9+
</p>
10+
<p>
11+
Learn about the{' '}
12+
<a href="https://dvc.org/doc/command-reference/exp">exp commands</a>.
13+
</p>
14+
</div>
15+
)

webview/src/experiments/util/messages.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export const addStarredFilter = () =>
1515
type: MessageFromWebviewType.ADD_STARRED_EXPERIMENT_FILTER
1616
})
1717

18+
export const selectColumns = () =>
19+
sendMessage({ type: MessageFromWebviewType.SELECT_COLUMNS })
20+
1821
export const showMoreCommits = (branch: string) =>
1922
sendMessage({
2023
payload: branch,

webview/src/plots/components/GetStarted.tsx

Lines changed: 0 additions & 90 deletions
This file was deleted.

webview/src/plots/components/Plots.tsx

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import React, { createRef, useLayoutEffect } from 'react'
22
import { useSelector, useDispatch } from 'react-redux'
3-
import { AddPlots, Welcome } from './GetStarted'
3+
import { ErrorState } from './emptyState/ErrorState'
4+
import { GetStarted } from './emptyState/GetStarted'
45
import { ZoomedInPlot } from './ZoomedInPlot'
56
import { CustomPlotsWrapper } from './customPlots/CustomPlotsWrapper'
67
import { TemplatePlotsWrapper } from './templatePlots/TemplatePlotsWrapper'
78
import { ComparisonTableWrapper } from './comparisonTable/ComparisonTableWrapper'
89
import { Ribbon } from './ribbon/Ribbon'
910
import { setMaxNbPlotsPerRow, setZoomedInPlot } from './webviewSlice'
10-
import styles from './styles.module.scss'
1111
import { EmptyState } from '../../shared/components/emptyState/EmptyState'
1212
import { Modal } from '../../shared/components/modal/Modal'
1313
import { WebviewWrapper } from '../../shared/components/webviewWrapper/WebviewWrapper'
14-
import { GetStarted } from '../../shared/components/getStarted/GetStarted'
1514
import { PlotsState } from '../store'
1615

1716
const PlotsContent = () => {
@@ -60,30 +59,26 @@ const PlotsContent = () => {
6059
</Modal>
6160
)
6261

63-
const hasNoCustomPlots = customPlotIds.length === 0
62+
const hasCustomPlots = customPlotIds.length > 0
63+
64+
if (cliError) {
65+
return (
66+
<ErrorState
67+
cliError={cliError}
68+
hasCustomPlots={hasCustomPlots}
69+
modal={modal}
70+
/>
71+
)
72+
}
6473

6574
if (!hasComparisonData && !hasTemplateData) {
6675
return (
67-
<div className={styles.getStartedWrapper}>
68-
<GetStarted
69-
addItems={
70-
<AddPlots
71-
hasUnselectedPlots={hasUnselectedPlots}
72-
hasNoCustomPlots={hasNoCustomPlots}
73-
cliError={cliError}
74-
/>
75-
}
76-
showEmpty={!hasPlots && !cliError}
77-
welcome={<Welcome />}
78-
isFullScreen={hasNoCustomPlots}
79-
/>
80-
{!hasNoCustomPlots && (
81-
<>
82-
<CustomPlotsWrapper />
83-
{modal}
84-
</>
85-
)}
86-
</div>
76+
<GetStarted
77+
hasCustomPlots={hasCustomPlots}
78+
hasPlots={hasPlots}
79+
hasUnselectedPlots={hasUnselectedPlots}
80+
modal={modal}
81+
/>
8782
)
8883
}
8984

@@ -93,7 +88,6 @@ const PlotsContent = () => {
9388
<TemplatePlotsWrapper />
9489
<ComparisonTableWrapper />
9590
<CustomPlotsWrapper />
96-
9791
{modal}
9892
</div>
9993
)

0 commit comments

Comments
 (0)