@@ -4,77 +4,70 @@ define(function(require, exports/*, module*/) {
44
55"use strict" ;
66
7+ // Dependencies
8+ const React = require ( "react" ) ;
9+
10+ // WebSockets Monitor
11+ const { filterFrames } = require ( "../actions/frames" ) ;
12+
13+ // Shortcuts
14+ const { input } = React . DOM ;
15+
716/**
8- * TODO docs xxxHonza: use ReactJS.
17+ * This component renders a search box that allows the
18+ * user to filter on the content of the frames in the
19+ * list. It dispatches a "filterFrames" event with the
20+ * updated text filter.
921 */
10- var SearchBox =
22+ var SearchBox = React . createClass ( {
1123/** @lends SearchBox */
12- {
13- create : function ( parentNode ) {
14- var doc = parentNode . ownerDocument ;
15- var win = doc . defaultView ;
16- var toolbar = doc . querySelector ( ".mainPanel .toolbar" ) ;
17-
18- // Search box
19- var searchBox = doc . createElement ( "input" ) ;
20- searchBox . setAttribute ( "class" , "devtools-searchinput" ) ;
21- searchBox . setAttribute ( "type" , "search" ) ;
22- searchBox . setAttribute ( "results" , "true" ) ;
23- toolbar . appendChild ( searchBox ) ;
24-
25- searchBox . addEventListener ( "command" , this . onChange . bind ( this , searchBox ) , false ) ;
26- searchBox . addEventListener ( "input" , this . onChange . bind ( this , searchBox ) , false ) ;
27- searchBox . addEventListener ( "keypress" , this . onKeyPress . bind ( this , searchBox ) , false ) ;
28-
29- this . handleThemeChange = this . handleThemeChange . bind ( this , searchBox ) ;
30- win . addEventListener ( "theme-changed" , this . handleThemeChange ) ;
24+
25+ displayName : "SearchBox" ,
26+
27+ getInitialState ( ) {
28+ return {
29+ text : ""
30+ } ;
31+ } ,
32+
33+ componentDidMount ( ) {
34+ document . defaultView . addEventListener ( "theme-changed" , this . handleThemeChange ) ;
3135 } ,
3236
33- destroy : function ( parentNode ) {
34- var doc = parentNode . ownerDocument ;
35- var searchBox = doc . querySelector ( ".searchBox" ) ;
36- searchBox . remove ( ) ;
37- win . removeEventListener ( "theme-changed" , this . handleThemeChange ) ;
37+ componentWillUnmount ( ) {
38+ document . defaultView . removeEventListener ( "theme-changed" , this . handleThemeChange ) ;
3839 } ,
3940
40- handleThemeChange : function ( searchBox , event ) {
41- var data = event . data ;
42- var win = searchBox . ownerDocument . defaultView ;
41+ handleThemeChange ( event ) {
42+ const data = event . data ;
4343
4444 // Reset the filter if Firebug theme has been activated or deactivated.
4545 if ( data . newTheme == "firebug" || data . oldTheme == "firebug" ) {
46- searchBox . value = "" ;
47- this . dispatch ( win , {
48- text : ""
49- } ) ;
46+ this . onChange ( "" ) ;
5047 }
5148 } ,
5249
53- onKeyPress : function ( searchBox /*, event*/ ) {
54- this . onSearch ( searchBox ) ;
55- } ,
56-
57- onChange : function ( searchBox /*, event*/ ) {
58- this . onSearch ( searchBox ) ;
59- } ,
50+ onChange ( text ) {
51+ const currentFilter = this . props . frames . filter ;
6052
61- onSearch : function ( searchBox ) {
62- var win = searchBox . ownerDocument . defaultView ;
63- this . dispatch ( win , {
64- text : searchBox . value
65- } ) ;
53+ // Dispatch new filter, merging with old filter to
54+ // retain connectionId filter alongside this filter.
55+ this . props . dispatch ( filterFrames (
56+ Object . assign ( { } , currentFilter , { text } )
57+ ) ) ;
58+ this . setState ( { text } ) ;
6659 } ,
6760
68- dispatch : function ( win , filter ) {
69- var event = new win . MessageEvent ( "firebug.sdk/chrome-event" , {
70- data : {
71- method : "onSearch" ,
72- args : filter
73- }
61+ render ( ) {
62+ return input ( {
63+ className : "devtools-searchinput" ,
64+ type : "search" ,
65+ results : "true" ,
66+ value : this . state . text ,
67+ onChange : e => this . onChange ( e . target . value )
7468 } ) ;
75- win . dispatchEvent ( event ) ;
7669 }
77- } ;
70+ } ) ;
7871
7972// Exports from this module
8073exports . SearchBox = SearchBox ;
0 commit comments