diff --git a/x-pack/plugins/triggers_actions_ui/public/application/hooks/use_load_rule_alerts_aggregations.ts b/x-pack/plugins/triggers_actions_ui/public/application/hooks/use_load_rule_alerts_aggregations.ts index 4660e8cfff73d..efd830dd4b24f 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/hooks/use_load_rule_alerts_aggregations.ts +++ b/x-pack/plugins/triggers_actions_ui/public/application/hooks/use_load_rule_alerts_aggregations.ts @@ -214,7 +214,7 @@ export async function fetchRuleAlertsAggByTimeRange({ ( acc: AlertChartData[], dayAlerts: { - key_as_string: string; + key: number; doc_count: number; alertStatus: { buckets: Array<{ @@ -226,8 +226,8 @@ export async function fetchRuleAlertsAggByTimeRange({ ) => { // We are adding this to each day to construct the 30 days bars (background bar) when there is no data for a given day or to show the delta today alerts/total alerts. const totalDayAlerts = { - date: dayAlerts.key_as_string, - count: totalAlerts, + date: dayAlerts.key, + count: totalAlerts === 0 ? 1 : totalAlerts, status: 'total', }; @@ -238,14 +238,14 @@ export async function fetchRuleAlertsAggByTimeRange({ dayAlerts.alertStatus.buckets.forEach((alert) => { countOfRecoveredActiveAlerts += alert.doc_count; localAlertChartData.push({ - date: dayAlerts.key_as_string, + date: dayAlerts.key, count: alert.doc_count, status: alert.key, }); }); if (totalAlerts - countOfRecoveredActiveAlerts > 0) { localAlertChartData.push({ - date: dayAlerts.key_as_string, + date: dayAlerts.key, count: totalAlerts - countOfRecoveredActiveAlerts, status: 'total', }); @@ -261,7 +261,11 @@ export async function fetchRuleAlertsAggByTimeRange({ return { active, recovered, - alertsChartData, + alertsChartData: [ + ...alertsChartData.filter((acd) => acd.status === 'active'), + ...alertsChartData.filter((acd) => acd.status === 'recovered'), + ...alertsChartData.filter((acd) => acd.status === 'total'), + ], }; } catch (error) { return { diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/rule_details/components/alert_summary/helpers.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/rule_details/components/alert_summary/helpers.tsx index b9b71f1f7a6a8..020742c6c3010 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/rule_details/components/alert_summary/helpers.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/rule_details/components/alert_summary/helpers.tsx @@ -10,7 +10,7 @@ import { AlertChartData } from './types'; export const formatChartAlertData = ( data: AlertChartData[] -): Array<{ x: string; y: number; g: string }> => +): Array<{ x: number; y: number; g: string }> => data.map((alert) => ({ x: alert.date, y: alert.count, diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/rule_details/components/alert_summary/rule_alerts_summary.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/rule_details/components/alert_summary/rule_alerts_summary.tsx index 55ca8a407cf66..b1133ac4a9b32 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/rule_details/components/alert_summary/rule_alerts_summary.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/rule_details/components/alert_summary/rule_alerts_summary.tsx @@ -32,6 +32,7 @@ import { EUI_SPARKLINE_THEME_PARTIAL, } from '@elastic/eui/dist/eui_charts_theme'; import { useUiSetting } from '@kbn/kibana-react-plugin/public'; +import moment from 'moment'; import { useLoadRuleAlertsAggs } from '../../../../hooks/use_load_rule_alerts_aggregations'; import { useLoadRuleTypes } from '../../../../hooks/use_load_rule_types'; import { formatChartAlertData, getColorSeries } from '.'; @@ -44,6 +45,7 @@ const G_ACCESSORS = ['g']; export const RuleAlertsSummary = ({ rule, filteredRuleTypes }: RuleAlertsSummaryProps) => { const [features, setFeatures] = useState(''); const isDarkMode = useUiSetting('theme:darkMode'); + const dateFormat = useUiSetting('dateFormat'); const theme = useMemo( () => [ EUI_SPARKLINE_THEME_PARTIAL, @@ -64,6 +66,15 @@ export const RuleAlertsSummary = ({ rule, filteredRuleTypes }: RuleAlertsSummary features, }); const chartData = useMemo(() => formatChartAlertData(alertsChartData), [alertsChartData]); + const tooltipSettings = useMemo( + () => ({ + type: TooltipType.VerticalCursor, + headerFormatter: ({ value }: { value: number }) => { + return <>{moment(value).format(dateFormat)}; + }, + }), + [dateFormat] + ); useEffect(() => { const matchedRuleType = ruleTypes.find((type) => type.id === rule.ruleTypeId); @@ -184,7 +195,7 @@ export const RuleAlertsSummary = ({ rule, filteredRuleTypes }: RuleAlertsSummary - +