Skip to content
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
67 changes: 65 additions & 2 deletions webview/src/experiments/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,80 @@ import {
} from 'dvc/src/webview/contract'
import { TableData } from 'dvc/src/experiments/webview/contract'
import Experiments from './Experiments'
import { update } from './table/tableDataSlice'
import {
update,
updateChanges,
updateColumnOrder,
updateColumns,
updateColumnWidths,
updateFilteredCounts,
updateFilters,
updateHasCheckpoints,
updateHasColumns,
updateHasConfig,
updateHasRunningExperiment,
updateHasValidDvcYaml,
updateRows,
updateSorts
} from './table/tableDataSlice'
import { useVsCodeMessaging } from '../../shared/hooks/useVsCodeMessaging'

export const App: React.FC<Record<string, unknown>> = () => {
const dispatch = useDispatch()

useVsCodeMessaging(
useCallback(
// eslint-disable-next-line sonarjs/cognitive-complexity
({ data }: { data: MessageToWebview<TableData> }) => {
if (data.type === MessageToWebviewType.SET_DATA) {
dispatch(update(data.data))
dispatch(update(!!data.data))
for (const key of Object.keys(data.data)) {
switch (key) {
case 'changes':
dispatch(updateChanges(data.data.changes))
continue
case 'columnOrder':
dispatch(updateColumnOrder(data.data.columnOrder))
continue
case 'columns':
dispatch(updateColumns(data.data.columns))
continue
case 'columnsWidths':
dispatch(updateColumnWidths(data.data.columnWidths))
continue
case 'filteredCounts':
dispatch(updateFilteredCounts(data.data.filteredCounts))
continue
case 'filters':
dispatch(updateFilters(data.data.filters))
continue
case 'hasCheckpoints':
dispatch(updateHasCheckpoints(data.data.hasCheckpoints))
continue
case 'hasColumns':
dispatch(updateHasColumns(data.data.hasColumns))
continue
case 'hasConfig':
dispatch(updateHasConfig(data.data.hasConfig))
continue
case 'hasRunningExperiment':
dispatch(
updateHasRunningExperiment(data.data.hasRunningExperiment)
)
continue
case 'hasValidDvcYaml':
dispatch(updateHasValidDvcYaml(data.data.hasValidDvcYaml))
continue
case 'rows':
dispatch(updateRows(data.data.rows))
continue
case 'sorts':
dispatch(updateSorts(data.data.sorts))
continue
default:
continue
}
}
}
},
[dispatch]
Expand Down
106 changes: 77 additions & 29 deletions webview/src/experiments/components/table/tableDataSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,87 @@ export const tableDataSlice = createSlice({
initialState: tableDataInitialState,
name: 'tableData',
reducers: {
update: (state, action: PayloadAction<TableData>) => {
if (action.payload) {
return {
...state,
...action.payload,
columnWidths: keepReferenceIfEqual(
state.columnWidths,
action.payload.columnWidths
) as Record<string, number>,
columns: keepEqualOldReferencesInArray(
state.columns,
action.payload.columns
) as Column[],
filteredCounts: keepReferenceIfEqual(
state.filteredCounts,
action.payload.filteredCounts
) as FilteredCounts,
hasData: true,
rows: keepEqualOldReferencesInArray(
state.rows,
action.payload.rows
) as Row[],
sorts: keepEqualOldReferencesInArray(
state.sorts,
action.payload.sorts
) as SortDefinition[]
}
update: (state, action: PayloadAction<boolean>) => {
state.hasData = action.payload
if (!action.payload) {
return tableDataInitialState
}
return tableDataInitialState
},
updateChanges: (state, action: PayloadAction<string[]>) => {
state.changes = action.payload
},
updateColumnOrder: (state, action: PayloadAction<string[]>) => {
state.columnOrder = action.payload
},
updateColumnWidths: (
state,
action: PayloadAction<Record<string, number>>
) => {
state.columnWidths = keepReferenceIfEqual(
state.columnWidths,
action.payload
) as Record<string, number>
},
updateColumns: (state, action: PayloadAction<Column[]>) => {
state.columns = keepEqualOldReferencesInArray(
state.columns,
action.payload
) as Column[]
},
updateFilteredCounts: (state, action: PayloadAction<FilteredCounts>) => {
state.filteredCounts = keepReferenceIfEqual(
state.filteredCounts,
action.payload
) as FilteredCounts
},
updateFilters: (state, action: PayloadAction<string[]>) => {
state.filters = action.payload
},
updateHasCheckpoints: (state, action: PayloadAction<boolean>) => {
state.hasCheckpoints = action.payload
},
updateHasColumns: (state, action: PayloadAction<boolean>) => {
state.hasColumns = action.payload
},
updateHasConfig: (state, action: PayloadAction<boolean>) => {
state.hasConfig = action.payload
},
updateHasRunningExperiment: (state, action: PayloadAction<boolean>) => {
state.hasRunningExperiment = action.payload
},
updateHasValidDvcYaml: (state, action: PayloadAction<boolean>) => {
state.hasValidDvcYaml = action.payload
},
updateRows: (state, action: PayloadAction<Row[]>) => {
state.rows = keepEqualOldReferencesInArray(
state.rows,
action.payload
) as Row[]
},
updateSorts: (state, action: PayloadAction<SortDefinition[]>) => {
state.sorts = keepEqualOldReferencesInArray(
state.sorts,
action.payload
) as SortDefinition[]
}
}
})

export const { update } = tableDataSlice.actions
export const {
update,
updateChanges,
updateColumnOrder,
updateColumnWidths,
updateColumns,
updateFilteredCounts,
updateFilters,
updateHasCheckpoints,
updateHasColumns,
updateHasConfig,
updateHasRunningExperiment,
updateHasValidDvcYaml,
updateRows,
updateSorts
} = tableDataSlice.actions

export default tableDataSlice.reducer