Skip to content

Commit b193ce6

Browse files
committed
fixinf starwars and formdata appearance from create and edit view
1 parent 192d480 commit b193ce6

File tree

7 files changed

+22
-21
lines changed

7 files changed

+22
-21
lines changed

packages/tdb-dashboard/src/pages/DocumentEdit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const DocumentEdit = () => {
1616
const [showModal, setShowModal] = useState(false)
1717
const {type, docid} = useParams()
1818
const navigate = useNavigate()
19-
19+
2020
const {
2121
updateDocument,
2222
getDocument,

packages/tdb-dashboard/src/pages/DocumentNew.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export const DocumentNew = () => {
1919
error,
2020
setError,
2121
getDocumentFrames,
22-
createDocument
22+
createDocument,
23+
formData
2324
} = useTDBDocuments(woqlClient)
2425
const navigate = useNavigate()
2526

@@ -51,11 +52,12 @@ export const DocumentNew = () => {
5152
{showModal && <CreateChangeRequestModal showModal={showModal} type={type} setShowModal={setShowModal} updateViewMode={setChangeRequestBranch}/>}
5253
{error && <ErrorMessageReport error={error} setError={setError}/>}
5354
{currentChangeRequest && frames &&
54-
<NewDocumentComponent
55+
<NewDocumentComponent
5556
SearchComponent={DocumentSearchComponent}
5657
frames={frames}
5758
createDocument={callCreateDocument}
5859
type={type}
60+
jsonContent={formData}
5961
closeButtonClick={closeButtonClick}
6062
/>
6163
}

packages/tdb-documents-ui-template/src/EditDocumentComponent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const EditDocumentComponent = ({type,updateDocument,selectedDocument,fram
4343
<FrameViewer frame={frames}
4444
type={type}
4545
mode={CONST.EDIT_DOCUMENT}
46-
onSubmit={updateDocument}
46+
onSubmit={updateDocument}
4747
//onChange={handleChange}
4848
language={selectedLanguage}
4949
{...onSelect}

packages/tdb-documents-ui-template/src/NewDocumentComponent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const NewDocumentComponent = ({type,createDocument,jsonContent,frames,clo
3838
<JsonFrameViewer jsonData={jsonContent} mode={CONST.CREATE_DOCUMENT} setExtracted={createDocument}/>
3939
}
4040
{view === CONST.FORM_VIEW &&
41-
<FrameViewer frame={frames}
41+
<FrameViewer frame={frames}
4242
type={type}
4343
mode={CONST.CREATE_DOCUMENT}
4444
language={selectedLanguage}

packages/tdb-documents-ui/src/components/CreateDocumentLink.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ import { documentInternalProperties } from "../helpers/documentHelpers"
1515
// display based on action
1616
const DisplayLinkFrame = ({ reference, args, linkPropertyComment, formData, order_by, onSelect, propertyDocumentation, documentData, cardKey, setDocumentData, action, onChange, documentLinkPropertyName, extracted, required, mode, linked_to, linkId }) => {
1717

18-
let nextCreateLink = false
19-
2018
if(action === CONST.LINK_NEW_DOCUMENT) {
2119

2220
let fields = []
2321

24-
function handleChange(data, fieldName, b_boxField) {
22+
function handleChange(data, fieldName, b_boxField, fieldLink) {
2523
//console.log("documentData", documentData)
2624
let tempDocumentData = documentData
2725

@@ -97,9 +95,9 @@ const DisplayLinkFrame = ({ reference, args, linkPropertyComment, formData, orde
9795
// if field name is undefined
9896
// at this point means that its the document link's data
9997
// so we pass linked_to as param
100-
// nextCreateLink stores the next link
98+
// fieldLink stores the next link
10199
//tempDocumentData[fieldName ? fieldName : documentLinkPropertyName]=data
102-
tempDocumentData[fieldName ? fieldName : nextCreateLink]=data
100+
tempDocumentData[fieldName ? fieldName : fieldLink]=data
103101
setDocumentData(tempDocumentData)
104102
if(onChange) {
105103
if(CONST.GEOMETRY_ARRAY.includes(fieldName)) onChange(tempDocumentData, fieldName)
@@ -116,8 +114,6 @@ const DisplayLinkFrame = ({ reference, args, linkPropertyComment, formData, orde
116114
linked_to = definitions.properties[field][CONST.PLACEHOLDER]
117115
// if field is a document link then @placeholder will point to linked document at this point
118116
if(util.availableInReference(reference, linked_to)) {
119-
// store the field name here to connect to correct changed data on create
120-
nextCreateLink = field
121117
// another document link
122118
fields.push(<CreateDocument name={field}
123119
linked_to={linked_to}
@@ -131,9 +127,9 @@ const DisplayLinkFrame = ({ reference, args, linkPropertyComment, formData, orde
131127
depth={cardKey}
132128
reference={reference}
133129
extracted={definitions}
134-
onChange={handleChange}
130+
onChange={(data, fieldName, b_boxField) => handleChange(data, fieldName, b_boxField, field) }
135131
linkPropertyComment={linkPropertyComment}
136-
required={required} />)
132+
required={definitions.required.includes(field)} />)
137133
}
138134
else {
139135
// internal properties

packages/tdb-documents-ui/src/components/EditDocumentLink.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@ const DisplayFilledFrame = ({ args, documentData, propertyDocumentation, onTrave
2222
if(action === CONST.LINK_NEW_DOCUMENT) {
2323

2424
let fields = []
25-
let nextCreateLink = false
2625

27-
function handleChange(data, fieldName) {
26+
function handleChange(data, fieldName, field) {
2827
let tempDocumentData = documentData
2928
// if field name is undefined
3029
// at this point means that its the document link's data
3130
// so we pass linked_to as param
3231
//tempDocumentData[fieldName ? fieldName : documentLinkPropertyName]=data
33-
tempDocumentData[fieldName ? fieldName : nextCreateLink]=data
32+
tempDocumentData[fieldName ? fieldName : field]=data
3433
setDocumentData(tempDocumentData)
3534
if(onChange) onChange(tempDocumentData)
3635
setUpdate(Date.now())
@@ -45,7 +44,6 @@ const DisplayFilledFrame = ({ args, documentData, propertyDocumentation, onTrave
4544
linked_to = definitions.properties[field][CONST.PLACEHOLDER]
4645
if(util.availableInReference(reference, linked_to)) {
4746
if(!formData.hasOwnProperty(field)) {
48-
nextCreateLink = field
4947
fields.push(<CreateDocument name={field}
5048
linked_to={linked_to}
5149
mode={mode}
@@ -56,14 +54,13 @@ const DisplayFilledFrame = ({ args, documentData, propertyDocumentation, onTrave
5654
onSelect={onSelect}
5755
reference={reference}
5856
extracted={extracted}
59-
onChange={handleChange}
57+
onChange={(data, fieldName) => handleChange(data, fieldName, field)}
6058
//comment={comment} // review
6159
required={required} />)
6260
}
6361
else {
64-
nextCreateLink = field
6562
fields.push(<EditDocument name={field}
66-
onChange={handleChange}
63+
onChange={(data, fieldName) => handleChange(data, fieldName, field)}
6764
linked_to={linked_to}
6865
mode={mode}
6966
clickedUnlinked={clickedUnlinked}

packages/tdb-documents-ui/src/hook/useTDBDocuments.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ export const useTDBDocuments = (woqlClient) => {
2222
// bool|Object
2323
const [frames, setFrames]=useState(false)
2424

25+
// store the state of formData entered by the user
26+
const [formData, setFormData]= useState()
27+
2528
//get all the Document Classes (no abstract or subdocument)
2629
// I can need to call this again
2730
// improve performance with check last commit
@@ -116,6 +119,7 @@ export const useTDBDocuments = (woqlClient) => {
116119
const res = await woqlClient.addDocument(jsonDocument)
117120
return res
118121
}catch(err){
122+
setFormData(jsonDocument)
119123
setError(err.data || {message:err.message})
120124
}finally{
121125
setLoading(false)
@@ -166,12 +170,14 @@ export const useTDBDocuments = (woqlClient) => {
166170
}
167171
catch(err){
168172
//display conflict
173+
setSelectedDocument(jsonDoc)
169174
setError(err.data || {message:err.message})
170175
}finally{setLoading(false)}
171176
}
172177

173178
return {
174179
setError,
180+
formData,
175181
selectedDocument,
176182
getDocument,
177183
deleteDocument,

0 commit comments

Comments
 (0)