Skip to content

fix(material): Resolve refs in object renderer #2202

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

Merged
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
7 changes: 6 additions & 1 deletion packages/angular-material/src/other/object.renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ export class ObjectControlRenderer extends JsonFormsControlWithDetail {
delete newSchema.oneOf;
delete newSchema.anyOf;
delete newSchema.allOf;
return Generate.uiSchema(newSchema, 'Group');
return Generate.uiSchema(
newSchema,
'Group',
undefined,
this.rootSchema
);
},
props.uischema,
props.rootSchema
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/reducers/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const findUISchema = (
return fallback();
}
// force generation of uischema
return Generate.uiSchema(schema, fallback);
return Generate.uiSchema(schema, fallback, undefined, rootSchema);
}
} else if (typeof control.options.detail === 'object') {
// check if detail is a valid uischema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface CombinatorPropertiesProps {
schema: JsonSchema;
combinatorKeyword: 'oneOf' | 'anyOf';
path: string;
rootSchema: JsonSchema;
}

export class CombinatorProperties extends React.Component<
Expand All @@ -45,15 +46,17 @@ export class CombinatorProperties extends React.Component<
{}
> {
render() {
const { schema, combinatorKeyword, path } = this.props;
const { schema, combinatorKeyword, path, rootSchema } = this.props;

const otherProps: JsonSchema = omit(
schema,
combinatorKeyword
) as JsonSchema;
const foundUISchema: UISchemaElement = Generate.uiSchema(
otherProps,
'VerticalLayout'
'VerticalLayout',
undefined,
rootSchema
);
let isLayoutWithElements = false;
if (foundUISchema !== null && isLayout(foundUISchema)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export const MaterialAnyOfRenderer = ({
schema={schema}
combinatorKeyword={anyOf}
path={path}
rootSchema={rootSchema}
/>
<Tabs value={selectedAnyOf} onChange={handleTabChange}>
{anyOfRenderInfos.map((anyOfRenderInfo) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ export const MaterialObjectRenderer = ({
path,
() =>
isEmpty(path)
? Generate.uiSchema(schema, 'VerticalLayout')
: { ...Generate.uiSchema(schema, 'Group'), label },
? Generate.uiSchema(schema, 'VerticalLayout', undefined, rootSchema)
: {
...Generate.uiSchema(schema, 'Group', undefined, rootSchema),
label,
},
uischema,
rootSchema
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export const MaterialOneOfRenderer = ({
schema={schema}
combinatorKeyword={'oneOf'}
path={path}
rootSchema={rootSchema}
/>
<Tabs value={selectedIndex} onChange={handleTabChange}>
{oneOfRenderInfos.map((oneOfRenderInfo) => (
Expand Down
4 changes: 3 additions & 1 deletion packages/react/src/JsonForms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ export const JsonForms = (
);
const uischemaToUse = useMemo(
() =>
typeof uischema === 'object' ? uischema : Generate.uiSchema(schemaToUse),
typeof uischema === 'object'
? uischema
: Generate.uiSchema(schemaToUse, undefined, undefined, schemaToUse),
[uischema, schemaToUse]
);

Expand Down
7 changes: 6 additions & 1 deletion packages/vue-vanilla/src/complex/ObjectRenderer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ const controlRenderer = defineComponent({
computed: {
detailUiSchema(): UISchemaElement {
const uiSchemaGenerator = () => {
const uiSchema = Generate.uiSchema(this.control.schema, 'Group');
const uiSchema = Generate.uiSchema(
this.control.schema,
'Group',
undefined,
this.control.rootSchema
);
if (isEmpty(this.control.path)) {
uiSchema.type = 'VerticalLayout';
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface CombinatorProps {
schema: JsonSchema;
combinatorKeyword: 'oneOf' | 'anyOf' | 'allOf';
path: string;
rootSchema: JsonSchema;
}

export default defineComponent({
Expand All @@ -38,6 +39,10 @@ export default defineComponent({
type: String,
required: true,
},
rootSchema: {
type: Object as PropType<JsonSchema>,
required: true,
},
},
setup(props: CombinatorProps) {
const otherProps: JsonSchema = omit(
Expand All @@ -46,7 +51,9 @@ export default defineComponent({
) as JsonSchema;
const foundUISchema: UISchemaElement = Generate.uiSchema(
otherProps,
'VerticalLayout'
'VerticalLayout',
undefined,
props.rootSchema
);

const isLayout = (uischema: UISchemaElement): uischema is Layout =>
Expand Down
23 changes: 19 additions & 4 deletions packages/vue/src/components/JsonForms.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,11 @@ export default defineComponent({
data() {
const dataToUse = this.data;
const generatorData = isObject(dataToUse) ? dataToUse : {};
const schemaToUse = this.schema ?? Generate.jsonSchema(generatorData);
const uischemaToUse = this.uischema ?? Generate.uiSchema(schemaToUse);
const schemaToUse: JsonSchema =
this.schema ?? Generate.jsonSchema(generatorData);
const uischemaToUse =
this.uischema ??
Generate.uiSchema(schemaToUse, undefined, undefined, schemaToUse);
const initCore = (): JsonFormsCore => {
const initialCore = {
data: dataToUse,
Expand Down Expand Up @@ -177,11 +180,23 @@ export default defineComponent({
const generatorData = isObject(this.data) ? this.data : {};
this.schemaToUse = newSchema ?? Generate.jsonSchema(generatorData);
if (!this.uischema) {
this.uischemaToUse = Generate.uiSchema(this.schemaToUse);
this.uischemaToUse = Generate.uiSchema(
this.schemaToUse,
undefined,
undefined,
this.schemaToUse
);
}
},
uischema(newUischema) {
this.uischemaToUse = newUischema ?? Generate.uiSchema(this.schemaToUse);
this.uischemaToUse =
newUischema ??
Generate.uiSchema(
this.schemaToUse,
undefined,
undefined,
this.schemaToUse
);
},
data(newData) {
this.dataToUse = newData;
Expand Down