Skip to content

Commit

Permalink
typings and such
Browse files Browse the repository at this point in the history
  • Loading branch information
sfoster1 committed Oct 22, 2024
1 parent 2b94028 commit d1ac787
Show file tree
Hide file tree
Showing 15 changed files with 282 additions and 266 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
27 changes: 14 additions & 13 deletions app/src/organisms/Desktop/Devices/ProtocolRun/ProtocolRunSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import { SetupLiquids } from './SetupLiquids'
import { EmptySetupStep } from './EmptySetupStep'
import { HowLPCWorksModal } from './SetupLabwarePositionCheck/HowLPCWorksModal'

import type { Dispatch, State } from '/app/redux'
import type { Dispatch, State } from '/app/redux/types'
import type { StepKey } from '/app/redux/protocol-runs'

const STEP_KEY_TO_I18N_KEY = {

Check failure on line 66 in app/src/organisms/Desktop/Devices/ProtocolRun/ProtocolRunSetup.tsx

View workflow job for this annotation

GitHub Actions / js checks

'STEP_KEY_TO_I18N_KEY' is assigned a value but never used
Expand Down Expand Up @@ -143,7 +143,9 @@ export function ProtocolRunSetup({
? t('install_modules', { count: modules.length })
: t('no_deck_hardware_specified')

const missingSteps = useSelector(state => getMissingSetupSteps(state, runId))
const missingSteps = useSelector<State, StepKey[]>(
(state: State): StepKey[] => getMissingSetupSteps(state, runId)
)

if (robot == null) {
return null
Expand Down Expand Up @@ -224,7 +226,7 @@ export function ProtocolRunSetup({
{...{ runId, robotName }}
setOffsetsConfirmed={confirmed => {
dispatch(
updateRunSetupStepsComplete(runId, { [LPC_STEP_KEY]: true })
updateRunSetupStepsComplete(runId, { [LPC_STEP_KEY]: confirmed })
)
if (confirmed) {
setExpandedStepKey(LABWARE_SETUP_STEP_KEY)
Expand All @@ -251,14 +253,10 @@ export function ProtocolRunSetup({
setLabwareConfirmed={(confirmed: boolean) => {
dispatch(
updateRunSetupStepsComplete(runId, {
[LABWARE_SETUP_STEP_KEY]: true,
[LABWARE_SETUP_STEP_KEY]: confirmed,
})
)
setLabwareSetupComplete(confirmed)
if (confirmed) {
setMissingSteps(
missingSteps.filter(step => step !== 'labware_placement')
)
const nextStep =
orderedApplicableSteps.findIndex(
v => v === LABWARE_SETUP_STEP_KEY
Expand All @@ -274,7 +272,7 @@ export function ProtocolRunSetup({
description: t(`${LABWARE_SETUP_STEP_KEY}_description`),
rightElProps: {
stepKey: LABWARE_SETUP_STEP_KEY,
complete: labwareSetupComplete,
complete: !missingSteps.includes(LABWARE_SETUP_STEP_KEY),
completeText: t('placements_ready'),
incompleteText: null,
incompleteElement: null,
Expand All @@ -286,11 +284,14 @@ export function ProtocolRunSetup({
robotName={robotName}
runId={runId}
protocolAnalysis={protocolAnalysis}
isLiquidSetupConfirmed={liquidSetupComplete}
isLiquidSetupConfirmed={!missingSteps.includes(LIQUID_SETUP_STEP_KEY)}
setLiquidSetupConfirmed={(confirmed: boolean) => {
setLiquidSetupComplete(confirmed)
dispatch(
updateRunSetupStepsComplete(runId, {
[LIQUID_SETUP_STEP_KEY]: confirmed,
})
)
if (confirmed) {
setMissingSteps(missingSteps.filter(step => step !== 'liquids'))
setExpandedStepKey(null)
}
}}
Expand All @@ -301,7 +302,7 @@ export function ProtocolRunSetup({
: i18n.format(t('liquids_not_in_the_protocol'), 'capitalize'),
rightElProps: {
stepKey: LIQUID_SETUP_STEP_KEY,
complete: liquidSetupComplete,
complete: !missingSteps.includes(LIQUID_SETUP_STEP_KEY),
completeText: t('liquids_ready'),
incompleteText: null,
incompleteElement: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { RUN_STATUS_STOPPED } from '@opentrons/api-client'
import { useIsFlex } from '/app/redux-resources/robots'

import type { ProtocolCalibrationStatus } from '/app/redux/calibration/types'
import type { StepKey } from './ProtocolRunSetup'
import type { StepKey } from '/app/redux/protocol-runs'

interface SetupRobotCalibrationProps {
robotName: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import { EmptySetupStep } from '../EmptySetupStep'
import { ProtocolRunSetup } from '../ProtocolRunSetup'
import * as ReduxRuns from '/app/redux/protocol-runs'

import type { MissingSteps } from '../ProtocolRunSetup'
import type { StepKey } from '/app/redux/protocol-runs'

import type * as SharedData from '@opentrons/shared-data'

Expand Down Expand Up @@ -78,18 +78,12 @@ vi.mock('@opentrons/shared-data', async importOriginal => {
const ROBOT_NAME = 'otie'
const RUN_ID = '1'
const MOCK_PROTOCOL_LIQUID_KEY = { liquids: [] }
let mockMissingSteps: MissingSteps = []
const mockSetMissingSteps = vi.fn((missingSteps: MissingSteps) => {
mockMissingSteps = missingSteps
})
const render = () => {
return renderWithProviders(
<ProtocolRunSetup
protocolRunHeaderRef={null}
robotName={ROBOT_NAME}
runId={RUN_ID}
missingSteps={mockMissingSteps}
setMissingSteps={mockSetMissingSteps}
/>,
{
i18nInstance: i18n,
Expand All @@ -99,7 +93,6 @@ const render = () => {

describe('ProtocolRunSetup', () => {
beforeEach(() => {
mockMissingSteps = []
when(vi.mocked(useIsFlex)).calledWith(ROBOT_NAME).thenReturn(false)
when(vi.mocked(useMostRecentCompletedAnalysis))
.calledWith(RUN_ID)
Expand All @@ -119,11 +112,14 @@ describe('ProtocolRunSetup', () => {
when(vi.mocked(useRequiredSetupStepsInOrder))
.calledWith({
runId: RUN_ID,
protocolAnalysis: { ...noModulesProtocol, ...MOCK_PROTOCOL_LIQUID_KEY },
protocolAnalysis: ({
...noModulesProtocol,
...MOCK_PROTOCOL_LIQUID_KEY,
} as any) as SharedData.CompletedProtocolAnalysis,
})
.thenReturn({
orderedSteps: ReduxRuns.SETUP_STEP_KEYS,
orderedApplicableSteps: ReduxRuns.SETUP_STEP_KEYS,
orderedApplicableSteps: (ReduxRuns.SETUP_STEP_KEYS as any) as StepKey[],
})
vi.mocked(parseAllRequiredModuleModels).mockReturnValue([])
vi.mocked(parseLiquidsInLoadOrder).mockReturnValue([])
Expand Down Expand Up @@ -194,11 +190,18 @@ describe('ProtocolRunSetup', () => {
.thenReturn(null)
when(vi.mocked(useRequiredSetupStepsInOrder))
.calledWith({ runId: RUN_ID, protocolAnalysis: null })
.thenReturn([
ReduxRuns.ROBOT_CALIBRATION_STEP_KEY,
ReduxRuns.LPC_STEP_KEY,
ReduxRuns.LABWARE_SETUP_STEP_KEY,
])
.thenReturn({
orderedSteps: [
ReduxRuns.ROBOT_CALIBRATION_STEP_KEY,
ReduxRuns.LPC_STEP_KEY,
ReduxRuns.LABWARE_SETUP_STEP_KEY,
],
orderedApplicableSteps: [
ReduxRuns.ROBOT_CALIBRATION_STEP_KEY,
ReduxRuns.LPC_STEP_KEY,
ReduxRuns.LABWARE_SETUP_STEP_KEY,
],
})
render()
screen.getByText('Loading data...')
})
Expand Down
12 changes: 1 addition & 11 deletions app/src/pages/Desktop/Devices/ProtocolRunDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ import { ApiHostProvider } from '@opentrons/react-api-client'
import { useSyncRobotClock } from '/app/organisms/Desktop/Devices/hooks'
import { ProtocolRunHeader } from '/app/organisms/Desktop/Devices/ProtocolRun/ProtocolRunHeader'
import { RunPreview } from '/app/organisms/Desktop/Devices/RunPreview'
import {
ProtocolRunSetup,
initialMissingSteps,
} from '/app/organisms/Desktop/Devices/ProtocolRun/ProtocolRunSetup'
import { ProtocolRunSetup } from '/app/organisms/Desktop/Devices/ProtocolRun/ProtocolRunSetup'
import { BackToTopButton } from '/app/organisms/Desktop/Devices/ProtocolRun/BackToTopButton'
import { ProtocolRunModuleControls } from '/app/organisms/Desktop/Devices/ProtocolRun/ProtocolRunModuleControls'
import { ProtocolRunRuntimeParameters } from '/app/organisms/Desktop/Devices/ProtocolRun/ProtocolRunRunTimeParameters'
Expand Down Expand Up @@ -187,10 +184,6 @@ function PageContents(props: PageContentsProps): JSX.Element {
}
}, [jumpedIndex])

const [missingSteps, setMissingSteps] = useState<
ReturnType<typeof initialMissingSteps>
>(initialMissingSteps())

const makeHandleScrollToStep = (i: number) => () => {
listRef.current?.scrollToIndex(i, true, -1 * JUMP_OFFSET_FROM_TOP_PX)
}
Expand All @@ -210,8 +203,6 @@ function PageContents(props: PageContentsProps): JSX.Element {
protocolRunHeaderRef={protocolRunHeaderRef}
robotName={robotName}
runId={runId}
setMissingSteps={setMissingSteps}
missingSteps={missingSteps}
/>
),
backToTop: (
Expand Down Expand Up @@ -269,7 +260,6 @@ function PageContents(props: PageContentsProps): JSX.Element {
robotName={robotName}
runId={runId}
makeHandleJumpToStep={makeHandleJumpToStep}
missingSetupSteps={missingSteps}
/>
<Flex gridGap={SPACING.spacing8} marginBottom={SPACING.spacing12}>
<SetupTab
Expand Down
Loading

0 comments on commit d1ac787

Please sign in to comment.