Skip to content

Commit a629ade

Browse files
committed
Merge branch 'oneOfFix' into newDoc
2 parents 5d59092 + 710177e commit a629ade

File tree

13 files changed

+273
-179
lines changed

13 files changed

+273
-179
lines changed

packages/tdb-dashboard/src/components/DiffView.js

Lines changed: 1 addition & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -180,98 +180,6 @@ function DiffViewDocument ({documentID,diffObj, CRObject,propertyModifiedCount,f
180180
</Accordion>
181181
}
182182

183-
/**
184-
*
185-
* @param {*} diffs diff list
186-
* @param {*} trackingBranchDocumentList document list of tracking branch
187-
* @param {*} originBranchDocumentList document list of origin branch
188-
* @returns
189-
*/
190-
export const DiffView_OLD = ({diffs, CRObject, start, setStart }) => {
191-
const {woqlClient} = WOQLClientObj()
192-
193-
// I need to copy the woqlClient and set the original_branch
194-
// to get the right frame
195-
const woqlClientCopy = woqlClient.copy()
196-
woqlClientCopy.checkout(CRObject.original_branch)
197-
198-
const {frames,getDocumentFrames} = useTDBDocuments(woqlClientCopy)
199-
// pagination constants
200-
const [activePage, setActivePage]=useState(1)
201-
const [current, setCurrent]=useState(0)
202-
203-
const [page, setPage] = useState(start)
204-
205-
let elements=[], paginationItems=[]
206-
207-
let divide = Math.ceil(diffs.length/DIFFS_PER_PAGE_LIMIT)
208-
209-
useEffect(() => {
210-
getDocumentFrames()
211-
},[])
212-
// function to handle on click of page
213-
function handlePagination(number) {
214-
alert(number)
215-
/*let position=DIFFS_PER_PAGE_LIMIT * (number-1)
216-
217-
setCurrent(position)
218-
setActivePage(number) */
219-
220-
}
221-
222-
// populate pagination Item
223-
/*for (let number = 1; number <= divide; number++) {
224-
paginationItems.push(
225-
<Pagination.Item key={number} active={number === activePage} onClick={(e) => handlePagination(number)}>
226-
{number}
227-
</Pagination.Item>
228-
)
229-
}*/
230-
231-
if(!frames) return <Loading message={`Loading Frames ...`}/>
232-
if(!diffs) return <Loading message={`Loading Diffs ...`}/>
233-
234-
235-
// looping through diff lists
236-
for(let start=current; start<(current + DIFFS_PER_PAGE_LIMIT); start++) {
237-
238-
if(start >= diffs.length) continue
239-
240-
const propertyModifiedCount = getPropertyModifiedCount(diffs[start])
241-
const diffObj = diffs[start]
242-
const action = diffObj["@op"] || "Change"
243-
const actionKey = `@${action.toLowerCase()}`
244-
const eventKey= diffObj[actionKey] && diffObj[actionKey]["@id"] ? diffObj[actionKey]["@id"] : diffObj["@id"]
245-
const docType = diffObj[actionKey] && diffObj[actionKey]["@type"] ? diffObj[actionKey]["@type"] : diffObj["@type"]
246-
247-
// this are the diff panel for document
248-
elements.push(
249-
<React.Fragment key={`item__${start}`}>
250-
<DiffViewDocument frames={frames} key={actionKey}
251-
action={action}
252-
docType={docType}
253-
propertyModifiedCount={propertyModifiedCount}
254-
documentID={eventKey}
255-
diffObj={diffObj}
256-
CRObject={CRObject}/>
257-
</React.Fragment>
258-
)
259-
}
260-
261-
return <React.Fragment>
262-
{elements}
263-
<Row className="w-100">
264-
<Col/>
265-
<Col>
266-
<Pagination className="justify-content-center ">
267-
<Pagination.Prev onClick={(e) => handlePagination(e)}/>
268-
<Pagination.Next onClick={(e) => handlePagination(e)}/>
269-
</Pagination>
270-
</Col>
271-
<Col/>
272-
</Row>
273-
</React.Fragment>
274-
}
275183

276184
/**
277185
*
@@ -292,7 +200,7 @@ export const DiffView = ({diffs, CRObject, start, setStart }) => {
292200

293201
let elements=[]
294202

295-
203+
296204
useEffect(() => {
297205
getDocumentFrames()
298206
},[])

packages/tdb-documents-ui/src/formActions.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EDIT, OBJECT_TYPE } from "./constants"
1+
import { EDIT, ONEOFVALUES } from "./constants"
22

33
// function to remove all empty json object
44
// this is to remove all optional subdocument data other wise database will
@@ -21,6 +21,17 @@ function removeEmptyObject(data) {
2121
}, {});
2222
}
2323

24+
function removeOneOfPropertyFromDocumentLevel(data) {
25+
if(!data.hasOwnProperty(ONEOFVALUES)) return data
26+
let newData = data
27+
let oneOfData = data[ONEOFVALUES]
28+
delete newData[ONEOFVALUES]
29+
for(let choice in oneOfData) {
30+
newData[choice] = oneOfData[choice]
31+
}
32+
return newData
33+
}
34+
2435

2536

2637
/**
@@ -34,7 +45,8 @@ function removeEmptyObject(data) {
3445
*/
3546
export const handleSubmit = (data, onSubmit, setData, type, mode) => {
3647
if(onSubmit) {
37-
let formData=removeEmptyObject(data.formData)
48+
let alteredFormData=removeEmptyObject(data.formData)
49+
let formData=removeOneOfPropertyFromDocumentLevel(alteredFormData)
3850
console.log("Before submit: ", formData)
3951
setData(formData)
4052
let extracted = formData

packages/tdb-documents-ui/src/helpers/displayHelper.js

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { extractPropertyDocumentation } from "./widgetHelper"
1919
import { TDBRDFLanguage } from "../widgets/rdfLanguageWidget"
2020
import { TDBSysUnit } from "../widgets/sysUnitWidget"
2121
import { TDBChoiceDocuments } from "../widgets/choiceDocumentsWidget"
22+
import { displayDocumentFieldArrayHelpers } from "./documentFieldArrayHelpers"
2223
import { display } from "./display"
2324
import { 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
251269
export 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

packages/tdb-documents-ui/src/helpers/documentHelpers.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function addUiFrameForEachField(docConfig, property) {
1818
function extractDocumentFrame(currentDocumentClass, fullFrame, property) {
1919
let documentFrame = fullFrame[currentDocumentClass]
2020

21-
if(util.isArrayTypeFromFrames(documentFrame, property)) {
21+
if(util.isArrayTypeFromFrames(documentFrame, property)) {
2222
// ARRAY TYPE
2323
return { [CONST.TYPE]: documentFrame[property][CONST.TYPE] , propertyFrame: documentFrame[property][CONST.CLASS] }
2424
}
@@ -56,9 +56,10 @@ function constructProps(fieldID, field, expanded, docConfig) {
5656

5757
let data = null, selectedForOneOf = null
5858
if(field === CONST.ONEOFVALUES) {
59-
let extractedData = getPropertyName(docConfig)
59+
/*let extractedData = getPropertyName(docConfig)
6060
data = extractedData.data
61-
selectedForOneOf=extractedData[CONST.ONEOF_SELECTED]
61+
selectedForOneOf=extractedData[CONST.ONEOF_SELECTED] */
62+
data = docConfig.formData
6263
}
6364
else data = docConfig.formData[field]
6465

@@ -84,9 +85,9 @@ function constructProps(fieldID, field, expanded, docConfig) {
8485
hideFieldLabel: false,
8586
mode: docConfig.mode
8687
}
87-
if(field === CONST.ONEOFVALUES) {
88+
/*if(field === CONST.ONEOFVALUES) {
8889
props[CONST.ONEOF_SELECTED] = selectedForOneOf
89-
}
90+
}*/
9091
return props
9192
}
9293

packages/tdb-documents-ui/src/helpers/fieldDisplay.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ export const getDisplay = (props, args, property) => {
1616
//(props, args, property, dataType, id, onChange)
1717
return display.displayDataTypesWidget(props, args, property, field, props.id, props.onChange) // review
1818
}
19+
else if(util.isArrayTypeFromFrames(documentFrame, property) && property !== CONST.COORDINATES_FIELD) {
20+
// ARRAY TYPES
21+
if(props.mode === CONST.VIEW && props.formData === "") return <div/>
22+
let id = props.id, linked_to=props.linked_to
23+
let extracted=args.reference[linked_to]
24+
let expand=props.isArray ? true : props.expand
25+
return display.displayArrayWidgets(props, args, extracted, property, expand, id, true, linked_to)
26+
}
1927
else if(util.isSubDocumentType(field)){
2028
// SUBDOCUMENT TYPE
2129
if(props.mode === CONST.VIEW && props.formData === "") return <div/>

packages/tdb-documents-ui/src/helpers/typeHelper.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ export const typeHelper = (documentFrame, property, fullFrame, isArray) => {
1414
return CONST.BOOLEAN_TYPE
1515
return CONST.STRING_TYPE
1616
}
17+
else if(util.isOneOfDataType(documentFrame, property)) {
18+
// ONE OF TYPE
19+
return [ CONST.STRING_TYPE, CONST.OBJECT_TYPE ]
20+
}
1721
else if(util.isSubDocumentType(field)){
1822
// SUBDOCUMENT TYPE
1923
//return [ "null", CONST.OBJECT_TYPE ]

packages/tdb-documents-ui/src/helpers/uiHelper.js

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -191,35 +191,36 @@ export const uiHelper = (args, property) => {
191191
else if(util.isOneOfDataType(documentFrame, property)) {
192192

193193
//field.map(subDocs => {
194-
let oneOfField = documentFrame[property][0]
195-
for(let choices in oneOfField) {
196-
let argsHolder={...args}
197-
if(oneOfField[choices].hasOwnProperty(CONST.CLASS)) {
198-
let linked_to=oneOfField[choices][CONST.CLASS]
199-
let extracted={}
200-
// if linked_to definition is not available in references
201-
if(!util.availableInReference(reference, linked_to)){
202-
let config=constructSubDocumentConfig(argsHolder, property, oneOfField[choices])
203-
extracted=getProperties(config)
204-
// add extracted documentation
205-
extracted.extractedDocumentation=argsHolder.extractedDocumentation
206-
207-
// check for SubDocument MetaData
208-
let metaDataType=util.fetchMetaData(documentFrame, property), expanded = false
209-
if(metaDataType) {
210-
// expecting JSON at this point
211-
expanded=metaDataType
212-
}
213-
// add extracted to references
214-
addToReference(args, extracted, linked_to)
215-
}
216-
else {
217-
// reference available
218-
extracted=reference[linked_to]
194+
let oneOfField = documentFrame[property]
195+
oneOfField.map(oneOf => {
196+
for(let choices in oneOf) {
197+
let argsHolder={...args}
198+
if(oneOf[choices].hasOwnProperty(CONST.CLASS)) {
199+
let linked_to=oneOf[choices][CONST.CLASS]
200+
let extracted={}
201+
// if linked_to definition is not available in references
202+
if(!util.availableInReference(reference, linked_to)){
203+
let config=constructSubDocumentConfig(argsHolder, property, oneOf[choices])
204+
extracted=getProperties(config)
205+
// add extracted documentation
206+
extracted.extractedDocumentation=argsHolder.extractedDocumentation
207+
208+
// check for SubDocument MetaData
209+
let metaDataType=util.fetchMetaData(documentFrame, property), expanded = false
210+
if(metaDataType) {
211+
// expecting JSON at this point
212+
expanded=metaDataType
213+
}
214+
// add extracted to references
215+
addToReference(args, extracted, linked_to)
216+
}
217+
else {
218+
// reference available
219+
extracted=reference[linked_to]
220+
}
219221
}
220222
}
221-
}
222-
223+
})
223224
return widget.getOneOfUIDisplay(args, property)
224225
}
225226
else if(util.isChoiceDocumentType(field, fullFrame)){

packages/tdb-documents-ui/src/mandatoryFrames.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ export function makeMandatoryFrames (args, property) {
3737
// assign default value if sys unit
3838
layout["default"]=[]
3939
}
40-
41-
40+
4241
let uiLayout = uiHelper(args, property)
4342

4443
return { layout, uiLayout }

packages/tdb-documents-ui/src/tests/constants/geoJSON.datatypes.constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ export const MULTI_POLYGON_DATA_TYPE_EDIT_DATA = {
500500
["51.52", "-0.12"]
501501
]
502502
],
503-
"type": "MultiPolygon"
503+
"type": "MultiPolygon"
504504
}
505505

506506
export const SUBDOCUMENT_LINE_STRING_CREATE_DATA = {

packages/tdb-documents-ui/src/tests/nestedLineString.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import '@testing-library/jest-dom'
66
import { logRoles } from '@testing-library/dom';
77
import selectEvent from 'react-select-event'
88
import { extractPropertyDocumentation } from '../helpers/widgetHelper';
9-
9+
1010
describe("Create a location with Line String", () => {
1111

1212
/**

0 commit comments

Comments
 (0)