-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app, shared-data): create odd boolean and choice selection screen (
- Loading branch information
Showing
14 changed files
with
304 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import * as React from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { | ||
ALIGN_CENTER, | ||
DIRECTION_COLUMN, | ||
Flex, | ||
SPACING, | ||
StyledText, | ||
TYPOGRAPHY, | ||
} from '@opentrons/components' | ||
import { RadioButton } from '../../atoms/buttons' | ||
import { useToaster } from '../ToasterOven' | ||
import { ChildNavigation } from '../ChildNavigation' | ||
import type { RunTimeParameter } from '@opentrons/shared-data' | ||
|
||
interface ChooseEnumProps { | ||
handleGoBack: () => void | ||
parameter: RunTimeParameter | ||
setParameter: (value: boolean | string | number, variableName: string) => void | ||
rawValue: number | string | boolean | ||
} | ||
|
||
export function ChooseEnum({ | ||
handleGoBack, | ||
parameter, | ||
setParameter, | ||
rawValue, | ||
}: ChooseEnumProps): JSX.Element { | ||
const { makeSnackbar } = useToaster() | ||
|
||
const { t } = useTranslation(['protocol_setup', 'shared']) | ||
if (parameter.type !== 'str') { | ||
console.error( | ||
`parameter type is expected to be a string for parameter ${parameter.displayName}` | ||
) | ||
} | ||
const options = parameter.type === 'str' ? parameter.choices : undefined | ||
const handleOnClick = (newValue: string | number | boolean): void => { | ||
setParameter(newValue, parameter.variableName) | ||
} | ||
const resetValueDisabled = parameter.default === rawValue | ||
|
||
return ( | ||
<> | ||
<ChildNavigation | ||
header={t('choose_enum', { displayName: parameter.displayName })} | ||
onClickBack={handleGoBack} | ||
buttonType="tertiaryLowLight" | ||
buttonText={t('restore_default')} | ||
onClickButton={() => | ||
resetValueDisabled | ||
? makeSnackbar(t('no_custom_values')) | ||
: setParameter(parameter.default, parameter.variableName) | ||
} | ||
/> | ||
<Flex | ||
marginTop="7.75rem" | ||
alignSelf={ALIGN_CENTER} | ||
gridGap={SPACING.spacing8} | ||
paddingX={SPACING.spacing40} | ||
flexDirection={DIRECTION_COLUMN} | ||
paddingBottom={SPACING.spacing40} | ||
> | ||
<StyledText | ||
as="h4" | ||
textAlign={TYPOGRAPHY.textAlignLeft} | ||
marginBottom={SPACING.spacing16} | ||
> | ||
{parameter.description} | ||
</StyledText> | ||
|
||
{options?.map(option => { | ||
return ( | ||
<RadioButton | ||
key={`${option.value}`} | ||
data-testid={`${option.value}`} | ||
buttonLabel={option.displayName} | ||
buttonValue={`${option.value}`} | ||
onChange={() => handleOnClick(option.value)} | ||
isSelected={option.value === rawValue} | ||
/> | ||
) | ||
})} | ||
</Flex> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
79 changes: 79 additions & 0 deletions
79
app/src/organisms/ProtocolSetupParameters/__tests__/ChooseEnum.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import * as React from 'react' | ||
import { it, describe, beforeEach, vi, expect } from 'vitest' | ||
import { fireEvent, screen } from '@testing-library/react' | ||
import '@testing-library/jest-dom/vitest' | ||
import { COLORS } from '@opentrons/components' | ||
import { renderWithProviders } from '../../../__testing-utils__' | ||
import { i18n } from '../../../i18n' | ||
import { ChooseEnum } from '../ChooseEnum' | ||
|
||
vi.mocked('../../ToasterOven') | ||
const render = (props: React.ComponentProps<typeof ChooseEnum>) => { | ||
return renderWithProviders(<ChooseEnum {...props} />, { | ||
i18nInstance: i18n, | ||
}) | ||
} | ||
describe('ChooseEnum', () => { | ||
let props: React.ComponentProps<typeof ChooseEnum> | ||
|
||
beforeEach(() => { | ||
props = { | ||
setParameter: vi.fn(), | ||
handleGoBack: vi.fn(), | ||
parameter: { | ||
displayName: 'Default Module Offsets', | ||
variableName: 'DEFAULT_OFFSETS', | ||
value: 'none', | ||
description: '', | ||
type: 'str', | ||
choices: [ | ||
{ | ||
displayName: 'no offsets', | ||
value: 'none', | ||
}, | ||
{ | ||
displayName: 'temp offset', | ||
value: '1', | ||
}, | ||
{ | ||
displayName: 'heater-shaker offset', | ||
value: '2', | ||
}, | ||
], | ||
default: 'none', | ||
}, | ||
rawValue: '1', | ||
} | ||
}) | ||
it('renders the back icon and calls the prop', () => { | ||
render(props) | ||
fireEvent.click(screen.getAllByRole('button')[0]) | ||
expect(props.handleGoBack).toHaveBeenCalled() | ||
}) | ||
it('calls the prop if reset default is clicked when the default has changed', () => { | ||
render(props) | ||
fireEvent.click(screen.getByText('Restore default values')) | ||
expect(props.setParameter).toHaveBeenCalled() | ||
}) | ||
it('calls does not call prop if reset default is clicked when the default has not changed', () => { | ||
props = { | ||
...props, | ||
rawValue: 'none', | ||
} | ||
render(props) | ||
fireEvent.click(screen.getByText('Restore default values')) | ||
expect(props.setParameter).not.toHaveBeenCalled() | ||
}) | ||
it('should render the text and buttons for choice param', () => { | ||
render(props) | ||
screen.getByText('no offsets') | ||
screen.getByText('temp offset') | ||
screen.getByText('heater-shaker offset') | ||
const notSelectedOption = screen.getByRole('label', { name: 'no offsets' }) | ||
const selectedOption = screen.getByRole('label', { | ||
name: 'temp offset', | ||
}) | ||
expect(notSelectedOption).toHaveStyle(`background-color: ${COLORS.blue40}`) | ||
expect(selectedOption).toHaveStyle(`background-color: ${COLORS.blue60}`) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.