-
Notifications
You must be signed in to change notification settings - Fork 422
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
972c194
8353196
aa5b3c4
4af7884
66e5c00
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 |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
|
|
||
| <script lang="ts"> | ||
| import { PropType, reactive, defineComponent } from 'vue'; | ||
| import isEqual from 'lodash/isEqual'; | ||
| import { | ||
| coreReducer, | ||
| Actions, | ||
|
|
@@ -26,21 +27,26 @@ 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 getSchemaGeneratorInput = (data: any) => | ||
| data === undefined ? {} : data; | ||
| const generateUISchema = (schema: JsonSchema) => | ||
| Generate.uiSchema(schema, undefined, undefined, schema) ?? | ||
| createDefaultLayout(); | ||
|
Comment on lines
+40
to
+48
Contributor
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. 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.
Contributor
Author
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. yes since jsonforms expects not undefined ui schema this code works to handle the cases where the uiSchema returns null - if we do not wrap that then jsonforms throws error since it does expect valid uiSchema. I haven't modified the uiSchema generation since that might break some expectation - just wasn't sure if that is the case but yes if you think that modifying the generateUiSchema to never return null/undefined or change the jsonforms to handle null/undefined uiSchema then that code can be removed |
||
|
|
||
| export default defineComponent({ | ||
| name: 'JsonForms', | ||
| components: { | ||
|
|
@@ -124,12 +130,9 @@ export default defineComponent({ | |
| emits: ['change'], | ||
| data() { | ||
| const dataToUse = this.data; | ||
| const generatorData = isObject(dataToUse) ? dataToUse : {}; | ||
| const schemaToUse: JsonSchema = | ||
| this.schema ?? Generate.jsonSchema(generatorData); | ||
| const uischemaToUse = | ||
| this.uischema ?? | ||
| Generate.uiSchema(schemaToUse, undefined, undefined, schemaToUse); | ||
| this.schema ?? Generate.jsonSchema(getSchemaGeneratorInput(dataToUse)); | ||
| const uischemaToUse = this.uischema ?? generateUISchema(schemaToUse); | ||
| const initCore = (): JsonFormsCore => { | ||
| const initialCore = { | ||
| data: dataToUse, | ||
|
|
@@ -189,29 +192,30 @@ export default defineComponent({ | |
| }, | ||
| watch: { | ||
| schema(newSchema) { | ||
| const generatorData = isObject(this.data) ? this.data : {}; | ||
| this.schemaToUse = newSchema ?? Generate.jsonSchema(generatorData); | ||
| this.schemaToUse = | ||
| newSchema ?? Generate.jsonSchema(getSchemaGeneratorInput(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) { | ||
| const isSameAsCurrentData = newData === this.dataToUse; | ||
| this.dataToUse = newData; | ||
|
|
||
| if (!this.schema && !isSameAsCurrentData) { | ||
| const nextSchema = Generate.jsonSchema( | ||
| getSchemaGeneratorInput(this.dataToUse) | ||
| ); | ||
| if (!isEqual(nextSchema, this.schemaToUse)) { | ||
| this.schemaToUse = nextSchema; | ||
| if (!this.uischema) { | ||
| this.uischemaToUse = generateUISchema(this.schemaToUse); | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| renderers(newRenderers) { | ||
| this.jsonforms.renderers = newRenderers; | ||
|
|
@@ -251,6 +255,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: { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.