Skip to content

Commit

Permalink
fix(protocol-designer): set form field value if 1 option, add newLoca…
Browse files Browse the repository at this point in the history
…tion error (#17490)

In `DropdownStepFormField`, if the length of `options` passed in changes
to 1, we need to set the form field value for this component to the
single value

Closes RQA-3955
  • Loading branch information
ncdiehl11 authored Feb 11, 2025
1 parent 8ea3427 commit bd91faa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions protocol-designer/src/molecules/DropdownStepFormField/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useEffect } from 'react'
import { useTranslation } from 'react-i18next'
import { useDispatch } from 'react-redux'
import {
Expand Down Expand Up @@ -79,6 +80,12 @@ export function DropdownStepFormField(
}
}

useEffect(() => {
if (options.length === 1) {
updateValue(options[0].value)
}
}, [options.length])

return (
<Flex padding={padding ?? SPACING.spacing16}>
{options.length > 1 || options.length === 0 ? (
Expand Down Expand Up @@ -138,6 +145,11 @@ export function DropdownStepFormField(
</Flex>
</Flex>
</ListItem>
{errorToShow != null ? (
<StyledText desktopStyle="bodyDefaultRegular" color={COLORS.red50}>
{errorToShow}
</StyledText>
) : null}
</Flex>
)}
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ describe('MagnetTools', () => {
updateValue: vi.fn(),
value: 'engage',
},
moduleId: {
onFieldFocus: vi.fn(),
onFieldBlur: vi.fn(),
errorToShow: null,
disabled: false,
name: 'magnetAction',
updateValue: vi.fn(),
value: 'engage',
},
engageHeight: {
onFieldFocus: vi.fn(),
onFieldBlur: vi.fn(),
Expand Down

0 comments on commit bd91faa

Please sign in to comment.