-
Notifications
You must be signed in to change notification settings - Fork 421
preserve the form data so when we update the additionalErrors the dat… #2478
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
base: master
Are you sure you want to change the base?
Changes from all commits
e41c15d
a6a21e3
d5218b1
0b979c0
ebe262b
51aa0bc
b27ce7f
87bfaa6
e413248
7bde214
6f736d2
4803dec
22b4016
fd04fe0
d9de6ab
63f16bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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(); | ||
kchobantonov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export default defineComponent({ | ||
| name: 'JsonForms', | ||
| components: { | ||
|
|
@@ -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, | ||
|
|
@@ -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; | ||
kchobantonov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (!this.schema) { | ||
|
Comment on lines
200
to
+203
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Combined with the other change sof the PR, this means that on every user edit (in schema-less mode) the schema and uischema are regenerated from the core's data, which is expensive and likely unnecessary since the shape of the data typically doesn't change between edits the user can make through JSON Forms We need to differentiate between outside and user based changes and only regenerate on outside changes. |
||
| this.schemaToUse = Generate.jsonSchema(this.dataToUse); | ||
| if (!this.uischema) { | ||
| this.uischemaToUse = generateUISchema(this.schemaToUse); | ||
| } | ||
| } | ||
| }, | ||
| renderers(newRenderers) { | ||
| this.jsonforms.renderers = newRenderers; | ||
|
|
@@ -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: { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No tests cover the new behavior. All existing tests in
schema.test.tspass objects. Tests forgenerateJsonSchema("hello"),generateJsonSchema(42),generateJsonSchema([1,2])etc. are needed.