From c906aaa1f89d34547aa87a4dde9d5d74f74802bd Mon Sep 17 00:00:00 2001 From: ncdiehl11 Date: Wed, 17 Apr 2024 15:30:30 -0400 Subject: [PATCH 1/4] fix(app): reset robot and protocol slideout states on close When a user clicks out of a ChooseRobot or ChooseProtocol slideout, the slideout should 1) reset to the first page if a multi-page slideout, 2) reset default robot or protocol selection to the first valid option if one exists, and 3) restore runtime parameter values to default if setting up protocol. Note that if a user is on runtime parameters step and selects 'Change robot', any overriden parameter values will persist when parameter setup screen is proceeded to again. --- .../ChooseProtocolSlideout/index.tsx | 23 ++++++++++++------- .../organisms/ChooseRobotSlideout/index.tsx | 12 +++------- .../index.tsx | 21 ++++++++++++++--- 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/app/src/organisms/ChooseProtocolSlideout/index.tsx b/app/src/organisms/ChooseProtocolSlideout/index.tsx index 6a1c1a0aa8c..6f00082013a 100644 --- a/app/src/organisms/ChooseProtocolSlideout/index.tsx +++ b/app/src/organisms/ChooseProtocolSlideout/index.tsx @@ -331,6 +331,15 @@ export function ChooseProtocolSlideoutComponent( } }) ?? null + const resetRunTimeParameters = (): void => { + setRunTimeParametersOverrides( + runTimeParametersOverrides?.map(parameter => ({ + ...parameter, + value: parameter.default, + })) + ) + } + const pageTwoBody = ( @@ -339,13 +348,7 @@ export function ChooseProtocolSlideoutComponent( css={ isRestoreDefaultsLinkEnabled ? ENABLED_LINK_CSS : DISABLED_LINK_CSS } - onClick={() => { - const clone = runTimeParametersOverrides.map(parameter => ({ - ...parameter, - value: parameter.default, - })) - setRunTimeParametersOverrides(clone) - }} + onClick={resetRunTimeParameters} paddingBottom={SPACING.spacing10} {...targetProps} > @@ -408,7 +411,11 @@ export function ChooseProtocolSlideoutComponent( return ( { + onCloseClick() + setCurrentPage(1) + resetRunTimeParameters() + }} currentStep={currentPage} maxSteps={hasRunTimeParameters ? 2 : 1} title={t('choose_protocol_to_run', { name })} diff --git a/app/src/organisms/ChooseRobotSlideout/index.tsx b/app/src/organisms/ChooseRobotSlideout/index.tsx index 066bd28eb61..a1b8c1bfd43 100644 --- a/app/src/organisms/ChooseRobotSlideout/index.tsx +++ b/app/src/organisms/ChooseRobotSlideout/index.tsx @@ -113,6 +113,7 @@ interface ChooseRobotSlideoutProps showIdleOnly?: boolean multiSlideout?: { currentPage: number } | null setHasParamError?: (isError: boolean) => void + resetRunTimeParameters?: () => void } export function ChooseRobotSlideout( @@ -139,6 +140,7 @@ export function ChooseRobotSlideout( runTimeParametersOverrides, setRunTimeParametersOverrides, setHasParamError, + resetRunTimeParameters = () => {}, } = props const dispatch = useDispatch() @@ -506,15 +508,7 @@ export function ChooseRobotSlideout( ? ENABLED_LINK_CSS : DISABLED_LINK_CSS } - onClick={() => { - const clone = runTimeParametersOverrides.map(parameter => ({ - ...parameter, - value: parameter.default, - })) - if (setRunTimeParametersOverrides != null) { - setRunTimeParametersOverrides(clone) - } - }} + onClick={() => resetRunTimeParameters()} paddingBottom={SPACING.spacing10} {...targetProps} > diff --git a/app/src/organisms/ChooseRobotToRunProtocolSlideout/index.tsx b/app/src/organisms/ChooseRobotToRunProtocolSlideout/index.tsx index 8ef332adaa3..17e64b4fb6b 100644 --- a/app/src/organisms/ChooseRobotToRunProtocolSlideout/index.tsx +++ b/app/src/organisms/ChooseRobotToRunProtocolSlideout/index.tsx @@ -132,6 +132,8 @@ export function ChooseRobotToRunProtocolSlideoutComponent( 'downgrade', ].includes(autoUpdateAction) + const hasRunTimeParameters = runTimeParameters.length > 0 + if ( protocolKey == null || srcFileNames == null || @@ -174,7 +176,14 @@ export function ChooseRobotToRunProtocolSlideoutComponent( ) - const hasRunTimeParameters = runTimeParameters.length > 0 + const resetRunTimeParameters = (): void => { + setRunTimeParametersOverrides( + runTimeParametersOverrides?.map(parameter => ({ + ...parameter, + value: parameter.default, + })) + ) + } return ( { + onCloseClick() + resetRunTimeParameters() + setCurrentPage(1) + setSelectedRobot(null) + }} title={ hasRunTimeParameters && currentPage === 2 ? t('select_parameters_for_robot', { @@ -250,8 +264,9 @@ export function ChooseRobotToRunProtocolSlideoutComponent( reset={resetCreateRun} runCreationError={runCreationError} runCreationErrorCode={runCreationErrorCode} - showIdleOnly={true} + showIdleOnly setHasParamError={setHasParamError} + resetRunTimeParameters={resetRunTimeParameters} /> ) } From 8206a3140cc4d7917f72e69475dcedf032c5625f Mon Sep 17 00:00:00 2001 From: ncdiehl11 Date: Wed, 17 Apr 2024 15:42:17 -0400 Subject: [PATCH 2/4] handle undefined resetRTP callback --- app/src/organisms/ChooseRobotSlideout/index.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/organisms/ChooseRobotSlideout/index.tsx b/app/src/organisms/ChooseRobotSlideout/index.tsx index a1b8c1bfd43..c47c715fa4d 100644 --- a/app/src/organisms/ChooseRobotSlideout/index.tsx +++ b/app/src/organisms/ChooseRobotSlideout/index.tsx @@ -140,7 +140,7 @@ export function ChooseRobotSlideout( runTimeParametersOverrides, setRunTimeParametersOverrides, setHasParamError, - resetRunTimeParameters = () => {}, + resetRunTimeParameters, } = props const dispatch = useDispatch() @@ -508,7 +508,9 @@ export function ChooseRobotSlideout( ? ENABLED_LINK_CSS : DISABLED_LINK_CSS } - onClick={() => resetRunTimeParameters()} + onClick={ + resetRunTimeParameters != undefined && resetRunTimeParameters() + } paddingBottom={SPACING.spacing10} {...targetProps} > From d7a18225a239c2c78671c777306869e4c7ccaee1 Mon Sep 17 00:00:00 2001 From: ncdiehl11 Date: Wed, 17 Apr 2024 15:43:40 -0400 Subject: [PATCH 3/4] !== instead of != --- app/src/organisms/ChooseRobotSlideout/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/organisms/ChooseRobotSlideout/index.tsx b/app/src/organisms/ChooseRobotSlideout/index.tsx index c47c715fa4d..17536ea8248 100644 --- a/app/src/organisms/ChooseRobotSlideout/index.tsx +++ b/app/src/organisms/ChooseRobotSlideout/index.tsx @@ -509,7 +509,7 @@ export function ChooseRobotSlideout( : DISABLED_LINK_CSS } onClick={ - resetRunTimeParameters != undefined && resetRunTimeParameters() + resetRunTimeParameters !== undefined && resetRunTimeParameters() } paddingBottom={SPACING.spacing10} {...targetProps} From 1acab395476fdfdaf01847fd67b7647d88d4c9e5 Mon Sep 17 00:00:00 2001 From: ncdiehl11 Date: Wed, 17 Apr 2024 15:45:46 -0400 Subject: [PATCH 4/4] cleaner handling for optional callback --- app/src/organisms/ChooseRobotSlideout/index.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/src/organisms/ChooseRobotSlideout/index.tsx b/app/src/organisms/ChooseRobotSlideout/index.tsx index 17536ea8248..f151fa00e3b 100644 --- a/app/src/organisms/ChooseRobotSlideout/index.tsx +++ b/app/src/organisms/ChooseRobotSlideout/index.tsx @@ -508,9 +508,7 @@ export function ChooseRobotSlideout( ? ENABLED_LINK_CSS : DISABLED_LINK_CSS } - onClick={ - resetRunTimeParameters !== undefined && resetRunTimeParameters() - } + onClick={() => resetRunTimeParameters?.()} paddingBottom={SPACING.spacing10} {...targetProps} >