From c5e0ead3ec69108b0de08fcf0e477b2686d0fcd2 Mon Sep 17 00:00:00 2001 From: Nick Diehl <47604184+ncdiehl11@users.noreply.github.com> Date: Tue, 2 Apr 2024 13:01:28 -0400 Subject: [PATCH] feat(app): add support for toggling boolean RTPs and restoring defaults (#14770) closes [AUTH-117](https://opentrons.atlassian.net/browse/AUTH-117) --- .../ResetValuesModal.tsx | 12 ++++++++++- .../__tests__/ResetValuesModal.test.tsx | 12 ++++++++++- .../ProtocolSetupParameters/index.tsx | 20 ++++++++++++++----- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/app/src/organisms/ProtocolSetupParameters/ResetValuesModal.tsx b/app/src/organisms/ProtocolSetupParameters/ResetValuesModal.tsx index 458b1172f3a..b49151f883b 100644 --- a/app/src/organisms/ProtocolSetupParameters/ResetValuesModal.tsx +++ b/app/src/organisms/ProtocolSetupParameters/ResetValuesModal.tsx @@ -14,13 +14,18 @@ import { import { SmallButton } from '../../atoms/buttons' import { Modal } from '../../molecules/Modal' +import type { RunTimeParameter } from '@opentrons/shared-data' import type { ModalHeaderBaseProps } from '../../molecules/Modal/types' interface ResetValuesModalProps { + runTimeParametersOverrides: RunTimeParameter[] + setRunTimeParametersOverrides: (parameters: RunTimeParameter[]) => void handleGoBack: () => void } export function ResetValuesModal({ + runTimeParametersOverrides, + setRunTimeParametersOverrides, handleGoBack, }: ResetValuesModalProps): JSX.Element { const { t } = useTranslation(['protocol_setup', 'shared']) @@ -33,7 +38,12 @@ export function ResetValuesModal({ // ToDo (kk:03/18/2024) reset values function will be implemented const handleResetValues = (): void => { - console.log('todo add reset values function') + setRunTimeParametersOverrides( + runTimeParametersOverrides.map(param => { + return { ...param, value: param.default } + }) + ) + handleGoBack() } const modalProps = { diff --git a/app/src/organisms/ProtocolSetupParameters/__tests__/ResetValuesModal.test.tsx b/app/src/organisms/ProtocolSetupParameters/__tests__/ResetValuesModal.test.tsx index a8f876b94f3..ec2eb28a81c 100644 --- a/app/src/organisms/ProtocolSetupParameters/__tests__/ResetValuesModal.test.tsx +++ b/app/src/organisms/ProtocolSetupParameters/__tests__/ResetValuesModal.test.tsx @@ -5,8 +5,10 @@ import { fireEvent, screen } from '@testing-library/react' import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { ResetValuesModal } from '../ResetValuesModal' +import { RunTimeParameter } from '@opentrons/shared-data' const mockGoBack = vi.fn() +const mockSetRunTimeParametersOverrides = vi.fn() const render = (props: React.ComponentProps) => { return renderWithProviders(, { @@ -19,6 +21,8 @@ describe('ResetValuesModal', () => { beforeEach(() => { props = { + runTimeParametersOverrides: [] as RunTimeParameter[], + setRunTimeParametersOverrides: mockSetRunTimeParametersOverrides, handleGoBack: mockGoBack, } }) @@ -42,5 +46,11 @@ describe('ResetValuesModal', () => { }) // ToDo (kk: 03/18/2024) reset value button test will be added - it.todo('should call a mock function when tapping reset values button') + it('should call a mock function when tapping reset values button', () => { + render(props) + const resetValuesButton = screen.getByText('Reset values') + fireEvent.click(resetValuesButton) + expect(mockSetRunTimeParametersOverrides) + expect(mockGoBack).toHaveBeenCalled() + }) }) diff --git a/app/src/organisms/ProtocolSetupParameters/index.tsx b/app/src/organisms/ProtocolSetupParameters/index.tsx index c99c4ebeff6..a95f1b59b23 100644 --- a/app/src/organisms/ProtocolSetupParameters/index.tsx +++ b/app/src/organisms/ProtocolSetupParameters/index.tsx @@ -3,13 +3,13 @@ import { useTranslation } from 'react-i18next' import { useHistory } from 'react-router-dom' import { useCreateRunMutation, useHost } from '@opentrons/react-api-client' import { useQueryClient } from 'react-query' -import { formatRunTimeParameterValue } from '@opentrons/shared-data' import { ALIGN_CENTER, DIRECTION_COLUMN, Flex, SPACING, } from '@opentrons/components' +import { formatRunTimeParameterValue } from '@opentrons/shared-data' import { ProtocolSetupStep } from '../../pages/ProtocolSetup' import { ChildNavigation } from '../ChildNavigation' @@ -179,8 +179,14 @@ export function ProtocolSetupParameters({ const [resetValuesModal, showResetValuesModal] = React.useState( false ) - const parameters = runTimeParameters ?? [] - // TODO(jr, 3/20/24): modify useCreateRunMutation to take in optional run time parameters + + // todo (nd:04/01/2024): remove mock and look at runTimeParameters prop + // const parameters = runTimeParameters ?? [] + const parameters = runTimeParameters ?? mockData + const [ + runTimeParametersOverrides, + setRunTimeParametersOverrides, + ] = React.useState(parameters) const { createRun, isLoading } = useCreateRunMutation({ onSuccess: data => { queryClient @@ -197,7 +203,11 @@ export function ProtocolSetupParameters({ return ( <> {resetValuesModal ? ( - showResetValuesModal(false)} /> + showResetValuesModal(false)} + /> ) : null} {parameters.map((parameter, index) => { return (