@@ -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 = function ( 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,40 @@ 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
+ id = "checkboxes-tags-filter"
73
+ options = { options }
74
+ onChange = { ( _event , values ) => {
75
+ setUrlParam ( column . id , values ) ;
76
+ onChange ( values ) ;
77
+ setSelectedFilter ( { ...selectedFilter , [ column . id ] : values } ) ;
78
+ } }
79
+ disableCloseOnSelect
80
+ defaultValue = { selectedFilter [ column . id ] }
81
+ fullWidth = { true }
82
+ renderOption = { ( props , option , { selected } ) => {
83
+ const { key, ...optionProps } = props ;
84
+ return (
85
+ < li key = { key } { ...optionProps } >
86
+ < Checkbox style = { { marginRight : 8 } } checked = { selected } />
87
+ { option }
88
+ </ li >
89
+ ) ;
90
+ } }
91
+ renderInput = { ( params ) => (
92
+ < TextField style = { { border : 'none' , padding : '0' } } { ...params } />
93
+ ) }
94
+ />
95
+ ) ;
96
+ } ;
97
+
50
98
const columns = [
51
99
{
52
100
Header : 'Bug' ,
@@ -80,51 +128,28 @@ const MainView = (props) => {
80
128
accessor : 'product' ,
81
129
maxWidth : 100 ,
82
130
filterMethod : ( filter , row ) => {
83
- const regex = RegExp ( filter . value . join ( '|' ) , 'i' ) ;
84
- if ( regex . test ( row . product ) ) {
85
- return row ;
131
+ if ( filter . value ) {
132
+ const regex = RegExp ( filter . value . join ( '|' ) , 'i' ) ;
133
+ if ( regex . test ( row . product ) ) {
134
+ return row ;
135
+ }
86
136
}
87
137
} ,
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
- } ,
138
+ Filter : autoCompleteFilter ,
122
139
} ,
123
140
{
124
141
Header : 'Component' ,
125
142
accessor : 'component' ,
126
143
maxWidth : 100 ,
127
- filterMethod : ( filter , row ) => textFilter ( filter , row ) ,
144
+ filterMethod : ( filter , row ) => {
145
+ if ( filter . value ) {
146
+ const regex = RegExp ( filter . value . join ( '|' ) , 'i' ) ;
147
+ if ( regex . test ( row . component ) ) {
148
+ return row ;
149
+ }
150
+ }
151
+ } ,
152
+ Filter : autoCompleteFilter ,
128
153
} ,
129
154
{
130
155
Header : 'Summary' ,
@@ -173,8 +198,16 @@ const MainView = (props) => {
173
198
if ( param ) {
174
199
if ( header === 'product' ) {
175
200
filters . push ( { id : header , value : param . split ( ',' ) } ) ;
176
- if ( selectedProduct . length === 0 ) {
177
- setSelectedProduct ( param . split ( ',' ) ) ;
201
+ if ( selectedFilter . product . length === 0 ) {
202
+ setSelectedFilter ( { ...selectedFilter , product : param . split ( ',' ) } ) ;
203
+ }
204
+ } else if ( header === 'component' ) {
205
+ filters . push ( { id : header , value : param . split ( ',' ) } ) ;
206
+ if ( selectedFilter . component . length === 0 ) {
207
+ setSelectedFilter ( {
208
+ ...selectedFilter ,
209
+ component : param . split ( ',' ) ,
210
+ } ) ;
178
211
}
179
212
} else {
180
213
filters . push ( { id : header , value : param } ) ;
0 commit comments