@@ -263,6 +263,9 @@ class Browser extends DashboardView {
263
263
this . fetchAggregationPanelData = this . fetchAggregationPanelData . bind ( this ) ;
264
264
this . setAggregationPanelData = this . setAggregationPanelData . bind ( this ) ;
265
265
266
+ // Handle for the ongoing info panel cloud function request
267
+ this . currentInfoPanelQuery = null ;
268
+
266
269
this . dataBrowserRef = React . createRef ( ) ;
267
270
268
271
window . addEventListener ( 'popstate' , ( ) => {
@@ -299,6 +302,10 @@ class Browser extends DashboardView {
299
302
if ( this . currentQuery ) {
300
303
this . currentQuery . cancel ( ) ;
301
304
}
305
+ if ( this . currentInfoPanelQuery ) {
306
+ this . currentInfoPanelQuery . cancel ?. ( ) ;
307
+ this . currentInfoPanelQuery = null ;
308
+ }
302
309
this . removeLocation ( ) ;
303
310
window . removeEventListener ( 'mouseup' , this . onMouseUpRowCheckBox ) ;
304
311
}
@@ -346,20 +353,37 @@ class Browser extends DashboardView {
346
353
}
347
354
348
355
fetchAggregationPanelData ( objectId , className , appId ) {
356
+ if ( this . currentInfoPanelQuery ) {
357
+ this . currentInfoPanelQuery . cancel ?. ( ) ;
358
+ this . currentInfoPanelQuery = null ;
359
+ }
360
+
349
361
this . setState ( {
350
362
isLoadingInfoPanel : true ,
351
363
} ) ;
364
+
352
365
const params = {
353
366
object : Parse . Object . extend ( className ) . createWithoutData ( objectId ) . toPointer ( ) ,
354
367
} ;
368
+ let requestTask ;
355
369
const options = {
356
370
useMasterKey : true ,
371
+ requestTask : task => {
372
+ requestTask = task ;
373
+ } ,
357
374
} ;
358
375
const appName = this . props . params . appId ;
359
376
const cloudCodeFunction =
360
377
this . state . classwiseCloudFunctions [ `${ appId } ${ appName } ` ] ?. [ className ] [ 0 ] . cloudCodeFunction ;
361
- Parse . Cloud . run ( cloudCodeFunction , params , options ) . then (
378
+
379
+ const promise = Parse . Cloud . run ( cloudCodeFunction , params , options ) ;
380
+ promise . cancel = ( ) => requestTask ?. abort ( ) ;
381
+ this . currentInfoPanelQuery = promise ;
382
+ promise . then (
362
383
result => {
384
+ if ( this . currentInfoPanelQuery !== promise ) {
385
+ return ;
386
+ }
363
387
if ( result && result . panel && result . panel && result . panel . segments ) {
364
388
this . setState ( { AggregationPanelData : result , isLoadingInfoPanel : false } ) ;
365
389
} else {
@@ -371,13 +395,20 @@ class Browser extends DashboardView {
371
395
}
372
396
} ,
373
397
error => {
398
+ if ( this . currentInfoPanelQuery !== promise ) {
399
+ return ;
400
+ }
374
401
this . setState ( {
375
402
isLoadingInfoPanel : false ,
376
403
errorAggregatedData : error . message ,
377
404
} ) ;
378
405
this . showNote ( this . state . errorAggregatedData , true ) ;
379
406
}
380
- ) ;
407
+ ) . finally ( ( ) => {
408
+ if ( this . currentInfoPanelQuery === promise ) {
409
+ this . currentInfoPanelQuery = null ;
410
+ }
411
+ } ) ;
381
412
}
382
413
383
414
setAggregationPanelData ( data ) {
0 commit comments