@@ -10,6 +10,7 @@ import DeleteTuple from './DeleteTuple/DeleteTuple'
1010import TableAttributesInfo from './DataStorageClasses/TableAttributesInfo' ;
1111import TableAttribute from './DataStorageClasses/TableAttribute'
1212import TableAttributeType from './enums/TableAttributeType'
13+ import Restriction from './DataStorageClasses/Restriction'
1314
1415enum PaginationCommand {
1516 FORWARD ,
@@ -19,27 +20,23 @@ enum PaginationCommand {
1920}
2021
2122enum TableActionType {
22- FILTER = 0 ,
23- INSERT = 1 ,
24- UPDATE = 2 ,
25- DELETE = 3
23+ FILTER ,
24+ INSERT ,
25+ UPDATE ,
26+ DELETE
2627}
2728
2829type TableContentStatus = {
2930 currentSelectedTableActionMenu : TableActionType ,
3031 hideTableActionMenu : boolean ,
31- pageIncrement : number ,
32- paginatorState : Array < number > ,
33- selectedTableIndex : number ,
34- selectedTableEntry ?: { } , // Has to be an object with each attribute name as key cause the way tuple_buffer is handle in the subcomponents
32+ selectedTupleIndex : number ,
33+ selectedTuple ?: { } , // Has to be an object with each attribute name as key cause the way tuple_buffer is handle in the subcomponents
3534 showWarning : boolean , // text warning when duplicate selection is made for delete/update, most likely to be take out once disable checkbox feature is finished
3635 isDisabledCheckbox : boolean , // tells the UI to disable any other checkboxes once there is already a selection in delete/update mode
3736 headerWidth : number , // part of table column resizer feature
3837 dragStart : number , // part of table column resizer feature
3938 dragDistance : number , // part of table column resizer feature
4039 resizeIndex : any , // part of table column resizer feature
41- atEndPage : boolean , // tells the UI to disable certain pagination icons if user is on the last page
42- atStartPage : boolean // tells the UI to disable certain pagination icons if user is on the first page
4340}
4441
4542/**
@@ -59,38 +56,38 @@ class TableContent extends React.Component<{
5956 selectedTableName : string ,
6057 selectedTableType : TableType ,
6158 contentData : Array < any > ,
62- tableTotal : number ,
63- tableAttributesInfo ?: TableAttributesInfo ,
64- fetchTableContent : any } ,
59+ totalNumOfTuples : number ,
60+ currentPageNumber : number ,
61+ maxPageNumber : number ,
62+ tuplePerPage : number ,
63+ tableAttributesInfo ?: TableAttributesInfo ,
64+ setPageNumber : any ,
65+ setNumberOfTuplesPerPage : any ,
66+ fetchTableContent : any ,
67+ setRestrictions : ( restrictions : Array < Restriction > ) => void } ,
6568 TableContentStatus > {
6669 constructor ( props : any ) {
6770 super ( props ) ;
6871 this . state = {
6972 currentSelectedTableActionMenu : TableActionType . FILTER ,
7073 hideTableActionMenu : true ,
71- pageIncrement : 25 ,
72- paginatorState : [ 0 , 25 ] ,
73- selectedTableIndex : - 1 ,
74- selectedTableEntry : undefined ,
74+ selectedTupleIndex : - 1 ,
75+ selectedTuple : undefined ,
7576 showWarning : false ,
7677 isDisabledCheckbox : false ,
7778 headerWidth : 0 ,
7879 dragStart : 0 ,
7980 dragDistance : 0 ,
80- resizeIndex : undefined ,
81- atEndPage : false ,
82- atStartPage : true
81+ resizeIndex : undefined
8382 }
8483
8584 this . getCurrentTableActionMenuComponent = this . getCurrentTableActionMenuComponent . bind ( this ) ;
8685 this . getShowWarningComponent = this . getShowWarningComponent . bind ( this ) ;
87-
88- // TODO: use effect to add reference for table column styling
89- // cellRef: React.RefObject<HTMLTableDataCellElement>;
90- // this.cellRef = createRef<HTMLTableDataCellElement>()
91- // const [colRefs, setColRefs] = React.useState([]);
92- // React.useEffect(() => {
93- // })
86+ this . goToFirstPage = this . goToFirstPage . bind ( this ) ;
87+ this . goToLastPage = this . goToLastPage . bind ( this ) ;
88+ this . goForwardAPage = this . goForwardAPage . bind ( this ) ;
89+ this . goBackwardAPage = this . goBackwardAPage . bind ( this ) ;
90+ this . handleNumberOfTuplesPerPageChange = this . handleNumberOfTuplesPerPageChange . bind ( this ) ;
9491 }
9592
9693 /**
@@ -99,31 +96,13 @@ class TableContent extends React.Component<{
9996 * @param prevState
10097 */
10198 componentDidUpdate ( prevProps : any , prevState : any ) {
102- // check to see if contentData updated, if so, check length to update page info
103- if ( this . props . contentData !== prevProps . contentData ) {
104- // Update paginator state if contentData is less than 25
105- if ( this . props . contentData . length < 25 ) {
106- this . setState ( { paginatorState : [ 0 , this . props . contentData . length ] } )
107- } else {
108- this . setState ( { paginatorState : [ 0 , this . state . pageIncrement ] } ) // set to default increment of 25
109- }
110- }
111-
11299 // Break if the the selectedTable did not change
113100 if ( prevProps . selectedTableName === this . props . selectedTableName ) {
114101 return ;
115102 }
116103
117104 // Reset TableActionview
118- this . setState ( { currentSelectedTableActionMenu : TableActionType . FILTER , hideTableActionMenu : true , selectedTableEntry : undefined } ) ;
119-
120- // TODO: part of reference for table column width update
121- // console.log('cellRef: ', this.cellRef)
122- // let cellStyle
123- // if (this.cellRef.current) {
124- // cellStyle = getComputedStyle(this.cellRef.current)
125- // console.log('width: ', cellStyle.width)
126- // }
105+ this . setState ( { currentSelectedTableActionMenu : TableActionType . FILTER , hideTableActionMenu : true , selectedTuple : undefined } ) ;
127106 }
128107
129108 /**
@@ -141,59 +120,25 @@ class TableContent extends React.Component<{
141120 }
142121 }
143122
144- /**
145- * Function for paginating between data entries. Takes in forward/backward/start/end commands to set
146- * the page view state by increments (currently hardcoded on pageIncrement state) of 25 entries.
147- * @param cmd
148- */
149- handlePagination ( cmd : PaginationCommand ) {
150- // check to see if paginator needs to even run for pages with small entries, if not, break
151- if ( this . state . paginatorState [ 1 ] < this . state . pageIncrement ) {
152- this . setState ( { atStartPage : true , atEndPage : true } )
153- return ;
123+ goToFirstPage ( ) {
124+ this . props . setPageNumber ( 1 ) ;
125+ }
126+
127+ goToLastPage ( ) {
128+ this . props . setPageNumber ( this . props . maxPageNumber ) ;
129+ }
130+
131+ goForwardAPage ( ) {
132+ if ( this . props . currentPageNumber != this . props . maxPageNumber ) {
133+ this . props . setPageNumber ( this . props . currentPageNumber + 1 ) ;
154134 }
155135
156- // jump to beginning/end/next/previous page and update the page position and style status accordingly
157- if ( cmd === PaginationCommand . START ) {
158- this . setState ( { paginatorState : [ 0 , this . state . pageIncrement ] , atStartPage : true , atEndPage : false } )
159- }
160- else if ( cmd === PaginationCommand . END ) {
161- if ( this . props . contentData . length % this . state . pageIncrement > 0 ) {
162- this . setState ( { paginatorState : [ this . props . contentData . length - this . props . contentData . length % this . state . pageIncrement , this . props . contentData . length ] } )
163- }
164- else {
165- this . setState ( { paginatorState : [ this . props . contentData . length - this . state . pageIncrement , this . props . contentData . length ] } )
166- }
167- this . setState ( { atStartPage : false , atEndPage : true } )
168- }
169- else if ( cmd === PaginationCommand . FORWARD ) {
170- if ( this . state . paginatorState [ 1 ] + this . state . pageIncrement < this . props . contentData . length ) {
171- this . setState ( { paginatorState : [ this . state . paginatorState [ 0 ] + this . state . pageIncrement , this . state . paginatorState [ 1 ] + this . state . pageIncrement ] ,
172- atStartPage : false } )
173- }
174- else if ( this . props . contentData . length % this . state . pageIncrement > 0 ) {
175- this . setState ( { paginatorState : [ this . props . contentData . length - this . props . contentData . length % this . state . pageIncrement , this . props . contentData . length ] ,
176- atStartPage : false , atEndPage : true } )
177- }
178- else {
179- this . setState ( { paginatorState : [ this . props . contentData . length - this . state . pageIncrement , this . props . contentData . length ] ,
180- atStartPage : false , atEndPage : true } )
181- }
136+ }
137+
138+ goBackwardAPage ( ) {
139+ if ( this . props . currentPageNumber != 1 ) {
140+ this . props . setPageNumber ( this . props . currentPageNumber - 1 ) ;
182141 }
183- else if ( cmd === PaginationCommand . BACKWARD ) {
184- if ( this . state . paginatorState [ 0 ] - this . state . pageIncrement > 0 ) {
185- this . setState ( { paginatorState : [ this . state . paginatorState [ 0 ] - this . state . pageIncrement , this . state . paginatorState [ 0 ] ] ,
186- atEndPage : false } )
187- }
188- else if ( this . state . paginatorState [ 0 ] - this . state . pageIncrement === 0 ) {
189- this . setState ( { paginatorState : [ this . state . paginatorState [ 0 ] - this . state . pageIncrement , this . state . paginatorState [ 0 ] ] ,
190- atStartPage : true , atEndPage : false } )
191- }
192- else {
193- this . setState ( { paginatorState : [ 0 , this . state . pageIncrement ] ,
194- atStartPage : true , atEndPage : false } )
195- }
196- }
197142 }
198143
199144 /**
@@ -204,7 +149,7 @@ class TableContent extends React.Component<{
204149 return ( < div className = "actionMenuContainer" >
205150 < Filter
206151 tableAttributesInfo = { this . props . tableAttributesInfo }
207- fetchTableContent = { this . props . fetchTableContent }
152+ setRestrictions = { this . props . setRestrictions }
208153 />
209154 </ div > )
210155 }
@@ -217,7 +162,7 @@ class TableContent extends React.Component<{
217162 tableAttributesInfo = { this . props . tableAttributesInfo }
218163 fetchTableContent = { this . props . fetchTableContent }
219164 clearEntrySelection = { ( ) => this . handleSelectionClearRequest ( ) }
220- selectedTableEntry = { this . state . selectedTableEntry }
165+ selectedTableEntry = { this . state . selectedTuple }
221166 />
222167 </ div > )
223168 }
@@ -231,7 +176,7 @@ class TableContent extends React.Component<{
231176 tableAttributesInfo = { this . props . tableAttributesInfo }
232177 fetchTableContent = { this . props . fetchTableContent }
233178 clearEntrySelection = { ( ) => this . handleSelectionClearRequest ( ) }
234- selectedTableEntry = { this . state . selectedTableEntry }
179+ selectedTableEntry = { this . state . selectedTuple }
235180 />
236181 </ div > )
237182 }
@@ -246,7 +191,7 @@ class TableContent extends React.Component<{
246191 tableAttributesInfo = { this . props . tableAttributesInfo }
247192 fetchTableContent = { this . props . fetchTableContent }
248193 clearEntrySelection = { ( ) => this . handleSelectionClearRequest ( ) }
249- selectedTableEntry = { this . state . selectedTableEntry }
194+ selectedTableEntry = { this . state . selectedTuple }
250195 />
251196 </ div > )
252197 }
@@ -270,8 +215,8 @@ class TableContent extends React.Component<{
270215 }
271216
272217 // If the tupleIndex is already selected, deselect it
273- if ( tupleIndex === this . state . selectedTableIndex ) {
274- this . setState ( { selectedTableIndex : - 1 , selectedTableEntry : undefined } ) ;
218+ if ( tupleIndex === this . state . selectedTupleIndex ) {
219+ this . setState ( { selectedTupleIndex : - 1 , selectedTuple : undefined } ) ;
275220 return ;
276221 }
277222
@@ -303,7 +248,11 @@ class TableContent extends React.Component<{
303248
304249 // Covert array into object
305250
306- this . setState ( { selectedTableIndex : tupleIndex , selectedTableEntry : tupleBuffer } ) ;
251+ this . setState ( { selectedTupleIndex : tupleIndex , selectedTuple : tupleBuffer } ) ;
252+ }
253+
254+ handleNumberOfTuplesPerPageChange ( event : any ) {
255+ this . props . setNumberOfTuplesPerPage ( event . target . value )
307256 }
308257
309258 /**
@@ -320,7 +269,7 @@ class TableContent extends React.Component<{
320269 * Clears the staging once delete/update is successful and table content has been modified
321270 */
322271 handleSelectionClearRequest ( ) {
323- this . setState ( { selectedTableIndex : - 1 , selectedTableEntry : undefined } ) ;
272+ this . setState ( { selectedTupleIndex : - 1 , selectedTuple : undefined } ) ;
324273 }
325274
326275 /**
@@ -499,14 +448,14 @@ class TableContent extends React.Component<{
499448 </ tr >
500449 </ thead >
501450 < tbody >
502- { this . props . contentData . slice ( this . state . paginatorState [ 0 ] , this . state . paginatorState [ 1 ] ) . map ( ( entry : any , tupleIndex : number ) => {
451+ { this . props . contentData . map ( ( entry : any , tupleIndex : number ) => {
503452 return ( < tr key = { entry } className = "tableRow" onMouseMove = { ( event ) => { this . cellResizeMouseMove ( event ) } } onMouseUp = { ( event ) => { this . cellResizeMouseUp ( event ) } } >
504453 < td colSpan = { 1 } >
505454 < input type = "checkbox"
506455 // disable multiple check for insert mode as well until multiple insert is supported.
507- disabled = { this . state . selectedTableIndex > - 1 && this . state . selectedTableIndex !== tupleIndex }
456+ disabled = { this . state . selectedTupleIndex > - 1 && this . state . selectedTupleIndex !== tupleIndex }
508457 onChange = { ( event ) => this . handleCheckedEntry ( event , tupleIndex ) }
509- checked = { this . state . selectedTableIndex === tupleIndex } />
458+ checked = { this . state . selectedTupleIndex === tupleIndex } />
510459 </ td >
511460 { entry . map ( ( column : any , index : number ) => {
512461 return (
@@ -520,16 +469,21 @@ class TableContent extends React.Component<{
520469 </ table >
521470 </ div >
522471 < div className = "paginator" >
523- < p > Total Table Entries: { this . props . tableTotal } </ p >
524- { Object . entries ( this . props . contentData ) . length ?
525- < div className = "controls" >
526- < FontAwesomeIcon className = { ! this . state . atStartPage ? "backAll icon" : "backAll icon disabled" } icon = { faStepBackward } onClick = { ( ) => this . handlePagination ( PaginationCommand . START ) } />
527- < FontAwesomeIcon className = { ! this . state . atStartPage ? "backOne icon" : "backOne icon disabled" } icon = { faChevronLeft } onClick = { ( ) => this . handlePagination ( PaginationCommand . BACKWARD ) } />
528- Currently viewing: { this . state . paginatorState [ 0 ] + 1 } - { this . state . paginatorState [ 1 ] }
529- < FontAwesomeIcon className = { ! this . state . atEndPage ? "forwardOne icon" : "forwardOne icon disabled" } icon = { faChevronRight } onClick = { ( ) => this . handlePagination ( PaginationCommand . FORWARD ) } />
530- < FontAwesomeIcon className = { ! this . state . atEndPage ? "forwardAll icon" : "forwardAll icon disabled" } icon = { faStepForward } onClick = { ( ) => this . handlePagination ( PaginationCommand . END ) } />
472+ < p > Total Table Entries: { this . props . totalNumOfTuples } </ p >
473+ < div className = "number-of-rows-per-page-input" >
474+ < p > Number of row per page</ p >
475+ < input type = 'number' value = { this . props . tuplePerPage } onChange = { this . handleNumberOfTuplesPerPageChange } > </ input >
531476 </ div >
532- : '' }
477+ { Object . entries ( this . props . contentData ) . length ?
478+ < div className = "controls" >
479+ < FontAwesomeIcon className = { true ? "backAll icon" : "backAll icon disabled" } icon = { faStepBackward } onClick = { ( ) => this . goToFirstPage ( ) } />
480+ < FontAwesomeIcon className = { true ? "backOne icon" : "backOne icon disabled" } icon = { faChevronLeft } onClick = { ( ) => this . goBackwardAPage ( ) } />
481+ Page: ({ this . props . currentPageNumber + ' / ' + this . props . maxPageNumber } )
482+ < FontAwesomeIcon className = { true ? "forwardOne icon" : "forwardOne icon disabled" } icon = { faChevronRight } onClick = { ( ) => this . goForwardAPage ( ) } />
483+ < FontAwesomeIcon className = { true ? "forwardAll icon" : "forwardAll icon disabled" } icon = { faStepForward } onClick = { ( ) => this . goToLastPage ( ) } />
484+ </ div >
485+ : ''
486+ }
533487 </ div >
534488 </ div >
535489 </ div >
0 commit comments