Skip to content

Commit 31c8f6c

Browse files
authored
Fix plots get started screen (#3382)
1 parent b4aa55b commit 31c8f6c

File tree

5 files changed

+46
-44
lines changed

5 files changed

+46
-44
lines changed

extension/src/plots/model/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,14 @@ export class PlotsModel extends ModelWithPersistence {
200200
}
201201

202202
public recreateCustomPlots() {
203+
const experiments = this.experiments.getExperiments()
204+
if (experiments.length === 0) {
205+
this.customPlots = undefined
206+
return
207+
}
203208
const customPlots: CustomPlotData[] = collectCustomPlotsData(
204209
this.getCustomPlotsOrder(),
205-
this.experiments.getExperiments()
210+
experiments
206211
)
207212
this.customPlots = customPlots
208213
}

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

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -378,21 +378,18 @@ describe('App', () => {
378378
expect(screen.getAllByText('No Plots to Display')).toHaveLength(2)
379379
})
380380

381-
it('should render other sections given a message with only custom plots data', () => {
381+
it('should render an empty state given a message with only custom plots data', () => {
382382
renderAppWithOptionalData({
383383
custom: customPlotsFixture
384384
})
385385

386386
expect(screen.queryByText('Loading Plots...')).not.toBeInTheDocument()
387-
expect(screen.getByText('Trends')).toBeInTheDocument()
388-
expect(screen.getByText('Data Series')).toBeInTheDocument()
389-
expect(screen.getByText('Images')).toBeInTheDocument()
390-
expect(screen.getByText('Custom')).toBeInTheDocument()
391-
expect(screen.getAllByText('No Plots to Display')).toHaveLength(2)
392-
expect(screen.getByText('No Images to Compare')).toBeInTheDocument()
387+
const addExperimentsButton = screen.queryByText('Add Experiments')
388+
389+
expect(addExperimentsButton).toBeInTheDocument()
393390
})
394391

395-
it('should render custom even when there is no custom plots data', () => {
392+
it('should render custom with "No Plots to Display" message when there is no custom plots data', () => {
396393
renderAppWithOptionalData({
397394
comparison: comparisonTableFixture
398395
})
@@ -402,6 +399,21 @@ describe('App', () => {
402399
expect(screen.getAllByText('No Plots to Display')).toHaveLength(3)
403400
})
404401

402+
it('should render custom with "No Plots Added" message when there are no plots added', () => {
403+
renderAppWithOptionalData({
404+
comparison: comparisonTableFixture,
405+
custom: {
406+
...customPlotsFixture,
407+
plots: []
408+
}
409+
})
410+
411+
expect(screen.queryByText('Loading Plots...')).not.toBeInTheDocument()
412+
expect(screen.getByText('Custom')).toBeInTheDocument()
413+
expect(screen.getAllByText('No Plots to Display')).toHaveLength(2)
414+
expect(screen.getByText('No Plots Added')).toBeInTheDocument()
415+
})
416+
405417
it('should render the comparison table when given a message with comparison plots data', () => {
406418
const expectedSectionName = 'Images'
407419

@@ -837,6 +849,7 @@ describe('App', () => {
837849

838850
it('should add a custom plot if a user creates a custom plot', () => {
839851
renderAppWithOptionalData({
852+
comparison: comparisonTableFixture,
840853
custom: {
841854
...customPlotsFixture,
842855
plots: customPlotsFixture.plots.slice(1)
@@ -863,6 +876,7 @@ describe('App', () => {
863876

864877
it('should remove a custom plot if a user deletes a custom plot', () => {
865878
renderAppWithOptionalData({
879+
comparison: comparisonTableFixture,
866880
custom: customPlotsFixture
867881
})
868882

webview/src/plots/components/GetStarted.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { StartButton } from '../../shared/components/button/StartButton'
55

66
export type AddPlotsProps = {
77
hasUnselectedPlots: boolean
8-
hasSelectedRevisions: boolean
98
}
109

1110
export const AddPlots: React.FC<AddPlotsProps> = ({
@@ -14,16 +13,14 @@ export const AddPlots: React.FC<AddPlotsProps> = ({
1413
<div>
1514
<p>No Plots to Display.</p>
1615
<div>
17-
{
18-
<StartButton
19-
onClick={() =>
20-
sendMessage({
21-
type: MessageFromWebviewType.SELECT_EXPERIMENTS
22-
})
23-
}
24-
text="Add Experiments"
25-
/>
26-
}
16+
<StartButton
17+
onClick={() =>
18+
sendMessage({
19+
type: MessageFromWebviewType.SELECT_EXPERIMENTS
20+
})
21+
}
22+
text="Add Experiments"
23+
/>
2724
{hasUnselectedPlots && (
2825
<StartButton
2926
isNested={hasUnselectedPlots}

webview/src/plots/components/Plots.tsx

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@ import { PlotsState } from '../store'
1717
// eslint-disable-next-line sonarjs/cognitive-complexity
1818
const PlotsContent = () => {
1919
const dispatch = useDispatch()
20-
const {
21-
hasData,
22-
hasPlots,
23-
hasUnselectedPlots,
24-
selectedRevisions,
25-
zoomedInPlot
26-
} = useSelector((state: PlotsState) => state.webview)
20+
const { hasData, hasPlots, hasUnselectedPlots, zoomedInPlot } = useSelector(
21+
(state: PlotsState) => state.webview
22+
)
2723
const hasCheckpointData = useSelector(
2824
(state: PlotsState) => state.checkpoint.hasData
2925
)
@@ -33,7 +29,6 @@ const PlotsContent = () => {
3329
const hasTemplateData = useSelector(
3430
(state: PlotsState) => state.template.hasData
3531
)
36-
const hasCustomData = useSelector((state: PlotsState) => state.custom.hasData)
3732
const wrapperRef = createRef<HTMLDivElement>()
3833

3934
useLayoutEffect(() => {
@@ -54,20 +49,10 @@ const PlotsContent = () => {
5449
return <EmptyState>Loading Plots...</EmptyState>
5550
}
5651

57-
if (
58-
!hasCheckpointData &&
59-
!hasComparisonData &&
60-
!hasTemplateData &&
61-
!hasCustomData
62-
) {
52+
if (!hasCheckpointData && !hasComparisonData && !hasTemplateData) {
6353
return (
6454
<GetStarted
65-
addItems={
66-
<AddPlots
67-
hasUnselectedPlots={hasUnselectedPlots}
68-
hasSelectedRevisions={!!selectedRevisions?.length}
69-
/>
70-
}
55+
addItems={<AddPlots hasUnselectedPlots={hasUnselectedPlots} />}
7156
showEmpty={!hasPlots}
7257
welcome={<Welcome />}
7358
/>

webview/src/plots/components/customPlots/CustomPlots.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ export const CustomPlots: React.FC<CustomPlotsProps> = ({ plotsIds }) => {
4747
return <EmptyState isFullScreen={false}>No Plots to Display</EmptyState>
4848
}
4949

50+
if (order.length === 0) {
51+
return <EmptyState isFullScreen={false}>No Plots Added</EmptyState>
52+
}
53+
5054
const items = order.map(plot => (
5155
<div key={plot} id={plot}>
5256
<CustomPlot id={plot} />
@@ -66,8 +70,7 @@ export const CustomPlots: React.FC<CustomPlotsProps> = ({ plotsIds }) => {
6670
const handleDropAtTheEnd = () => {
6771
setPlotsIdsOrder(changeOrderWithDraggedInfo(order, draggedRef))
6872
}
69-
70-
return items.length > 0 ? (
73+
return (
7174
<div
7275
data-testid="custom-plots"
7376
id="custom-plots"
@@ -97,7 +100,5 @@ export const CustomPlots: React.FC<CustomPlotsProps> = ({ plotsIds }) => {
97100
parentDraggedOver={onSection}
98101
/>
99102
</div>
100-
) : (
101-
<EmptyState isFullScreen={false}>No Plots Added</EmptyState>
102103
)
103104
}

0 commit comments

Comments
 (0)