Skip to content

Commit 4966cf6

Browse files
mattseddonsroy3
andauthored
Show empty state when final comparison plot is deselected (#2290)
Co-authored-by: Stephanie Roy <[email protected]>
1 parent 7f090fe commit 4966cf6

File tree

3 files changed

+56
-14
lines changed

3 files changed

+56
-14
lines changed

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

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,46 @@ describe('App', () => {
291291
expect(screen.getByText(expectedSectionName)).toBeInTheDocument()
292292
})
293293

294-
it('should remove checkpoint plots given a message showing checkpoint plots as null', () => {
294+
it('should remove image plots given a message showing image plots as null', async () => {
295+
const emptyStateText = 'No Images to Compare'
296+
297+
renderAppWithOptionalData({
298+
checkpoint: checkpointPlotsFixture,
299+
comparison: comparisonTableFixture
300+
})
301+
302+
expect(screen.queryByText(emptyStateText)).not.toBeInTheDocument()
303+
304+
sendSetDataMessage({
305+
comparison: null
306+
})
307+
308+
const emptyState = await screen.findByText(emptyStateText)
309+
310+
expect(emptyState).toBeInTheDocument()
311+
})
312+
313+
it('should remove checkpoint plots given a message showing checkpoint plots as null', async () => {
314+
const emptyStateText = 'No Plots to Display'
315+
316+
renderAppWithOptionalData({
317+
checkpoint: checkpointPlotsFixture,
318+
comparison: comparisonTableFixture,
319+
template: templatePlotsFixture
320+
})
321+
322+
expect(screen.queryByText(emptyStateText)).not.toBeInTheDocument()
323+
324+
sendSetDataMessage({
325+
checkpoint: null
326+
})
327+
328+
const emptyState = await screen.findByText(emptyStateText)
329+
330+
expect(emptyState).toBeInTheDocument()
331+
})
332+
333+
it('should remove all sections from the document if there is no data provided', () => {
295334
renderAppWithOptionalData({
296335
checkpoint: checkpointPlotsFixture
297336
})

webview/src/plots/components/checkpointPlots/checkpointPlotsSlice.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,20 @@ export const checkpointPlotsSlice = createSlice({
4040
state.isCollapsed = action.payload
4141
},
4242
update: (state, action: PayloadAction<CheckpointPlotsData>) => {
43-
if (action.payload) {
44-
const { plots, ...statePayload } = action.payload
45-
const plotsIds = plots?.map(plot => plot.title) || []
46-
const snapShots = addCheckpointPlotsWithSnapshots(plots)
47-
removeCheckpointPlots(plotsIds)
48-
return {
49-
...state,
50-
...statePayload,
51-
hasData: !!action.payload,
52-
plotsIds: plots?.map(plot => plot.title) || [],
53-
plotsSnapshots: snapShots
54-
}
43+
if (!action.payload) {
44+
return checkpointPlotsInitialState
45+
}
46+
const { plots, ...statePayload } = action.payload
47+
const plotsIds = plots?.map(plot => plot.title) || []
48+
const snapShots = addCheckpointPlotsWithSnapshots(plots)
49+
removeCheckpointPlots(plotsIds)
50+
return {
51+
...state,
52+
...statePayload,
53+
hasData: !!action.payload,
54+
plotsIds: plots?.map(plot => plot.title) || [],
55+
plotsSnapshots: snapShots
5556
}
56-
return checkpointPlotsInitialState
5757
}
5858
}
5959
})

webview/src/plots/components/comparisonTable/comparisonTableSlice.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ export const comparisonTableSlice = createSlice({
3030
state.isCollapsed = action.payload
3131
},
3232
update: (state, action: PayloadAction<PlotsComparisonData>) => {
33+
if (!action.payload) {
34+
return comparisonTableInitialState
35+
}
3336
return {
3437
...state,
3538
...action.payload,

0 commit comments

Comments
 (0)