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