Skip to content

Commit 657d259

Browse files
authored
fix(app): fallback to current run command on ODD if run diverges from analysis (#14821)
In the case of a non-deterministic protocol, the running protocol screen of the on device display app will fall back to showing no command text at all, instead it should fall back to showing the current running command Closes PLAT-274
1 parent 3f10d09 commit 657d259

File tree

9 files changed

+35
-37
lines changed

9 files changed

+35
-37
lines changed

app/src/organisms/Devices/hooks/useLastRunCommandKey.ts renamed to app/src/organisms/Devices/hooks/useLastRunCommand.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from '@opentrons/api-client'
1313

1414
import type { UseQueryOptions } from 'react-query'
15-
import type { CommandsData } from '@opentrons/api-client'
15+
import type { CommandsData, RunCommandSummary } from '@opentrons/api-client'
1616

1717
const LIVE_RUN_STATUSES = [
1818
RUN_STATUS_IDLE,
@@ -26,10 +26,10 @@ const LIVE_RUN_STATUSES = [
2626
]
2727
const LIVE_RUN_COMMANDS_POLL_MS = 3000
2828

29-
export function useLastRunCommandKey(
29+
export function useLastRunCommand(
3030
runId: string,
3131
options: UseQueryOptions<CommandsData, Error> = {}
32-
): string | null {
32+
): RunCommandSummary | null {
3333
const runStatus = useRunStatus(runId)
3434
const { data: commandsData } = useAllCommandsQuery(
3535
runId,
@@ -44,8 +44,6 @@ export function useLastRunCommandKey(
4444
)
4545

4646
return commandsData?.data?.[0]?.intent !== 'setup'
47-
? commandsData?.links?.current?.meta?.key ??
48-
commandsData?.data?.[0]?.key ??
49-
null
47+
? commandsData?.data?.[0] ?? null
5048
: null
5149
}

app/src/organisms/OnDeviceDisplay/RunningProtocol/CurrentRunningProtocolCommand.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import type {
3030
RobotType,
3131
RunTimeCommand,
3232
} from '@opentrons/shared-data'
33-
import type { RunStatus } from '@opentrons/api-client'
33+
import type { RunCommandSummary, RunStatus } from '@opentrons/api-client'
3434
import type { TrackProtocolRunEvent } from '../../Devices/hooks'
3535
import type { RobotAnalyticsData } from '../../../redux/analytics/types'
3636

@@ -117,6 +117,7 @@ interface CurrentRunningProtocolCommandProps {
117117
trackProtocolRunEvent: TrackProtocolRunEvent
118118
robotAnalyticsData: RobotAnalyticsData | null
119119
lastAnimatedCommand: string | null
120+
lastRunCommand: RunCommandSummary | null
120121
updateLastAnimatedCommand: (newCommandKey: string) => void
121122
protocolName?: string
122123
currentRunCommandIndex?: number
@@ -134,13 +135,15 @@ export function CurrentRunningProtocolCommand({
134135
robotType,
135136
protocolName,
136137
currentRunCommandIndex,
138+
lastRunCommand,
137139
lastAnimatedCommand,
138140
updateLastAnimatedCommand,
139141
}: CurrentRunningProtocolCommandProps): JSX.Element | null {
140142
const { t } = useTranslation('run_details')
141-
const currentCommand = robotSideAnalysis?.commands.find(
142-
(c: RunTimeCommand, index: number) => index === currentRunCommandIndex
143-
)
143+
const currentCommand =
144+
robotSideAnalysis?.commands.find(
145+
(c: RunTimeCommand, index: number) => index === currentRunCommandIndex
146+
) ?? lastRunCommand
144147

145148
let shouldAnimate = true
146149
if (currentCommand?.key != null) {

app/src/organisms/OnDeviceDisplay/RunningProtocol/__tests__/CurrentRunningProtocolCommand.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ describe('CurrentRunningProtocolCommand', () => {
4646
protocolName: 'mockRunningProtocolName',
4747
currentRunCommandIndex: 0,
4848
lastAnimatedCommand: null,
49+
lastRunCommand: null,
4950
updateLastAnimatedCommand: mockUpdateLastAnimatedCommand,
5051
robotType: FLEX_ROBOT_TYPE,
5152
}

app/src/organisms/RunPreview/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import {
2121

2222
import { useMostRecentCompletedAnalysis } from '../LabwarePositionCheck/useMostRecentCompletedAnalysis'
2323
import {
24+
useNotifyLastRunCommand,
2425
useNotifyAllCommandsAsPreSerializedList,
25-
useNotifyLastRunCommandKey,
2626
} from '../../resources/runs'
2727
import { CommandText } from '../CommandText'
2828
import { Divider } from '../../atoms/structure'
@@ -68,9 +68,9 @@ export const RunPreviewComponent = (
6868
const nullCheckedCommandsFromQuery =
6969
commandsFromQuery == null ? robotSideAnalysis?.commands : commandsFromQuery
7070
const viewPortRef = React.useRef<HTMLDivElement | null>(null)
71-
const currentRunCommandKey = useNotifyLastRunCommandKey(runId, {
71+
const currentRunCommandKey = useNotifyLastRunCommand(runId, {
7272
refetchInterval: LIVE_RUN_COMMANDS_POLL_MS,
73-
})
73+
})?.key
7474
const [
7575
isCurrentCommandVisible,
7676
setIsCurrentCommandVisible,

app/src/organisms/RunProgressMeter/__tests__/RunProgressMeter.test.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
RUN_STATUS_IDLE,
1212
RUN_STATUS_RUNNING,
1313
RUN_STATUS_SUCCEEDED,
14+
RunCommandSummary,
1415
} from '@opentrons/api-client'
1516

1617
import { i18n } from '../../../i18n'
@@ -19,7 +20,7 @@ import { ProgressBar } from '../../../atoms/ProgressBar'
1920
import { useRunStatus } from '../../RunTimeControl/hooks'
2021
import { useMostRecentCompletedAnalysis } from '../../LabwarePositionCheck/useMostRecentCompletedAnalysis'
2122
import {
22-
useNotifyLastRunCommandKey,
23+
useNotifyLastRunCommand,
2324
useNotifyRunQuery,
2425
} from '../../../resources/runs'
2526
import { useDownloadRunLog } from '../../Devices/hooks'
@@ -82,9 +83,9 @@ describe('RunProgressMeter', () => {
8283
downloadRunLog: vi.fn(),
8384
isRunLogLoading: false,
8485
})
85-
when(useNotifyLastRunCommandKey)
86+
when(useNotifyLastRunCommand)
8687
.calledWith(NON_DETERMINISTIC_RUN_ID, { refetchInterval: 1000 })
87-
.thenReturn(NON_DETERMINISTIC_COMMAND_KEY)
88+
.thenReturn({ key: NON_DETERMINISTIC_COMMAND_KEY } as RunCommandSummary)
8889

8990
vi.mocked(useNotifyRunQuery).mockReturnValue({ data: null } as any)
9091

app/src/pages/RunningProtocol/__tests__/RunningProtocol.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ import { RunPausedSplash } from '../../../organisms/OnDeviceDisplay/RunningProto
3535
import { OpenDoorAlertModal } from '../../../organisms/OpenDoorAlertModal'
3636
import { RunningProtocol } from '..'
3737
import {
38-
useNotifyLastRunCommandKey,
38+
useNotifyLastRunCommand,
3939
useNotifyRunQuery,
4040
} from '../../../resources/runs'
4141
import { useFeatureFlag } from '../../../redux/config'
4242

4343
import type { UseQueryResult } from 'react-query'
44-
import type { ProtocolAnalyses } from '@opentrons/api-client'
44+
import type { ProtocolAnalyses, RunCommandSummary } from '@opentrons/api-client'
4545

4646
vi.mock('@opentrons/react-api-client')
4747
vi.mock('../../../organisms/Devices/hooks')
@@ -137,9 +137,9 @@ describe('RunningProtocol', () => {
137137
when(vi.mocked(useAllCommandsQuery))
138138
.calledWith(RUN_ID, { cursor: null, pageLength: 1 })
139139
.thenReturn(mockUseAllCommandsResponseNonDeterministic)
140-
vi.mocked(useNotifyLastRunCommandKey).mockReturnValue({
141-
data: {},
142-
} as any)
140+
vi.mocked(useNotifyLastRunCommand).mockReturnValue({
141+
key: 'FAKE_COMMAND_KEY',
142+
} as RunCommandSummary)
143143
when(vi.mocked(useFeatureFlag))
144144
.calledWith('enableRunNotes')
145145
.thenReturn(true)

app/src/pages/RunningProtocol/index.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
useSwipe,
1919
} from '@opentrons/components'
2020
import {
21-
useAllCommandsQuery,
2221
useProtocolQuery,
2322
useRunActionMutations,
2423
} from '@opentrons/react-api-client'
@@ -32,7 +31,7 @@ import { useFeatureFlag } from '../../redux/config'
3231
import { StepMeter } from '../../atoms/StepMeter'
3332
import { useMostRecentCompletedAnalysis } from '../../organisms/LabwarePositionCheck/useMostRecentCompletedAnalysis'
3433
import {
35-
useNotifyLastRunCommandKey,
34+
useNotifyLastRunCommand,
3635
useNotifyRunQuery,
3736
} from '../../resources/runs'
3837
import { InterventionModal } from '../../organisms/InterventionModal'
@@ -95,12 +94,13 @@ export function RunningProtocol(): JSX.Element {
9594
const lastAnimatedCommand = React.useRef<string | null>(null)
9695
const swipe = useSwipe()
9796
const robotSideAnalysis = useMostRecentCompletedAnalysis(runId)
98-
const currentRunCommandKey = useNotifyLastRunCommandKey(runId, {
97+
const lastRunCommand = useNotifyLastRunCommand(runId, {
9998
refetchInterval: LIVE_RUN_COMMANDS_POLL_MS,
10099
})
100+
101101
const totalIndex = robotSideAnalysis?.commands.length
102102
const currentRunCommandIndex = robotSideAnalysis?.commands.findIndex(
103-
c => c.key === currentRunCommandKey
103+
c => c.key === lastRunCommand?.key
104104
)
105105
const runStatus = useRunStatus(runId, {
106106
refetchInterval: RUN_STATUS_REFETCH_INTERVAL,
@@ -143,12 +143,6 @@ export function RunningProtocol(): JSX.Element {
143143
}
144144
}, [currentOption, swipe, swipe.setSwipeType])
145145

146-
const { data: allCommandsQueryData } = useAllCommandsQuery(runId, {
147-
cursor: null,
148-
pageLength: 1,
149-
})
150-
const lastRunCommand = allCommandsQueryData?.data[0] ?? null
151-
152146
React.useEffect(() => {
153147
if (
154148
lastRunCommand != null &&
@@ -242,6 +236,7 @@ export function RunningProtocol(): JSX.Element {
242236
stoppedAt,
243237
completedAt,
244238
}}
239+
lastRunCommand={lastRunCommand}
245240
lastAnimatedCommand={lastAnimatedCommand.current}
246241
updateLastAnimatedCommand={(newCommandKey: string) =>
247242
(lastAnimatedCommand.current = newCommandKey)

app/src/resources/runs/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ export * from './hooks'
22
export * from './utils'
33
export * from './useNotifyAllRunsQuery'
44
export * from './useNotifyRunQuery'
5-
export * from './useNotifyLastRunCommandKey'
5+
export * from './useNotifyLastRunCommand'
66
export * from './useNotifyAllCommandsAsPreSerializedList'

app/src/resources/runs/useNotifyLastRunCommandKey.ts renamed to app/src/resources/runs/useNotifyLastRunCommand.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import * as React from 'react'
22

33
import { useNotifyService } from '../useNotifyService'
4-
import { useLastRunCommandKey } from '../../organisms/Devices/hooks/useLastRunCommandKey'
4+
import { useLastRunCommand } from '../../organisms/Devices/hooks/useLastRunCommand'
55

6-
import type { CommandsData } from '@opentrons/api-client'
6+
import type { CommandsData, RunCommandSummary } from '@opentrons/api-client'
77
import type {
88
QueryOptionsWithPolling,
99
HTTPRefetchFrequency,
1010
} from '../useNotifyService'
1111

12-
export function useNotifyLastRunCommandKey(
12+
export function useNotifyLastRunCommand(
1313
runId: string,
1414
options: QueryOptionsWithPolling<CommandsData, Error> = {}
15-
): string | null {
15+
): RunCommandSummary | null {
1616
const [refetch, setRefetch] = React.useState<HTTPRefetchFrequency>(null)
1717

1818
useNotifyService({
@@ -21,7 +21,7 @@ export function useNotifyLastRunCommandKey(
2121
options,
2222
})
2323

24-
const httpResponse = useLastRunCommandKey(runId, {
24+
const httpResponse = useLastRunCommand(runId, {
2525
...options,
2626
enabled: options?.enabled !== false && refetch != null,
2727
onSettled: refetch === 'once' ? () => setRefetch(null) : () => null,

0 commit comments

Comments
 (0)