Skip to content

Commit

Permalink
refactor(app): reduce superfluous protocol analysis scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
mjhuff committed Oct 22, 2024
1 parent e551948 commit f8ed107
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
24 changes: 15 additions & 9 deletions app/src/organisms/ErrorRecoveryFlows/hooks/useDeckMapUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useMemo } from 'react'

import {
getDeckDefFromRobotType,
getLoadedLabwareDefinitionsByUri,
getFixedTrashLabwareDefinition,
getModuleDef2,
getPositionFromSlotId,
Expand All @@ -22,21 +21,27 @@ import type {
LoadedLabware,
RobotType,
LabwareDefinitionsByUri,
LoadedModule,
} from '@opentrons/shared-data'
import type { ErrorRecoveryFlowsProps } from '..'
import type { UseFailedLabwareUtilsResult } from './useFailedLabwareUtils'
import type { ERUtilsProps } from './useERUtils'

interface UseDeckMapUtilsProps {
runId: ErrorRecoveryFlowsProps['runId']
protocolAnalysis: ErrorRecoveryFlowsProps['protocolAnalysis']
failedLabwareUtils: UseFailedLabwareUtilsResult
labwareDefinitionsByUri: ERUtilsProps['labwareDefinitionsByUri']
runRecord?: Run
}

export interface UseDeckMapUtilsResult {
deckConfig: CutoutConfigProtocolSpec[]
modulesOnDeck: RunCurrentModulesOnDeck[]
labwareOnDeck: RunCurrentLabwareOnDeck[]
loadedLabware: LoadedLabware[]
loadedModules: LoadedModule[]
movedLabwareDef: LabwareDefinition2 | null
highlightLabwareEventuallyIn: string[]
kind: 'intervention'
robotType: RobotType
Expand All @@ -47,19 +52,12 @@ export function useDeckMapUtils({
runRecord,
runId,
failedLabwareUtils,
labwareDefinitionsByUri,
}: UseDeckMapUtilsProps): UseDeckMapUtilsResult {
const robotType = protocolAnalysis?.robotType ?? OT2_ROBOT_TYPE
const deckConfig = getSimplestDeckConfigForProtocol(protocolAnalysis)
const deckDef = getDeckDefFromRobotType(robotType)

const labwareDefinitionsByUri = useMemo(
() =>
protocolAnalysis != null
? getLoadedLabwareDefinitionsByUri(protocolAnalysis?.commands)
: null,
[protocolAnalysis]
)

const currentModulesInfo = useMemo(
() =>
getRunCurrentModulesInfo({
Expand Down Expand Up @@ -93,6 +91,11 @@ export function useDeckMapUtils({
[runId, protocolAnalysis, runRecord, deckDef, failedLabwareUtils]
)

const movedLabwareDef =
labwareDefinitionsByUri != null && failedLabwareUtils.failedLabware != null
? labwareDefinitionsByUri[failedLabwareUtils.failedLabware.definitionUri]
: null

return {
deckConfig,
modulesOnDeck: runCurrentModules.map(
Expand All @@ -112,6 +115,9 @@ export function useDeckMapUtils({
.filter(maybeSlot => maybeSlot != null) as string[],
kind: 'intervention',
robotType,
loadedModules: runRecord?.data.modules ?? [],
loadedLabware: runRecord?.data.labware ?? [],
movedLabwareDef,
}
}

Expand Down
9 changes: 8 additions & 1 deletion app/src/organisms/ErrorRecoveryFlows/hooks/useERUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ import { useShowDoorInfo } from './useShowDoorInfo'
import { useCleanupRecoveryState } from './useCleanupRecoveryState'
import { useFailedPipetteUtils } from './useFailedPipetteUtils'

import type { LabwareDefinition2, RobotType } from '@opentrons/shared-data'
import type {
LabwareDefinition2,
LabwareDefinitionsByUri,
RobotType,
} from '@opentrons/shared-data'
import type { IRecoveryMap, RouteStep, RecoveryRoute } from '../types'
import type { ErrorRecoveryFlowsProps } from '..'
import type { UseRouteUpdateActionsResult } from './useRouteUpdateActions'
Expand Down Expand Up @@ -48,6 +52,7 @@ export type ERUtilsProps = Omit<ErrorRecoveryFlowsProps, 'failedCommand'> & {
failedCommand: ReturnType<typeof useRetainedFailedCommandBySource>
showTakeover: boolean
allRunDefs: LabwareDefinition2[]
labwareDefinitionsByUri: LabwareDefinitionsByUri | null
}

export interface ERUtilsResults {
Expand Down Expand Up @@ -82,6 +87,7 @@ export function useERUtils({
runStatus,
showTakeover,
allRunDefs,
labwareDefinitionsByUri,
}: ERUtilsProps): ERUtilsResults {
const { data: attachedInstruments } = useInstrumentsQuery()
const { data: runRecord } = useNotifyRunQuery(runId)
Expand Down Expand Up @@ -168,6 +174,7 @@ export function useERUtils({
runRecord,
protocolAnalysis,
failedLabwareUtils,
labwareDefinitionsByUri,
})

const recoveryActionMutationUtils = useRecoveryActionMutation(
Expand Down
19 changes: 14 additions & 5 deletions app/src/organisms/ErrorRecoveryFlows/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import {
RUN_STATUS_STOP_REQUESTED,
RUN_STATUS_SUCCEEDED,
} from '@opentrons/api-client'
import { OT2_ROBOT_TYPE } from '@opentrons/shared-data'
import {
getLoadedLabwareDefinitionsByUri,
OT2_ROBOT_TYPE,
} from '@opentrons/shared-data'
import { useHost } from '@opentrons/react-api-client'

import { getIsOnDevice } from '/app/redux/config'
import { getLabwareDefinitionsFromCommands } from '/app/local-resources/labware'
import { ErrorRecoveryWizard, useERWizard } from './ErrorRecoveryWizard'
import { RecoverySplash, useRecoverySplash } from './RecoverySplash'
import { RecoveryTakeover } from './RecoveryTakeover'
Expand Down Expand Up @@ -127,13 +129,19 @@ export function ErrorRecoveryFlows(
const robotName = useHost()?.robotName ?? 'robot'

const isValidRobotSideAnalysis = protocolAnalysis != null
const allRunDefs = useMemo(

// TODO(jh, 10-22-24): EXEC-769.
const labwareDefinitionsByUri = useMemo(
() =>
protocolAnalysis != null
? getLabwareDefinitionsFromCommands(protocolAnalysis.commands)
: [],
? getLoadedLabwareDefinitionsByUri(protocolAnalysis?.commands)
: null,
[isValidRobotSideAnalysis]
)
const allRunDefs =
labwareDefinitionsByUri != null
? Object.values(labwareDefinitionsByUri)
: []

const {
showTakeover,
Expand All @@ -151,6 +159,7 @@ export function ErrorRecoveryFlows(
showTakeover,
failedCommand: failedCommandBySource,
allRunDefs,
labwareDefinitionsByUri,
})

const renderWizard =
Expand Down

0 comments on commit f8ed107

Please sign in to comment.