Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable group elements on group disable rule #1794

Merged
merged 1 commit into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/material/src/controls/MaterialRadioGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export const MaterialRadioGroup = (props: ControlProps & OwnPropsOfEnum) => {
visible,
options,
handleChange,
path
path,
enabled
} = props;
const isValid = errors.length === 0;
const appliedUiSchemaOptions = merge(
Expand Down Expand Up @@ -99,6 +100,7 @@ export const MaterialRadioGroup = (props: ControlProps & OwnPropsOfEnum) => {
key={option.label}
control={<Radio checked={data === option.value} />}
label={option.label}
disabled={!enabled}
/>
))}
</RadioGroup>
Expand Down
2 changes: 2 additions & 0 deletions packages/vanilla/src/controls/InputControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export class InputControl extends Control<
uischema,
schema,
visible,
enabled,
required,
path,
cells,
Expand Down Expand Up @@ -104,6 +105,7 @@ export class InputControl extends Control<
schema={schema}
path={path}
id={id + '-input'}
enabled={enabled}
/>
<div className={divClassNames}>
{!isValid ? errors : showDescription ? description : null}
Expand Down
4 changes: 3 additions & 1 deletion packages/vanilla/src/controls/RadioGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export class RadioGroup extends Control<
data,
uischema,
visible,
config
config,
enabled
} = this.props;
const isValid = errors.length === 0;
const divClassNames = `validation ${isValid ? classNames.description : 'validation_error'
Expand Down Expand Up @@ -93,6 +94,7 @@ export class RadioGroup extends Control<
name={id}
checked={data === option.value}
onChange={ev => this.handleChange(ev.currentTarget.value)}
disabled={!enabled}
/>
<label htmlFor={option.value}>{option.label}</label>
</div>
Expand Down
3 changes: 2 additions & 1 deletion packages/vanilla/src/layouts/GroupLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const GroupLayoutRendererComponent: FunctionComponent<RendererProps & VanillaRen
schema,
uischema,
path,
enabled,
visible,
getStyle,
getStyleAsClassName
Expand All @@ -70,7 +71,7 @@ const GroupLayoutRendererComponent: FunctionComponent<RendererProps & VanillaRen
{group.label}
</legend> : ''
}
{renderChildren(group, schema, childClassNames, path)}
{renderChildren(group, schema, childClassNames, path, enabled)}
</fieldset>
);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/vanilla/src/layouts/HorizontalLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const HorizontalLayoutRendererComponent: FunctionComponent<RendererProps & Vanil
getStyle={getStyle}
getStyleAsClassName={getStyleAsClassName}
>
{renderChildren(horizontalLayout, schema, childClassNames, path)}
{renderChildren(horizontalLayout, schema, childClassNames, path, enabled)}
</JsonFormsLayout>
);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/vanilla/src/layouts/VerticalLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const VerticalLayoutRendererComponent: FunctionComponent<RendererProps & Vanilla
getStyle={getStyle}
getStyleAsClassName={getStyleAsClassName}
>
{renderChildren(verticalLayout, schema, childClassNames, path)}
{renderChildren(verticalLayout, schema, childClassNames, path, enabled)}
</JsonFormsLayout>
);
});
Expand Down
4 changes: 3 additions & 1 deletion packages/vanilla/src/layouts/util.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export const renderChildren = (
layout: Layout,
schema: JsonSchema,
className: string,
path: string
path: string,
enabled: boolean
) => {
if (isEmpty(layout.elements)) {
return [];
Expand All @@ -54,6 +55,7 @@ export const renderChildren = (
uischema={child}
schema={schema}
path={path}
enabled={enabled}
/>
</div>
);
Expand Down
14 changes: 14 additions & 0 deletions packages/vanilla/test/renderers/GroupLayout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,20 @@ describe('Group layout', () => {
expect(groupLayout.props().hidden).toBe(true);
});

test('pass enabled prop to children', () => {
const core = initCore({}, fixture.uischema, {});
wrapper = mount(
<JsonFormsStateProvider initState={{ core }}>
<GroupLayoutRenderer
uischema={fixture.uischema}
enabled={false}
/>
</JsonFormsStateProvider>
);
const child = wrapper.find('JsonFormsDispatchRenderer');
expect(child.prop('enabled')).toBe(false);
});

test('show by default', () => {
const core = initCore({}, fixture.uischema, {});
wrapper = mount(
Expand Down