Skip to content

Commit 8a9eca0

Browse files
author
Ruben van Leeuwen
committed
1904: Adds radiobutton field for simple 2 way choices
1 parent bbae7ad commit 8a9eca0

File tree

5 files changed

+54
-1
lines changed

5 files changed

+54
-1
lines changed

packages/orchestrator-ui-components/src/components/WfoPydanticForm/WfoPydanticForm.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ import { FormValidationError } from '@/types';
2727
import { Footer } from './Footer';
2828
import { Header } from './Header';
2929
import { Row } from './Row';
30-
import { Checkbox, Divider, Label, Summary, Text, TextArea } from './fields';
30+
import {
31+
Checkbox,
32+
Divider,
33+
Label,
34+
Radio,
35+
Summary,
36+
Text,
37+
TextArea,
38+
} from './fields';
3139

3240
interface WfoPydanticFormProps {
3341
processName: string;
@@ -209,6 +217,21 @@ export const WfoPydanticForm = ({
209217
return field.type === PydanticFormFieldType.BOOLEAN;
210218
},
211219
},
220+
{
221+
id: 'radio',
222+
ElementMatch: {
223+
Element: Radio,
224+
isControlledElement: true,
225+
},
226+
matcher(field) {
227+
// We are looking for a single value from a set list of options. With less than 4 options, use radio buttons.
228+
return (
229+
field.type === PydanticFormFieldType.STRING &&
230+
field.options.length > 0 &&
231+
field.options.length <= 3
232+
);
233+
},
234+
},
212235
...currentMatchers.filter((matcher) => matcher.id !== 'text'),
213236
{
214237
id: 'text',
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react';
2+
3+
import type { PydanticFormControlledElement } from 'pydantic-forms';
4+
5+
import { EuiRadioGroup } from '@elastic/eui';
6+
7+
export const Radio: PydanticFormControlledElement = ({
8+
pydanticFormField,
9+
onChange,
10+
value,
11+
disabled,
12+
}) => {
13+
const radioOptions = pydanticFormField.options.map((option) => ({
14+
id: option.value,
15+
label: option.label,
16+
}));
17+
18+
return (
19+
<EuiRadioGroup
20+
options={radioOptions}
21+
idSelected={value}
22+
onChange={(id) => onChange(id)}
23+
name={pydanticFormField.id}
24+
disabled={disabled}
25+
/>
26+
);
27+
};

packages/orchestrator-ui-components/src/components/WfoPydanticForm/fields/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export * from './Label';
44
export * from './Divider';
55
export * from './Checkbox';
66
export * from './Summary';
7+
export * from './Radio';

packages/orchestrator-ui-components/src/messages/en-GB.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
"nodePort": {
131131
"loadingNodes": "Loading Node subscriptions...",
132132
"loadingPorts": "Loading IMS ports...",
133+
"noPorts": "NO PORTS FOUND FOR THIS NODE",
133134
"selectNode": "Select node",
134135
"selectPort": "Select port",
135136
"selectNodeFirst": "Select a node first"

packages/orchestrator-ui-components/src/messages/nl-NL.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
"loadingPorts": "IMS poorten laden...",
132132
"selectNode": "Selecteer node",
133133
"selectPort": "Selecteer poort",
134+
"noPorts": "GEEN POORTEN GEVONDEN VOOR DEZE NODE",
134135
"selectNodeFirst": "Selecteer eerst een node"
135136
},
136137
"fileUpload": {

0 commit comments

Comments
 (0)