diff --git a/app/src/local-resources/offsets/utils/getLwOffsetLocSeqFromLocSeq.ts b/app/src/local-resources/offsets/utils/getLwOffsetLocSeqFromLocSeq.ts index 0bdf2c01321..db83845c4f7 100644 --- a/app/src/local-resources/offsets/utils/getLwOffsetLocSeqFromLocSeq.ts +++ b/app/src/local-resources/offsets/utils/getLwOffsetLocSeqFromLocSeq.ts @@ -3,7 +3,10 @@ import type { LoadedLabware, LoadedModule, } from '@opentrons/shared-data' -import type { LabwareOffsetLocationSequence } from '@opentrons/api-client' +import type { + LabwareOffsetLocationSequence, + OnAddressableAreaOffsetLocationSequenceComponent, +} from '@opentrons/api-client' // Returns the offset location sequence, which is used to get/store offsets from the server, // and drive LPC UI. @@ -12,7 +15,14 @@ export function getLwOffsetLocSeqFromLocSeq( lw: LoadedLabware[], modules: LoadedModule[] ): LabwareOffsetLocationSequence { - return locSequence.reduce( + // The addressable area name is always the last item of an offset loc seq, but + // can appear above a module in a loc seq, so we always append the addressable + // area component last. + // This assumes there is always only one addressable area component! + const { mainItems, addressableAreaComponent } = locSequence.reduce<{ + mainItems: LabwareOffsetLocationSequence + addressableAreaComponent: OnAddressableAreaOffsetLocationSequenceComponent | null + }>( (acc, locSeqComponent) => { const { kind } = locSeqComponent @@ -22,30 +32,46 @@ export function getLwOffsetLocSeqFromLocSeq( const matchingMod = modules.find(mod => mod.id === moduleId) return matchingMod != null - ? [...acc, { kind, moduleModel: matchingMod.model }] + ? { + ...acc, + mainItems: [ + ...acc.mainItems, + { kind, moduleModel: matchingMod.model }, + ], + } : acc } case 'onAddressableArea': { - return [ + return { ...acc, - { + addressableAreaComponent: { kind, addressableAreaName: locSeqComponent.addressableAreaName, }, - ] + } } case 'onLabware': { const { labwareId } = locSeqComponent const matchingLw = lw.find(aLw => aLw.id === labwareId) return matchingLw != null - ? [...acc, { kind, labwareUri: matchingLw.definitionUri }] + ? { + ...acc, + mainItems: [ + ...acc.mainItems, + { kind, labwareUri: matchingLw.definitionUri }, + ], + } : acc } default: return acc } }, - [] + { mainItems: [], addressableAreaComponent: null } ) + + return addressableAreaComponent != null + ? [...mainItems, addressableAreaComponent] + : mainItems }