Skip to content

Commit 9a3af89

Browse files
Merge pull request #217 from terminusdb/oneOfFix
One of fix
2 parents 78f494b + 710177e commit 9a3af89

File tree

18 files changed

+311
-142
lines changed

18 files changed

+311
-142
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export const AboutDataProduct = ({dataProductDetails, setShowDeleteModal, setSho
9696
<Card className="bg-transparent p-1 mb-5 tdb__align__container" border="muted">
9797
<Card.Body>
9898
<h4 className="text-light mb-3 fw-bold">About</h4>
99+
99100
{dataProductDetails.comment!== 'false' && <span className="text-light mb-4 ">
100101
{dataProductDetails.comment}
101102
</span>}
@@ -145,10 +146,10 @@ export const AboutDataProduct = ({dataProductDetails, setShowDeleteModal, setSho
145146
</span>
146147
{accessControlDashboard && accessControlDashboard.createDB() && <Fragment>
147148
<div className="w-100 d-block align-items-center gx-0">
148-
<Button variant="secondary"
149+
<Button variant="light"
149150
id="update_database"
150151
title={`Update Data Product ${dataProduct} info`}
151-
className=" btn btn-lg h2 fw-bold w-100 mt-4"
152+
className=" btn btn-md h4 w-100 mt-4 text-dark"
152153
onClick={showUpdateHandler}>
153154
Update Dataproduct details
154155
</Button>

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,14 @@ export const ChangeDiffComponent = () => {
5858
currentCRObject
5959
} = WOQLClientObj()
6060

61-
const {getDiffList,error:errorMsg,loading,result} = DocumentHook()
61+
const {getDiffList,error:errorMsg,loading,result} = DocumentHook()
6262

6363
const [key, setKey] = useState(DIFFS)
64+
const [start, setStart] = useState(0)
6465

6566
useEffect(() => {
66-
getDiffList(changeid)
67-
}, [])
67+
getDiffList(changeid, start)
68+
}, [start])
6869

6970

7071
if(!client) return <div/>
@@ -98,7 +99,7 @@ export const ChangeDiffComponent = () => {
9899
<Card.Body>
99100
{currentCRObject.status === SUBMITTED &&
100101
<ReviewComponent/> }
101-
<DiffView diffs={result} CRObject={currentCRObject}/>
102+
<DiffView diffs={result} CRObject={currentCRObject} start={start} setStart={setStart}/>
102103
</Card.Body>
103104
</Card>
104105
</Tab>

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

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {useTDBDocuments} from "@terminusdb/terminusdb-documents-ui"
1717
import {WOQLClientObj} from '../init-woql-client'
1818

1919
import { PaginationControl } from 'react-bootstrap-pagination-control';
20+
import { MdAlternateEmail } from "react-icons/md"
2021
/**
2122
*
2223
* @param {*} diff diff list
@@ -179,14 +180,15 @@ function DiffViewDocument ({documentID,diffObj, CRObject,propertyModifiedCount,f
179180
</Accordion>
180181
}
181182

183+
182184
/**
183185
*
184186
* @param {*} diffs diff list
185187
* @param {*} trackingBranchDocumentList document list of tracking branch
186188
* @param {*} originBranchDocumentList document list of origin branch
187189
* @returns
188190
*/
189-
export const DiffView = ({diffs, CRObject}) => {
191+
export const DiffView = ({diffs, CRObject, start, setStart }) => {
190192
const {woqlClient} = WOQLClientObj()
191193

192194
// I need to copy the woqlClient and set the original_branch
@@ -195,56 +197,41 @@ export const DiffView = ({diffs, CRObject}) => {
195197
woqlClientCopy.checkout(CRObject.original_branch)
196198

197199
const {frames,getDocumentFrames} = useTDBDocuments(woqlClientCopy)
198-
// pagination constants
199-
const [activePage, setActivePage]=useState(1)
200-
const [current, setCurrent]=useState(0)
201-
202-
const [page, setPage] = useState(1)
203-
204-
let elements=[], paginationItems=[]
205200

206-
let divide = Math.ceil(diffs.length/DIFFS_PER_PAGE_LIMIT)
201+
let elements=[]
207202

203+
208204
useEffect(() => {
209205
getDocumentFrames()
210206
},[])
207+
211208
// function to handle on click of page
212-
function handlePagination(number) {
213-
let position=DIFFS_PER_PAGE_LIMIT * (number-1)
214-
215-
setCurrent(position)
216-
setActivePage(number)
209+
function handlePagination(action) {
210+
if(action === "next") {
211+
setStart(start+DIFFS_PER_PAGE_LIMIT+1)
212+
}
213+
else {
214+
// previous
215+
if(start) setStart(start-DIFFS_PER_PAGE_LIMIT-1)
216+
}
217217

218218
}
219219

220-
// populate pagination Item
221-
for (let number = 1; number <= divide; number++) {
222-
paginationItems.push(
223-
<Pagination.Item key={number} active={number === activePage} onClick={(e) => handlePagination(number)}>
224-
{number}
225-
</Pagination.Item>
226-
)
227-
}
228-
229220
if(!frames) return <Loading message={`Loading Frames ...`}/>
230221
if(!diffs) return <Loading message={`Loading Diffs ...`}/>
231222

232-
233-
// looping through diff lists
234-
for(let start=current; start<(current + DIFFS_PER_PAGE_LIMIT); start++) {
235-
236-
if(start >= diffs.length) continue
237-
238-
const propertyModifiedCount = getPropertyModifiedCount(diffs[start])
239-
const diffObj = diffs[start]
223+
224+
diffs.map((diffItems, index) => {
225+
const propertyModifiedCount = getPropertyModifiedCount(diffItems)
226+
const diffObj = diffItems
240227
const action = diffObj["@op"] || "Change"
241228
const actionKey = `@${action.toLowerCase()}`
242229
const eventKey= diffObj[actionKey] && diffObj[actionKey]["@id"] ? diffObj[actionKey]["@id"] : diffObj["@id"]
243230
const docType = diffObj[actionKey] && diffObj[actionKey]["@type"] ? diffObj[actionKey]["@type"] : diffObj["@type"]
244231

245232
// this are the diff panel for document
246233
elements.push(
247-
<React.Fragment key={`item__${start}`}>
234+
<React.Fragment key={`item__${index}`}>
248235
<DiffViewDocument frames={frames} key={actionKey}
249236
action={action}
250237
docType={docType}
@@ -254,25 +241,18 @@ export const DiffView = ({diffs, CRObject}) => {
254241
CRObject={CRObject}/>
255242
</React.Fragment>
256243
)
257-
}
244+
})
245+
258246

259247
return <React.Fragment>
260248
{elements}
261249
<Row className="w-100">
262250
<Col/>
263251
<Col>
264-
{/*<Pagination className="justify-content-center ">{paginationItems}</Pagination>*/}
265-
<PaginationControl
266-
page={page}
267-
between={3}
268-
total={diffs.length}
269-
limit={5}
270-
changePage={(page) => {
271-
setPage(page)
272-
handlePagination(page)
273-
}}
274-
ellipsis={1}
275-
/>
252+
<Pagination className="justify-content-center ">
253+
<Pagination.Prev key={"previous"} onClick={(e) => handlePagination("previous")}/>
254+
<Pagination.Next key={"next"} onClick={(e) => handlePagination("next")}/>
255+
</Pagination>
276256
</Col>
277257
<Col/>
278258
</Row>

packages/tdb-dashboard/src/hooks/DocumentHook.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, {useState,useEffect} from "react";
22
import { WOQLClientObj } from "../init-woql-client";
3+
import { DIFFS_PER_PAGE_LIMIT } from "../components/constants"
34

45
export function DocumentHook(){
56
const {woqlClient,currentChangeRequest} = WOQLClientObj()
@@ -50,9 +51,9 @@ export function DocumentHook(){
5051
}finally{setLoading(false)}
5152
}
5253

53-
async function getDiffList(changeRequestID,start=0,count=5) {
54+
async function getDiffList(changeRequestID, start=0, count=DIFFS_PER_PAGE_LIMIT) {
5455
try{
55-
const client = woqlClient.copy()
56+
const client = woqlClient.copy()
5657
client.connectionConfig.api_extension = 'api/'
5758
const baseUrl = client.connectionConfig.dbBase("changes")
5859
const result = await client.sendCustomRequest("GET", `${baseUrl}/${changeRequestID}/diff?count=${count}&start=${start}`)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ export const ChangeRequestsPage = () => {
196196
<div className="ms-2 me-auto">
197197
<div className="fw-bold text-success">
198198
{name}
199-
<span class="text-dark ml-1 badge badge-info mr-1">{item.tracking_branch}</span>
199+
<span class="text-dark ml-1 badge bg-light mr-1">{item.tracking_branch}</span>
200200
from branch
201-
<span class="text-dark ml-1 badge badge-success">{item.original_branch}</span>
201+
<span class="text-dark ml-1 badge bg-success">{item.original_branch}</span>
202202

203203
</div>
204204
<div className="text-gray font-italic">

packages/tdb-documents-ui-template/src/components/JsonFrameViewer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export const JsonFrameViewer = ({type, jsonData, mode, setExtracted}) => {
6565
// onBlur
6666
return <React.Fragment>
6767
<CodeMirror
68-
value={JSON.stringify(data, null, 2)}
68+
value={JSON.stringify(!data ? {} : data, null, 2)}
6969
options={cmOptions}
7070
className={"document__interface__main"}
7171
onBlur={(editor, data, value) => {

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/>

0 commit comments

Comments
 (0)