Skip to content

Commit e7c1562

Browse files
authored
Remove clear data action (#1945)
* Remove clear data action * Fix comparison table stories
1 parent 74311f9 commit e7c1562

File tree

8 files changed

+20
-74
lines changed

8 files changed

+20
-74
lines changed

webview/src/plots/actions.ts

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

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import {
66
PlotSize,
77
Section
88
} from 'dvc/src/plots/webview/contract'
9-
import { clearData } from '../../actions'
10-
import { ReducerName } from '../../constants'
119
import {
1210
addCheckpointPlotsWithSnapshots,
1311
removeCheckpointPlots
@@ -31,17 +29,8 @@ export const checkpointPlotsInitialState: CheckpointPlotsState = {
3129
}
3230

3331
export const checkpointPlotsSlice = createSlice({
34-
extraReducers: builder => {
35-
builder
36-
.addCase(clearData, (_, action) => {
37-
if (!action.payload || action.payload === ReducerName.CHECKPOINT) {
38-
return { ...checkpointPlotsInitialState }
39-
}
40-
})
41-
.addDefaultCase(() => {})
42-
},
4332
initialState: checkpointPlotsInitialState,
44-
name: ReducerName.CHECKPOINT,
33+
name: 'checkpoint',
4534
reducers: {
4635
changeSize: (state, action: PayloadAction<PlotSize>) => {
4736
state.size = action.payload

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import {
66
PlotSize,
77
Section
88
} from 'dvc/src/plots/webview/contract'
9-
import { clearData } from '../../actions'
10-
import { ReducerName } from '../../constants'
119

1210
export interface ComparisonTableState extends PlotsComparisonData {
1311
isCollapsed: boolean
@@ -22,17 +20,8 @@ export const comparisonTableInitialState: ComparisonTableState = {
2220
}
2321

2422
export const comparisonTableSlice = createSlice({
25-
extraReducers: builder => {
26-
builder
27-
.addCase(clearData, (_, action) => {
28-
if (!action.payload || action.payload === ReducerName.COMPARISON) {
29-
return { ...comparisonTableInitialState }
30-
}
31-
})
32-
.addDefaultCase(() => {})
33-
},
3423
initialState: comparisonTableInitialState,
35-
name: ReducerName.COMPARISON,
24+
name: 'comparison',
3625
reducers: {
3726
changeSize: (state, action: PayloadAction<PlotSize>) => {
3827
state.size = action.payload

webview/src/plots/components/templatePlots/templatePlotsSlice.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import {
66
Section,
77
TemplatePlotsData
88
} from 'dvc/src/plots/webview/contract'
9-
import { clearData } from '../../actions'
10-
import { ReducerName } from '../../constants'
119
import { plotDataStore } from '../plotDataStore'
1210

1311
export interface TemplatePlotsState extends Omit<TemplatePlotsData, 'plots'> {
@@ -24,17 +22,8 @@ export const templatePlotsInitialState: TemplatePlotsState = {
2422
}
2523

2624
export const templatePlotsSlice = createSlice({
27-
extraReducers: builder => {
28-
builder
29-
.addCase(clearData, (_, action) => {
30-
if (!action.payload || action.payload === ReducerName.TEMPLATE) {
31-
return { ...templatePlotsInitialState }
32-
}
33-
})
34-
.addDefaultCase(() => {})
35-
},
3625
initialState: templatePlotsInitialState,
37-
name: ReducerName.TEMPLATE,
26+
name: 'template',
3827
reducers: {
3928
changeSize: (state, action: PayloadAction<PlotSize>) => {
4029
state.size = action.payload

webview/src/plots/components/webviewSlice.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
22
import { Revision } from 'dvc/src/plots/webview/contract'
33
import { VegaProps } from 'react-vega/lib/Vega'
4-
import { clearData } from '../actions'
5-
import { ReducerName } from '../constants'
64

75
type ZoomedInPlotState = {
86
plot: VegaProps | undefined
@@ -29,17 +27,8 @@ export const webviewInitialState: WebviewState = {
2927
}
3028

3129
export const webviewSlice = createSlice({
32-
extraReducers: builder => {
33-
builder
34-
.addCase(clearData, (_, action) => {
35-
if (!action.payload || action.payload === ReducerName.WEBVIEW) {
36-
return { ...webviewInitialState }
37-
}
38-
})
39-
.addDefaultCase(() => {})
40-
},
4130
initialState: webviewInitialState,
42-
name: ReducerName.WEBVIEW,
31+
name: 'webview',
4332
reducers: {
4433
initialize: state => {
4534
state.hasData = true

webview/src/plots/constants.ts

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

webview/src/stories/ComparisonTable.stories.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Meta, Story } from '@storybook/react/types-6-0'
2+
import { configureStore } from '@reduxjs/toolkit'
23
import { fireEvent, within } from '@testing-library/react'
34
import React from 'react'
45
import { Provider, useDispatch } from 'react-redux'
@@ -13,18 +14,18 @@ import comparisonTableFixture from 'dvc/src/test/fixtures/plotsDiff/comparison'
1314
import { ComparisonTable } from '../plots/components/comparisonTable/ComparisonTable'
1415
import { WebviewWrapper } from '../shared/components/webviewWrapper/WebviewWrapper'
1516
import { DragDropProvider } from '../shared/components/dragDrop/DragDropContext'
16-
import { clearData } from '../plots/actions'
17-
import { ReducerName } from '../plots/constants'
18-
import { update } from '../plots/components/comparisonTable/comparisonTableSlice'
19-
import { store } from '../plots/store'
20-
import { updateSelectedRevisions } from '../plots/components/webviewSlice'
17+
import comparisonTableReducer, {
18+
update
19+
} from '../plots/components/comparisonTable/comparisonTableSlice'
20+
import webviewReducer, {
21+
updateSelectedRevisions
22+
} from '../plots/components/webviewSlice'
2123

2224
const MockedState: React.FC<{
2325
data: PlotsComparisonData
2426
selectedRevisions: Revision[]
2527
}> = ({ children, data, selectedRevisions }) => {
2628
const dispatch = useDispatch()
27-
dispatch(clearData(ReducerName.COMPARISON))
2829
dispatch(update(data))
2930
dispatch(updateSelectedRevisions(selectedRevisions))
3031

@@ -38,6 +39,12 @@ export default {
3839
} as Meta
3940

4041
const Template: Story = ({ plots, revisions }) => {
42+
const store = configureStore({
43+
reducer: {
44+
comparison: comparisonTableReducer,
45+
webview: webviewReducer
46+
}
47+
})
4148
return (
4249
<Provider store={store}>
4350
<MockedState

webview/src/stories/Plots.stories.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { configureStore } from '@reduxjs/toolkit'
12
import React from 'react'
23
import { Provider, useDispatch } from 'react-redux'
34
import { Story, Meta } from '@storybook/react/types-6-0'
@@ -21,14 +22,11 @@ import { Plots } from '../plots/components/Plots'
2122
import './test-vscode-styles.scss'
2223
import '../shared/style.scss'
2324
import '../plots/components/styles.module.scss'
24-
import { store } from '../plots/store'
2525
import { feedStore } from '../plots/components/App'
26-
import { clearData } from '../plots/actions'
26+
import { storeReducers } from '../plots/store'
2727

2828
const MockedState: React.FC<{ data: PlotsData }> = ({ children, data }) => {
2929
const dispatch = useDispatch()
30-
dispatch(clearData())
31-
3230
const message = { data, type: MessageToWebviewType.SET_DATA }
3331
feedStore(message, dispatch)
3432

@@ -54,6 +52,7 @@ export default {
5452
const Template: Story<{
5553
data?: PlotsData
5654
}> = ({ data }) => {
55+
const store = configureStore({ reducer: storeReducers })
5756
return (
5857
<Provider store={store}>
5958
<MockedState data={data}>

0 commit comments

Comments
 (0)