diff --git a/app/src/organisms/ErrorRecoveryFlows/hooks/__tests__/useDeckMapUtils.test.ts b/app/src/organisms/ErrorRecoveryFlows/hooks/__tests__/useDeckMapUtils.test.ts index 4e341acda99..7e51669bd9a 100644 --- a/app/src/organisms/ErrorRecoveryFlows/hooks/__tests__/useDeckMapUtils.test.ts +++ b/app/src/organisms/ErrorRecoveryFlows/hooks/__tests__/useDeckMapUtils.test.ts @@ -171,7 +171,6 @@ describe('getRunCurrentModulesInfo', () => { }, } as any const mockDeckDef = {} as any - const mockProtocolAnalysis = {} as any beforeEach(() => { vi.mocked(getLoadedLabwareDefinitionsByUri).mockReturnValue({ @@ -185,7 +184,7 @@ describe('getRunCurrentModulesInfo', () => { const result = getRunCurrentModulesInfo({ runRecord: null as any, deckDef: mockDeckDef, - protocolAnalysis: mockProtocolAnalysis, + labwareDefinitionsByUri: {}, }) expect(result).toEqual([]) @@ -195,7 +194,7 @@ describe('getRunCurrentModulesInfo', () => { const result = getRunCurrentModulesInfo({ runRecord: mockRunRecord, deckDef: mockDeckDef, - protocolAnalysis: null, + labwareDefinitionsByUri: null, }) expect(result).toEqual([]) @@ -205,7 +204,9 @@ describe('getRunCurrentModulesInfo', () => { const result = getRunCurrentModulesInfo({ runRecord: mockRunRecord, deckDef: mockDeckDef, - protocolAnalysis: mockProtocolAnalysis, + labwareDefinitionsByUri: { + 'opentrons/opentrons_96_pcr_adapter/1': 'MOCK_LW_DEF', + } as any, }) expect(result).toEqual([ @@ -226,7 +227,7 @@ describe('getRunCurrentModulesInfo', () => { data: { modules: [mockModule], labware: [] }, }, deckDef: mockDeckDef, - protocolAnalysis: mockProtocolAnalysis, + labwareDefinitionsByUri: {}, }) expect(result).toEqual([ { @@ -245,7 +246,7 @@ describe('getRunCurrentModulesInfo', () => { const result = getRunCurrentModulesInfo({ runRecord: mockRunRecord, deckDef: mockDeckDef, - protocolAnalysis: mockProtocolAnalysis, + labwareDefinitionsByUri: null, }) expect(result).toEqual([]) }) @@ -270,7 +271,7 @@ describe('getRunCurrentLabwareInfo', () => { it('should return an empty array if runRecord is null', () => { const result = getRunCurrentLabwareInfo({ runRecord: undefined, - protocolAnalysis: {} as any, + labwareDefinitionsByUri: {} as any, }) expect(result).toEqual([]) @@ -279,7 +280,7 @@ describe('getRunCurrentLabwareInfo', () => { it('should return an empty array if protocolAnalysis is null', () => { const result = getRunCurrentLabwareInfo({ runRecord: { data: { labware: [] } } as any, - protocolAnalysis: null, + labwareDefinitionsByUri: null, }) expect(result).toEqual([]) @@ -293,7 +294,9 @@ describe('getRunCurrentLabwareInfo', () => { const result = getRunCurrentLabwareInfo({ runRecord: { data: { labware: [mockPickUpTipLwSlotName] } } as any, - protocolAnalysis: { commands: [] } as any, + labwareDefinitionsByUri: { + [mockPickUpTipLabware.definitionUri]: mockLabwareDef, + }, }) expect(result).toEqual([ diff --git a/app/src/organisms/ErrorRecoveryFlows/hooks/useDeckMapUtils.ts b/app/src/organisms/ErrorRecoveryFlows/hooks/useDeckMapUtils.ts index 93caceaf4c2..95dac5abdb7 100644 --- a/app/src/organisms/ErrorRecoveryFlows/hooks/useDeckMapUtils.ts +++ b/app/src/organisms/ErrorRecoveryFlows/hooks/useDeckMapUtils.ts @@ -3,6 +3,7 @@ import { useMemo } from 'react' import { getDeckDefFromRobotType, getLoadedLabwareDefinitionsByUri, + getFixedTrashLabwareDefinition, getModuleDef2, getPositionFromSlotId, getSimplestDeckConfigForProtocol, @@ -20,6 +21,7 @@ import type { CutoutConfigProtocolSpec, LoadedLabware, RobotType, + LabwareDefinitionsByUri, } from '@opentrons/shared-data' import type { ErrorRecoveryFlowsProps } from '..' import type { UseFailedLabwareUtilsResult } from './useFailedLabwareUtils' @@ -50,14 +52,22 @@ export function useDeckMapUtils({ const deckConfig = getSimplestDeckConfigForProtocol(protocolAnalysis) const deckDef = getDeckDefFromRobotType(robotType) + const labwareDefinitionsByUri = useMemo( + () => + protocolAnalysis != null + ? getLoadedLabwareDefinitionsByUri(protocolAnalysis?.commands) + : null, + [protocolAnalysis] + ) + const currentModulesInfo = useMemo( () => getRunCurrentModulesInfo({ runRecord, deckDef, - protocolAnalysis, + labwareDefinitionsByUri, }), - [runRecord, deckDef, protocolAnalysis] + [runRecord, deckDef, labwareDefinitionsByUri] ) const runCurrentModules = useMemo( @@ -70,8 +80,8 @@ export function useDeckMapUtils({ ) const currentLabwareInfo = useMemo( - () => getRunCurrentLabwareInfo({ runRecord, protocolAnalysis }), - [runRecord, protocolAnalysis] + () => getRunCurrentLabwareInfo({ runRecord, labwareDefinitionsByUri }), + [runRecord, labwareDefinitionsByUri] ) const runCurrentLabware = useMemo( @@ -182,13 +192,13 @@ interface RunCurrentModuleInfo { export const getRunCurrentModulesInfo = ({ runRecord, deckDef, - protocolAnalysis, + labwareDefinitionsByUri, }: { - protocolAnalysis: UseDeckMapUtilsProps['protocolAnalysis'] runRecord: UseDeckMapUtilsProps['runRecord'] deckDef: DeckDefinition + labwareDefinitionsByUri?: LabwareDefinitionsByUri | null }): RunCurrentModuleInfo[] => { - if (runRecord == null || protocolAnalysis == null) { + if (runRecord == null || labwareDefinitionsByUri == null) { return [] } else { return runRecord.data.modules.reduce( @@ -203,10 +213,6 @@ export const getRunCurrentModulesInfo = ({ lw.location.moduleId === module.id ) - const labwareDefinitionsByUri = getLoadedLabwareDefinitionsByUri( - protocolAnalysis.commands - ) - const nestedLabwareDef = nestedLabware != null ? labwareDefinitionsByUri[nestedLabware.definitionUri] @@ -249,21 +255,18 @@ interface RunCurrentLabwareInfo { // Derive the labware info necessary to render labware on the deck. export function getRunCurrentLabwareInfo({ runRecord, - protocolAnalysis, + labwareDefinitionsByUri, }: { runRecord: UseDeckMapUtilsProps['runRecord'] - protocolAnalysis: UseDeckMapUtilsProps['protocolAnalysis'] + labwareDefinitionsByUri?: LabwareDefinitionsByUri | null }): RunCurrentLabwareInfo[] { - if (runRecord == null || protocolAnalysis == null) { + if (runRecord == null || labwareDefinitionsByUri == null) { return [] } else { return runRecord.data.labware.reduce((acc: RunCurrentLabwareInfo[], lw) => { const loc = lw.location const [slotName, labwareLocation] = getSlotNameAndLwLocFrom(loc, true) // Exclude modules since handled separately. - const labwareDefinitionsByUri = getLoadedLabwareDefinitionsByUri( - protocolAnalysis.commands - ) - const labwareDef = labwareDefinitionsByUri[lw.definitionUri] + const labwareDef = getLabwareDefinition(lw, labwareDefinitionsByUri) if (slotName == null || labwareLocation == null) { return acc @@ -281,6 +284,17 @@ export function getRunCurrentLabwareInfo({ } } +const getLabwareDefinition = ( + labware: LoadedLabware, + protocolLabwareDefinitionsByUri: LabwareDefinitionsByUri +): LabwareDefinition2 => { + if (labware.id === 'fixedTrash') { + return getFixedTrashLabwareDefinition() + } else { + return protocolLabwareDefinitionsByUri[labware.definitionUri] + } +} + // Get the slotName for on deck labware. export function getSlotNameAndLwLocFrom( location: LabwareLocation | null, diff --git a/shared-data/js/helpers/__tests__/getFixedTrashLabwareDefinition.test.ts b/shared-data/js/helpers/__tests__/getFixedTrashLabwareDefinition.test.ts new file mode 100644 index 00000000000..06131197e07 --- /dev/null +++ b/shared-data/js/helpers/__tests__/getFixedTrashLabwareDefinition.test.ts @@ -0,0 +1,12 @@ +import { describe, it, expect } from 'vitest' +import { getFixedTrashLabwareDefinition } from '../index' +import type { LabwareDefinition2 } from '../..' +import fixedTrashUncasted from '../../../labware/definitions/2/opentrons_1_trash_3200ml_fixed/1.json' + +describe('getFixedTrashLabwareDefinition', () => { + it(`should return the fixed trash labware defition`, () => { + expect(getFixedTrashLabwareDefinition()).toEqual( + (fixedTrashUncasted as unknown) as LabwareDefinition2 + ) + }) +}) diff --git a/shared-data/js/helpers/getFixedTrashLabwareDefinition.ts b/shared-data/js/helpers/getFixedTrashLabwareDefinition.ts new file mode 100644 index 00000000000..0818827b1b2 --- /dev/null +++ b/shared-data/js/helpers/getFixedTrashLabwareDefinition.ts @@ -0,0 +1,7 @@ +import type { LabwareDefinition2 } from '..' +import fixedTrashUncasted from '../../labware/definitions/2/opentrons_1_trash_3200ml_fixed/1.json' + +export function getFixedTrashLabwareDefinition(): LabwareDefinition2 { + const LabwareDefinition2 = (fixedTrashUncasted as unknown) as LabwareDefinition2 + return LabwareDefinition2 +} diff --git a/shared-data/js/helpers/index.ts b/shared-data/js/helpers/index.ts index 8bf9c6edb45..93c25c78c1a 100644 --- a/shared-data/js/helpers/index.ts +++ b/shared-data/js/helpers/index.ts @@ -28,6 +28,7 @@ export * from './getModuleVizDims' export * from './getVectorDifference' export * from './getVectorSum' export * from './getLoadedLabwareDefinitionsByUri' +export * from './getFixedTrashLabwareDefinition' export * from './getOccludedSlotCountForModule' export * from './labwareInference' export * from './getAddressableAreasInProtocol'