From 88bef034624a2d95450c1cee8959889d8abd3dba Mon Sep 17 00:00:00 2001 From: Jethary Date: Wed, 6 Nov 2024 11:53:32 -0500 Subject: [PATCH] fix(protocol-designer): single item dropdown update the value automatically --- .../molecules/DropdownStepFormField/index.tsx | 9 +++- .../StepForm/PipetteFields/LabwareField.tsx | 1 - .../StepTools/HeaterShakerTools/index.tsx | 37 +++------------- .../StepTools/TemperatureTools/index.tsx | 43 ++++--------------- 4 files changed, 21 insertions(+), 69 deletions(-) diff --git a/protocol-designer/src/molecules/DropdownStepFormField/index.tsx b/protocol-designer/src/molecules/DropdownStepFormField/index.tsx index 869d272ddde..39da4a74ca9 100644 --- a/protocol-designer/src/molecules/DropdownStepFormField/index.tsx +++ b/protocol-designer/src/molecules/DropdownStepFormField/index.tsx @@ -1,4 +1,5 @@ import { useTranslation } from 'react-i18next' +import { useEffect } from 'react' import { COLORS, DIRECTION_COLUMN, @@ -36,9 +37,15 @@ export function DropdownStepFormField( const { t } = useTranslation('tooltip') const availableOptionId = options.find(opt => opt.value === value) + useEffect(() => { + if (options.length === 1) { + updateValue(options[0].value) + } + }, []) + return ( - {options.length > 1 ? ( + {options.length > 1 || options.length === 0 ? ( { - if (moduleLabwareOptions.length === 1) { - propsForFields.moduleId.updateValue(moduleLabwareOptions[0].value) - } - }, []) - const mappedErrorsToField = getFormErrorsMappedToField(visibleFormErrors) return ( - {moduleLabwareOptions.length > 1 ? ( - - ) : ( - - - {t('protocol_steps:module')} - - - - - {moduleLabwareOptions[0].name} - - - - - )} + { - if (moduleLabwareOptions.length === 1) { - propsForFields.moduleId.updateValue(moduleLabwareOptions[0].value) - } - }, []) - return ( - {moduleLabwareOptions.length > 1 ? ( - - ) : ( - - - {t('protocol_steps:module')} - - - - - {moduleLabwareOptions[0].name} - - - - - )} + {temperatureModuleIds != null ? temperatureModuleIds.map(id => @@ -73,7 +46,7 @@ export function TemperatureTools(props: StepFormProps): JSX.Element { ) => { + onChange={(e: ChangeEvent) => { propsForFields.setTemperature.updateValue( e.currentTarget.value ) @@ -96,7 +69,7 @@ export function TemperatureTools(props: StepFormProps): JSX.Element { ) => { + onChange={(e: ChangeEvent) => { propsForFields.setTemperature.updateValue( e.currentTarget.value )