@@ -19,6 +19,7 @@ import { extractPropertyDocumentation } from "./widgetHelper"
1919import { TDBRDFLanguage } from "../widgets/rdfLanguageWidget"
2020import { TDBSysUnit } from "../widgets/sysUnitWidget"
2121import { TDBChoiceDocuments } from "../widgets/choiceDocumentsWidget"
22+ import { displayDocumentFieldArrayHelpers } from "./documentFieldArrayHelpers"
2223import { display } from "./display"
2324import { displayGeoJSONViewUI } from "./widgetHelper"
2425
@@ -247,14 +248,46 @@ export function displayChoiceSubDocument (props, args, property, id) {
247248 props = { props } />
248249}
249250
251+ function getOneOfFormData ( props , args ) {
252+ if ( props . formData ) return props . formData
253+ else if ( ! props . formData && args . formData ) {
254+ // check args.formData if one of available at document level
255+ let choices = args . documentFrame [ CONST . ONEOFVALUES ] , populatedFormData = { }
256+ choices . map ( choice => {
257+ for ( let val in choice ) {
258+ if ( args . formData . hasOwnProperty ( val ) ) {
259+ // filled form data available
260+ populatedFormData [ val ] = args . formData [ val ]
261+ }
262+ }
263+ } )
264+ return populatedFormData
265+ }
266+ }
267+
250268// ONE OF
251269export function displayOneOfProperty ( props , args , property , id ) {
252- const [ oneOfDocumentData , setOneOfDocumentData ] = useState ( props . formData ? props . formData : [ ] )
253-
254- useEffect ( ( ) => {
255- // formdata on change
270+ //const [oneOfDocumentData, setOneOfDocumentData] = useState(props.formData ? props.formData : {})
271+ const [ oneOfDocumentData , setOneOfDocumentData ] = useState ( getOneOfFormData ( props , args ) )
272+
273+
274+ /*useEffect(() => {
275+
256276 if(props.formData) setOneOfDocumentData(props.formData)
257- } , [ props . formData ] )
277+ else if(!props.formData && args.formData) {
278+ // check args.formData if one of available at document level
279+ let choices = args.documentFrame[CONST.ONEOFVALUES], populatedFormData = {}
280+ choices.map(choice => {
281+ for(let val in choice){
282+ if(args.formData.hasOwnProperty(val)) {
283+ // filled form data available
284+ populatedFormData[val] = args.formData[val]
285+ }
286+ }
287+ })
288+ setOneOfDocumentData(populatedFormData)
289+ }
290+ }, [props.formData])*/
258291
259292 return < TDBOneOfDocuments args = { args }
260293 property = { property }
@@ -488,4 +521,34 @@ export function displayBBoxDocument (props, args, property, id) {
488521
489522 return < TDBBBoxDocuments config = { config } />
490523}
524+
525+
526+ // ARRAY
527+ export function displayArrayWidgets ( props , args , extracted , property , expand , id , hideFieldLabel , linked_to ) {
528+
529+ function handleArrayOnChange ( data , selectedField ) {
530+ props . onChange ( data , selectedField )
531+ }
532+
533+ let fieldID = `root_${ property } `
534+ let docConfig = {
535+ properties : args . reference [ linked_to ] ,
536+ propertyName : property ,
537+ id : fieldID ,
538+ key : fieldID ,
539+ //formData: {},
540+ formData : ! props . formData ? { } : { [ property ] : props . formData } ,
541+ required : true ,
542+ mode : args . mode ,
543+ args : args ,
544+ hideFieldLabel : hideFieldLabel ,
545+ //fieldUIFrame: fieldUIFrame,
546+ onChange : ( data , selectedField ) => handleArrayOnChange ( data , selectedField ) ,
547+ //defaultClassName: defaultClassName,
548+ ///propertyDocumentation: propertyDocumentation
549+ }
550+ let argsHolder = { ...args }
551+ argsHolder . documentFrame = { [ property ] : linked_to }
552+ return displayDocumentFieldArrayHelpers ( fieldID , property , null , argsHolder , docConfig )
553+ }
491554
0 commit comments