@@ -7,9 +7,10 @@ import update from 'immutability-helper';
7
7
import ClearIcon from 'react-icons/lib/md/clear-all' ;
8
8
import { Decode , Console as ConsoleFeed } from 'console-feed' ;
9
9
10
+ import Select from 'common/components/Select' ;
10
11
import Input from './Input' ;
11
12
12
- import { Container , Messages , inspectorTheme } from './elements' ;
13
+ import { Container , Messages , inspectorTheme , FilterInput } from './elements' ;
13
14
14
15
export type IMessage = {
15
16
type : 'message' | 'command' | 'return' ,
@@ -22,6 +23,8 @@ class Console extends React.Component {
22
23
messages : [ ] ,
23
24
scrollToBottom : true ,
24
25
initialClear : true ,
26
+ filter : [ ] ,
27
+ searchKeywords : '' ,
25
28
} ;
26
29
27
30
listener ;
@@ -104,6 +107,14 @@ class Console extends React.Component {
104
107
}
105
108
break ;
106
109
}
110
+ case 'search-log' : {
111
+ this . setState ( { searchKeywords : data . value } ) ;
112
+ break ;
113
+ }
114
+ case 'filter-log' : {
115
+ this . setState ( { filter : data . filters } ) ;
116
+ break ;
117
+ }
107
118
default : {
108
119
break ;
109
120
}
@@ -193,6 +204,7 @@ class Console extends React.Component {
193
204
return null ;
194
205
}
195
206
207
+ const { messages, filter, searchKeywords } = this . state ;
196
208
return (
197
209
< Container >
198
210
< Messages
@@ -201,9 +213,11 @@ class Console extends React.Component {
201
213
} }
202
214
>
203
215
< ConsoleFeed
204
- logs = { this . state . messages }
216
+ logs = { messages }
205
217
variant = { this . props . theme . light ? 'light' : 'dark' }
206
218
styles = { inspectorTheme ( this . props . theme ) }
219
+ filter = { filter }
220
+ searchKeywords = { searchKeywords }
207
221
/>
208
222
</ Messages >
209
223
< Input evaluateConsole = { this . evaluateConsole } />
@@ -212,6 +226,40 @@ class Console extends React.Component {
212
226
}
213
227
}
214
228
229
+ const ConsoleFilterInput = ( { style } ) => (
230
+ < FilterInput
231
+ placeholder = "Filter"
232
+ style = { style }
233
+ onChange = { ( { target : { value } } ) =>
234
+ dispatch ( { type : 'search-log' , value } )
235
+ }
236
+ />
237
+ ) ;
238
+
239
+ const ConsoleFilterSelect = props => {
240
+ const handleOnChange = ( { target : { value } } ) => {
241
+ if ( value === 'all' ) {
242
+ dispatch ( { type : 'filter-log' , filters : [ ] } ) ;
243
+ } else {
244
+ const filters = value === 'info' ? [ 'info' , 'log' ] : [ value ] ;
245
+ dispatch ( { type : 'filter-log' , filters } ) ;
246
+ }
247
+ } ;
248
+
249
+ return (
250
+ < Select
251
+ style = { { ...props . style , borderColor : '#2c2e30' } }
252
+ onChange = { handleOnChange }
253
+ >
254
+ < option value = "all" > All</ option >
255
+ < option value = "info" > Info</ option >
256
+ < option value = "warn" > Warning</ option >
257
+ < option value = "error" > Error</ option >
258
+ < option value = "debug" > Debug</ option >
259
+ </ Select >
260
+ ) ;
261
+ } ;
262
+
215
263
export default {
216
264
title : 'Console' ,
217
265
Content : withTheme ( Console ) ,
@@ -223,5 +271,17 @@ export default {
223
271
} ,
224
272
Icon : ClearIcon ,
225
273
} ,
274
+ {
275
+ title : 'Search' ,
276
+ onClick : ( ) => {
277
+ dispatch ( { type : 'Search Click' } ) ;
278
+ } ,
279
+ Icon : withTheme ( ConsoleFilterInput ) ,
280
+ } ,
281
+ {
282
+ title : 'Log Filter' ,
283
+ onClick : ( ) => { } ,
284
+ Icon : withTheme ( ConsoleFilterSelect ) ,
285
+ } ,
226
286
] ,
227
287
} ;
0 commit comments