Skip to content

Commit

Permalink
move reducers back into apps
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed Jan 15, 2024
1 parent c16cf0b commit c0c97f2
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 159 deletions.
51 changes: 46 additions & 5 deletions webview/src/experiments/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,55 @@
import React from 'react'
import { TableData } from 'dvc/src/experiments/webview/contract'
import {
MessageToWebview,
MessageToWebviewType
} from 'dvc/src/webview/contract'
import { TableData } from 'dvc/src/experiments/webview/contract'
import React from 'react'
import Experiments from './Experiments'
import { update } from '../state/tableDataSlice'
import { dispatchActions } from '../../shared/dispatchActions'
import { useVsCodeMessaging } from '../../shared/hooks/useVsCodeMessaging'
import {
update,
updateChanges,
updateCliError,
updateColumnOrder,
updateColumnWidths,
updateColumns,
updateFilters,
updateHasBranchesToSelect,
updateHasCheckpoints,
updateHasConfig,
updateHasMoreCommits,
updateHasRunningWorkspaceExperiment,
updateIsShowingMoreCommits,
updateRows,
updateSelectedBranches,
updateSelectedForPlotsCount,
updateShowOnlyChanged,
updateSorts
} from '../state/tableDataSlice'
import { ExperimentsDispatch } from '../store'
import { dispatchAction } from '../../shared/dispatchAction'

const actionToDispatch = {
changes: updateChanges,
cliError: updateCliError,
columnOrder: updateColumnOrder,
columnWidths: updateColumnWidths,
columns: updateColumns,
filters: updateFilters,
hasBranchesToSelect: updateHasBranchesToSelect,
hasCheckpoints: updateHasCheckpoints,
hasConfig: updateHasConfig,
hasMoreCommits: updateHasMoreCommits,
hasRunningWorkspaceExperiment: updateHasRunningWorkspaceExperiment,
isShowingMoreCommits: updateIsShowingMoreCommits,
rows: updateRows,
selectedBranches: updateSelectedBranches,
selectedForPlotsCount: updateSelectedForPlotsCount,
showOnlyChanged: updateShowOnlyChanged,
sorts: updateSorts
}

export type ExperimentsActions = typeof actionToDispatch

