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(protocol-designer): fix the display when dropdown menu option is only one #16640

Merged
merged 5 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"untilTemperature": "<text>Pausing until</text><semiBoldText>{{module}}</semiBoldText><text>reaches</text><tag/>",
"untilTime": "<text>Pausing for</text><tag/>"
},
"pipette": "Pipette",
"protocol_steps": "Protocol steps",
"protocol_timeline": "Protocol timeline",
"rename": "Rename",
Expand Down Expand Up @@ -124,6 +125,7 @@
}
},
"time": "Time",
"tiprack": "Tiprack",
"tip_position": "{{prefix}} tip position",
"touch_tip_position": "Touch tip position from top",
"valid_range": "Valid range between {{min}} - {{max}} {{unit}}",
Expand Down
61 changes: 44 additions & 17 deletions protocol-designer/src/molecules/DropdownStepFormField/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { useTranslation } from 'react-i18next'
import { DropdownMenu, Flex, SPACING } from '@opentrons/components'
import {
COLORS,
DIRECTION_COLUMN,
DropdownMenu,
Flex,
ListItem,
SPACING,
StyledText,
} from '@opentrons/components'
import type { Options } from '@opentrons/components'
import type { FieldProps } from '../../pages/Designer/ProtocolSteps/StepForm/types'

Expand Down Expand Up @@ -30,22 +38,41 @@ export function DropdownStepFormField(

return (
<Flex padding={addPadding ? SPACING.spacing16 : 0}>
<DropdownMenu
tooltipText={tooltipContent != null ? t(`${tooltipContent}`) : null}
width={width}
error={errorToShow}
dropdownType="neutral"
filterOptions={options}
title={title}
onBlur={onFieldBlur}
onFocus={onFieldFocus}
currentOption={
availableOptionId ?? { name: 'Choose option', value: '' }
}
onClick={value => {
updateValue(value)
}}
/>
{options.length > 1 ? (
<DropdownMenu
tooltipText={tooltipContent != null ? t(`${tooltipContent}`) : null}
width={width}
error={errorToShow}
dropdownType="neutral"
filterOptions={options}
title={title}
onBlur={onFieldBlur}
onFocus={onFieldFocus}
currentOption={
availableOptionId ?? { name: 'Choose option', value: '' }
}
onClick={value => {
updateValue(value)
}}
/>
) : (
<Flex
gridGap={SPACING.spacing8}
flexDirection={DIRECTION_COLUMN}
width="100%"
>
<StyledText desktopStyle="captionRegular" color={COLORS.grey60}>
{title}
</StyledText>
<ListItem type="noActive">
<Flex padding={SPACING.spacing12}>
<StyledText desktopStyle="bodyDefaultRegular">
{options[0].name}
</StyledText>
</Flex>
</ListItem>
</Flex>
)}
</Flex>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const PipetteField = (props: FieldProps): JSX.Element => {
{...props}
options={pipetteOptions}
value={value ? String(value) : null}
title={t('select_pipette')}
title={pipetteOptions.length === 1 ? t('pipette') : t('select_pipette')}
/>
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { useEffect } from 'react'
import { useTranslation } from 'react-i18next'
import { useSelector } from 'react-redux'
import {
COLORS,
DIRECTION_COLUMN,
Flex,
ListItem,
SPACING,
StyledText,
} from '@opentrons/components'
import { getPipetteEntities } from '../../../../../step-forms/selectors'
import { getTiprackOptions } from '../../../../../ui/labware/selectors'
import { DropdownStepFormField } from '../../../../../molecules'
Expand Down Expand Up @@ -29,12 +37,33 @@ export function TiprackField(props: TiprackFieldProps): JSX.Element {
}, [defaultTiprackUris, value, updateValue])
const hasMissingTiprack = defaultTiprackUris.length > tiprackOptions.length
return (
<DropdownStepFormField
{...props}
options={tiprackOptions}
value={String(value) != null ? String(value) : null}
title={t('select_tiprack')}
tooltipContent={hasMissingTiprack ? 'missing_tiprack' : null}
/>
<>
{tiprackOptions.length > 1 ? (
<DropdownStepFormField
{...props}
options={tiprackOptions}
value={String(value) != null ? String(value) : null}
title={t('select_tiprack')}
tooltipContent={hasMissingTiprack ? 'missing_tiprack' : null}
/>
) : (
<Flex
gridGap={SPACING.spacing8}
flexDirection={DIRECTION_COLUMN}
width="100%"
>
<StyledText desktopStyle="captionRegular" color={COLORS.grey60}>
{t('tiprack')}
</StyledText>
<ListItem type="noActive">
<Flex padding={SPACING.spacing12}>
<StyledText desktopStyle="bodyDefaultRegular">
{tiprackOptions[0].name}
</StyledText>
</Flex>
</ListItem>
</Flex>
)}
</>
)
}
Loading