From 1a1ee4e61ff41a74700ba8d2d350aadb617223af Mon Sep 17 00:00:00 2001 From: smb2268 Date: Mon, 28 Oct 2024 14:37:32 -0400 Subject: [PATCH] Fix linting, add recursion protection --- .../ProtocolRun/SetupLabware/LabwareListItem.tsx | 2 +- shared-data/js/helpers/parseProtocolCommands.ts | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/organisms/Desktop/Devices/ProtocolRun/SetupLabware/LabwareListItem.tsx b/app/src/organisms/Desktop/Devices/ProtocolRun/SetupLabware/LabwareListItem.tsx index 5b0bbae6bbf..f31a3bcf28d 100644 --- a/app/src/organisms/Desktop/Devices/ProtocolRun/SetupLabware/LabwareListItem.tsx +++ b/app/src/organisms/Desktop/Devices/ProtocolRun/SetupLabware/LabwareListItem.tsx @@ -106,7 +106,7 @@ export function LabwareListItem( const isStacked = labwareQuantity > 1 || - bottomLabwareId != topLabwareId || + bottomLabwareId !== topLabwareId || moduleModel != null const { i18n, t } = useTranslation('protocol_setup') diff --git a/shared-data/js/helpers/parseProtocolCommands.ts b/shared-data/js/helpers/parseProtocolCommands.ts index b351713449d..4f111e4d3e5 100644 --- a/shared-data/js/helpers/parseProtocolCommands.ts +++ b/shared-data/js/helpers/parseProtocolCommands.ts @@ -142,7 +142,8 @@ export function parseInitialLoadedLabwareBySlot( // information export function getTopLabwareInfo( labwareId: string, - loadLabwareCommands: LoadLabwareRunTimeCommand[] + loadLabwareCommands: LoadLabwareRunTimeCommand[], + currentStackHeight: number = 0 ): { topLabwareId: string topLabwareDefinition?: LabwareDefinition2 @@ -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' && @@ -174,7 +177,8 @@ export function getTopLabwareInfo( } else { return getTopLabwareInfo( nestedCommand?.result?.labwareId as string, - loadLabwareCommands + loadLabwareCommands, + currentStackHeight + 1 ) } } @@ -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,