Skip to content

Commit 0de5d17

Browse files
committed
checkboxes for features
1 parent ea185d7 commit 0de5d17

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

web/src/components/forms/config/uiSchema.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ export const FlowCollectorUISchema: UiSchema = {
9797
'ui:title': 'Privileged mode'
9898
},
9999
features: {
100-
'ui:title': 'Features'
100+
'ui:title': 'Features',
101+
'ui:widget': 'arrayCheckboxes',
102+
'ui:descriptionFirst': 'true'
101103
},
102104
flowFilter: {
103105
'ui:title': 'Filters',

web/src/components/forms/dynamic-form/templates.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ export const AtomicFieldTemplate: React.FC<FieldTemplateProps> = ({
2727
schema,
2828
uiSchema
2929
}) => {
30+
// put description before or after children based on widget type
31+
const descriptionFirst = uiSchema?.['ui:descriptionFirst'] === 'true';
3032
return (
3133
<FormField id={id} defaultLabel={label} required={required || false} schema={schema} uiSchema={uiSchema || {}}>
34+
{descriptionFirst && description}
3235
{children}
33-
{description}
36+
{!descriptionFirst && description}
3437
{!_.isEmpty(rawErrors) && (
3538
<>
3639
{_.map(rawErrors, error => (

web/src/components/forms/dynamic-form/widgets.tsx

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import * as React from 'react';
1616
import { useTranslation } from 'react-i18next';
1717
import { useTheme } from '../../../utils/theme-hook';
1818
import { JSON_SCHEMA_NUMBER_TYPES } from './const';
19+
import { DescriptionField } from './fields';
1920
import { AtomicFieldTemplate } from './templates';
2021

2122
export const TextWidget: React.FC<WidgetProps> = props => {
@@ -161,6 +162,8 @@ export const JSONWidget: React.FC<WidgetProps> = props => {
161162
export const ArrayCheckboxesWidget: React.FC<WidgetProps> = props => {
162163
const { schema, value, id, onBlur, onChange, onFocus } = props;
163164

165+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
166+
const enums = (schema.items as any).enum || [];
164167
const errFunc = () => console.error('Function not implemented.');
165168

166169
return (
@@ -169,36 +172,38 @@ export const ArrayCheckboxesWidget: React.FC<WidgetProps> = props => {
169172
<AtomicFieldTemplate
170173
onKeyChange={() => errFunc}
171174
onDropPropertyClick={() => errFunc}
175+
description={
176+
<DescriptionField schema={schema} description={(schema.items as any)?.description || props.description} />
177+
}
172178
{...{
173179
...props,
174180
// eslint-disable-next-line @typescript-eslint/no-explicit-any
175181
style: props.style as React.StyleHTMLAttributes<any> | undefined,
176-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
177-
description: (schema.items as any)?.description || props.description,
178182
readonly: props.readonly === true,
179183
disabled: props.disabled === true
180184
}}
181185
>
182-
<Flex direction={{ default: 'row' }} onBlur={() => onBlur(id, value)} onFocus={() => onFocus(id, value)}>
183-
{
184-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
185-
(schema.items as any).enum.map((option: string, index: number) => (
186-
<FlexItem key={`${id}-${index}`}>
187-
<Checkbox
188-
id={`${id}-${index}`}
189-
label={option}
190-
isChecked={_.isNil(value) ? false : value.includes(option)}
191-
onClick={() =>
192-
onChange(
193-
value.includes(option) ? value.filter((v: string) => v !== option) : [...value, option],
194-
undefined,
195-
id
196-
)
197-
}
198-
/>
199-
</FlexItem>
200-
))
201-
}
186+
<Flex
187+
direction={{ default: enums.length < 4 ? 'row' : 'column' }}
188+
onBlur={() => onBlur(id, value)}
189+
onFocus={() => onFocus(id, value)}
190+
>
191+
{enums.map((option: string, index: number) => (
192+
<FlexItem key={`${id}-${index}`}>
193+
<Checkbox
194+
id={`${id}-${index}`}
195+
label={option}
196+
isChecked={_.isNil(value) ? false : value.includes(option)}
197+
onClick={() =>
198+
onChange(
199+
value.includes(option) ? value.filter((v: string) => v !== option) : [...value, option],
200+
undefined,
201+
id
202+
)
203+
}
204+
/>
205+
</FlexItem>
206+
))}
202207
</Flex>
203208
</AtomicFieldTemplate>
204209
);

0 commit comments

Comments
 (0)