From a0ea43d3c7620d19b0dbe3dd18836af308203433 Mon Sep 17 00:00:00 2001 From: TamarZanzouri Date: Mon, 16 Sep 2024 16:15:32 -0400 Subject: [PATCH] fix(app): includeFixitCommands in GET run commands (#16253) # Overview closes [EXEC-704](https://opentrons.atlassian.net/browse/EXEC-704). revert do not render fixit commands and add query string to req. ## Test Plan and Hands on Testing - load an ER protocol. - enter ER. - dispatch a few fixit commands. - finish run. - make sure there are no fixit commands in the run preview. ## Changelog revert commend intent logic from UI. add `includeFixitCommands` in query string to GET run commands. ## Review requests am I missing anyhting? ## Risk assessment low. no change in appearance. [EXEC-704]: https://opentrons.atlassian.net/browse/EXEC-704?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ --------- Co-authored-by: Jamey Huffnagle --- api-client/src/runs/commands/getCommands.ts | 4 +-- .../getCommandsAsPreSerializedList.ts | 4 +-- api-client/src/runs/commands/types.ts | 8 ++++++ .../Devices/hooks/useDownloadRunLog.ts | 2 ++ .../getPipettesWithTipAttached.ts | 2 ++ .../hooks/useCurrentRunCommands.ts | 4 +-- .../ProtocolUpload/hooks/useRunCommands.ts | 4 +-- app/src/organisms/RunPreview/index.tsx | 11 ++------ .../__tests__/RunProgressMeter.test.tsx | 5 +++- .../__tests__/RunningProtocol.test.tsx | 5 +++- ...useNotifyAllCommandsAsPreSerializedList.ts | 4 +-- .../runs/useNotifyAllCommandsQuery.ts | 28 +++++++++++++++++-- .../runs/useAllCommandsAsPreSerializedList.ts | 14 +++++++--- .../src/runs/useAllCommandsQuery.ts | 24 ++++++++++++---- 14 files changed, 86 insertions(+), 33 deletions(-) diff --git a/api-client/src/runs/commands/getCommands.ts b/api-client/src/runs/commands/getCommands.ts index 4833b94e5a8..95283c81b64 100644 --- a/api-client/src/runs/commands/getCommands.ts +++ b/api-client/src/runs/commands/getCommands.ts @@ -3,12 +3,12 @@ import { GET, request } from '../../request' import type { ResponsePromise } from '../../request' import type { HostConfig } from '../../types' import type { CommandsData } from '..' -import type { GetCommandsParams } from './types' +import type { GetRunCommandsParamsRequest } from './types' export function getCommands( config: HostConfig, runId: string, - params: GetCommandsParams + params: GetRunCommandsParamsRequest ): ResponsePromise { return request( GET, diff --git a/api-client/src/runs/commands/getCommandsAsPreSerializedList.ts b/api-client/src/runs/commands/getCommandsAsPreSerializedList.ts index 420f984b280..1d96f3d2209 100644 --- a/api-client/src/runs/commands/getCommandsAsPreSerializedList.ts +++ b/api-client/src/runs/commands/getCommandsAsPreSerializedList.ts @@ -4,13 +4,13 @@ import type { ResponsePromise } from '../../request' import type { HostConfig } from '../../types' import type { CommandsAsPreSerializedListData, - GetCommandsParams, + GetRunCommandsParamsRequest, } from './types' export function getCommandsAsPreSerializedList( config: HostConfig, runId: string, - params: GetCommandsParams + params: GetRunCommandsParamsRequest ): ResponsePromise { return request( GET, diff --git a/api-client/src/runs/commands/types.ts b/api-client/src/runs/commands/types.ts index cd18924201c..8c5517a1fe3 100644 --- a/api-client/src/runs/commands/types.ts +++ b/api-client/src/runs/commands/types.ts @@ -5,6 +5,14 @@ export interface GetCommandsParams { pageLength: number // the number of items to include } +export interface GetRunCommandsParams extends GetCommandsParams { + includeFixitCommands?: boolean +} + +export interface GetRunCommandsParamsRequest extends GetCommandsParams { + includeFixitCommands: boolean | null +} + export interface RunCommandErrors { data: RunCommandError[] meta: GetCommandsParams & { totalLength: number } diff --git a/app/src/organisms/Devices/hooks/useDownloadRunLog.ts b/app/src/organisms/Devices/hooks/useDownloadRunLog.ts index 1652efc4442..777f50bb806 100644 --- a/app/src/organisms/Devices/hooks/useDownloadRunLog.ts +++ b/app/src/organisms/Devices/hooks/useDownloadRunLog.ts @@ -29,12 +29,14 @@ export function useDownloadRunLog( getCommands(host, runId, { cursor: null, pageLength: 0, + includeFixitCommands: true, }) .then(response => { const { totalLength } = response.data.meta getCommands(host, runId, { cursor: 0, pageLength: totalLength, + includeFixitCommands: true, }) .then(response => { const commands = response.data diff --git a/app/src/organisms/DropTipWizardFlows/hooks/useTipAttachmentStatus/getPipettesWithTipAttached.ts b/app/src/organisms/DropTipWizardFlows/hooks/useTipAttachmentStatus/getPipettesWithTipAttached.ts index 99bcd949093..42b006ca0b2 100644 --- a/app/src/organisms/DropTipWizardFlows/hooks/useTipAttachmentStatus/getPipettesWithTipAttached.ts +++ b/app/src/organisms/DropTipWizardFlows/hooks/useTipAttachmentStatus/getPipettesWithTipAttached.ts @@ -50,11 +50,13 @@ function getCommandsExecutedDuringRun( 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) }) } diff --git a/app/src/organisms/ProtocolUpload/hooks/useCurrentRunCommands.ts b/app/src/organisms/ProtocolUpload/hooks/useCurrentRunCommands.ts index b6cc00709f9..543d90cb899 100644 --- a/app/src/organisms/ProtocolUpload/hooks/useCurrentRunCommands.ts +++ b/app/src/organisms/ProtocolUpload/hooks/useCurrentRunCommands.ts @@ -4,11 +4,11 @@ import type { UseQueryOptions } from 'react-query' import type { CommandsData, RunCommandSummary, - GetCommandsParams, + GetRunCommandsParams, } from '@opentrons/api-client' export function useCurrentRunCommands( - params?: GetCommandsParams, + params?: GetRunCommandsParams, options?: UseQueryOptions ): RunCommandSummary[] | null { const currentRunId = useCurrentRunId() diff --git a/app/src/organisms/ProtocolUpload/hooks/useRunCommands.ts b/app/src/organisms/ProtocolUpload/hooks/useRunCommands.ts index 394c8a3eac0..cb3e70296f8 100644 --- a/app/src/organisms/ProtocolUpload/hooks/useRunCommands.ts +++ b/app/src/organisms/ProtocolUpload/hooks/useRunCommands.ts @@ -4,14 +4,14 @@ import type { UseQueryOptions } from 'react-query' import type { CommandsData, RunCommandSummary, - GetCommandsParams, + GetRunCommandsParams, } from '@opentrons/api-client' const REFETCH_INTERVAL = 3000 export function useRunCommands( runId: string | null, - params?: GetCommandsParams, + params?: GetRunCommandsParams, options?: UseQueryOptions ): RunCommandSummary[] | null { const { data: commandsData } = useNotifyAllCommandsQuery(runId, params, { diff --git a/app/src/organisms/RunPreview/index.tsx b/app/src/organisms/RunPreview/index.tsx index 8efdc6dce3e..27ed73fedf9 100644 --- a/app/src/organisms/RunPreview/index.tsx +++ b/app/src/organisms/RunPreview/index.tsx @@ -64,7 +64,7 @@ export const RunPreviewComponent = ( isLoading: isRunCommandDataLoading, } = useNotifyAllCommandsAsPreSerializedList( runId, - { cursor: 0, pageLength: MAX_COMMANDS }, + { cursor: 0, pageLength: MAX_COMMANDS, includeFixitCommands: false }, { enabled: isRunTerminal, } @@ -78,20 +78,13 @@ export const RunPreviewComponent = ( isCurrentCommandVisible, setIsCurrentCommandVisible, ] = React.useState(true) - const filteredCommandsFromQuery = React.useMemo( - () => - commandsFromQuery?.filter( - command => !('intent' in command) || command.intent !== 'fixit' - ), - [commandsFromQuery == null] - ) if (robotSideAnalysis == null) { return null } const commands = isRunTerminal - ? filteredCommandsFromQuery + ? commandsFromQuery : robotSideAnalysis.commands // pass relevant data from run rather than analysis so that CommandText utilities can properly hash the entities' IDs diff --git a/app/src/organisms/RunProgressMeter/__tests__/RunProgressMeter.test.tsx b/app/src/organisms/RunProgressMeter/__tests__/RunProgressMeter.test.tsx index 17bbdb279c0..f84087b4c3c 100644 --- a/app/src/organisms/RunProgressMeter/__tests__/RunProgressMeter.test.tsx +++ b/app/src/organisms/RunProgressMeter/__tests__/RunProgressMeter.test.tsx @@ -76,7 +76,10 @@ describe('RunProgressMeter', () => { .calledWith(NON_DETERMINISTIC_RUN_ID) .thenReturn(null) when(useNotifyAllCommandsQuery) - .calledWith(NON_DETERMINISTIC_RUN_ID, { cursor: null, pageLength: 1 }) + .calledWith(NON_DETERMINISTIC_RUN_ID, { + cursor: null, + pageLength: 1, + }) .thenReturn(mockUseAllCommandsResponseNonDeterministic) when(useCommandQuery) .calledWith(NON_DETERMINISTIC_RUN_ID, NON_DETERMINISTIC_COMMAND_KEY) diff --git a/app/src/pages/ODD/RunningProtocol/__tests__/RunningProtocol.test.tsx b/app/src/pages/ODD/RunningProtocol/__tests__/RunningProtocol.test.tsx index 5c74ad7e95e..866f33e34e7 100644 --- a/app/src/pages/ODD/RunningProtocol/__tests__/RunningProtocol.test.tsx +++ b/app/src/pages/ODD/RunningProtocol/__tests__/RunningProtocol.test.tsx @@ -151,7 +151,10 @@ describe('RunningProtocol', () => { .calledWith(RUN_ID) .thenReturn(mockRobotSideAnalysis) when(vi.mocked(useNotifyAllCommandsQuery)) - .calledWith(RUN_ID, { cursor: null, pageLength: 1 }) + .calledWith(RUN_ID, { + cursor: null, + pageLength: 1, + }) .thenReturn(mockUseAllCommandsResponseNonDeterministic) vi.mocked(useLastRunCommand).mockReturnValue({ key: 'FAKE_COMMAND_KEY', diff --git a/app/src/resources/runs/useNotifyAllCommandsAsPreSerializedList.ts b/app/src/resources/runs/useNotifyAllCommandsAsPreSerializedList.ts index 5811c051e54..5668b824667 100644 --- a/app/src/resources/runs/useNotifyAllCommandsAsPreSerializedList.ts +++ b/app/src/resources/runs/useNotifyAllCommandsAsPreSerializedList.ts @@ -4,12 +4,12 @@ import { useNotifyDataReady } from '../useNotifyDataReady' import type { UseQueryResult } from 'react-query' import type { AxiosError } from 'axios' -import type { CommandsData, GetCommandsParams } from '@opentrons/api-client' +import type { CommandsData, GetRunCommandsParams } from '@opentrons/api-client' import type { QueryOptionsWithPolling } from '../useNotifyDataReady' export function useNotifyAllCommandsAsPreSerializedList( runId: string | null, - params?: GetCommandsParams | null, + params?: GetRunCommandsParams | null, options: QueryOptionsWithPolling = {} ): UseQueryResult { const { shouldRefetch, queryOptionsNotify } = useNotifyDataReady({ diff --git a/app/src/resources/runs/useNotifyAllCommandsQuery.ts b/app/src/resources/runs/useNotifyAllCommandsQuery.ts index 4482ea972fd..12bafb21ef3 100644 --- a/app/src/resources/runs/useNotifyAllCommandsQuery.ts +++ b/app/src/resources/runs/useNotifyAllCommandsQuery.ts @@ -3,12 +3,23 @@ import { useAllCommandsQuery } from '@opentrons/react-api-client' import { useNotifyDataReady } from '../useNotifyDataReady' import type { UseQueryResult } from 'react-query' -import type { CommandsData, GetCommandsParams } from '@opentrons/api-client' +import type { + CommandsData, + GetRunCommandsParams, + GetCommandsParams, +} 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( runId: string | null, - params?: GetCommandsParams | null, + params?: GetRunCommandsParams | null, options: QueryOptionsWithPolling = {} ): UseQueryResult { // Assume the useAllCommandsQuery() response can only change when the command links change. @@ -21,8 +32,19 @@ export function useNotifyAllCommandsQuery( 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, params, queryOptionsNotify) + const httpQueryResult = useAllCommandsQuery( + runId, + finalizedNullCheckParams, + queryOptionsNotify + ) if (shouldRefetch) { void httpQueryResult.refetch() diff --git a/react-api-client/src/runs/useAllCommandsAsPreSerializedList.ts b/react-api-client/src/runs/useAllCommandsAsPreSerializedList.ts index 4d0a34295d0..4f7e2fdc0e0 100644 --- a/react-api-client/src/runs/useAllCommandsAsPreSerializedList.ts +++ b/react-api-client/src/runs/useAllCommandsAsPreSerializedList.ts @@ -7,21 +7,21 @@ import { useHost } from '../api' import type { UseQueryOptions, UseQueryResult } from 'react-query' import type { - GetCommandsParams, + GetRunCommandsParams, HostConfig, CommandsData, RunCommandSummary, } from '@opentrons/api-client' const DEFAULT_PAGE_LENGTH = 30 -export const DEFAULT_PARAMS: GetCommandsParams = { +export const DEFAULT_PARAMS: GetRunCommandsParams = { cursor: null, pageLength: DEFAULT_PAGE_LENGTH, } export function useAllCommandsAsPreSerializedList( runId: string | null, - params?: GetCommandsParams | null, + params?: GetRunCommandsParams | null, options: UseQueryOptions = {} ): UseQueryResult { const host = useHost() @@ -32,6 +32,11 @@ export function useAllCommandsAsPreSerializedList( enabled: host !== null && runId != null && options.enabled !== false, } const { cursor, pageLength } = nullCheckedParams + const nullCheckedFixitCommands = params?.includeFixitCommands ?? null + const finalizedNullCheckParams = { + ...nullCheckedParams, + includeFixitCommands: nullCheckedFixitCommands, + } // map undefined values to null to agree with react query caching // TODO (nd: 05/15/2024) create sanitizer for react query key objects @@ -45,12 +50,13 @@ export function useAllCommandsAsPreSerializedList( 'getCommandsAsPreSerializedList', cursor, pageLength, + nullCheckedFixitCommands, ], () => { return getCommandsAsPreSerializedList( host as HostConfig, runId as string, - nullCheckedParams + finalizedNullCheckParams ).then(response => { const responseData = response.data return { diff --git a/react-api-client/src/runs/useAllCommandsQuery.ts b/react-api-client/src/runs/useAllCommandsQuery.ts index 20c598d733f..427e96b554f 100644 --- a/react-api-client/src/runs/useAllCommandsQuery.ts +++ b/react-api-client/src/runs/useAllCommandsQuery.ts @@ -3,20 +3,21 @@ import { getCommands } from '@opentrons/api-client' import { useHost } from '../api' import type { UseQueryOptions, UseQueryResult } from 'react-query' import type { - GetCommandsParams, + GetRunCommandsParamsRequest, HostConfig, CommandsData, } from '@opentrons/api-client' const DEFAULT_PAGE_LENGTH = 30 -export const DEFAULT_PARAMS: GetCommandsParams = { +export const DEFAULT_PARAMS: GetRunCommandsParamsRequest = { cursor: null, pageLength: DEFAULT_PAGE_LENGTH, + includeFixitCommands: null, } export function useAllCommandsQuery( runId: string | null, - params?: GetCommandsParams | null, + params?: GetRunCommandsParamsRequest | null, options: UseQueryOptions = {} ): UseQueryResult { const host = useHost() @@ -27,13 +28,26 @@ export function useAllCommandsQuery( enabled: host !== null && runId != null && options.enabled !== false, } const { cursor, pageLength } = nullCheckedParams + const nullCheckedFixitCommands = params?.includeFixitCommands ?? null + const finalizedNullCheckParams = { + ...nullCheckedParams, + includeFixitCommands: nullCheckedFixitCommands, + } const query = useQuery( - [host, 'runs', runId, 'commands', cursor, pageLength], + [ + host, + 'runs', + runId, + 'commands', + cursor, + pageLength, + finalizedNullCheckParams, + ], () => { return getCommands( host as HostConfig, runId as string, - nullCheckedParams + finalizedNullCheckParams ).then(response => response.data) }, allOptions