@@ -3,63 +3,68 @@ import { tracked } from '@glimmer/tracking';
3
3
import { isEmpty } from '@ember/utils' ;
4
4
import Controller from '@ember/controller' ;
5
5
import { inject as service } from '@ember/service' ;
6
- import escapeRegExp from 'ember-inspector/utils/escape-reg-exp' ;
7
- import debounceComputed from 'ember-inspector/computed/debounce' ;
8
- import { and , equal } from '@ember/object/computed' ;
6
+
7
+ import escapeRegExp from '../utils/escape-reg-exp' ;
8
+ // @ts -expect-error TODO: not yet typed
9
+ import debounceComputed from '../computed/debounce' ;
10
+ import type WebExtension from '../services/adapters/web-extension' ;
11
+ import type PortService from '../services/port' ;
12
+ import type StorageService from '../services/storage' ;
13
+ import type { RenderTreeModel } from '../routes/render-tree' ;
14
+ import { isNullish } from '../utils/nullish' ;
9
15
10
16
export default class RenderTreeController extends Controller {
11
- @service adapter ;
12
- @service port ;
17
+ @service declare adapter : WebExtension ;
18
+ @service declare port : PortService ;
13
19
/**
14
20
* Storage is needed for remembering if the user closed the warning
15
- *
16
- * @property storage
17
- * @type {Service }
18
21
*/
19
- @service storage ;
22
+ @service declare storage : StorageService ;
23
+
24
+ declare model : RenderTreeModel ;
20
25
21
- initialEmpty = false ;
26
+ @ tracked initialEmpty = false ;
22
27
@tracked shouldHighlightRender = false ;
23
28
@tracked search = '' ;
24
29
25
- @equal ( 'model.profiles.length' , 0 )
26
- modelEmpty ;
30
+ get escapedSearch ( ) {
31
+ return escapeRegExp ( this . search ?. toLowerCase ( ) ) ;
32
+ }
27
33
28
- @and ( 'initialEmpty' , 'modelEmpty' )
29
- showEmpty ;
34
+ /**
35
+ * Indicate the table's header's height in pixels.
36
+ *
37
+ * @property headerHeight
38
+ * @type {Number }
39
+ */
40
+ get headerHeight ( ) {
41
+ return this . isWarningClosed ? 31 : 56 ;
42
+ }
30
43
31
44
/**
32
45
* Checks if the user previously closed the warning by referencing localStorage
33
- *
34
- * @property isWarningClosed
35
- * @type {Boolean }
36
46
*/
37
47
get isWarningClosed ( ) {
38
48
return ! ! this . storage . getItem ( 'is-render-tree-warning-closed' ) ;
39
49
}
40
50
41
51
set isWarningClosed ( value ) {
52
+ // @ts -expect-error Ignore this boolean/string mismatch for now.
42
53
this . storage . setItem ( 'is-render-tree-warning-closed' , value ) ;
43
54
}
44
55
45
- /**
46
- * Indicate the table's header's height in pixels.
47
- *
48
- * @property headerHeight
49
- * @type {Number }
50
- */
51
- get headerHeight ( ) {
52
- return this . isWarningClosed ? 31 : 56 ;
56
+ get modelEmpty ( ) {
57
+ return this . model . profiles . length === 0 ;
58
+ }
59
+
60
+ get showEmpty ( ) {
61
+ return this . initialEmpty && this . modelEmpty ;
53
62
}
54
63
55
64
// bound to the input field, updates the `search` property
56
65
// 300ms after changing
57
66
@debounceComputed ( 'search' , 300 )
58
- searchValue ;
59
-
60
- get escapedSearch ( ) {
61
- return escapeRegExp ( this . search ?. toLowerCase ( ) ) ;
62
- }
67
+ searchValue : any ;
63
68
64
69
@computed ( 'model.isHighlightSupported' )
65
70
get isHighlightEnabled ( ) {
@@ -68,14 +73,16 @@ export default class RenderTreeController extends Controller {
68
73
69
74
@computed ( 'escapedSearch' , 'model.profiles.@each.name' , 'search' )
70
75
get filtered ( ) {
71
- if ( isEmpty ( this . escapedSearch ) ) {
76
+ if ( isNullish ( this . escapedSearch ) ) {
72
77
return this . model . profiles ;
73
78
}
74
79
75
- return this . model . profiles . filter ( ( item ) => {
76
- const regExp = new RegExp ( this . escapedSearch ) ;
77
- return recursiveMatch ( item , regExp ) ;
78
- } ) ;
80
+ return this . model . profiles . filter (
81
+ ( item : RenderTreeModel [ 'profiles' ] [ number ] ) => {
82
+ const regExp = new RegExp ( this . escapedSearch as string ) ;
83
+ return recursiveMatch ( item , regExp ) ;
84
+ } ,
85
+ ) ;
79
86
}
80
87
81
88
@action
@@ -85,7 +92,7 @@ export default class RenderTreeController extends Controller {
85
92
86
93
@action
87
94
closeWarning ( ) {
88
- this . set ( ' isWarningClosed' , true ) ;
95
+ this . isWarningClosed = true ;
89
96
}
90
97
91
98
@action
@@ -98,18 +105,19 @@ export default class RenderTreeController extends Controller {
98
105
}
99
106
}
100
107
101
- function recursiveMatch ( item , regExp ) {
102
- let children , child ;
103
- let name = item . name ;
104
- if ( name . toLowerCase ( ) . match ( regExp ) ) {
108
+ function recursiveMatch (
109
+ item : RenderTreeModel [ 'profiles' ] [ number ] ,
110
+ regExp : string | RegExp ,
111
+ ) {
112
+ if ( item . name . toLowerCase ( ) . match ( regExp ) ) {
105
113
return true ;
106
114
}
107
- children = item . children ;
108
- for ( let i = 0 ; i < children . length ; i ++ ) {
109
- child = children [ i ] ;
115
+
116
+ for ( const child of item . children ) {
110
117
if ( recursiveMatch ( child , regExp ) ) {
111
118
return true ;
112
119
}
113
120
}
121
+
114
122
return false ;
115
123
}
0 commit comments