Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(app): reset robot and protocol slideout states on close #14939

Merged
merged 4 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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}
>
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
Loading