@@ -173,6 +173,12 @@ export const AnomalyHistory = (props: AnomalyHistoryProps) => {
173
173
const backgroundColor = darkModeEnabled ( ) ? '#29017' : '#F7F7F7' ;
174
174
const resultIndex = get ( props , 'detector.resultIndex' , '' ) ;
175
175
176
+ // Utility fn to only fetch data when either it is non-historical, or historical and
177
+ // there is a populated task ID which will be used to fetch the historical results
178
+ const isValidToFetch = ( ) => {
179
+ return ! props . isHistorical || ( props . isHistorical && taskId . current ) ;
180
+ } ;
181
+
176
182
// Tracking which parent category fields the user has selected to filter by.
177
183
const [ selectedCategoryFields , setSelectedCategoryFields ] = useState (
178
184
getCategoryFieldOptions ( detectorCategoryField )
@@ -325,7 +331,8 @@ export const AnomalyHistory = (props: AnomalyHistoryProps) => {
325
331
useEffect ( ( ) => {
326
332
if (
327
333
! isEmpty ( bucketizedAnomalyResults ) &&
328
- ! isDateRangeOversize ( zoomRange , detectorInterval , MAX_ANOMALIES )
334
+ ! isDateRangeOversize ( zoomRange , detectorInterval , MAX_ANOMALIES ) &&
335
+ isValidToFetch ( )
329
336
) {
330
337
setBucketizedAnomalyResults ( undefined ) ;
331
338
if ( isHCDetector && selectedHeatmapCell ) {
@@ -350,14 +357,16 @@ export const AnomalyHistory = (props: AnomalyHistoryProps) => {
350
357
} , [ zoomRange ] ) ;
351
358
352
359
useEffect ( ( ) => {
353
- fetchRawAnomalyResults ( isHCDetector ) ;
354
- if (
355
- ! isHCDetector &&
356
- isDateRangeOversize ( dateRange , detectorInterval , MAX_ANOMALIES )
357
- ) {
358
- getBucketizedAnomalyResults ( ) ;
359
- } else {
360
- setBucketizedAnomalyResults ( undefined ) ;
360
+ if ( isValidToFetch ( ) ) {
361
+ fetchRawAnomalyResults ( isHCDetector ) ;
362
+ if (
363
+ ! isHCDetector &&
364
+ isDateRangeOversize ( dateRange , detectorInterval , MAX_ANOMALIES )
365
+ ) {
366
+ getBucketizedAnomalyResults ( ) ;
367
+ } else {
368
+ setBucketizedAnomalyResults ( undefined ) ;
369
+ }
361
370
}
362
371
} , [ dateRange , props . detector ] ) ;
363
372
@@ -399,13 +408,7 @@ export const AnomalyHistory = (props: AnomalyHistoryProps) => {
399
408
) ;
400
409
const detectorResultResponse = props . isHistorical
401
410
? await dispatch (
402
- getDetectorResults (
403
- taskId . current || '' ,
404
- params ,
405
- true ,
406
- resultIndex ,
407
- true
408
- )
411
+ getDetectorResults ( taskId . current , params , true , resultIndex , true )
409
412
) . catch ( ( error : any ) => {
410
413
setIsLoading ( false ) ;
411
414
setIsLoadingAnomalyResults ( false ) ;
@@ -457,17 +460,19 @@ export const AnomalyHistory = (props: AnomalyHistoryProps) => {
457
460
useEffect ( ( ) => {
458
461
// For any change, we will want to clear any selected heatmap cell to clear any populated charts / graphs
459
462
setSelectedHeatmapCell ( undefined ) ;
460
- fetchHCAnomalySummaries ( ) ;
463
+ if ( isValidToFetch ( ) ) {
464
+ fetchHCAnomalySummaries ( ) ;
465
+ }
461
466
} , [ selectedCategoryFields ] ) ;
462
467
463
468
useEffect ( ( ) => {
464
- if ( isHCDetector ) {
469
+ if ( isHCDetector && isValidToFetch ( ) ) {
465
470
fetchHCAnomalySummaries ( ) ;
466
471
}
467
472
} , [ dateRange , heatmapDisplayOption ] ) ;
468
473
469
474
useEffect ( ( ) => {
470
- if ( selectedHeatmapCell ) {
475
+ if ( selectedHeatmapCell && isValidToFetch ( ) ) {
471
476
if (
472
477
isMultiCategory &&
473
478
get ( selectedCategoryFields , 'length' , 0 ) <
@@ -491,7 +496,7 @@ export const AnomalyHistory = (props: AnomalyHistoryProps) => {
491
496
492
497
// Getting the latest sets of time series based on the selected parent + child entities
493
498
useEffect ( ( ) => {
494
- if ( selectedHeatmapCell ) {
499
+ if ( selectedHeatmapCell && isValidToFetch ( ) ) {
495
500
// Get a list of entity lists, where each list represents a unique entity combination of
496
501
// all parent + child entities (a single model). And, for each one of these lists, fetch the time series data.
497
502
const entityCombosToFetch = getAllEntityCombos (
0 commit comments