@@ -15,6 +15,7 @@ import BlockView from '../View/BlockView';
15
15
import TransactionView from '../View/TransactionView' ;
16
16
import MultiSelect from '../Styled/MultiSelect' ;
17
17
import DatePicker from '../Styled/DatePicker' ;
18
+ import SearchIcon from "@material-ui/icons/Search" ;
18
19
import {
19
20
blockListSearchType ,
20
21
blockRangeSearchType ,
@@ -25,6 +26,12 @@ import {
25
26
txnListType
26
27
} from '../types' ;
27
28
import { FormHelperText , TablePagination , TextField } from '@mui/material' ;
29
+ import {
30
+ MenuItem ,
31
+ Select
32
+ } from "@material-ui/core" ;
33
+ import { reg , rowsPerPageOptions , rangeLimitOptions , defaultRangeLimit , E001 , E002 , E003 , E004 , E005 } from "./constants" ;
34
+ import { Info } from "@material-ui/icons" ;
28
35
29
36
/* istanbul ignore next */
30
37
const styles = theme => {
@@ -36,6 +43,21 @@ const styles = theme => {
36
43
overflow : 'visible !important'
37
44
}
38
45
} ,
46
+ htinputs : {
47
+ display : "flex" ,
48
+ marginBottom : "15px" ,
49
+ position : "relative"
50
+ } ,
51
+ errorText : {
52
+ width : "100%" ,
53
+ position : "absolute" ,
54
+ left : "0px" ,
55
+ bottom : "-20px" ,
56
+ cursor : 'default'
57
+ } ,
58
+ startBlock : {
59
+ marginRight : "5px"
60
+ } ,
39
61
partialHash : {
40
62
textAlign : 'center' ,
41
63
position : 'relative !important' ,
@@ -103,7 +125,8 @@ const styles = theme => {
103
125
blockRangeRow : {
104
126
marginBottom : '10px !important' ,
105
127
marginLeft : '10px !important' ,
106
- justifyContent : 'space-around' ,
128
+ minWidth : "25vw" ,
129
+ // justifyContent: 'space-around',
107
130
'& > div' : {
108
131
marginRight : '10px'
109
132
} ,
@@ -121,6 +144,10 @@ const styles = theme => {
121
144
width : '40% !important'
122
145
}
123
146
} ,
147
+ iconButton : {
148
+ color : "#21295c" ,
149
+ alignSelf : "center"
150
+ }
124
151
} ;
125
152
} ;
126
153
const tablePaginationStyle = {
@@ -133,11 +160,7 @@ const tablePaginationStyle = {
133
160
alignItems : 'baseline'
134
161
}
135
162
} ;
136
- const rowsPerPageOptions = [ 5 , 10 , 25 , 50 , 100 ] ;
137
- const reg = new RegExp ( '^[0-9]{0,9}$' ) ;
138
163
let timer ;
139
- const E001 = 'Please enter valid Block Height' ;
140
- const E002 = 'Second number should be greater than first number' ;
141
164
export class Blocks extends Component {
142
165
constructor ( props ) {
143
166
super ( props ) ;
@@ -162,6 +185,7 @@ export class Blocks extends Component {
162
185
endBlock : '' ,
163
186
rangeErr : '' ,
164
187
brs : false ,
188
+ rangeLimit : defaultRangeLimit
165
189
} ;
166
190
}
167
191
@@ -193,7 +217,7 @@ export class Blocks extends Component {
193
217
this . searchBlockList ( this . props . currentChannel ) ;
194
218
}
195
219
if (
196
- prevState . page != this . state . page ||
220
+ ( ! this . state . brs && prevState . page != this . state . page ) ||
197
221
prevState . rowsPerPage != this . state . rowsPerPage ||
198
222
this . state . searchClick
199
223
) {
@@ -204,11 +228,6 @@ export class Blocks extends Component {
204
228
if ( prevProps . blockRangeLoaded != this . props . blockRangeLoaded ) {
205
229
if ( this . props . blockRangeLoaded ) {
206
230
if ( typeof this . props . blockRangeSearch === 'string' ) { this . setState ( { rangeErr : this . props . blockRangeSearch } ) }
207
- else {
208
- if ( this . state . rangeErr && this . state . rangeErr !== E001 && this . state . rangeErr != E002 ) {
209
- this . setState ( { rangeErr : '' } )
210
- }
211
- }
212
231
} else {
213
232
if ( this . state . rangeErr )
214
233
this . setState ( { rangeErr : '' } )
@@ -319,8 +338,16 @@ export class Blocks extends Component {
319
338
} ) ;
320
339
return ;
321
340
}
341
+ if ( this . state . endBlock - this . state . startBlock >= this . state . rangeLimit ) {
342
+ if ( this . state . rangeLimit < 100 ) {
343
+ this . setState ( { rangeErr : E004 ( this . state . rangeLimit ) } ) ;
344
+ } else {
345
+ this . setState ( { rangeErr : E003 } ) ;
346
+ }
347
+ return ;
348
+ }
322
349
this . searchBlockRange ( ) ;
323
- this . setState ( { search : true , brs : true } ) ;
350
+ this . setState ( { search : true , brs : true , page : 0 } ) ;
324
351
} ;
325
352
handleClearSearch = ( ) => {
326
353
if ( this . interval !== undefined ) {
@@ -538,11 +565,26 @@ export class Blocks extends Component {
538
565
] ;
539
566
540
567
render ( ) {
541
- const blockList = this . state . brs ?
542
- ( typeof this . props . blockRangeSearch !== 'string' && this . props . blockRangeLoaded ? this . props . blockRangeSearch : [ ] )
543
- : this . props . blockListSearch
544
- const noOfPages = this . props . blockListSearchTotalPages ;
545
- const { transaction, txnList, classes } = this . props ;
568
+ const reversedBlockRangeList =
569
+ typeof this . props . blockRangeSearch !== "string" &&
570
+ this . props . blockRangeLoaded
571
+ ? this . props . blockRangeSearch
572
+ . slice ( )
573
+ . sort ( )
574
+ . reverse ( )
575
+ : [ ] ;
576
+ const blockList = this . state . brs
577
+ ? reversedBlockRangeList . slice (
578
+ this . state . page * this . state . rowsPerPage ,
579
+ ( this . state . page + 1 ) * this . state . rowsPerPage
580
+ )
581
+ : this . props . blockListSearch ;
582
+ const noOfPages = this . state . brs
583
+ ? typeof this . props . blockRangeSearch !== "string" &&
584
+ this . props . blockRangeLoaded &&
585
+ Math . ceil ( this . props . blockRangeSearch . length / this . state . rowsPerPage )
586
+ : this . props . blockListSearchTotalPages ;
587
+ const { transaction, txnList, classes } = this . props ;
546
588
const { blockHash, dialogOpen, dialogOpenBlockHash } = this . state ;
547
589
return (
548
590
< div >
@@ -658,48 +700,85 @@ export class Blocks extends Component {
658
700
</ div >
659
701
< form onSubmit = { this . handleRangeSubmit } >
660
702
< div className = { `${ classes . filter } row searchRow` } >
661
- < span className = { classes . text } > Block Height:</ span >
662
- < div
663
- className = { `${ classes . filterElement } col-md-3 ${ classes . blockRangeRow } ` }
703
+ < span className = { classes . text } >
704
+ No of Blocks
705
+ < sup title = { E005 } style = { { padding : "3px" } } >
706
+ < Info style = { { fontSize : "medium" } } />
707
+ </ sup >
708
+ </ span >
709
+ < Select
710
+ id = 'rangeLimitDropdown'
711
+ className = 'rangeLimitDropdown'
712
+ value = { this . state . rangeLimit }
713
+ onChange = { e => this . setState ( { rangeLimit : e . target . value } ) }
714
+ displayEmpty
715
+ inputProps = { { "aria-label" : "Without label" } }
716
+ disableUnderline
664
717
>
665
- < TextField
666
- type = "text"
667
- name = "startBlock"
668
- value = { this . state . startBlock }
669
- onChange = { e => this . handleRangeChange ( e ) }
670
- variant = "standard"
671
- InputLabelProps = { { shrink : true } }
672
- label = "From"
673
- error = { Boolean ( this . state . rangeErr ) }
674
- size = "small"
675
- />
676
- < TextField
677
- type = "text"
678
- name = "endBlock"
679
- value = { this . state . endBlock }
680
- onChange = { e => this . handleRangeChange ( e ) }
681
- variant = "standard"
682
- InputLabelProps = { { shrink : true } }
683
- label = "To"
684
- error = { Boolean ( this . state . rangeErr ) }
685
- size = "small"
686
- />
687
- </ div >
718
+ { rangeLimitOptions . map ( opt => (
719
+ < MenuItem
720
+ key = { opt }
721
+ value = { opt }
722
+ >
723
+ { opt }
724
+ </ MenuItem >
725
+ ) ) }
726
+ </ Select >
727
+
688
728
< div
689
- className = { classes . iconButton }
690
- type = "submit"
691
- onClick = { e => this . handleRangeSubmit ( e ) }
729
+ className = { `${ classes . filterElement } ${ classes . blockRangeRow } ` }
730
+ style = { { width : "50vw" } }
692
731
>
693
- < SearchIcon />
732
+ < div style = { { whiteSpace : "no-wrap" , alignSelf : "center" } } >
733
+ Block No:
734
+ </ div >
735
+ < div className = { classes . htinputs } >
736
+ < TextField
737
+ type = "text"
738
+ name = "startBlock"
739
+ className = { classes . startBlock }
740
+ id = 'startBlock'
741
+ style = { { marginRight : "5px" } }
742
+ value = { this . state . startBlock }
743
+ onChange = { e => this . handleRangeChange ( e ) }
744
+ variant = "standard"
745
+ InputLabelProps = { { shrink : true } }
746
+ label = "From"
747
+ error = { Boolean ( this . state . rangeErr ) }
748
+ size = "small"
749
+ />
750
+ < TextField
751
+ type = "text"
752
+ name = "endBlock"
753
+ id = 'endBlock'
754
+ value = { this . state . endBlock }
755
+ onChange = { e => this . handleRangeChange ( e ) }
756
+ variant = "standard"
757
+ InputLabelProps = { { shrink : true } }
758
+ label = "To"
759
+ error = { Boolean ( this . state . rangeErr ) }
760
+ size = "small"
761
+ />
762
+ < div className = { `${ classes . errorText } ` } >
763
+ {
764
+ < FormHelperText title = { this . state . rangeErr }
765
+ style = { { color : "rgb(211, 47, 47)" , whiteSpace : "nowrap" , overflow :'hidden' , textOverflow :'ellipsis' } }
766
+ >
767
+ { this . state . rangeErr }
768
+ </ FormHelperText >
769
+ }
770
+ </ div >
771
+ </ div >
772
+ < div
773
+ id = 'blockRangeSearchIcon'
774
+ className = { classes . iconButton }
775
+ type = "submit"
776
+ onClick = { e => this . handleRangeSubmit ( e ) }
777
+ >
778
+ < SearchIcon />
779
+ </ div >
694
780
</ div >
695
781
</ div >
696
- < div className = { `${ classes . filter } row searchRow` } >
697
- { this . state . rangeErr && (
698
- < FormHelperText style = { { marginLeft : '120px' , color : 'rgb(211, 47, 47)' } } >
699
- { this . state . rangeErr }
700
- </ FormHelperText >
701
- ) }
702
- </ div >
703
782
</ form >
704
783
< ReactTable
705
784
data = { blockList || [ ] }
@@ -725,7 +804,7 @@ export class Blocks extends Component {
725
804
style = { { height : '750px' } }
726
805
showPaginationBottom = { false }
727
806
/>
728
- { ( blockList ?. length > 0 && ! this . state . brs ) && (
807
+ { blockList ?. length > 0 && (
729
808
< TablePagination
730
809
page = { this . state . page }
731
810
sx = { tablePaginationStyle }
0 commit comments