scaffolder: extract ui:* fields from conditional fields.
With this change the `ui:*` schema config is extracted also for the `then` and `else` branch of a conditional schema Signed-off-by: Andreas Berger <andreas@berger-ecommerce.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-react': patch
|
||||
---
|
||||
|
||||
Extract `ui:*` fields from conditional `then` and `else` schema branches.
|
||||
@@ -411,4 +411,84 @@ describe('extractSchemaFromStep', () => {
|
||||
uiSchema: expectedUiSchema,
|
||||
});
|
||||
});
|
||||
|
||||
it('transforms conditional schema', () => {
|
||||
const inputSchema: JsonObject = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
flag: {
|
||||
type: 'boolean',
|
||||
},
|
||||
},
|
||||
if: {
|
||||
properties: {
|
||||
flag: {
|
||||
const: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
then: {
|
||||
properties: {
|
||||
user: {
|
||||
type: 'string',
|
||||
'ui:field': 'EntityPicker',
|
||||
'ui:options': {
|
||||
catalogFilter: [{ kind: 'User' }],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
else: {
|
||||
properties: {
|
||||
email: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const expectedSchema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
flag: {
|
||||
type: 'boolean',
|
||||
},
|
||||
},
|
||||
if: {
|
||||
properties: {
|
||||
flag: {
|
||||
const: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
then: {
|
||||
properties: {
|
||||
user: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
},
|
||||
else: {
|
||||
properties: {
|
||||
email: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const expectedUiSchema = {
|
||||
flag: {},
|
||||
user: {
|
||||
'ui:field': 'EntityPicker',
|
||||
'ui:options': {
|
||||
catalogFilter: [{ kind: 'User' }],
|
||||
},
|
||||
},
|
||||
email: {},
|
||||
};
|
||||
|
||||
expect(extractSchemaFromStep(inputSchema)).toEqual({
|
||||
schema: expectedSchema,
|
||||
uiSchema: expectedUiSchema,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -25,7 +25,16 @@ function extractUiSchema(schema: JsonObject, uiSchema: JsonObject) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { properties, items, anyOf, oneOf, allOf, dependencies } = schema;
|
||||
const {
|
||||
properties,
|
||||
items,
|
||||
anyOf,
|
||||
oneOf,
|
||||
allOf,
|
||||
dependencies,
|
||||
then,
|
||||
else: _else,
|
||||
} = schema;
|
||||
|
||||
for (const propName in schema) {
|
||||
if (!schema.hasOwnProperty(propName)) {
|
||||
@@ -96,6 +105,14 @@ function extractUiSchema(schema: JsonObject, uiSchema: JsonObject) {
|
||||
extractUiSchema(schemaNode, uiSchema);
|
||||
}
|
||||
}
|
||||
|
||||
if (isObject(then)) {
|
||||
extractUiSchema(then, uiSchema);
|
||||
}
|
||||
|
||||
if (isObject(_else)) {
|
||||
extractUiSchema(_else, uiSchema);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user