Skip to content

Commit 11b03e0

Browse files
fix(app): refactor logic for getSimplestDeckConfigForProtocol to be able to use combo fixtures (#19186)
1 parent 5f49987 commit 11b03e0

File tree

3 files changed

+46
-17
lines changed

3 files changed

+46
-17
lines changed

app/src/organisms/Desktop/Devices/ProtocolRun/SetupLabware/SetupLabwareMap.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ export function SetupLabwareMap({
5050
stack: StackItem[]
5151
} | null>(null)
5252
const [hoverLabwareId, setHoverLabwareId] = useState<string | null>(null)
53+
54+
const deckConfig = useMemo(() => {
55+
return getSimplestDeckConfigForProtocol(protocolAnalysis)
56+
}, [protocolAnalysis])
57+
5358
const startingDeck = useMemo(
5459
() =>
5560
getStackedItemsOnStartingDeck(
@@ -147,9 +152,6 @@ export function SetupLabwareMap({
147152
}
148153
}
149154
)
150-
151-
const deckConfig = getSimplestDeckConfigForProtocol(protocolAnalysis)
152-
153155
const labwareOnDeck: Array<LabwareOnDeck | null> = Object.entries(
154156
getLabwareOnDeck(startingDeck)
155157
).map(([slotName, stackedItems]) => {

shared-data/js/fixtures.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,31 @@ export const getMainUsbModuleFixtureIdForComboFixture = (
11651165
)
11661166
}
11671167

1168+
export const getMainFixtureIdForAA = (
1169+
compatibleCutoutFixtureIds: CutoutFixtureId[],
1170+
addressableAreaIds: AddressableAreaName[],
1171+
cutoutId: CutoutId
1172+
): CutoutFixtureId | null => {
1173+
if (addressableAreaIds.length === 1) {
1174+
return getMainNonComboFixtureId(
1175+
compatibleCutoutFixtureIds,
1176+
addressableAreaIds,
1177+
cutoutId
1178+
)
1179+
}
1180+
1181+
const deckDef = getDeckDefFromRobotType('OT-3 Standard')
1182+
const cutoutFixtures = deckDef.cutoutFixtures.filter(cf =>
1183+
compatibleCutoutFixtureIds.includes(cf.id)
1184+
)
1185+
const cutoutFixturesWithAddressableAreas = cutoutFixtures.find(cf =>
1186+
Object.values(cf.providesAddressableAreas).some(providedAAs =>
1187+
addressableAreaIds.every(aa => providedAAs.includes(aa))
1188+
)
1189+
)
1190+
return cutoutFixturesWithAddressableAreas?.id ?? null
1191+
}
1192+
11681193
export const getMainNonComboFixtureId = (
11691194
compatibleCutoutFixtureIds: CutoutFixtureId[],
11701195
addressableAreaIds: AddressableAreaName[],

shared-data/js/helpers/getSimplestFlexDeckConfig.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getAddressableAreasInProtocol, getDeckDefFromRobotType } from '.'
22
import { FLEX_ROBOT_TYPE } from '../constants'
33
import {
44
getAddressableAreaFromSlotId,
5-
getMainNonComboFixtureId,
5+
getMainFixtureIdForAA,
66
} from '../fixtures'
77

88
import type { AddressableAreaName, CutoutFixtureId, CutoutId } from '../../deck'
@@ -44,29 +44,34 @@ export function getSimplestDeckConfigForProtocol(
4444
): CutoutConfigProtocolSpec[] {
4545
// TODO(BC, 2023-11-06): abstract out the robot type
4646
const deckDef = getDeckDefFromRobotType(FLEX_ROBOT_TYPE)
47-
4847
const addressableAreas =
4948
protocolAnalysis != null
5049
? getAddressableAreasInProtocol(protocolAnalysis, deckDef)
5150
: []
51+
// iterates through the list of required addressable areas for the protocol
5252
const simplestDeckConfig = addressableAreas.reduce<
5353
CutoutConfigProtocolSpec[]
5454
>((acc, addressableArea) => {
55+
// finds all cutout fixtures that provide this addressable area
5556
const cutoutFixturesForAddressableArea = getCutoutFixturesForAddressableAreas(
5657
[addressableArea],
5758
deckDef.cutoutFixtures
5859
)
60+
// grabs the cutout id for the addressable area
5961
const cutoutIdForAddressableArea = getCutoutIdForAddressableArea(
6062
addressableArea,
6163
cutoutFixturesForAddressableArea
6264
)
65+
// grabs all possible cutout fixtures for that cutout id
6366
const cutoutFixturesForCutoutId =
6467
cutoutIdForAddressableArea != null
6568
? getCutoutFixturesForCutoutId(
6669
cutoutIdForAddressableArea,
6770
deckDef.cutoutFixtures
6871
)
6972
: null
73+
// this grabs the previously found CutoutConfig if we've already added one to our acc
74+
// for a different addressable area required by the same CutoutId
7075
const existingCutoutConfig = acc.find(
7176
cutoutConfig => cutoutConfig.cutoutId === cutoutIdForAddressableArea
7277
)
@@ -76,32 +81,29 @@ export function getSimplestDeckConfigForProtocol(
7681
cutoutFixturesForCutoutId != null &&
7782
cutoutIdForAddressableArea != null
7883
) {
79-
const indexOfExistingFixture = cutoutFixturesForCutoutId.findIndex(
80-
({ id }) => id === existingCutoutConfig.cutoutFixtureId
81-
)
84+
// finds what index in our acc that the `existingCutoutConfig` is at so that
85+
// we know which item to swap out with a new CutoutConfig that provides the previously
86+
// and newly found addressable areas
8287
const accIndex = acc.findIndex(
8388
({ cutoutId }) => cutoutId === cutoutIdForAddressableArea
8489
)
90+
// what addressable areas we've already looped through and added to this cutout
8591
const previousRequiredAAs = acc[accIndex]?.requiredAddressableAreas
8692
const allNextRequiredAddressableAreas =
8793
previousRequiredAAs != null &&
8894
previousRequiredAAs.includes(addressableArea)
8995
? previousRequiredAAs
9096
: [...previousRequiredAAs, addressableArea]
91-
97+
// check for the next compatible fixture for the new, longer list of addressable areas
9298
const nextCompatibleCutoutFixture = getSimplestFixtureForAddressableAreas(
9399
cutoutIdForAddressableArea,
94100
allNextRequiredAddressableAreas,
95101
cutoutFixturesForCutoutId
96102
)
97-
const indexOfCurrentFixture = cutoutFixturesForCutoutId.findIndex(
98-
({ id }) => id === nextCompatibleCutoutFixture?.id
99-
)
100103

101-
if (
102-
nextCompatibleCutoutFixture != null &&
103-
indexOfCurrentFixture > indexOfExistingFixture
104-
) {
104+
// this logic swaps out the newly found cutoutfixture id with the existing one
105+
// that was added for the last addressable area we referenced
106+
if (nextCompatibleCutoutFixture != null) {
105107
return [
106108
...acc.slice(0, accIndex),
107109
{
@@ -192,7 +194,7 @@ export function getSimplestFixtureForAddressableAreas(
192194
cutoutFixturesForCutoutId
193195
)
194196
if (nextCompatibleCutoutFixtures.length > 1) {
195-
const mainFixture = getMainNonComboFixtureId(
197+
const mainFixture = getMainFixtureIdForAA(
196198
nextCompatibleCutoutFixtures.map(cf => cf.id),
197199
requiredAddressableAreas,
198200
cutoutId

0 commit comments

Comments
 (0)