const feedStore = (
data: MessageToWebview<TableData>,
Expand All @@ -20,7 +61,7 @@ const feedStore = (
const stateUpdate = data?.data
dispatch(update(!!stateUpdate))

dispatchAction('experiments', stateUpdate, dispatch)
dispatchActions(actionToDispatch, stateUpdate, dispatch)
}

export const App: React.FC<Record<string, unknown>> = () => {
Expand Down
49 changes: 42 additions & 7 deletions webview/src/plots/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
import React from 'react'
import {
PlotsData,
PlotsDataKeys,
PlotsSection,
SectionCollapsed
} from 'dvc/src/plots/webview/contract'
import { MessageToWebview } from 'dvc/src/webview/contract'
import React from 'react'
import { Plots } from './Plots'
import { setCollapsed as setCustomPlotsCollapsed } from './customPlots/customPlotsSlice'
import { setCollapsed as setComparisonTableCollapsed } from './comparisonTable/comparisonTableSlice'
import { setCollapsed as setTemplatePlotsCollapsed } from './templatePlots/templatePlotsSlice'
import { initialize } from './webviewSlice'
import {
setCollapsed as setComparisonTableCollapsed,
update as updateComparisonTable,
updateShouldShowTooManyPlotsMessage as updateShouldShowTooManyImagesMessage
} from './comparisonTable/comparisonTableSlice'
import {
setCollapsed as setCustomPlotsCollapsed,
update as updateCustomPlots
} from './customPlots/customPlotsSlice'
import {
setCollapsed as setTemplatePlotsCollapsed,
updateShouldShowTooManyPlotsMessage as updateShouldShowTooManyTemplatesMessage,
update as updateTemplatePlots
} from './templatePlots/templatePlotsSlice'
import {
initialize,
updateCliError,
updateHasPlots,
updateHasUnselectedPlots,
updatePlotErrors,
updateSelectedRevisions
} from './webviewSlice'
import { PlotsDispatch } from '../store'
import { useVsCodeMessaging } from '../../shared/hooks/useVsCodeMessaging'
import { dispatchAction } from '../../shared/dispatchAction'
import { dispatchActions } from '../../shared/dispatchActions'

const dispatchCollapsedSections = (
sections: SectionCollapsed,
Expand All @@ -28,6 +46,23 @@ const dispatchCollapsedSections = (
}
}

const actionToDispatch = {
[PlotsDataKeys.CLI_ERROR]: updateCliError,
[PlotsDataKeys.CUSTOM]: updateCustomPlots,
[PlotsDataKeys.COMPARISON]: updateComparisonTable,
[PlotsDataKeys.TEMPLATE]: updateTemplatePlots,
[PlotsDataKeys.HAS_PLOTS]: updateHasPlots,
[PlotsDataKeys.HAS_UNSELECTED_PLOTS]: updateHasUnselectedPlots,
[PlotsDataKeys.PLOT_ERRORS]: updatePlotErrors,
[PlotsDataKeys.SELECTED_REVISIONS]: updateSelectedRevisions,
[PlotsDataKeys.SHOW_TOO_MANY_TEMPLATE_PLOTS]:
updateShouldShowTooManyTemplatesMessage,
[PlotsDataKeys.SHOW_TOO_MANY_COMPARISON_IMAGES]:
updateShouldShowTooManyImagesMessage
} as const

export type PlotsActions = typeof actionToDispatch

export const feedStore = (
data: MessageToWebview<PlotsData>,
dispatch: PlotsDispatch
Expand All @@ -45,7 +80,7 @@ export const feedStore = (
dispatch
)
}
dispatchAction('plots', stateUpdate, dispatch)
dispatchActions(actionToDispatch, stateUpdate, dispatch)
}

export const App = () => {
Expand Down
59 changes: 51 additions & 8 deletions webview/src/setup/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
import { SetupSection, SetupData } from 'dvc/src/setup/webview/contract'
import { SetupData, SetupSection } from 'dvc/src/setup/webview/contract'
import { MessageToWebview } from 'dvc/src/webview/contract'
import React from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { SetupContainer } from './SetupContainer'
import { Dvc } from './dvc/Dvc'
import { Experiments } from './experiments/Experiments'
import { Studio } from './studio/Studio'
import { SetupContainer } from './SetupContainer'
import { Remotes } from './remotes/Remotes'
import { useVsCodeMessaging } from '../../shared/hooks/useVsCodeMessaging'
import { Studio } from './studio/Studio'
import { TooltipIconType } from '../../shared/components/sectionContainer/InfoTooltip'
import { dispatchActions } from '../../shared/dispatchActions'
import { useVsCodeMessaging } from '../../shared/hooks/useVsCodeMessaging'
import {
updateCanGitInitialize,
updateCliCompatible,
updateDvcCliDetails,
updateIsAboveLatestTestedVersion,
updateIsPythonEnvironmentGlobal,
updateIsPythonExtensionInstalled,
updateIsPythonExtensionUsed,
updateNeedsGitInitialized,
updateProjectInitialized,
updatePythonBinPath
} from '../state/dvcSlice'
import {
updateHasData as updateExperimentsHasData,
updateNeedsGitCommit
} from '../state/experimentsSlice'
import { updateRemoteList } from '../state/remoteSlice'
import {
updateIsStudioConnected,
updateSelfHostedStudioUrl,
updateShareLiveToStudio
} from '../state/studioSlice'
import { initialize, updateSectionCollapsed } from '../state/webviewSlice'
import { SetupDispatch, SetupState } from '../store'
import { initialize } from '../state/webviewSlice'
import { updateShareLiveToStudio } from '../state/studioSlice'
import { setStudioShareExperimentsLive } from '../util/messages'
import { dispatchAction } from '../../shared/dispatchAction'

const getDvcStatusIcon = (
isDvcSetup: boolean,
Expand All @@ -36,6 +57,28 @@ const getStudioStatusIcon = (cliCompatible: boolean, isConnected: boolean) => {
return isConnected ? TooltipIconType.PASSED : TooltipIconType.WARNING
}

const actionToDispatch = {
canGitInitialize: updateCanGitInitialize,
cliCompatible: updateCliCompatible,
dvcCliDetails: updateDvcCliDetails,
hasData: updateExperimentsHasData,
isAboveLatestTestedVersion: updateIsAboveLatestTestedVersion,
isPythonEnvironmentGlobal: updateIsPythonEnvironmentGlobal,
isPythonExtensionInstalled: updateIsPythonExtensionInstalled,
isPythonExtensionUsed: updateIsPythonExtensionUsed,
isStudioConnected: updateIsStudioConnected,
needsGitCommit: updateNeedsGitCommit,
needsGitInitialized: updateNeedsGitInitialized,
projectInitialized: updateProjectInitialized,
pythonBinPath: updatePythonBinPath,
remoteList: updateRemoteList,
sectionCollapsed: updateSectionCollapsed,
selfHostedStudioUrl: updateSelfHostedStudioUrl,
shareLiveToStudio: updateShareLiveToStudio
} as const

export type SetupActions = typeof actionToDispatch

export const feedStore = (
data: MessageToWebview<SetupData>,
dispatch: SetupDispatch
Expand All @@ -46,7 +89,7 @@ export const feedStore = (
}
dispatch(initialize())

dispatchAction('setup', stateUpdate, dispatch)
dispatchActions(actionToDispatch, stateUpdate, dispatch)
}

export const App: React.FC = () => {
Expand Down
139 changes: 0 additions & 139 deletions webview/src/shared/dispatchAction.ts

This file was deleted.

Loading

0 comments on commit c0c97f2

Please sign in to comment.