@@ -17,6 +17,7 @@ import {useTDBDocuments} from "@terminusdb/terminusdb-documents-ui"
1717import { WOQLClientObj } from '../init-woql-client'
1818
1919import { PaginationControl } from 'react-bootstrap-pagination-control' ;
20+ import { MdAlternateEmail } from "react-icons/md"
2021/**
2122 *
2223 * @param {* } diff diff list
@@ -186,7 +187,7 @@ function DiffViewDocument ({documentID,diffObj, CRObject,propertyModifiedCount,f
186187 * @param {* } originBranchDocumentList document list of origin branch
187188 * @returns
188189 */
189- export const DiffView = ( { diffs, CRObject} ) => {
190+ export const DiffView_OLD = ( { diffs, CRObject, start , setStart } ) => {
190191 const { woqlClient} = WOQLClientObj ( )
191192
192193 // I need to copy the woqlClient and set the original_branch
@@ -199,7 +200,7 @@ export const DiffView = ({diffs, CRObject}) => {
199200 const [ activePage , setActivePage ] = useState ( 1 )
200201 const [ current , setCurrent ] = useState ( 0 )
201202
202- const [ page , setPage ] = useState ( 1 )
203+ const [ page , setPage ] = useState ( start )
203204
204205 let elements = [ ] , paginationItems = [ ]
205206
@@ -210,21 +211,22 @@ export const DiffView = ({diffs, CRObject}) => {
210211 } , [ ] )
211212 // function to handle on click of page
212213 function handlePagination ( number ) {
213- let position = DIFFS_PER_PAGE_LIMIT * ( number - 1 )
214+ alert ( number )
215+ /*let position=DIFFS_PER_PAGE_LIMIT * (number-1)
214216
215217 setCurrent(position)
216- setActivePage ( number )
218+ setActivePage(number) */
217219
218220 }
219221
220222 // populate pagination Item
221- for ( let number = 1 ; number <= divide ; number ++ ) {
223+ /* for (let number = 1; number <= divide; number++) {
222224 paginationItems.push(
223225 <Pagination.Item key={number} active={number === activePage} onClick={(e) => handlePagination(number)}>
224226 {number}
225227 </Pagination.Item>
226228 )
227- }
229+ }*/
228230
229231 if ( ! frames ) return < Loading message = { `Loading Frames ...` } />
230232 if ( ! diffs ) return < Loading message = { `Loading Diffs ...` } />
@@ -261,18 +263,88 @@ export const DiffView = ({diffs, CRObject}) => {
261263 < Row className = "w-100" >
262264 < Col />
263265 < 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- />
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+ }
275+
276+ /**
277+ *
278+ * @param {* } diffs diff list
279+ * @param {* } trackingBranchDocumentList document list of tracking branch
280+ * @param {* } originBranchDocumentList document list of origin branch
281+ * @returns
282+ */
283+ export const DiffView = ( { diffs, CRObject, start, setStart } ) => {
284+ const { woqlClient} = WOQLClientObj ( )
285+
286+ // I need to copy the woqlClient and set the original_branch
287+ // to get the right frame
288+ const woqlClientCopy = woqlClient . copy ( )
289+ woqlClientCopy . checkout ( CRObject . original_branch )
290+
291+ const { frames, getDocumentFrames} = useTDBDocuments ( woqlClientCopy )
292+
293+ let elements = [ ]
294+
295+
296+ useEffect ( ( ) => {
297+ getDocumentFrames ( )
298+ } , [ ] )
299+
300+ // function to handle on click of page
301+ function handlePagination ( action ) {
302+ if ( action === "next" ) {
303+ setStart ( start + DIFFS_PER_PAGE_LIMIT + 1 )
304+ }
305+ else {
306+ // previous
307+ if ( start ) setStart ( start - DIFFS_PER_PAGE_LIMIT - 1 )
308+ }
309+
310+ }
311+
312+ if ( ! frames ) return < Loading message = { `Loading Frames ...` } />
313+ if ( ! diffs ) return < Loading message = { `Loading Diffs ...` } />
314+
315+
316+ diffs . map ( ( diffItems , index ) => {
317+ const propertyModifiedCount = getPropertyModifiedCount ( diffItems )
318+ const diffObj = diffItems
319+ const action = diffObj [ "@op" ] || "Change"
320+ const actionKey = `@${ action . toLowerCase ( ) } `
321+ const eventKey = diffObj [ actionKey ] && diffObj [ actionKey ] [ "@id" ] ? diffObj [ actionKey ] [ "@id" ] : diffObj [ "@id" ]
322+ const docType = diffObj [ actionKey ] && diffObj [ actionKey ] [ "@type" ] ? diffObj [ actionKey ] [ "@type" ] : diffObj [ "@type" ]
323+
324+ // this are the diff panel for document
325+ elements . push (
326+ < React . Fragment key = { `item__${ index } ` } >
327+ < DiffViewDocument frames = { frames } key = { actionKey }
328+ action = { action }
329+ docType = { docType }
330+ propertyModifiedCount = { propertyModifiedCount }
331+ documentID = { eventKey }
332+ diffObj = { diffObj }
333+ CRObject = { CRObject } />
334+ </ React . Fragment >
335+ )
336+ } )
337+
338+
339+ return < React . Fragment >
340+ { elements }
341+ < Row className = "w-100" >
342+ < Col />
343+ < Col >
344+ < Pagination className = "justify-content-center " >
345+ < Pagination . Prev key = { "previous" } onClick = { ( e ) => handlePagination ( "previous" ) } />
346+ < Pagination . Next key = { "next" } onClick = { ( e ) => handlePagination ( "next" ) } />
347+ </ Pagination >
276348 </ Col >
277349 < Col />
278350 </ Row >
0 commit comments