Skip to content

Commit ac2cbf8

Browse files
fix(orchestrator-form-react): preserve ui:hidden on objects with properties (#2653)
1 parent 60aa6a6 commit ac2cbf8

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@red-hat-developer-hub/backstage-plugin-orchestrator-form-react': patch
3+
---
4+
5+
Fix `extractUiSchema` so `ui:*` directives on object schemas that define `properties` (for example `ui:hidden` on a `workflowParams` object) are copied into the generated UI schema.

workspaces/orchestrator/plugins/orchestrator-form-react/src/utils/generateUiSchema.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,29 @@ describe('extract ui schema', () => {
6969
expect(uiSchema).toEqual({ name: { 'ui:autofocus': true } });
7070
});
7171

72+
it('extracts ui:hidden and other ui:* on object nodes that also have properties', () => {
73+
const mixedSchema: JSONSchema7 = {
74+
type: 'object',
75+
properties: {
76+
visibleField: {
77+
type: 'string',
78+
title: 'Visible',
79+
},
80+
workflowParams: {
81+
type: 'object',
82+
'ui:hidden': true,
83+
properties: {
84+
solutionName: { type: 'string', default: 'a' },
85+
solutionVersion: { type: 'string', default: '1.0' },
86+
},
87+
} as JSONSchema7,
88+
},
89+
};
90+
const uiSchema = generateUiSchema(mixedSchema, false);
91+
expect(uiSchema.workflowParams).toEqual({ 'ui:hidden': true });
92+
expect(uiSchema.visibleField).toMatchObject({ 'ui:autofocus': true });
93+
});
94+
7295
it('should extract from array', () => {
7396
const mixedSchema = {
7497
title: 'A list of tasks',

workspaces/orchestrator/plugins/orchestrator-form-react/src/utils/generateUiSchema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ function extractUiSchema(mixedSchema: JSONSchema7): UiSchema<JsonObject> {
106106
processObject(getSchemaDefinition(curSchema.$ref, rootSchema), path);
107107
} else if (curSchema.properties) {
108108
processObjectProperties(curSchema.properties, path);
109+
processLeafSchema(curSchema, path);
109110
} else if (curSchema.items) {
110111
processArraySchema(curSchema, path);
111112
} else {

0 commit comments

Comments
 (0)