From b69eb0fd0839325f29ac67c20bb3043e322b5b8d Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 24 Sep 2024 00:55:13 +1000 Subject: [PATCH] [8.x] [Obs Alerts table] Fix error on clicking alert reason message (#193693) (#193718) # Backport This will backport the following commits from `main` to `8.x`: - [[Obs Alerts table] Fix error on clicking alert reason message (#193693)](https://github.com/elastic/kibana/pull/193693) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Bena Kansara <69037875+benakansara@users.noreply.github.com> --- .../helpers/map_rules_params_with_flyout.ts | 47 +++++++++++++------ 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/x-pack/plugins/observability_solution/observability/public/components/alert_overview/helpers/map_rules_params_with_flyout.ts b/x-pack/plugins/observability_solution/observability/public/components/alert_overview/helpers/map_rules_params_with_flyout.ts index fce4bd35dbdeebe..b5819631406d781 100644 --- a/x-pack/plugins/observability_solution/observability/public/components/alert_overview/helpers/map_rules_params_with_flyout.ts +++ b/x-pack/plugins/observability_solution/observability/public/components/alert_overview/helpers/map_rules_params_with_flyout.ts @@ -89,7 +89,9 @@ export const mapRuleParamsWithFlyout = (alert: TopAlert): FlyoutThresholdData[] switch (ruleId) { case OBSERVABILITY_THRESHOLD_RULE_TYPE_ID: return observedValues.map((observedValue, metricIndex) => { - const criteria = ruleCriteria[metricIndex] as CustomMetricExpressionParams; + const criteria = Array.isArray(ruleCriteria) + ? (ruleCriteria[metricIndex] as CustomMetricExpressionParams) + : (ruleCriteria as CustomMetricExpressionParams); const fields = criteria.metrics.map((metric) => metric.field || 'COUNT_AGG'); const comparator = criteria.comparator; const threshold = criteria.threshold; @@ -118,12 +120,20 @@ export const mapRuleParamsWithFlyout = (alert: TopAlert): FlyoutThresholdData[] case METRIC_THRESHOLD_ALERT_TYPE_ID: return observedValues.map((observedValue, metricIndex) => { - const criteria = ruleCriteria[metricIndex] as BaseMetricExpressionParams & { - metric: string; - customMetrics: Array<{ - field?: string; - }>; - }; + const criteria = Array.isArray(ruleCriteria) + ? (ruleCriteria[metricIndex] as BaseMetricExpressionParams & { + metric: string; + customMetrics: Array<{ + field?: string; + }>; + }) + : (ruleCriteria as BaseMetricExpressionParams & { + metric: string; + customMetrics: Array<{ + field?: string; + }>; + }); + let fields: string[] = []; const metric = criteria.metric; const customMetric = criteria.customMetrics; @@ -157,14 +167,21 @@ export const mapRuleParamsWithFlyout = (alert: TopAlert): FlyoutThresholdData[] case METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID: return observedValues.map((observedValue, metricIndex) => { - const { threshold, customMetric, metric, comparator } = ruleCriteria[ - metricIndex - ] as BaseMetricExpressionParams & { - metric: string; - customMetric: { - field: string; - }; - }; + const criteria = Array.isArray(ruleCriteria) + ? (ruleCriteria[metricIndex] as BaseMetricExpressionParams & { + metric: string; + customMetric: { + field: string; + }; + }) + : (ruleCriteria as BaseMetricExpressionParams & { + metric: string; + customMetric: { + field: string; + }; + }); + + const { threshold, customMetric, metric, comparator } = criteria; const metricField = customMetric?.field || metric; const thresholdFormatted = threshold.map((thresholdToFormat) => { if (