From 9fb91da47e61a56caf8cd070256ac4722b0d391f Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Mon, 20 Jul 2020 10:33:01 -0500 Subject: [PATCH] [ML] Fix detector linking & add delayed_data(0) --- .../annotations_table/annotations_table.js | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/ml/public/application/components/annotations/annotations_table/annotations_table.js b/x-pack/plugins/ml/public/application/components/annotations/annotations_table/annotations_table.js index 86398a57c3a45..69f7635a66032 100644 --- a/x-pack/plugins/ml/public/application/components/annotations/annotations_table/annotations_table.js +++ b/x-pack/plugins/ml/public/application/components/annotations/annotations_table/annotations_table.js @@ -256,7 +256,7 @@ export class AnnotationsTable extends Component { // if the annotation is at the series level // then pass the partitioning field(s) and detector index to the Single Metric Viewer if (_.has(annotation, 'detector_index')) { - mlTimeSeriesExplorer.detector_index = annotation.detector_index; + mlTimeSeriesExplorer.detectorIndex = annotation.detector_index; } if (_.has(annotation, 'partition_field_value')) { entityCondition[annotation.partition_field_name] = annotation.partition_field_value; @@ -523,10 +523,26 @@ export class AnnotationsTable extends Component { const aggregations = this.props.aggregations ?? this.state.aggregations; if (aggregations) { const buckets = aggregations.event.buckets; - const foundUser = buckets.findIndex((d) => d.key === ANNOTATION_EVENT_USER) > -1; - filterOptions = foundUser - ? buckets - : [{ key: ANNOTATION_EVENT_USER, doc_count: 0 }, ...buckets]; + let foundUser = false; + let foundDelayedData = false; + + buckets.forEach((bucket) => { + if (bucket.key === ANNOTATION_EVENT_USER) { + foundUser = true; + } + if (bucket.key === ANNOTATION_EVENT_DELAYED_DATA) { + foundDelayedData = true; + } + }); + const adjustedBuckets = []; + if (!foundUser) { + adjustedBuckets.push({ key: ANNOTATION_EVENT_USER, doc_count: 0 }); + } + if (!foundDelayedData) { + adjustedBuckets.push({ key: ANNOTATION_EVENT_DELAYED_DATA, doc_count: 0 }); + } + + filterOptions = [...adjustedBuckets, ...buckets]; } const filters = [ {