1
- import React , { useRef } from 'react'
1
+ import React , { useRef , useMemo , useState } from 'react'
2
2
import { useSelector } from 'react-redux'
3
3
import { ExportCsvButton , ExportPDFButton } from 'src/components/buttons'
4
4
import {
@@ -25,16 +25,9 @@ import { cellGenericFormatter } from './CellGenericFormat'
25
25
import { ModalService } from '../utilities'
26
26
import { useLazyGenericGetRequestQuery , useLazyGenericPostRequestQuery } from 'src/store/api/app'
27
27
import { ConfirmModal } from '../utilities/SharedModal'
28
- import { useState } from 'react '
28
+ import { debounce } from 'lodash '
29
29
30
- const FilterComponent = ( {
31
- filterText,
32
- onFilter,
33
- onClear,
34
- filterlist,
35
- onFilterPreset,
36
- onFilterGraph,
37
- } ) => (
30
+ const FilterComponent = ( { filterText, onFilter, onClear, filterlist, onFilterPreset } ) => (
38
31
< >
39
32
< CInputGroup >
40
33
< CDropdown variant = "input-group" >
@@ -50,26 +43,17 @@ const FilterComponent = ({
50
43
< CDropdownItem
51
44
onClick = { ( ) => {
52
45
onFilterPreset ( '' )
53
- onFilterGraph ( '' )
54
46
} }
55
47
>
56
48
Clear Filter
57
49
</ CDropdownItem >
58
50
{ filterlist &&
59
51
filterlist . map ( ( item , idx ) => {
60
- if ( item . hasOwnProperty ( 'graphFilter' ) && item . graphFilter == true ) {
61
- return (
62
- < CDropdownItem key = { idx } onClick = { ( ) => onFilterGraph ( item . filter ) } >
63
- { item . filterName }
64
- </ CDropdownItem >
65
- )
66
- } else {
67
- return (
68
- < CDropdownItem key = { idx } onClick = { ( ) => onFilterPreset ( item . filter ) } >
69
- { item . filterName }
70
- </ CDropdownItem >
71
- )
72
- }
52
+ return (
53
+ < CDropdownItem key = { idx } onClick = { ( ) => onFilterPreset ( item . filter ) } >
54
+ { item . filterName }
55
+ </ CDropdownItem >
56
+ )
73
57
} ) }
74
58
</ CDropdownMenu >
75
59
</ CDropdown >
@@ -93,7 +77,6 @@ FilterComponent.propTypes = {
93
77
onClear : PropTypes . func ,
94
78
filterlist : PropTypes . arrayOf ( PropTypes . object ) ,
95
79
onFilterPreset : PropTypes . func ,
96
- onFilterGraph : PropTypes . func ,
97
80
}
98
81
99
82
const customSort = ( rows , selector , direction ) => {
@@ -204,8 +187,23 @@ export default function CippTable({
204
187
return string . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, '\\$&' )
205
188
}
206
189
190
+ const setGraphFilter = ( e ) => {
191
+ if ( graphFilterFunction ) {
192
+ graphFilterFunction ( e )
193
+ console . log ( e )
194
+ }
195
+ }
196
+
197
+ const debounceSetGraphFilter = useMemo ( ( ) => {
198
+ return debounce ( setGraphFilter , 1000 )
199
+ } , [ ] )
200
+
207
201
const filterData = ( data , filterText ) => {
208
- if ( filterText . startsWith ( 'Complex:' ) ) {
202
+ if ( filterText . startsWith ( 'Graph:' ) ) {
203
+ var query = filterText . slice ( 6 ) . trim ( )
204
+ debounceSetGraphFilter ( query )
205
+ return data
206
+ } else if ( filterText . startsWith ( 'Complex:' ) ) {
209
207
const conditions = filterText . slice ( 9 ) . split ( ';' )
210
208
211
209
return conditions . reduce ( ( filteredData , condition ) => {
@@ -262,12 +260,6 @@ export default function CippTable({
262
260
setFilterText ( e . target . value )
263
261
}
264
262
265
- const setGraphFilter = ( e ) => {
266
- if ( graphFilterFunction ) {
267
- graphFilterFunction ( e )
268
- }
269
- }
270
-
271
263
useEffect ( ( ) => {
272
264
if ( columns !== updatedColumns ) {
273
265
setUpdatedColumns ( columns )
@@ -592,11 +584,6 @@ export default function CippTable({
592
584
onFilter = { ( e ) => setFilterText ( e . target . value ) }
593
585
onFilterPreset = { ( e ) => {
594
586
setFilterText ( e )
595
- setGraphFilter ( '' )
596
- } }
597
- onFilterGraph = { ( e ) => {
598
- setFilterText ( '' )
599
- setGraphFilter ( e )
600
587
} }
601
588
onClear = { handleClear }
602
589
filterText = { filterText }
@@ -620,65 +607,61 @@ export default function CippTable({
620
607
const tablePageSize = useSelector ( ( state ) => state . app . tablePageSize )
621
608
return (
622
609
< div className = "ms-n3 me-n3 cipp-tablewrapper" >
623
- { ! isFetching && error && < span > Error loading data</ span > }
624
- { ! error && (
625
- < div >
626
- { ( columns . length === updatedColumns . length || ! dynamicColumns ) && (
627
- < >
628
- { ( massResults . length >= 1 || loopRunning ) && (
629
- < CCallout color = "info" >
630
- { massResults . map ( ( message , idx ) => {
631
- const results = message . data ?. Results
632
- const displayResults = Array . isArray ( results ) ? results . join ( ', ' ) : results
610
+ { ! isFetching && error && < CCallout color = "info" > Error loading data</ CCallout > }
611
+ < div >
612
+ { ( columns . length === updatedColumns . length || ! dynamicColumns ) && (
613
+ < >
614
+ { ( massResults . length >= 1 || loopRunning ) && (
615
+ < CCallout color = "info" >
616
+ { massResults . map ( ( message , idx ) => {
617
+ const results = message . data ?. Results
618
+ const displayResults = Array . isArray ( results ) ? results . join ( ', ' ) : results
633
619
634
- return < li key = { `message-${ idx } ` } > { displayResults } </ li >
635
- } ) }
636
- { loopRunning && (
637
- < li >
638
- < CSpinner size = "sm" />
639
- </ li >
640
- ) }
641
- </ CCallout >
642
- ) }
643
- < DataTable
644
- customStyles = { customStyles }
645
- className = "cipp-table"
646
- theme = { theme }
647
- subHeader = { subheader }
648
- selectableRows = { selectableRows }
649
- onSelectedRowsChange = {
650
- onSelectedRowsChange ? onSelectedRowsChange : handleSelectedChange
651
- }
652
- subHeaderComponent = { subHeaderComponentMemo }
653
- subHeaderAlign = "left"
654
- paginationResetDefaultPage = { resetPaginationToggle }
655
- //actions={actionsMemo}
656
- pagination = { pagination }
657
- responsive = { responsive }
658
- dense = { dense }
659
- striped = { striped }
660
- columns = { columns }
661
- data = { filteredItems }
662
- expandableRows = { expandableRows }
663
- expandableRowsComponent = { expandableRowsComponent }
664
- highlightOnHover = { highlightOnHover }
665
- expandOnRowClicked = { expandOnRowClicked }
666
- defaultSortAsc
667
- defaultSortFieldId = { 1 }
668
- sortFunction = { customSort }
669
- paginationPerPage = { tablePageSize }
670
- progressPending = { isFetching }
671
- progressComponent = { < CSpinner color = "info" component = "div" /> }
672
- paginationRowsPerPageOptions = { [ 25 , 50 , 100 , 200 , 500 ] }
673
- { ...rest }
674
- />
675
- { selectedRows . length >= 1 && (
676
- < CCallout > Selected { selectedRows . length } items</ CCallout >
677
- ) }
678
- </ >
679
- ) }
680
- </ div >
681
- ) }
620
+ return < li key = { `message-${ idx } ` } > { displayResults } </ li >
621
+ } ) }
622
+ { loopRunning && (
623
+ < li >
624
+ < CSpinner size = "sm" />
625
+ </ li >
626
+ ) }
627
+ </ CCallout >
628
+ ) }
629
+ < DataTable
630
+ customStyles = { customStyles }
631
+ className = "cipp-table"
632
+ theme = { theme }
633
+ subHeader = { subheader }
634
+ selectableRows = { selectableRows }
635
+ onSelectedRowsChange = {
636
+ onSelectedRowsChange ? onSelectedRowsChange : handleSelectedChange
637
+ }
638
+ subHeaderComponent = { subHeaderComponentMemo }
639
+ subHeaderAlign = "left"
640
+ paginationResetDefaultPage = { resetPaginationToggle }
641
+ //actions={actionsMemo}
642
+ pagination = { pagination }
643
+ responsive = { responsive }
644
+ dense = { dense }
645
+ striped = { striped }
646
+ columns = { columns }
647
+ data = { filteredItems }
648
+ expandableRows = { expandableRows }
649
+ expandableRowsComponent = { expandableRowsComponent }
650
+ highlightOnHover = { highlightOnHover }
651
+ expandOnRowClicked = { expandOnRowClicked }
652
+ defaultSortAsc
653
+ defaultSortFieldId = { 1 }
654
+ sortFunction = { customSort }
655
+ paginationPerPage = { tablePageSize }
656
+ progressPending = { isFetching }
657
+ progressComponent = { < CSpinner color = "info" component = "div" /> }
658
+ paginationRowsPerPageOptions = { [ 25 , 50 , 100 , 200 , 500 ] }
659
+ { ...rest }
660
+ />
661
+ { selectedRows . length >= 1 && < CCallout > Selected { selectedRows . length } items</ CCallout > }
662
+ </ >
663
+ ) }
664
+ </ div >
682
665
</ div >
683
666
)
684
667
}
0 commit comments