@@ -6,6 +6,7 @@ import ReactTable from 'react-table-6';
6
6
import Checkbox from '@mui/material/Checkbox' ;
7
7
import TextField from '@mui/material/TextField' ;
8
8
import Autocomplete from '@mui/material/Autocomplete' ;
9
+ import Popper from '@mui/material/Popper' ;
9
10
10
11
import { bugsEndpoint } from '../helpers/url' ;
11
12
import { setUrlParam , getUrlParam } from '../helpers/location' ;
@@ -21,6 +22,16 @@ import withView from './View';
21
22
import Layout from './Layout' ;
22
23
import DateRangePicker from './DateRangePicker' ;
23
24
25
+ const CustomPopper = ( props ) => {
26
+ return (
27
+ < Popper
28
+ { ...props }
29
+ style = { { width : '350px' , textAlign : 'left' } }
30
+ placement = "bottom-start"
31
+ />
32
+ ) ;
33
+ } ;
34
+
24
35
const MainView = ( props ) => {
25
36
const {
26
37
graphData,
@@ -35,7 +46,10 @@ const MainView = (props) => {
35
46
updateAppState,
36
47
} = props ;
37
48
38
- const [ selectedProduct , setSelectedProduct ] = React . useState ( [ ] ) ;
49
+ const [ selectedFilter , setSelectedFilter ] = React . useState ( {
50
+ product : [ ] ,
51
+ component : [ ] ,
52
+ } ) ;
39
53
const textFilter = ( filter , row ) => {
40
54
if ( getUrlParam ( filter . id ) !== filter . value ) {
41
55
setUrlParam ( filter . id , filter . value ) ;
@@ -47,6 +61,41 @@ const MainView = (props) => {
47
61
}
48
62
} ;
49
63
64
+ const autoCompleteFilter = ( { column, onChange } ) => {
65
+ const options = [ ...new Set ( tableData . map ( ( d ) => d [ column . id ] ) ) ] ;
66
+ options . sort ( ) ;
67
+ return (
68
+ < Autocomplete
69
+ slots = { { popper : CustomPopper } }
70
+ size = "small"
71
+ multiple
72
+ limitTags = { 0 }
73
+ id = "checkboxes-tags-filter"
74
+ options = { options }
75
+ onChange = { ( _event , values ) => {
76
+ setUrlParam ( column . id , values ) ;
77
+ onChange ( values ) ;
78
+ setSelectedFilter ( { ...selectedFilter , [ column . id ] : values } ) ;
79
+ } }
80
+ disableCloseOnSelect
81
+ defaultValue = { selectedFilter [ column . id ] }
82
+ fullWidth
83
+ renderOption = { ( props , option , { selected } ) => {
84
+ const { key, ...optionProps } = props ;
85
+ return (
86
+ < li key = { key } { ...optionProps } >
87
+ < Checkbox style = { { marginRight : 8 } } checked = { selected } />
88
+ { option }
89
+ </ li >
90
+ ) ;
91
+ } }
92
+ renderInput = { ( params ) => (
93
+ < TextField style = { { border : 'none' , padding : '0' } } { ...params } />
94
+ ) }
95
+ />
96
+ ) ;
97
+ } ;
98
+
50
99
const columns = [
51
100
{
52
101
Header : 'Bug' ,
@@ -80,51 +129,28 @@ const MainView = (props) => {
80
129
accessor : 'product' ,
81
130
maxWidth : 100 ,
82
131
filterMethod : ( filter , row ) => {
83
- const regex = RegExp ( filter . value . join ( '|' ) , 'i' ) ;
84
- if ( regex . test ( row . product ) ) {
85
- return row ;
132
+ if ( filter . value ) {
133
+ const regex = RegExp ( filter . value . join ( '|' ) , 'i' ) ;
134
+ if ( regex . test ( row . product ) ) {
135
+ return row ;
136
+ }
86
137
}
87
138
} ,
88
- Filter : ( { onChange } ) => {
89
- return (
90
- < Autocomplete
91
- multiple
92
- id = "checkboxes-tags-filter"
93
- options = { [ ...new Set ( tableData . map ( ( d ) => d . product ) ) ] }
94
- onChange = { ( _event , values ) => {
95
- setUrlParam ( 'product' , values ) ;
96
- onChange ( values ) ;
97
- } }
98
- limitTags = { 2 }
99
- disableCloseOnSelect
100
- defaultValue = { selectedProduct }
101
- style = { {
102
- width : '20em' ,
103
- } }
104
- renderOption = { ( props , option , { selected } ) => {
105
- const { key, ...optionProps } = props ;
106
- return (
107
- < li key = { key } { ...optionProps } >
108
- < Checkbox style = { { marginRight : 8 } } checked = { selected } />
109
- { option }
110
- </ li >
111
- ) ;
112
- } }
113
- renderInput = { ( params ) => (
114
- < TextField
115
- style = { { border : 'none' , height : '0.3em' , padding : '0' } }
116
- { ...params }
117
- />
118
- ) }
119
- />
120
- ) ;
121
- } ,
139
+ Filter : autoCompleteFilter ,
122
140
} ,
123
141
{
124
142
Header : 'Component' ,
125
143
accessor : 'component' ,
126
144
maxWidth : 100 ,
127
- filterMethod : ( filter , row ) => textFilter ( filter , row ) ,
145
+ filterMethod : ( filter , row ) => {
146
+ if ( filter . value ) {
147
+ const regex = RegExp ( filter . value . join ( '|' ) , 'i' ) ;
148
+ if ( regex . test ( row . component ) ) {
149
+ return row ;
150
+ }
151
+ }
152
+ } ,
153
+ Filter : autoCompleteFilter ,
128
154
} ,
129
155
{
130
156
Header : 'Summary' ,
@@ -173,8 +199,16 @@ const MainView = (props) => {
173
199
if ( param ) {
174
200
if ( header === 'product' ) {
175
201
filters . push ( { id : header , value : param . split ( ',' ) } ) ;
176
- if ( selectedProduct . length === 0 ) {
177
- setSelectedProduct ( param . split ( ',' ) ) ;
202
+ if ( selectedFilter . product . length === 0 ) {
203
+ setSelectedFilter ( { ...selectedFilter , product : param . split ( ',' ) } ) ;
204
+ }
205
+ } else if ( header === 'component' ) {
206
+ filters . push ( { id : header , value : param . split ( ',' ) } ) ;
207
+ if ( selectedFilter . component . length === 0 ) {
208
+ setSelectedFilter ( {
209
+ ...selectedFilter ,
210
+ component : param . split ( ',' ) ,
211
+ } ) ;
178
212
}
179
213
} else {
180
214
filters . push ( { id : header , value : param } ) ;
0 commit comments