Skip to content

Commit

Permalink
Fix linting, add recursion protection
Browse files Browse the repository at this point in the history
  • Loading branch information
smb2268 committed Oct 28, 2024
1 parent 024470f commit 1a1ee4e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export function LabwareListItem(

const isStacked =
labwareQuantity > 1 ||
bottomLabwareId != topLabwareId ||
bottomLabwareId !== topLabwareId ||
moduleModel != null

const { i18n, t } = useTranslation('protocol_setup')
Expand Down
14 changes: 10 additions & 4 deletions shared-data/js/helpers/parseProtocolCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ export function parseInitialLoadedLabwareBySlot(
// information
export function getTopLabwareInfo(
labwareId: string,
loadLabwareCommands: LoadLabwareRunTimeCommand[]
loadLabwareCommands: LoadLabwareRunTimeCommand[],
currentStackHeight: number = 0
): {
topLabwareId: string
topLabwareDefinition?: LabwareDefinition2
Expand All @@ -155,7 +156,9 @@ export function getTopLabwareInfo(
'labwareId' in command.params.location &&
command.params.location.labwareId === labwareId
)
if (nestedCommand == null) {
// prevent recurssion errors (like labware stacked on itself)
// by enforcing a max stack height
if (nestedCommand == null || currentStackHeight > 5) {
const loadCommand = loadLabwareCommands.find(
command =>
command.commandType === 'loadLabware' &&
Expand All @@ -174,7 +177,8 @@ export function getTopLabwareInfo(
} else {
return getTopLabwareInfo(
nestedCommand?.result?.labwareId as string,
loadLabwareCommands
loadLabwareCommands,
currentStackHeight + 1
)
}
}
Expand Down Expand Up @@ -221,7 +225,9 @@ export function getLabwareStackCountAndLocation(
loadLabwareCommand.params.loadName ===
lowerLabwareCommand?.params.loadName

if (isSameLabware) {
// add protection for recursion errors by having a max stack of 5 which is current
// allowed max stack of TC lids
if (isSameLabware && initialQuantity < 5) {
const newQuantity = initialQuantity + 1
return getLabwareStackCountAndLocation(
lowerLabwareCommand.result.labwareId,
Expand Down

0 comments on commit 1a1ee4e

Please sign in to comment.