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

Don't modify user-schemas in Material Object Renderer #1871

Merged
merged 1 commit into from
Apr 6, 2022
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
16 changes: 12 additions & 4 deletions packages/core/src/reducers/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,28 @@ export const jsonFormsReducerConfig = {
* @param schema the JSON schema describing the data to be rendered
* @param schemaPath the according schema path
* @param path the instance path
* @param fallbackLayoutType the type of the layout to use
* @param fallback the type of the layout to use or a UI-schema-generator function
* @param control may be checked for embedded inline uischema options
*/
export const findUISchema = (
uischemas: JsonFormsUISchemaRegistryEntry[],
schema: JsonSchema,
schemaPath: string,
path: string,
fallbackLayoutType = 'VerticalLayout',
fallback: string | (() => UISchemaElement) = 'VerticalLayout',
control?: ControlElement,
rootSchema?: JsonSchema
): UISchemaElement => {
// handle options
if (control && control.options && control.options.detail) {
if (typeof control.options.detail === 'string') {
if (control.options.detail.toUpperCase() === 'GENERATE') {
//use fallback generation function
if(typeof fallback === "function"){
return fallback();
}
// force generation of uischema
return Generate.uiSchema(schema, fallbackLayoutType);
return Generate.uiSchema(schema, fallback);
}
} else if (typeof control.options.detail === 'object') {
// check if detail is a valid uischema
Expand All @@ -99,7 +103,11 @@ export const findUISchema = (
// default
const uiSchema = findMatchingUISchema(uischemas)(schema, schemaPath, path);
if (uiSchema === undefined) {
return Generate.uiSchema(schema, fallbackLayoutType, '#', rootSchema);
//use fallback generation function
if(typeof fallback === 'function'){
return fallback();
}
return Generate.uiSchema(schema, fallback, '#', rootSchema);
}
return uiSchema;
};
Expand Down
13 changes: 13 additions & 0 deletions packages/examples/src/examples/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ export const uischemaNonRoot = {
scope: '#/properties/address/properties/state',
expectedValue: 'DC'
}
},
options: {
detail: {
type: 'Group',
label: 'User Data',
elements: [
{ type: 'Control', scope: '#/properties/name'},
{
type: 'Control',
scope: '#/properties/mail'
}
]
}
}
}
]
Expand Down
11 changes: 3 additions & 8 deletions packages/material/src/complex/MaterialObjectRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import isEmpty from 'lodash/isEmpty';
import {
findUISchema,
GroupLayout,
Generate,
isObjectControl,
RankedTester,
rankWith,
Expand Down Expand Up @@ -54,17 +54,12 @@ export const MaterialObjectRenderer = ({
schema,
uischema.scope,
path,
'Group',
() => isEmpty(path) ? Generate.uiSchema(schema, 'VerticalLayout') : {...Generate.uiSchema(schema, 'Group'), label},
uischema,
rootSchema
),
[uischemas, schema, uischema.scope, path, uischema, rootSchema]
[uischemas, schema, uischema.scope, path, label, uischema, rootSchema]
);
if (isEmpty(path)) {
detailUiSchema.type = 'VerticalLayout';
} else {
(detailUiSchema as GroupLayout).label = label;
}
return (
<Hidden xsUp={!visible}>
<JsonFormsDispatch
Expand Down