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 save behavior for bad liquid form #17171

Open
wants to merge 1 commit into
base: edge
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion protocol-designer/src/assets/localization/en/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
"liquid_placement": {
"liquid": "Liquid",
"volume": "Volume",
"volume_exceeded": "Warning: exceeded max volume per well: {{volume}}µL"
"errors": {
"liquid_required": "Define a liquid",
"volume_exceeded": "Warning: exceeded max volume per well: {{volume}}µL",
"volume_required": "Define a volume"
}
},
"pipette_mount_label": {
"left": "(L)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,12 @@ export function LiquidToolbox(props: LiquidToolboxProps): JSX.Element {
control,
setValue,
reset,
formState: { touchedFields },
formState,
} = useForm<ToolboxFormValues>({
defaultValues: getInitialValues(),
})

const { errors } = formState
const selectedLiquidId = watch('selectedLiquidId')
const volume = watch('volume')

Expand Down Expand Up @@ -184,15 +185,22 @@ export function LiquidToolbox(props: LiquidToolboxProps): JSX.Element {
reset()
}

let volumeErrors: string | null = null
if (Boolean(touchedFields.volume)) {
if (volume == null || volume === '0') {
volumeErrors = t('generic.error.more_than_zero')
} else if (parseInt(volume) > selectedWellsMaxVolume) {
volumeErrors = t('form:liquid_placement.volume_exceeded', {
const validateVolume = (
volume: string | null | undefined
): string | undefined => {
if (volume == null || volume === '') {
return t('form:liquid_placement.errors.volume_required')
}
const volumeNumber = parseFloat(volume)
if (volumeNumber === 0) {
return t('form:generic.error.more_than_zero')
}
if (volumeNumber > selectedWellsMaxVolume) {
return t('form:liquid_placement.errors.volume_exceeded', {
volume: selectedWellsMaxVolume,
})
}
return undefined
}

let wellContents: ContentsByWell | null = null
Expand Down Expand Up @@ -301,7 +309,12 @@ export function LiquidToolbox(props: LiquidToolboxProps): JSX.Element {
name="selectedLiquidId"
control={control}
rules={{
required: true,
required: {
value: true,
message: t(
'form:liquid_placement.errors.liquid_required'
),
},
}}
render={({ field }) => {
const fullOptions: DropdownOption[] = liquidSelectionOptions.map(
Expand Down Expand Up @@ -337,6 +350,7 @@ export function LiquidToolbox(props: LiquidToolboxProps): JSX.Element {
}}
onClick={field.onChange}
menuPlacement="bottom"
error={errors.selectedLiquidId?.message}
/>
)
}}
Expand All @@ -354,14 +368,14 @@ export function LiquidToolbox(props: LiquidToolboxProps): JSX.Element {
name="volume"
control={control}
rules={{
required: true,
validate: validateVolume,
}}
render={({ field }) => (
<InputField
name="volume"
units={t('application:units.microliter')}
value={volume}
error={volumeErrors}
error={errors.volume?.message}
onBlur={field.onBlur}
onChange={handleChangeVolume}
/>
Expand All @@ -377,18 +391,7 @@ export function LiquidToolbox(props: LiquidToolboxProps): JSX.Element {
{t('shared:cancel')}
</StyledText>
</Btn>
<PrimaryButton
disabled={
volumeErrors != null ||
volume == null ||
volume === '' ||
selectedLiquidId == null ||
selectedLiquidId === ''
}
type="submit"
>
{t('save')}
</PrimaryButton>
<PrimaryButton type="submit">{t('save')}</PrimaryButton>
</Flex>
</Flex>
</ListItem>
Expand Down
Loading