-
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): view-only run time parameters in odd (#14701)
- Loading branch information
Showing
12 changed files
with
358 additions
and
65 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
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
135 changes: 135 additions & 0 deletions
135
app/src/organisms/ProtocolSetupParameters/ViewOnlyParameters.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,135 @@ | ||
import * as React from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { | ||
ALIGN_CENTER, | ||
BORDERS, | ||
COLORS, | ||
DIRECTION_COLUMN, | ||
DIRECTION_ROW, | ||
Flex, | ||
SPACING, | ||
TYPOGRAPHY, | ||
} from '@opentrons/components' | ||
import { useMostRecentCompletedAnalysis } from '../LabwarePositionCheck/useMostRecentCompletedAnalysis' | ||
import { ChildNavigation } from '../ChildNavigation' | ||
import { StyledText } from '../../atoms/text' | ||
import { Chip } from '../../atoms/Chip' | ||
import { useToaster } from '../ToasterOven' | ||
import { mockData } from './index' | ||
|
||
import type { RunTimeParameter } from '@opentrons/shared-data' | ||
import type { SetupScreens } from '../../pages/ProtocolSetup' | ||
|
||
export interface ViewOnlyParametersProps { | ||
runId: string | ||
setSetupScreen: React.Dispatch<React.SetStateAction<SetupScreens>> | ||
} | ||
|
||
export function ViewOnlyParameters({ | ||
runId, | ||
setSetupScreen, | ||
}: ViewOnlyParametersProps): JSX.Element { | ||
const { t, i18n } = useTranslation('protocol_setup') | ||
const { makeSnackbar } = useToaster() | ||
const mostRecentAnalysis = useMostRecentCompletedAnalysis(runId) | ||
const handleOnClick = (): void => { | ||
makeSnackbar(t('reset_setup')) | ||
} | ||
|
||
// TODO(jr, 3/18/24): remove mockData | ||
const parameters = mostRecentAnalysis?.runTimeParameters ?? mockData | ||
|
||
const getDefault = (parameter: RunTimeParameter): string => { | ||
const { type, default: defaultValue } = parameter | ||
const suffix = | ||
'suffix' in parameter && parameter.suffix != null ? parameter.suffix : '' | ||
switch (type) { | ||
case 'int': | ||
case 'float': | ||
return `${defaultValue.toString()} ${suffix}` | ||
case 'boolean': | ||
return Boolean(defaultValue) | ||
? i18n.format(t('on'), 'capitalize') | ||
: i18n.format(t('off'), 'capitalize') | ||
case 'str': | ||
if ('choices' in parameter && parameter.choices != null) { | ||
const choice = parameter.choices.find( | ||
choice => choice.value === defaultValue | ||
) | ||
if (choice != null) { | ||
return choice.displayName | ||
} | ||
} | ||
break | ||
} | ||
return '' | ||
} | ||
|
||
return ( | ||
<> | ||
<ChildNavigation | ||
header={t('parameters')} | ||
onClickBack={() => setSetupScreen('prepare to run')} | ||
inlineNotification={{ | ||
type: 'neutral', | ||
heading: t('values_are_view_only'), | ||
}} | ||
/> | ||
<Flex | ||
marginTop="7.75rem" | ||
flexDirection={DIRECTION_COLUMN} | ||
gridGap={SPACING.spacing8} | ||
paddingX={SPACING.spacing8} | ||
> | ||
<Flex | ||
gridGap={SPACING.spacing8} | ||
color={COLORS.grey60} | ||
fontSize={TYPOGRAPHY.fontSize20} | ||
fontWeight={TYPOGRAPHY.fontWeightSemiBold} | ||
lineHeight={TYPOGRAPHY.lineHeight24} | ||
> | ||
<StyledText paddingLeft={SPACING.spacing16} width="50%"> | ||
{t('name')} | ||
</StyledText> | ||
<StyledText>{t('value')}</StyledText> | ||
</Flex> | ||
{parameters.map((parameter, index) => { | ||
// TODO(jr, 3/20/24): plug in the info if the | ||
// parameter changed from the default | ||
const hasCustomValue = true | ||
return ( | ||
<Flex | ||
onClick={handleOnClick} | ||
key={`${parameter.displayName}_${index}`} | ||
alignItems={ALIGN_CENTER} | ||
backgroundColor={COLORS.grey35} | ||
borderRadius={BORDERS.borderRadius8} | ||
padding={`${SPACING.spacing16} ${SPACING.spacing24}`} | ||
gridGap={SPACING.spacing24} | ||
> | ||
<StyledText | ||
width="48%" | ||
as="p" | ||
fontWeight={TYPOGRAPHY.fontWeightSemiBold} | ||
> | ||
{parameter.displayName} | ||
</StyledText> | ||
<Flex | ||
alignItems={ALIGN_CENTER} | ||
flexDirection={DIRECTION_ROW} | ||
gridGap={SPACING.spacing8} | ||
> | ||
<StyledText as="p" maxWidth="15rem" color={COLORS.grey60}> | ||
{getDefault(parameter)} | ||
</StyledText> | ||
{hasCustomValue ? ( | ||
<Chip type="success" text={t('updated')} hasIcon={false} /> | ||
) : null} | ||
</Flex> | ||
</Flex> | ||
) | ||
})} | ||
</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
65 changes: 65 additions & 0 deletions
65
app/src/organisms/ProtocolSetupParameters/__tests__/ViewOnlyParameters.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,65 @@ | ||
import * as React from 'react' | ||
import { when } from 'vitest-when' | ||
import { it, describe, beforeEach, vi, expect } from 'vitest' | ||
import { fireEvent, screen } from '@testing-library/react' | ||
import { i18n } from '../../../i18n' | ||
import { renderWithProviders } from '../../../__testing-utils__' | ||
import { useMostRecentCompletedAnalysis } from '../../LabwarePositionCheck/useMostRecentCompletedAnalysis' | ||
import { useToaster } from '../../ToasterOven' | ||
import { mockRunTimeParameterData } from '../../../pages/ProtocolDetails/fixtures' | ||
import { ViewOnlyParameters } from '../ViewOnlyParameters' | ||
|
||
vi.mock('../../LabwarePositionCheck/useMostRecentCompletedAnalysis') | ||
vi.mock('../../ToasterOven') | ||
const RUN_ID = 'mockId' | ||
const render = (props: React.ComponentProps<typeof ViewOnlyParameters>) => { | ||
return renderWithProviders(<ViewOnlyParameters {...props} />, { | ||
i18nInstance: i18n, | ||
}) | ||
} | ||
const mockMakeSnackBar = vi.fn() | ||
describe('ViewOnlyParameters', () => { | ||
let props: React.ComponentProps<typeof ViewOnlyParameters> | ||
|
||
beforeEach(() => { | ||
props = { | ||
runId: 'mockId', | ||
setSetupScreen: vi.fn(), | ||
} | ||
when(vi.mocked(useMostRecentCompletedAnalysis)) | ||
.calledWith(RUN_ID) | ||
.thenReturn({ | ||
runTimeParameters: mockRunTimeParameterData, | ||
} as any) | ||
when(useToaster) | ||
.calledWith() | ||
.thenReturn(({ | ||
makeSnackbar: mockMakeSnackBar, | ||
} as unknown) as any) | ||
}) | ||
it('renders the parameters labels and mock data', () => { | ||
render(props) | ||
screen.getByText('Parameters') | ||
screen.getByText('Values are view-only') | ||
screen.getByText('Name') | ||
screen.getByText('Value') | ||
screen.getByText('Dry Run') | ||
screen.getByText('6.5') | ||
screen.getByText('Use Gripper') | ||
screen.getByText('Default Module Offsets') | ||
screen.getByText('Columns of Samples') | ||
screen.getByText('4 mL') | ||
}) | ||
it('renders the snackbar from clicking on an item', () => { | ||
render(props) | ||
fireEvent.click(screen.getByText('4 mL')) | ||
expect(mockMakeSnackBar).toBeCalledWith('Restart setup to edit') | ||
}) | ||
it('renders the back icon and calls the prop', () => { | ||
render(props) | ||
fireEvent.click(screen.getAllByRole('button')[0]) | ||
expect(props.setSetupScreen).toHaveBeenCalled() | ||
}) | ||
// TODO(jr, 3/20/24):test the update chip when | ||
// custom value boolean is wired up | ||
}) |
Oops, something went wrong.