-
Notifications
You must be signed in to change notification settings - Fork 425
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
7194ebf
75a7203
1299f70
82e985c
c925284
f02d205
c1a54b7
18d6212
ade1fa2
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 |
|---|---|---|
|
|
@@ -52,9 +52,7 @@ class Gen { | |
| private findOption: (props: Properties) => (optionName: string) => any | ||
| ) {} | ||
|
|
||
| // TODO fix @typescript-eslint/ban-types | ||
| // eslint-disable-next-line @typescript-eslint/ban-types | ||
| schemaObject = (data: Object): JsonSchema4 => { | ||
| schemaObject = (data: Record<string, any>): JsonSchema4 => { | ||
| const props: Properties = this.properties(data); | ||
| const schema: JsonSchema4 = { | ||
| type: 'object', | ||
|
|
@@ -140,14 +138,12 @@ class Gen { | |
|
|
||
| /** | ||
| * Generate a JSON schema based on the given data and any additional options. | ||
| * @param {Object} instance the data to create a JSON schema for | ||
| * @param {unknown} instance the data to create a JSON schema for | ||
| * @param {any} options any additional options that may alter the generated JSON schema | ||
| * @returns {JsonSchema} the generated schema | ||
| */ | ||
| export const generateJsonSchema = ( | ||
| // TODO fix @typescript-eslint/ban-types | ||
| // eslint-disable-next-line @typescript-eslint/ban-types | ||
| instance: Object, | ||
| instance: unknown, | ||
| options: any = {} | ||
| ): JsonSchema4 => { | ||
| const findOption = | ||
|
|
@@ -177,5 +173,5 @@ export const generateJsonSchema = ( | |
|
|
||
| const gen = new Gen(findOption); | ||
|
|
||
| return gen.schemaObject(instance); | ||
| return gen.property(instance); | ||
|
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. Good fix, but it changes results for existing callers: |
||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -225,4 +225,4 @@ export const generateDefaultUISchema = ( | |
| wrapInLayoutIfNecessary( | ||
| generateUISchema(jsonSchema, [], prefix, '', layoutType, rootSchema), | ||
| layoutType | ||
| ); | ||
| ) ?? createLayout(layoutType); | ||
|
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.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,12 +37,13 @@ Optional props: | |
| Events: | ||
|
|
||
| - `change: {data: any; errors: AJVError[]}` - Whenever data and/or errors change this event is emitted. | ||
| - `update:data: any` - Emits the current data alongside `change`, enabling `v-model:data`. | ||
|
|
||
| Example: | ||
|
|
||
| ```html | ||
| <json-forms | ||
| :data="data" | ||
| v-model:data="data" | ||
| :renderers="renderers" | ||
| :schema="schema" | ||
| :uischema="uischema" | ||
|
|
@@ -82,7 +83,7 @@ export default defineComponent({ | |
| }, | ||
| methods: { | ||
| onChange(event: JsonFormsChangeEvent) { | ||
| this.data = event.data; | ||
| console.log(event); | ||
|
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.
|
||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,40 +7,39 @@ | |
| </template> | ||
|
|
||
| <script lang="ts"> | ||
| import { PropType, reactive, defineComponent } from 'vue'; | ||
| import { | ||
| coreReducer, | ||
| Actions, | ||
| Generate, | ||
| configReducer, | ||
| JsonSchema, | ||
| UISchemaElement, | ||
| ValidationMode, | ||
| JsonFormsCore, | ||
| JsonFormsUISchemaRegistryEntry, | ||
| JsonFormsRendererRegistryEntry, | ||
| JsonFormsCellRendererRegistryEntry, | ||
| CoreActions, | ||
| coreReducer, | ||
| defaultMiddleware, | ||
| Generate, | ||
| i18nReducer, | ||
| JsonFormsCellRendererRegistryEntry, | ||
| JsonFormsCore, | ||
| JsonFormsI18nState, | ||
| defaultMiddleware, | ||
| Middleware, | ||
| JsonFormsRendererRegistryEntry, | ||
| JsonFormsSubStates, | ||
| JsonFormsUISchemaRegistryEntry, | ||
| JsonSchema, | ||
| Middleware, | ||
| UISchemaElement, | ||
| ValidationMode, | ||
| } from '@jsonforms/core'; | ||
| import isEqual from 'lodash/isEqual'; | ||
| import { defineComponent, PropType, reactive } from 'vue'; | ||
| 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 getSchemaGeneratorInput = (data: any) => (data === undefined ? {} : data); | ||
|
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. With |
||
| const generateUISchema = (schema: JsonSchema) => | ||
| Generate.uiSchema(schema, undefined, undefined, schema); | ||
|
|
||
| export default defineComponent({ | ||
| name: 'JsonForms', | ||
| components: { | ||
|
|
@@ -121,15 +120,12 @@ export default defineComponent({ | |
| default: defaultMiddleware, | ||
| }, | ||
| }, | ||
| emits: ['change'], | ||
| emits: ['change', 'update:data'], | ||
| 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 +185,31 @@ 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.jsonforms.core.data; | ||
| this.dataToUse = newData; | ||
|
|
||
| if (!this.schema && !isSameAsCurrentData) { | ||
|
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.
|
||
| 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 +249,7 @@ export default defineComponent({ | |
| ); | ||
| }, | ||
| eventToEmit(newEvent) { | ||
| this.$emit('update:data', newEvent.data); | ||
|
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.$emit('change', newEvent); | ||
| }, | ||
| i18n: { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.