Skip to content

Commit

Permalink
fix(app): store run step completion in redux (#16570)
Browse files Browse the repository at this point in the history
[It turns out that since we implemented the green checks displayed for
completed steps as react component state, if you navigate away from the
component it loses the state.

To fix this we can throw it in redux. This PR does that, in the app
anyway.

## testing
- [x] the green checks on the desktop should still work, including when
you nav away and back

## reviews
- i have not done redux stuff in a while! does this look right?


Closes RQA-3304
  • Loading branch information
sfoster1 authored Oct 23, 2024
1 parent 9a65cc8 commit 33554cb
Show file tree
Hide file tree
Showing 22 changed files with 606 additions and 150 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useTranslation } from 'react-i18next'
import { useNavigate } from 'react-router-dom'
import { useSelector } from 'react-redux'

import {
RUN_STATUS_IDLE,
Expand All @@ -14,6 +15,7 @@ import {
useTrackEvent,
} from '/app/redux/analytics'
import { useTrackProtocolRunEvent } from '/app/redux-resources/analytics'
import { getMissingSetupSteps } from '/app/redux/protocol-runs'
import { useIsHeaterShakerInProtocol } from '/app/organisms/ModuleCard/hooks'
import { isAnyHeaterShakerShaking } from '../../../RunHeaderModalContainer/modals'
import {
Expand All @@ -24,6 +26,8 @@ import {

import type { IconName } from '@opentrons/components'
import type { BaseActionButtonProps } from '..'
import type { State } from '/app/redux/types'
import type { StepKey } from '/app/redux/protocol-runs'

interface UseButtonPropertiesProps extends BaseActionButtonProps {
isProtocolNotReady: boolean
Expand All @@ -42,7 +46,6 @@ interface UseButtonPropertiesProps extends BaseActionButtonProps {
export function useActionButtonProperties({
isProtocolNotReady,
runStatus,
missingSetupSteps,
robotName,
runId,
confirmAttachment,
Expand All @@ -66,6 +69,9 @@ export function useActionButtonProperties({
const isHeaterShakerInProtocol = useIsHeaterShakerInProtocol()
const isHeaterShakerShaking = isAnyHeaterShakerShaking(attachedModules)
const trackEvent = useTrackEvent()
const missingSetupSteps = useSelector<State, StepKey[]>((state: State) =>
getMissingSetupSteps(state, runId)
)

let buttonText = ''
let handleButtonClick = (): void => {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { useSelector } from 'react-redux'
import { RUN_STATUS_IDLE, RUN_STATUS_STOPPED } from '@opentrons/api-client'
import { useConditionalConfirm } from '@opentrons/components'

import { useIsHeaterShakerInProtocol } from '/app/organisms/ModuleCard/hooks'
import { isAnyHeaterShakerShaking } from '../modals'
import { getMissingSetupSteps } from '/app/redux/protocol-runs'

import type { UseConditionalConfirmResult } from '@opentrons/components'
import type { RunStatus, AttachedModule } from '@opentrons/api-client'
import type { ConfirmMissingStepsModalProps } from '../modals'
import type { State } from '/app/redux/types'
import type { StepKey } from '/app/redux/protocol-runs'

interface UseMissingStepsModalProps {
runStatus: RunStatus | null
attachedModules: AttachedModule[]
missingSetupSteps: string[]
runId: string
handleProceedToRunClick: () => void
}

Expand All @@ -30,12 +34,14 @@ export type UseMissingStepsModalResult =
export function useMissingStepsModal({
attachedModules,
runStatus,
missingSetupSteps,
runId,
handleProceedToRunClick,
}: UseMissingStepsModalProps): UseMissingStepsModalResult {
const isHeaterShakerInProtocol = useIsHeaterShakerInProtocol()
const isHeaterShakerShaking = isAnyHeaterShakerShaking(attachedModules)

const missingSetupSteps = useSelector<State, StepKey[]>((state: State) =>
getMissingSetupSteps(state, runId)
)
const shouldShowHSConfirm =
isHeaterShakerInProtocol &&
!isHeaterShakerShaking &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,27 @@ import {
TYPOGRAPHY,
Modal,
} from '@opentrons/components'
import {
LPC_STEP_KEY,
LABWARE_SETUP_STEP_KEY,
LIQUID_SETUP_STEP_KEY,
MODULE_SETUP_STEP_KEY,
ROBOT_CALIBRATION_STEP_KEY,
} from '/app/redux/protocol-runs'
import type { StepKey } from '/app/redux/protocol-runs'

const STEP_KEY_TO_I18N_KEY = {
[LPC_STEP_KEY]: 'applied_labware_offsets',
[LABWARE_SETUP_STEP_KEY]: 'labware_placement',
[LIQUID_SETUP_STEP_KEY]: 'liquids',
[MODULE_SETUP_STEP_KEY]: 'module_setup',
[ROBOT_CALIBRATION_STEP_KEY]: 'robot_calibration',
}

export interface ConfirmMissingStepsModalProps {
onCloseClick: () => void
onConfirmClick: () => void
missingSteps: string[]
missingSteps: StepKey[]
}
export const ConfirmMissingStepsModal = (
props: ConfirmMissingStepsModalProps
Expand All @@ -41,7 +57,7 @@ export const ConfirmMissingStepsModal = (
missingSteps: new Intl.ListFormat('en', {
style: 'short',
type: 'conjunction',
}).format(missingSteps.map(step => t(step))),
}).format(missingSteps.map(step => t(STEP_KEY_TO_I18N_KEY[step]))),
})}
</LegacyStyledText>
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export function useRunHeaderModalContainer({
runStatus,
runRecord,
attachedModules,
missingSetupSteps,
protocolRunControls,
runErrors,
}: UseRunHeaderModalContainerProps): UseRunHeaderModalContainerResult {
Expand Down Expand Up @@ -102,7 +101,7 @@ export function useRunHeaderModalContainer({
const missingStepsModalUtils = useMissingStepsModal({
attachedModules,
runStatus,
missingSetupSteps,
runId,
handleProceedToRunClick,
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ vi.mock('react-router-dom')
vi.mock('@opentrons/react-api-client')
vi.mock('/app/redux-resources/robots')
vi.mock('/app/resources/runs')
vi.mock('/app/redux/protocol-runs')
vi.mock('../RunHeaderModalContainer')
vi.mock('../RunHeaderBannerContainer')
vi.mock('../RunHeaderContent')
Expand All @@ -51,7 +52,6 @@ describe('ProtocolRunHeader', () => {
robotName: MOCK_ROBOT,
runId: MOCK_RUN_ID,
makeHandleJumpToStep: vi.fn(),
missingSetupSteps: [],
}

vi.mocked(useNavigate).mockReturnValue(mockNavigate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export interface ProtocolRunHeaderProps {
robotName: string
runId: string
makeHandleJumpToStep: (index: number) => () => void
missingSetupSteps: string[]
}

export function ProtocolRunHeader(
Expand Down
Loading

0 comments on commit 33554cb

Please sign in to comment.