[INFRA-420] | Anoop | Use custom ajv to support defaults

This commit is contained in:
anoop narang
2020-07-08 23:47:46 +05:30
parent 0e07db68e5
commit 814da2f2e6
5 changed files with 40 additions and 25 deletions

View File

@@ -12,9 +12,9 @@
"eject": "react-scripts eject" "eject": "react-scripts eject"
}, },
"dependencies": { "dependencies": {
"@jsonforms/core": "^2.3.2", "@jsonforms/core": "^2.4.0",
"@jsonforms/material-renderers": "^2.3.2", "@jsonforms/material-renderers": "^2.4.0",
"@jsonforms/react": "^2.3.2", "@jsonforms/react": "^2.4.0",
"@material-ui/core": "^4.9.12", "@material-ui/core": "^4.9.12",
"@material-ui/icons": "^4.9.1", "@material-ui/icons": "^4.9.1",
"@testing-library/jest-dom": "^4.2.4", "@testing-library/jest-dom": "^4.2.4",

View File

@@ -1,4 +1,3 @@
export const data :any={ export const data :any={
} }

View File

@@ -57,13 +57,29 @@ const Form = (props: any) => {
}).then((res) => res.json()); }).then((res) => res.json());
}; };
const getManifestDefaults = async (): Promise<any> => {
return fetch(`/api/manifest/defaults`, {
method: "GET",
credentials: "include",
headers: {
"X-XSRF-TOKEN": props.csrfToken,
Accept: "application/json",
"Content-Type": "application/json",
},
}).then((res) => res.json());
};
useEffect(() => { useEffect(() => {
if (manifestIdParam) { if (manifestIdParam) {
getManifestData(manifestIdParam).then((res) => { getManifestData(manifestIdParam).then((res) => {
setFormInitData(res); setFormInitData(res);
}); });
// eslint-disable-next-line react-hooks/exhaustive-deps } else {
getManifestDefaults().then((res) => {
setFormInitData(res)
});
} }
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []); }, []);
const formatDisplayData = (standaloneData) => { const formatDisplayData = (standaloneData) => {

View File

@@ -9,6 +9,7 @@
import * as React from 'react' import * as React from 'react'
import { JsonForms } from '@jsonforms/react' import { JsonForms } from '@jsonforms/react'
import { materialCells, materialRenderers } from '@jsonforms/material-renderers' import { materialCells, materialRenderers } from '@jsonforms/material-renderers'
import customAjv from '../../ajv/CustomAjv'
import _ from 'lodash' import _ from 'lodash'
interface IProps { interface IProps {
csrfToken?: any csrfToken?: any
@@ -29,7 +30,6 @@ function isProperJsonSchema(schema: any) {
export default function SchemaForm(props: IProps) { export default function SchemaForm(props: IProps) {
const [completeSchema, setCompleteSchema] = React.useState({ uiSchema: undefined, jsonSchema: undefined }) const [completeSchema, setCompleteSchema] = React.useState({ uiSchema: undefined, jsonSchema: undefined })
const [isLoading, setIsLoading] = React.useState(true) const [isLoading, setIsLoading] = React.useState(true)
const [formData, setFormData] = React.useState({})
React.useEffect(() => { React.useEffect(() => {
console.log(`Getting schema for ${props.name}`) console.log(`Getting schema for ${props.name}`)
@@ -81,8 +81,9 @@ export default function SchemaForm(props: IProps) {
(!props.updateCompleteSchemaHandler && isProperJsonSchema(completeSchema.jsonSchema)) ? (!props.updateCompleteSchemaHandler && isProperJsonSchema(completeSchema.jsonSchema)) ?
<JsonForms <JsonForms
schema={completeSchema.jsonSchema} schema={completeSchema.jsonSchema}
ajv={customAjv}
uischema={completeSchema.uiSchema} uischema={completeSchema.uiSchema}
data={props.manifestData || formData} data={props.manifestData}
renderers={[ renderers={[
...materialRenderers, ...materialRenderers,
]} ]}
@@ -91,7 +92,6 @@ export default function SchemaForm(props: IProps) {
if(props.onDataChange) { if(props.onDataChange) {
props.onDataChange(data) props.onDataChange(data)
} }
setFormData(data)
}} /> }} />
: null : null
} }

View File

@@ -1355,22 +1355,22 @@
"@types/yargs" "^15.0.0" "@types/yargs" "^15.0.0"
chalk "^3.0.0" chalk "^3.0.0"
"@jsonforms/core@^2.3.2": "@jsonforms/core@^2.4.0":
version "2.3.2" version "2.4.0"
resolved "https://registry.yarnpkg.com/@jsonforms/core/-/core-2.3.2.tgz#b8bef91cf56a28538b1e7cf786a9881f5e28258a" resolved "https://registry.yarnpkg.com/@jsonforms/core/-/core-2.4.0.tgz#81d2f51f2cf0cc520f4817144358736aea5308a5"
integrity sha512-+4u/gHJYqYydvcUh4awjot595oTkvnXYwL8PAgJ0nT2uSvCukzf/Ecno1SKwUg1hMPehs4hOIfR9NlOKa9cfiw== integrity sha512-x/3aCScsGa/QyTuQC2EO6uleGqf8SkMRcvpH209Jg+NE8poaq3ZOnOoygnQRmql4ay/ciwOJiaidImESjcDPrg==
dependencies: dependencies:
"@types/json-schema" "^7.0.3" "@types/json-schema" "^7.0.3"
ajv "^6.10.2" ajv "^6.10.2"
json-schema-ref-parser "^7.1.2" json-schema-ref-parser "7.1.3"
lodash "^4.17.15" lodash "^4.17.15"
uri-js "^4.2.2" uri-js "^4.2.2"
uuid "^3.3.3" uuid "^3.3.3"
"@jsonforms/material-renderers@^2.3.2": "@jsonforms/material-renderers@^2.4.0":
version "2.3.2" version "2.4.0"
resolved "https://registry.yarnpkg.com/@jsonforms/material-renderers/-/material-renderers-2.3.2.tgz#ededd0fd18e05ba630856ea0c4d074aabe70d651" resolved "https://registry.yarnpkg.com/@jsonforms/material-renderers/-/material-renderers-2.4.0.tgz#cad828ea16aae8674114da9e69579de516615898"
integrity sha512-4Ujj1adMvZgjuT8ggIY/Z+ET0/PP77qZsKHA+bRsVAayRaYBGgjdw4bHVOEmU59xXnB1Y7o2Ra3TjVKRuD4c0A== integrity sha512-1EQa18uho6Agb/xFx4ejcLtjKQ9O3qLh+Lf47qzFiQgxE4bVb/CMnKyPfhQAQXSRZuFjNgEAl1wEDvtTXPkXAg==
dependencies: dependencies:
"@date-io/moment" "1.3.11" "@date-io/moment" "1.3.11"
"@material-ui/pickers" "^3.2.8" "@material-ui/pickers" "^3.2.8"
@@ -1378,10 +1378,10 @@
moment "^2.24.0" moment "^2.24.0"
uuid "^3.3.3" uuid "^3.3.3"
"@jsonforms/react@^2.3.2": "@jsonforms/react@^2.4.0":
version "2.3.2" version "2.4.0"
resolved "https://registry.yarnpkg.com/@jsonforms/react/-/react-2.3.2.tgz#3493ab242ff3f4373f7557dd928f61321efa4799" resolved "https://registry.yarnpkg.com/@jsonforms/react/-/react-2.4.0.tgz#17b20ddfba85540687bc76c7464f29408d44fd10"
integrity sha512-Pz521oAVBo+o0WMX/udoUhkixJtuHU24I5ocXatkwo6oVmyW+XMnkDyiGU9HRZxI3MpjO51lpscmQvNoJmjTgg== integrity sha512-JPJU9+YO4wBtw5lYkh6zzbXPB+n0x1b9XoX4aTHZnFKndab2djEHjkY/WKlTxW+bYFVkFbNtyggoCL26iX0DkQ==
dependencies: dependencies:
"@types/object-hash" "^1.3.0" "@types/object-hash" "^1.3.0"
"@types/react" "^16.9.13" "@types/react" "^16.9.13"
@@ -7070,10 +7070,10 @@ json-parse-better-errors@^1.0.1, json-parse-better-errors@^1.0.2:
resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz#bb867cfb3450e69107c131d1c514bab3dc8bcaa9" resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz#bb867cfb3450e69107c131d1c514bab3dc8bcaa9"
integrity sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw== integrity sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==
json-schema-ref-parser@^7.1.2: json-schema-ref-parser@7.1.3:
version "7.1.4" version "7.1.3"
resolved "https://registry.yarnpkg.com/json-schema-ref-parser/-/json-schema-ref-parser-7.1.4.tgz#abb3f2613911e9060dc2268477b40591753facf0" resolved "https://registry.yarnpkg.com/json-schema-ref-parser/-/json-schema-ref-parser-7.1.3.tgz#21468cd180b2f1939ce93fe291f743b441e97d49"
integrity sha512-AD7bvav0vak1/63w3jH8F7eHId/4E4EPdMAEZhGxtjktteUv9dnNB/cJy6nVnMyoTPBJnLwFK6tiQPSTeleCtQ== integrity sha512-/Lmyl0PW27dOmCO03PI339+1gs4Z2PlqIyUgzIOtoRp08zkkMCB30TRbdppbPO7WWzZX0uT98HqkDiZSujkmbA==
dependencies: dependencies:
call-me-maybe "^1.0.1" call-me-maybe "^1.0.1"
js-yaml "^3.13.1" js-yaml "^3.13.1"