From c7bedcda34c580d3cea67ad5784a2a0a9bb539b8 Mon Sep 17 00:00:00 2001 From: Brian Cooper Date: Fri, 5 Apr 2024 12:52:47 -0400 Subject: [PATCH] fixup groupings in the protocol setup, and resolving module conflicts should remove serial number --- .../LocationConflictModal.tsx | 2 +- .../useModuleRenderInfoForProtocolById.ts | 3 +- shared-data/js/fixtures.ts | 58 +++++++++---------- .../js/helpers/getSimplestFlexDeckConfig.ts | 5 +- 4 files changed, 32 insertions(+), 36 deletions(-) diff --git a/app/src/organisms/Devices/ProtocolRun/SetupModuleAndDeck/LocationConflictModal.tsx b/app/src/organisms/Devices/ProtocolRun/SetupModuleAndDeck/LocationConflictModal.tsx index 002beb89644..f67c9def889 100644 --- a/app/src/organisms/Devices/ProtocolRun/SetupModuleAndDeck/LocationConflictModal.tsx +++ b/app/src/organisms/Devices/ProtocolRun/SetupModuleAndDeck/LocationConflictModal.tsx @@ -104,7 +104,7 @@ export const LocationConflictModal = ( if (requiredFixtureId != null) { const newRequiredFixtureDeckConfig = deckConfig.map(fixture => fixture.cutoutId === cutoutId - ? { ...fixture, cutoutFixtureId: requiredFixtureId } + ? { ...fixture, cutoutFixtureId: requiredFixtureId, opentronsModuleSerialNumber: undefined } : fixture ) diff --git a/app/src/organisms/Devices/hooks/useModuleRenderInfoForProtocolById.ts b/app/src/organisms/Devices/hooks/useModuleRenderInfoForProtocolById.ts index f3431b55ea7..51d44e6e518 100644 --- a/app/src/organisms/Devices/hooks/useModuleRenderInfoForProtocolById.ts +++ b/app/src/organisms/Devices/hooks/useModuleRenderInfoForProtocolById.ts @@ -69,7 +69,8 @@ export function useModuleRenderInfoForProtocolById( ) const moduleCutoutIds = getCutoutIdsFromModuleSlotName( protocolMod.slotName, - moduleFixtures + moduleFixtures, + deckDef ) const conflictedFixture = diff --git a/shared-data/js/fixtures.ts b/shared-data/js/fixtures.ts index 3bc9f755953..52d50c1498c 100644 --- a/shared-data/js/fixtures.ts +++ b/shared-data/js/fixtures.ts @@ -56,6 +56,7 @@ import type { } from './types' import type { LoadModuleCreateCommand, ModuleLocation } from '../command' import { getModuleDisplayName } from './modules' +import { getCutoutIdForSlotName } from './helpers' export function getCutoutDisplayName(cutout: CutoutId): string { return cutout.replace('cutout', '') @@ -134,10 +135,10 @@ export function getPositionFromSlotId( const slotPosition: CoordinateTuple | null = cutoutPosition != null ? [ - cutoutPosition[0] + offsetFromCutoutFixture[0], - cutoutPosition[1] + offsetFromCutoutFixture[1], - cutoutPosition[2] + offsetFromCutoutFixture[2], - ] + cutoutPosition[0] + offsetFromCutoutFixture[0], + cutoutPosition[1] + offsetFromCutoutFixture[1], + cutoutPosition[2] + offsetFromCutoutFixture[2], + ] : null return slotPosition @@ -174,26 +175,19 @@ export function getCutoutFixturesForModuleModel( export function getCutoutIdsFromModuleSlotName( slotName: string, - moduleFixtures: CutoutFixture[] + moduleFixtures: CutoutFixture[], // cutout fixtures for a specific module model + deckDef: DeckDefinition ): CutoutId[] { - return moduleFixtures.reduce((acc, moduleFixture) => { - const anchorCutoutId = moduleFixture.mayMountTo.find(cutoutId => - cutoutId.includes(slotName) - ) - const newGroupedFixtureIds = moduleFixture.fixtureGroup.filter( - fixtureId => fixtureId !== moduleFixture.id - ) - const newGroupedCutoutIds = newGroupedFixtureIds.reduce( - (innerAcc, fixtureId) => [ - ...innerAcc, - ...(moduleFixtures.find(mf => mf.id === fixtureId)?.mayMountTo ?? []), - ], - [] - ) - return anchorCutoutId != null - ? [...acc, anchorCutoutId, ...newGroupedCutoutIds] - : acc - }, []) + const anchorCutoutId = getCutoutIdForSlotName(slotName, deckDef) + // find the first fixture for this specific module model that may mount to the cutout implied by the slotName + const anchorFixture = moduleFixtures.find(fixture => fixture.mayMountTo.some(cutoutId => cutoutId === anchorCutoutId)) + if (anchorCutoutId != null && anchorFixture != null) { + const groupedFixtures = anchorFixture.fixtureGroup[anchorCutoutId] + return groupedFixtures != null + ? Object.keys((groupedFixtures ?? [])[0] ?? {}) as CutoutId[] + : [anchorCutoutId] + } + return [] } export function getAddressableAreaNamesFromLoadedModule( @@ -202,7 +196,7 @@ export function getAddressableAreaNamesFromLoadedModule( deckDef: DeckDefinition ): AddressableAreaName[] { const moduleFixtures = getCutoutFixturesForModuleModel(moduleModel, deckDef) - const cutoutIds = getCutoutIdsFromModuleSlotName(slotName, moduleFixtures) + const cutoutIds = getCutoutIdsFromModuleSlotName(slotName, moduleFixtures, deckDef) return moduleFixtures.reduce((acc, cutoutFixture) => { const providedAddressableAreas = cutoutIds.reduce( (innerAcc, cutoutId) => { @@ -236,28 +230,28 @@ export function getFixtureDisplayName( case HEATERSHAKER_MODULE_V1_FIXTURE: return usbPortNumber != null ? `${getModuleDisplayName( - HEATERSHAKER_MODULE_V1 - )} in USB-${usbPortNumber}` + HEATERSHAKER_MODULE_V1 + )} in USB-${usbPortNumber}` : getModuleDisplayName(HEATERSHAKER_MODULE_V1) case TEMPERATURE_MODULE_V2_FIXTURE: return usbPortNumber != null ? `${getModuleDisplayName( - TEMPERATURE_MODULE_V2 - )} in USB-${usbPortNumber}` + TEMPERATURE_MODULE_V2 + )} in USB-${usbPortNumber}` : getModuleDisplayName(TEMPERATURE_MODULE_V2) case MAGNETIC_BLOCK_V1_FIXTURE: return `${getModuleDisplayName(MAGNETIC_BLOCK_V1)}` case THERMOCYCLER_V2_REAR_FIXTURE: return usbPortNumber != null ? `${getModuleDisplayName( - THERMOCYCLER_MODULE_V2 - )} in USB-${usbPortNumber}` + THERMOCYCLER_MODULE_V2 + )} in USB-${usbPortNumber}` : getModuleDisplayName(THERMOCYCLER_MODULE_V2) case THERMOCYCLER_V2_FRONT_FIXTURE: return usbPortNumber != null ? `${getModuleDisplayName( - THERMOCYCLER_MODULE_V2 - )} in USB-${usbPortNumber}` + THERMOCYCLER_MODULE_V2 + )} in USB-${usbPortNumber}` : getModuleDisplayName(THERMOCYCLER_MODULE_V2) default: return 'Slot' diff --git a/shared-data/js/helpers/getSimplestFlexDeckConfig.ts b/shared-data/js/helpers/getSimplestFlexDeckConfig.ts index e7d09d493e7..65c4ccac3e5 100644 --- a/shared-data/js/helpers/getSimplestFlexDeckConfig.ts +++ b/shared-data/js/helpers/getSimplestFlexDeckConfig.ts @@ -10,6 +10,7 @@ import type { DeckDefinition, DeckConfiguration, CompletedProtocolAnalysis, + CutoutFixtureGroup, } from '../types' export interface CutoutConfigProtocolSpec extends CutoutConfig { @@ -153,9 +154,9 @@ export function getCutoutIdForSlotName( export function getFixtureGroupForCutoutFixture( cutoutFixtureId: CutoutFixtureId, cutoutFixtures: CutoutFixture[] -): CutoutFixtureId[] { +): CutoutFixtureGroup { return ( - cutoutFixtures.find(cf => cf.id === cutoutFixtureId)?.fixtureGroup ?? [] + cutoutFixtures.find(cf => cf.id === cutoutFixtureId)?.fixtureGroup ?? {} ) }