Skip to content
Open
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
2 changes: 1 addition & 1 deletion packages/core/src/generators/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,5 @@ export const generateJsonSchema = (

const gen = new Gen(findOption);

return gen.schemaObject(instance);
return gen.property(instance);
};
1 change: 0 additions & 1 deletion packages/vue-vuetify/dev/views/ExampleView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ const onChange = (event: JsonFormsChangeEvent): void => {
monaco.Uri.parse(toDataUri(props.example.name)),
event.data !== undefined ? JSON.stringify(event.data, null, 2) : '',
);
state.data = event.data;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get that this is introduced to test the new behavior but even if we were to merge it, I don't think the example app use this unrecommended mixed approach. Thus, this should be reverted

}
errors.value = event.errors;
};
Expand Down
55 changes: 26 additions & 29 deletions packages/vue/src/components/JsonForms.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,24 @@ import {
defaultMiddleware,
Middleware,
JsonFormsSubStates,
Layout,
} from '@jsonforms/core';
import { JsonFormsChangeEvent, MaybeReadonly } from '../types';
import DispatchRenderer from './DispatchRenderer.vue';

import type Ajv from 'ajv';
import type { ErrorObject } from 'ajv';

// TODO fix @typescript-eslint/ban-types
// eslint-disable-next-line @typescript-eslint/ban-types
const isObject = (elem: any): elem is Object => {
return elem && typeof elem === 'object';
};

const EMPTY: ErrorObject[] = reactive([]);

const createDefaultLayout = (): Layout => ({
type: 'VerticalLayout',
elements: [],
});
const generateUISchema = (schema: JsonSchema) =>
Generate.uiSchema(schema, undefined, undefined, schema) ??
createDefaultLayout();
Comment on lines +39 to +45
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is behavior that shouldn't be defined specifically here. If the Generator does not handle this already, we might fix it there for all.


export default defineComponent({
name: 'JsonForms',
components: {
Expand Down Expand Up @@ -123,13 +126,10 @@ export default defineComponent({
},
emits: ['change'],
data() {
const dataToUse = this.data;
const generatorData = isObject(dataToUse) ? dataToUse : {};
const dataToUse = this.data === undefined ? {} : this.data;
const schemaToUse: JsonSchema =
this.schema ?? Generate.jsonSchema(generatorData);
const uischemaToUse =
this.uischema ??
Generate.uiSchema(schemaToUse, undefined, undefined, schemaToUse);
this.schema ?? Generate.jsonSchema(dataToUse);
const uischemaToUse = this.uischema ?? generateUISchema(schemaToUse);
const initCore = (): JsonFormsCore => {
const initialCore = {
data: dataToUse,
Expand Down Expand Up @@ -189,29 +189,23 @@ export default defineComponent({
},
watch: {
schema(newSchema) {
const generatorData = isObject(this.data) ? this.data : {};
this.schemaToUse = newSchema ?? Generate.jsonSchema(generatorData);
this.schemaToUse = newSchema ?? Generate.jsonSchema(this.dataToUse);
if (!this.uischema) {
this.uischemaToUse = Generate.uiSchema(
this.schemaToUse,
undefined,
undefined,
this.schemaToUse
);
this.uischemaToUse = generateUISchema(this.schemaToUse);
}
},
uischema(newUischema) {
this.uischemaToUse =
newUischema ??
Generate.uiSchema(
this.schemaToUse,
undefined,
undefined,
this.schemaToUse
);
this.uischemaToUse = newUischema ?? generateUISchema(this.schemaToUse);
},
data(newData) {
this.dataToUse = newData;
this.dataToUse = newData === undefined ? {} : newData;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary? For instance, we don't do this in React


if (!this.schema) {
this.schemaToUse = Generate.jsonSchema(this.dataToUse);
if (!this.uischema) {
this.uischemaToUse = generateUISchema(this.schemaToUse);
}
}
},
renderers(newRenderers) {
this.jsonforms.renderers = newRenderers;
Expand Down Expand Up @@ -251,6 +245,9 @@ export default defineComponent({
);
},
eventToEmit(newEvent) {
// update the data so if we change the additionalErrors this won't reset the form data
this.dataToUse = newEvent.data;

this.$emit('change', newEvent);
},
i18n: {
Expand Down
Loading