1
+ import {
2
+ cachedFetch ,
3
+ clearFetchCache ,
4
+ setFetchCache ,
5
+ } from 'scripts/cachedFetch' ;
6
+ import { requestIdleCallback } from 'scripts/ric' ;
7
+
1
8
class VrtsTestRunAlerts extends window . HTMLElement {
2
9
constructor ( ) {
3
10
super ( ) ;
@@ -36,11 +43,13 @@ class VrtsTestRunAlerts extends window.HTMLElement {
36
43
this . handleAlertClick = this . handleAlertClick . bind ( this ) ;
37
44
this . handleActionClick = this . handleActionClick . bind ( this ) ;
38
45
this . updateRunsCount = this . updateRunsCount . bind ( this ) ;
46
+ this . handleAlertHover = this . handleAlertHover . bind ( this ) ;
39
47
}
40
48
41
49
bindEvents ( ) {
42
50
this . $alerts ?. forEach ( ( item ) => {
43
51
item . addEventListener ( 'click' , this . handleAlertClick ) ;
52
+ item . addEventListener ( 'pointerenter' , this . handleAlertHover ) ;
44
53
} ) ;
45
54
this . $actionButtons ?. forEach ( ( item ) => {
46
55
item . addEventListener ( 'click' , this . handleActionClick ) ;
@@ -144,6 +153,19 @@ class VrtsTestRunAlerts extends window.HTMLElement {
144
153
} ) ;
145
154
}
146
155
156
+ handleAlertHover ( e ) {
157
+ const $el = e . currentTarget ;
158
+ const isCurrent = $el . getAttribute ( 'data-vrts-current' ) === 'true' ;
159
+
160
+ if ( isCurrent ) {
161
+ return ;
162
+ }
163
+
164
+ const href = $el . getAttribute ( 'href' ) ;
165
+
166
+ requestIdleCallback ( ( ) => cachedFetch ( href ) ) ;
167
+ }
168
+
147
169
handleAlertClick ( e ) {
148
170
e . preventDefault ( ) ;
149
171
const $el = e . currentTarget ;
@@ -171,35 +193,31 @@ class VrtsTestRunAlerts extends window.HTMLElement {
171
193
$content . setAttribute ( 'data-vrts-loading' , 'true' ) ;
172
194
} , 200 ) ;
173
195
174
- fetch ( href )
175
- . then ( ( response ) => {
176
- return response . text ( ) ;
177
- } )
178
- . then ( ( data ) => {
179
- const parser = new window . DOMParser ( ) ;
180
- const $html = parser . parseFromString ( data , 'text/html' ) ;
196
+ cachedFetch ( href ) . then ( ( data ) => {
197
+ const parser = new window . DOMParser ( ) ;
198
+ const $html = parser . parseFromString ( data , 'text/html' ) ;
181
199
182
- const $newContent =
183
- $html . querySelector ( 'vrts-comparisons' ) ||
184
- $html . querySelector ( 'vrts-test-run-success' ) ;
185
- const $newPagination = $html . querySelector (
186
- 'vrts-test-run-pagination'
187
- ) ;
200
+ const $newContent =
201
+ $html . querySelector ( 'vrts-comparisons' ) ||
202
+ $html . querySelector ( 'vrts-test-run-success' ) ;
203
+ const $newPagination = $html . querySelector (
204
+ 'vrts-test-run-pagination'
205
+ ) ;
188
206
189
- window . history . replaceState ( { } , '' , href ) ;
207
+ window . history . replaceState ( { } , '' , href ) ;
190
208
191
- this . scrollTo ( $content . offsetTop - 62 ) ;
209
+ this . scrollTo ( $content . offsetTop - 62 ) ;
192
210
193
- if ( $newContent ) {
194
- $content . replaceWith ( $newContent ) ;
195
- }
211
+ if ( $newContent ) {
212
+ $content . replaceWith ( $newContent ) ;
213
+ }
196
214
197
- if ( $newPagination ) {
198
- $pagination . replaceWith ( $newPagination ) ;
199
- }
215
+ if ( $newPagination ) {
216
+ $pagination . replaceWith ( $newPagination ) ;
217
+ }
200
218
201
- clearTimeout ( timeout ) ;
202
- } ) ;
219
+ clearTimeout ( timeout ) ;
220
+ } ) ;
203
221
}
204
222
205
223
handleActionClick ( e ) {
@@ -240,6 +258,7 @@ class VrtsTestRunAlerts extends window.HTMLElement {
240
258
} ,
241
259
} )
242
260
. then ( ( response ) => {
261
+ clearFetchCache ( ) ;
243
262
return response . json ( ) ;
244
263
} )
245
264
. then ( ( ) => {
@@ -264,6 +283,10 @@ class VrtsTestRunAlerts extends window.HTMLElement {
264
283
shouldSetAction ? 'read' : 'unread'
265
284
) ;
266
285
} ) ;
286
+ setFetchCache (
287
+ window . location . href ,
288
+ document . body . innerHTML
289
+ ) ;
267
290
} , loadingTimeoutTime ) ;
268
291
269
292
clearTimeout ( timeout ) ;
@@ -287,6 +310,7 @@ class VrtsTestRunAlerts extends window.HTMLElement {
287
310
disconnectedCallback ( ) {
288
311
this . $alerts ?. forEach ( ( item ) => {
289
312
item . removeEventListener ( 'click' , this . handleAlertClick ) ;
313
+ item . removeEventListener ( 'pointerenter' , this . handleAlertHover ) ;
290
314
} ) ;
291
315
this . $actionButtons ?. forEach ( ( item ) => {
292
316
item . removeEventListener ( 'click' , this . handleActionClick ) ;
0 commit comments