Skip to content

Commit bd91faa

Browse files
authored
fix(protocol-designer): set form field value if 1 option, add newLocation 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
1 parent 8ea3427 commit bd91faa

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

protocol-designer/src/molecules/DropdownStepFormField/index.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useEffect } from 'react'
12
import { useTranslation } from 'react-i18next'
23
import { useDispatch } from 'react-redux'
34
import {
@@ -79,6 +80,12 @@ export function DropdownStepFormField(
7980
}
8081
}
8182

83+
useEffect(() => {
84+
if (options.length === 1) {
85+
updateValue(options[0].value)
86+
}
87+
}, [options.length])
88+
8289
return (
8390
<Flex padding={padding ?? SPACING.spacing16}>
8491
{options.length > 1 || options.length === 0 ? (
@@ -138,6 +145,11 @@ export function DropdownStepFormField(
138145
</Flex>
139146
</Flex>
140147
</ListItem>
148+
{errorToShow != null ? (
149+
<StyledText desktopStyle="bodyDefaultRegular" color={COLORS.red50}>
150+
{errorToShow}
151+
</StyledText>
152+
) : null}
141153
</Flex>
142154
)}
143155
</Flex>

protocol-designer/src/pages/Designer/ProtocolSteps/StepForm/StepTools/__tests__/MagnetTools.test.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ describe('MagnetTools', () => {
5959
updateValue: vi.fn(),
6060
value: 'engage',
6161
},
62+
moduleId: {
63+
onFieldFocus: vi.fn(),
64+
onFieldBlur: vi.fn(),
65+
errorToShow: null,
66+
disabled: false,
67+
name: 'magnetAction',
68+
updateValue: vi.fn(),
69+
value: 'engage',
70+
},
6271
engageHeight: {
6372
onFieldFocus: vi.fn(),
6473
onFieldBlur: vi.fn(),

0 commit comments

Comments
 (0)