@@ -13,7 +13,7 @@ import { DisplayDocumentation } from "../templates"
1313import { documentInternalProperties } from "../helpers/documentHelpers"
1414
1515// display based on action
16- const DisplayLinkFrame = ( { reference, args, linkPropertyComment, order_by, onSelect, propertyDocumentation, documentData, cardKey, setDocumentData, action, onChange, documentLinkPropertyName, extracted, required, mode, linked_to, linkId } ) => {
16+ const DisplayLinkFrame = ( { reference, args, linkPropertyComment, formData , order_by, onSelect, propertyDocumentation, documentData, cardKey, setDocumentData, action, onChange, documentLinkPropertyName, extracted, required, mode, linked_to, linkId } ) => {
1717
1818 let nextCreateLink = false
1919
@@ -126,6 +126,7 @@ const DisplayLinkFrame = ({ reference, args, linkPropertyComment, order_by, onSe
126126 //hideFieldLabel={hideFieldLabel}
127127 linkId = { linkId }
128128 onSelect = { onSelect }
129+ formData = { formData && formData . hasOwnProperty ( field ) && formData [ field ] ? formData [ field ] : false }
129130 args = { args }
130131 depth = { cardKey }
131132 reference = { reference }
@@ -147,7 +148,7 @@ const DisplayLinkFrame = ({ reference, args, linkPropertyComment, order_by, onSe
147148 propertyName : documentLinkPropertyName ,
148149 id : fieldID ,
149150 key : `${ linked_to } __${ uuidv4 ( ) } ` ,
150- formData : util . getFormDataPerProperty ( documentData , fieldName ) ,
151+ formData : formData && formData . hasOwnProperty ( fieldName ) && formData [ fieldName ] ? { [ fieldName ] : formData [ fieldName ] } : util . getFormDataPerProperty ( documentData , fieldName ) ,
151152 required : definitions . required . includes ( fieldName ) ,
152153 mode : mode ,
153154 args : args ,
@@ -172,7 +173,7 @@ const DisplayLinkFrame = ({ reference, args, linkPropertyComment, order_by, onSe
172173
173174 return < SearchExistingLink onSelect = { onSelect }
174175 mode = { mode }
175- formData = { null }
176+ formData = { formData }
176177 onChange = { onChange }
177178 id = { cardKey }
178179 linked_to = { linked_to } />
@@ -182,7 +183,7 @@ const DisplayLinkFrame = ({ reference, args, linkPropertyComment, order_by, onSe
182183}
183184
184185
185- export const CreateDisplay = ( { args, name, linkPropertyComment, order_by, reference, required, onSelect, propertyDocumentation, cardKey, linked_to, extracted, mode, onChange, action, setAction, documentData, setDocumentData, linkId } ) => {
186+ export const CreateDisplay = ( { args, name, formData , linkPropertyComment, order_by, reference, required, onSelect, propertyDocumentation, cardKey, linked_to, extracted, mode, onChange, action, setAction, documentData, setDocumentData, linkId } ) => {
186187
187188 return < >
188189 { getDocumentLinkChoiceDescription ( name , linked_to ) }
@@ -200,6 +201,7 @@ export const CreateDisplay = ({ args, name, linkPropertyComment, order_by, refer
200201 onChange = { onChange }
201202 onSelect = { onSelect }
202203 order_by = { order_by }
204+ formData = { formData }
203205 linked_to = { linked_to }
204206 documentLinkPropertyName = { name }
205207 documentData = { documentData }
@@ -214,12 +216,18 @@ function getID (linkId, depth) {
214216 }
215217 return depth + 1
216218}
219+
220+ export function extractFormData ( formData , linked_to ) {
221+ if ( typeof formData === CONST . STRING_TYPE ) return formData
222+ if ( Object . keys ( formData ) . length ) return formData
223+ return { [ CONST . TYPE ] : linked_to }
224+ }
217225
218226// CREATE MODE
219- export const CreateDocument = ( { args, name, required, onSelect, reference, order_by, hideFieldLabel, linked_to, extracted, mode, onChange, depth, propertyDocumentation, linkId } ) => {
227+ export const CreateDocument = ( { args, name, required, formData , onSelect, reference, order_by, hideFieldLabel, linked_to, extracted, mode, onChange, depth, propertyDocumentation, linkId } ) => {
220228
221- const [ action , setAction ] = useState ( false )
222- const [ documentData , setDocumentData ] = useState ( { [ CONST . TYPE ] : linked_to } )
229+ const [ action , setAction ] = useState ( formData ? typeof formData === CONST . STRING_TYPE ? CONST . LINK_EXISTING_DOCUMENT : CONST . LINK_NEW_DOCUMENT : false )
230+ const [ documentData , setDocumentData ] = useState ( formData ? extractFormData ( formData , linked_to ) : { [ CONST . TYPE ] : linked_to } )
223231 //const [cardKey, setCardKey]=useState(uuidv4())
224232 const [ cardKey , setCardKey ] = useState ( getID ( linkId , depth ) )
225233
@@ -230,6 +238,7 @@ export const CreateDocument = ({ args, name, required, onSelect, reference, orde
230238 if ( linked_to ) setDocumentData ( { [ CONST . TYPE ] : linked_to } )
231239 } , [ linked_to ] )
232240
241+
233242 return < >
234243 < DisplayDocumentation documentation = { propertyDocumentation } />
235244 < Stack direction = "horizontal" >
@@ -244,6 +253,7 @@ export const CreateDocument = ({ args, name, required, onSelect, reference, orde
244253 extracted = { extracted }
245254 mode = { mode }
246255 linkId = { linkId }
256+ formData = { formData }
247257 args = { args }
248258 order_by = { order_by }
249259 propertyDocumentation = { propertyDocumentation }
0 commit comments