Skip to content

Commit

Permalink
fix(app): reset robot and protocol slideout states on close (#14939)
Browse files Browse the repository at this point in the history
closes RQA-2572
  • Loading branch information
ncdiehl11 authored and Carlos-fernandez committed May 20, 2024
1 parent fddf523 commit ec9034d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
23 changes: 15 additions & 8 deletions app/src/organisms/ChooseProtocolSlideout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,15 @@ export function ChooseProtocolSlideoutComponent(
}
}) ?? null

const resetRunTimeParameters = (): void => {
setRunTimeParametersOverrides(
runTimeParametersOverrides?.map(parameter => ({
...parameter,
value: parameter.default,
}))
)
}

const pageTwoBody = (
<Flex flexDirection={DIRECTION_COLUMN}>
<Flex justifyContent={JUSTIFY_END}>
Expand All @@ -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}
>
Expand Down Expand Up @@ -408,7 +411,11 @@ export function ChooseProtocolSlideoutComponent(
return (
<MultiSlideout
isExpanded={showSlideout}
onCloseClick={onCloseClick}
onCloseClick={() => {
onCloseClick()
setCurrentPage(1)
resetRunTimeParameters()
}}
currentStep={currentPage}
maxSteps={hasRunTimeParameters ? 2 : 1}
title={t('choose_protocol_to_run', { name })}
Expand Down
12 changes: 3 additions & 9 deletions app/src/organisms/ChooseRobotSlideout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ interface ChooseRobotSlideoutProps
showIdleOnly?: boolean
multiSlideout?: { currentPage: number } | null
setHasParamError?: (isError: boolean) => void
resetRunTimeParameters?: () => void
}

export function ChooseRobotSlideout(
Expand All @@ -139,6 +140,7 @@ export function ChooseRobotSlideout(
runTimeParametersOverrides,
setRunTimeParametersOverrides,
setHasParamError,
resetRunTimeParameters,
} = props

const dispatch = useDispatch<Dispatch>()
Expand Down Expand Up @@ -507,15 +509,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}
>
Expand Down
21 changes: 18 additions & 3 deletions app/src/organisms/ChooseRobotToRunProtocolSlideout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ export function ChooseRobotToRunProtocolSlideoutComponent(
'downgrade',
].includes(autoUpdateAction)

const hasRunTimeParameters = runTimeParameters.length > 0

if (
protocolKey == null ||
srcFileNames == null ||
Expand Down Expand Up @@ -174,7 +176,14 @@ export function ChooseRobotToRunProtocolSlideoutComponent(
</PrimaryButton>
)

const hasRunTimeParameters = runTimeParameters.length > 0
const resetRunTimeParameters = (): void => {
setRunTimeParametersOverrides(
runTimeParametersOverrides?.map(parameter => ({
...parameter,
value: parameter.default,
}))
)
}

return (
<ChooseRobotSlideout
Expand All @@ -183,7 +192,12 @@ export function ChooseRobotToRunProtocolSlideoutComponent(
isSelectedRobotOnDifferentSoftwareVersion={
isSelectedRobotOnDifferentSoftwareVersion
}
onCloseClick={onCloseClick}
onCloseClick={() => {
onCloseClick()
resetRunTimeParameters()
setCurrentPage(1)
setSelectedRobot(null)
}}
title={
hasRunTimeParameters && currentPage === 2
? t('select_parameters_for_robot', {
Expand Down Expand Up @@ -250,8 +264,9 @@ export function ChooseRobotToRunProtocolSlideoutComponent(
reset={resetCreateRun}
runCreationError={runCreationError}
runCreationErrorCode={runCreationErrorCode}
showIdleOnly={true}
showIdleOnly
setHasParamError={setHasParamError}
resetRunTimeParameters={resetRunTimeParameters}
/>
)
}
Expand Down

0 comments on commit ec9034d

Please sign in to comment.