Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mjhuff committed Jan 21, 2025
1 parent 733cf27 commit 84618e8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useEffect } from 'react'
import { useDispatch } from 'react-redux'

import { getLabwareDefinitionsFromCommands } from '@opentrons/components'
Expand All @@ -13,36 +14,37 @@ import type { LPCWizardFlexProps } from '/app/organisms/LabwarePositionCheck/LPC
export interface UseLPCInitialStateProps
extends Omit<LPCWizardFlexProps, 'onCloseClick'> {}

// Inject initial LPC state into Redux.
export function useLPCInitialState({
mostRecentAnalysis,
runId,
...rest
}: UseLPCInitialStateProps): void {
const dispatch = useDispatch()

const protocolCommands: RunTimeCommand[] = mostRecentAnalysis.commands
const labwareDefs = getLabwareDefinitionsFromCommands(protocolCommands)
const deckConfig = useNotifyDeckConfigurationQuery().data ?? []
const LPCSteps = getLPCSteps({
protocolData: mostRecentAnalysis,
labwareDefs,
})

const initialState: LPCWizardState = {
...rest,
protocolData: mostRecentAnalysis,
labwareDefs,
workingOffsets: [],
deckConfig,
steps: {
currentStepIndex: 0,
totalStepCount: LPCSteps.length,
current: LPCSteps[0],
all: LPCSteps,
next: LPCSteps[1],
},
}

dispatch(startLPC(runId, initialState))

useEffect(() => {
const protocolCommands: RunTimeCommand[] = mostRecentAnalysis.commands
const labwareDefs = getLabwareDefinitionsFromCommands(protocolCommands)
const LPCSteps = getLPCSteps({
protocolData: mostRecentAnalysis,
labwareDefs,
})

const initialState: LPCWizardState = {
...rest,
protocolData: mostRecentAnalysis,
labwareDefs,
workingOffsets: [],
deckConfig,
steps: {
currentStepIndex: 0,
totalStepCount: LPCSteps.length,
current: LPCSteps[0],
all: LPCSteps,
next: LPCSteps[1],
},
}

dispatch(startLPC(runId, initialState))
}, [deckConfig])
}
74 changes: 37 additions & 37 deletions app/src/redux/protocol-runs/reducer/lpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,47 @@ export function LPCReducer(
state: LPCWizardState | undefined,
action: LPCWizardAction
): LPCWizardState | undefined {
if (state == null) {
if (action.type === START_LPC) {
return action.payload.state
} else if (state == null) {
return undefined
}

switch (action.type) {
case START_LPC: {
return action.payload.state
}
case PROCEED_STEP: {
const { currentStepIndex, totalStepCount } = state.steps
const newStepIdx =
currentStepIndex + 1 < totalStepCount
? currentStepIndex + 1
: currentStepIndex

const nextStepIdx =
newStepIdx + 1 < totalStepCount ? newStepIdx + 1 : null
const nextStep = nextStepIdx != null ? state.steps.all[nextStepIdx] : null

return {
...state,
steps: {
...state.steps,
currentStepIndex: newStepIdx,
current: state.steps.all[newStepIdx],
next: nextStep,
},
} else {
switch (action.type) {
case PROCEED_STEP: {
const { currentStepIndex, totalStepCount } = state.steps
const newStepIdx =
currentStepIndex + 1 < totalStepCount
? currentStepIndex + 1
: currentStepIndex

const nextStepIdx =
newStepIdx + 1 < totalStepCount ? newStepIdx + 1 : null
const nextStep =
nextStepIdx != null ? state.steps.all[nextStepIdx] : null

return {
...state,
steps: {
...state.steps,
currentStepIndex: newStepIdx,
current: state.steps.all[newStepIdx],
next: nextStep,
},
}
}
}

case SET_INITIAL_POSITION:
case SET_FINAL_POSITION:
return {
...state,
workingOffsets: updateWorkingOffset(state.workingOffsets, action),
}
case SET_INITIAL_POSITION:
case SET_FINAL_POSITION:
return {
...state,
workingOffsets: updateWorkingOffset(state.workingOffsets, action),
}

case FINISH_LPC:
return undefined
case FINISH_LPC:
return undefined

default:
return state
default:
return state
}
}
}

0 comments on commit 84618e8

Please sign in to comment.