Skip to content

Commit

Permalink
fix(app): Fix post run drop tip wizard always displaying after error …
Browse files Browse the repository at this point in the history
…recovery (#16893)

Closes RQA-3614
  • Loading branch information
mjhuff authored Nov 19, 2024
1 parent 2875150 commit 90389eb
Show file tree
Hide file tree
Showing 19 changed files with 43 additions and 88 deletions.
4 changes: 2 additions & 2 deletions api-client/src/runs/commands/types.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import type { RunTimeCommand, RunCommandError } from '@opentrons/shared-data'

export interface GetCommandsParams {
cursor: number | null // the index of the command at the center of the window
pageLength: number // the number of items to include
cursor?: number
}

export interface GetRunCommandsParams extends GetCommandsParams {
includeFixitCommands?: boolean
}

export interface GetRunCommandsParamsRequest extends GetCommandsParams {
includeFixitCommands: boolean | null
includeFixitCommands?: boolean
}

export interface RunCommandErrors {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export function useActionButtonProperties({
handleButtonClick = () => {
isResetRunLoadingRef.current = true
reset()
runHeaderModalContainerUtils.dropTipUtils.resetTipStatus()
trackEvent({
name: ANALYTICS_PROTOCOL_PROCEED_TO_RUN,
properties: { sourceLocation: 'RunRecordDetail', robotSerialNumber },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type { Run, RunStatus } from '@opentrons/api-client'
import type {
DropTipWizardFlowsProps,
PipetteWithTip,
TipAttachmentStatusResult,
} from '/app/organisms/DropTipWizardFlows'
import type { UseProtocolDropTipModalResult } from '../modals'
import type { PipetteDetails } from '/app/resources/maintenance_runs'
Expand All @@ -40,6 +41,7 @@ export interface UseRunHeaderDropTipParams {
export interface UseRunHeaderDropTipResult {
dropTipModalUtils: UseProtocolDropTipModalResult
dropTipWizardUtils: RunHeaderDropTipWizProps
resetTipStatus: TipAttachmentStatusResult['resetTipStatus']
}

// Handles all the tip related logic during a protocol run on the desktop app.
Expand Down Expand Up @@ -111,11 +113,9 @@ export function useRunHeaderDropTip({
{
includeFixitCommands: false,
pageLength: 1,
cursor: null,
},
{ enabled: isTerminalRunStatus(runStatus) }
)

// Manage tip checking
useEffect(() => {
// If a user begins a new run without navigating away from the run page, reset tip status.
Expand All @@ -127,7 +127,9 @@ export function useRunHeaderDropTip({
// have to do it here if done during Error Recovery.
else if (
runSummaryNoFixit != null &&
!lastRunCommandPromptedErrorRecovery(runSummaryNoFixit)
runSummaryNoFixit.length > 0 &&
!lastRunCommandPromptedErrorRecovery(runSummaryNoFixit) &&
isTerminalRunStatus(runStatus)
) {
void determineTipStatus()
}
Expand All @@ -150,7 +152,11 @@ export function useRunHeaderDropTip({
}
}, [runStatus, isRunCurrent, enteredER, initialPipettesWithTipsCount])

return { dropTipModalUtils, dropTipWizardUtils: buildDTWizUtils() }
return {
dropTipModalUtils,
dropTipWizardUtils: buildDTWizUtils(),
resetTipStatus,
}
}

// TODO(jh, 09-12-24): Consolidate this with the same utility that exists elsewhere.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export function useDownloadRunLog(
if (host == null) return
// first getCommands to get total length of commands
getCommands(host, runId, {
cursor: null,
pageLength: 0,
includeFixitCommands: true,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ describe('RunProgressMeter', () => {
.thenReturn(null)
when(useNotifyAllCommandsQuery)
.calledWith(NON_DETERMINISTIC_RUN_ID, {
cursor: null,
pageLength: 1,
})
.thenReturn(mockUseAllCommandsResponseNonDeterministic)
Expand Down
1 change: 0 additions & 1 deletion app/src/organisms/Desktop/RunProgressMeter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export function RunProgressMeter(props: RunProgressMeterProps): JSX.Element {
const runData = runRecord?.data ?? null

const { data: mostRecentCommandData } = useNotifyAllCommandsQuery(runId, {
cursor: null,
pageLength: 1,
})
// This lastRunCommand also includes "fixit" commands.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,13 @@ function getCommandsExecutedDuringRun(
runId: string
): Promise<CommandsData> {
return getCommands(host, runId, {
cursor: null,
pageLength: 0,
includeFixitCommands: true,
}).then(response => {
const { totalLength } = response.data.meta
return getCommands(host, runId, {
cursor: 0,
pageLength: totalLength,
includeFixitCommands: null,
}).then(response => response.data)
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('useCurrentlyRecoveringFrom', () => {

expect(vi.mocked(useNotifyAllCommandsQuery)).toHaveBeenCalledWith(
MOCK_RUN_ID,
{ cursor: null, pageLength: 0 },
{ pageLength: 0 },
{ enabled: false, refetchInterval: 5000 }
)
expect(vi.mocked(useCommandQuery)).toHaveBeenCalledWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function useCurrentlyRecoveringFrom(
isFetching: isAllCommandsFetching,
} = useNotifyAllCommandsQuery(
runId,
{ cursor: null, pageLength: 0 }, // pageLength 0 because we only care about the links.
{ pageLength: 0 }, // pageLength 0 because we only care about the links.
{
enabled: isRunInRecoveryMode,
refetchInterval: ALL_COMMANDS_POLL_MS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ export function CurrentRunningProtocolCommand({
}: CurrentRunningProtocolCommandProps): JSX.Element | null {
const { t } = useTranslation('run_details')
const { data: mostRecentCommandData } = useNotifyAllCommandsQuery(runId, {
cursor: null,
pageLength: 1,
})

Expand Down
3 changes: 1 addition & 2 deletions app/src/pages/ODD/RunSummary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,14 @@ export function RunSummary(): JSX.Element {
const runSummaryNoFixit = useCurrentRunCommands({
includeFixitCommands: false,
pageLength: 1,
cursor: null,
})
useEffect(() => {
if (
isRunCurrent &&
runSummaryNoFixit != null &&
runSummaryNoFixit.length > 0 &&
!lastRunCommandPromptedErrorRecovery(runSummaryNoFixit)
) {
console.log('HITTING THIS')
void determineTipStatus()
}
}, [runSummaryNoFixit, isRunCurrent])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ describe('RunningProtocol', () => {
.thenReturn(mockRobotSideAnalysis)
when(vi.mocked(useNotifyAllCommandsQuery))
.calledWith(RUN_ID, {
cursor: null,
pageLength: 1,
})
.thenReturn(mockUseAllCommandsResponseNonDeterministic)
Expand Down
2 changes: 1 addition & 1 deletion app/src/resources/runs/__tests__/useRunTimestamps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ vi.mock('../useNotifyRunQuery')
describe('useRunTimestamps hook', () => {
beforeEach(() => {
when(useRunCommands)
.calledWith(RUN_ID_2, { cursor: null, pageLength: 1 }, expect.any(Object))
.calledWith(RUN_ID_2, { pageLength: 1 }, expect.any(Object))
.thenReturn([mockCommand.data as any])
})

Expand Down
2 changes: 1 addition & 1 deletion app/src/resources/runs/useLastRunCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function useLastRunCommand(
const runStatus = useRunStatus(runId)
const { data: commandsData } = useNotifyAllCommandsQuery(
runId,
{ cursor: null, pageLength: 1 },
{ pageLength: 1 },
{
...options,
refetchInterval:
Expand Down
28 changes: 3 additions & 25 deletions app/src/resources/runs/useNotifyAllCommandsQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,12 @@ import { useAllCommandsQuery } from '@opentrons/react-api-client'
import { useNotifyDataReady } from '../useNotifyDataReady'

import type { UseQueryResult } from 'react-query'
import type {
CommandsData,
GetRunCommandsParams,
GetCommandsParams,
} from '@opentrons/api-client'
import type { CommandsData, GetRunCommandsParams } from '@opentrons/api-client'
import type { QueryOptionsWithPolling } from '../useNotifyDataReady'

const DEFAULT_PAGE_LENGTH = 30

export const DEFAULT_PARAMS: GetCommandsParams = {
cursor: null,
pageLength: DEFAULT_PAGE_LENGTH,
}

export function useNotifyAllCommandsQuery<TError = Error>(
runId: string | null,
params?: GetRunCommandsParams | null,
params?: GetRunCommandsParams,
options: QueryOptionsWithPolling<CommandsData, TError> = {}
): UseQueryResult<CommandsData, TError> {
// Assume the useAllCommandsQuery() response can only change when the command links change.
Expand All @@ -32,19 +21,8 @@ export function useNotifyAllCommandsQuery<TError = Error>(
topic: 'robot-server/runs/commands_links',
options,
})
const nullCheckedParams = params ?? DEFAULT_PARAMS

const nullCheckedFixitCommands = params?.includeFixitCommands ?? null
const finalizedNullCheckParams = {
...nullCheckedParams,
includeFixitCommands: nullCheckedFixitCommands,
}

const httpQueryResult = useAllCommandsQuery(
runId,
finalizedNullCheckParams,
queryOptionsNotify
)
const httpQueryResult = useAllCommandsQuery(runId, params, queryOptionsNotify)

if (shouldRefetch) {
void httpQueryResult.refetch()
Expand Down
2 changes: 1 addition & 1 deletion app/src/resources/runs/useRunTimestamps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function useRunTimestamps(runId: string | null): RunTimestamps {
const runCommands =
useRunCommands(
runId,
{ cursor: null, pageLength: 1 },
{ pageLength: 1 },
{
enabled:
runStatus === RUN_STATUS_SUCCEEDED ||
Expand Down
18 changes: 6 additions & 12 deletions react-api-client/src/runs/useAllCommandsAsPreSerializedList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,22 @@ import type {
} from '@opentrons/api-client'

const DEFAULT_PAGE_LENGTH = 30
export const DEFAULT_PARAMS: GetRunCommandsParams = {
cursor: null,
pageLength: DEFAULT_PAGE_LENGTH,
}

export function useAllCommandsAsPreSerializedList<TError = Error>(
runId: string | null,
params?: GetRunCommandsParams | null,
options: UseQueryOptions<CommandsData, TError> = {}
): UseQueryResult<CommandsData, TError> {
const host = useHost()
const nullCheckedParams = params ?? DEFAULT_PARAMS

const allOptions: UseQueryOptions<CommandsData, TError> = {
...options,
enabled: host !== null && runId != null && options.enabled !== false,
}
const { cursor, pageLength } = nullCheckedParams
const nullCheckedFixitCommands = params?.includeFixitCommands ?? null
const finalizedNullCheckParams = {
...nullCheckedParams,
includeFixitCommands: nullCheckedFixitCommands,
const { cursor, pageLength, includeFixitCommands } = params ?? {}
const finalizedParams = {
...params,
pageLength: params?.pageLength ?? DEFAULT_PAGE_LENGTH,
}

// map undefined values to null to agree with react query caching
Expand All @@ -50,13 +44,13 @@ export function useAllCommandsAsPreSerializedList<TError = Error>(
'getCommandsAsPreSerializedList',
cursor,
pageLength,
nullCheckedFixitCommands,
includeFixitCommands,
],
() => {
return getCommandsAsPreSerializedList(
host as HostConfig,
runId as string,
finalizedNullCheckParams
finalizedParams
).then(response => {
const responseData = response.data
return {
Expand Down
31 changes: 8 additions & 23 deletions react-api-client/src/runs/useAllCommandsQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,30 @@ import type {
} from '@opentrons/api-client'

const DEFAULT_PAGE_LENGTH = 30
export const DEFAULT_PARAMS: GetRunCommandsParamsRequest = {
cursor: null,
pageLength: DEFAULT_PAGE_LENGTH,
includeFixitCommands: null,
}

export function useAllCommandsQuery<TError = Error>(
runId: string | null,
params?: GetRunCommandsParamsRequest | null,
params?: GetRunCommandsParamsRequest,
options: UseQueryOptions<CommandsData, TError> = {}
): UseQueryResult<CommandsData, TError> {
const host = useHost()
const nullCheckedParams = params ?? DEFAULT_PARAMS

const allOptions: UseQueryOptions<CommandsData, TError> = {
...options,
enabled: host !== null && runId != null && options.enabled !== false,
}
const { cursor, pageLength } = nullCheckedParams
const nullCheckedFixitCommands = params?.includeFixitCommands ?? null
const finalizedNullCheckParams = {
...nullCheckedParams,
includeFixitCommands: nullCheckedFixitCommands,

const { cursor, pageLength, includeFixitCommands } = params ?? {}
const finalizedParams = {
...params,
pageLength: params?.pageLength ?? DEFAULT_PAGE_LENGTH,
}
const query = useQuery<CommandsData, TError>(
[
host,
'runs',
runId,
'commands',
cursor,
pageLength,
finalizedNullCheckParams,
],
[host, 'runs', runId, 'commands', cursor, pageLength, includeFixitCommands],
() => {
return getCommands(
host as HostConfig,
runId as string,
finalizedNullCheckParams
finalizedParams
).then(response => response.data)
},
allOptions
Expand Down
15 changes: 7 additions & 8 deletions react-api-client/src/runs/useRunCommandErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,30 @@ import type {
} from '@opentrons/api-client'

const DEFAULT_PAGE_LENGTH = 30
export const DEFAULT_PARAMS: GetCommandsParams = {
cursor: null,
pageLength: DEFAULT_PAGE_LENGTH,
}

export function useRunCommandErrors<TError = Error>(
runId: string | null,
params?: GetCommandsParams | null,
options: UseQueryOptions<RunCommandErrors, TError> = {}
): UseQueryResult<RunCommandErrors, TError> {
const host = useHost()
const nullCheckedParams = params ?? DEFAULT_PARAMS

const allOptions: UseQueryOptions<RunCommandErrors, TError> = {
...options,
enabled: host !== null && runId != null && options.enabled !== false,
}
const { cursor, pageLength } = nullCheckedParams

const { cursor, pageLength } = params ?? {}
const finalizedParams = {
...params,
pageLength: params?.pageLength ?? DEFAULT_PAGE_LENGTH,
}
const query = useQuery<RunCommandErrors, TError>(
[host, 'runs', runId, 'commandErrors', cursor, pageLength],
() => {
return getRunCommandErrors(
host as HostConfig,
runId as string,
nullCheckedParams
finalizedParams
).then(response => response.data)
},
allOptions
Expand Down

0 comments on commit 90389eb

Please sign in to comment.