From 73dcb07e3ee37b76f4ab582d247d63c6cba02573 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Sat, 5 Oct 2024 00:29:00 +1000 Subject: [PATCH] [8.15] [ResponseOps][Alerts] Fix Stack Alerts page filter controls error (#194785) (#194942) # Backport This will backport the following commits from `main` to `8.15`: - [[ResponseOps][Alerts] Fix Stack Alerts page filter controls error (#194785)](https://github.com/elastic/kibana/pull/194785) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Umberto Pepato --- .../src/alert_filter_controls/filter_group.tsx | 7 ++++--- .../src/alert_filter_controls/types.ts | 1 + .../url_synced_alerts_search_bar.tsx | 14 +++++++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/kbn-alerts-ui-shared/src/alert_filter_controls/filter_group.tsx b/packages/kbn-alerts-ui-shared/src/alert_filter_controls/filter_group.tsx index cc474ddf853e5..5f38b7394c9bb 100644 --- a/packages/kbn-alerts-ui-shared/src/alert_filter_controls/filter_group.tsx +++ b/packages/kbn-alerts-ui-shared/src/alert_filter_controls/filter_group.tsx @@ -47,6 +47,7 @@ import { URL_PARAM_ARRAY_EXCEPTION_MSG } from './translations'; export const FilterGroup = (props: PropsWithChildren) => { const { + featureIds, dataViewId, onFiltersChange, timeRange, @@ -61,7 +62,7 @@ export const FilterGroup = (props: PropsWithChildren) => { maxControls = Infinity, ControlGroupRenderer, Storage, - featureIds, + storageKey, } = props; const filterChangedSubscription = useRef(); @@ -82,8 +83,8 @@ export const FilterGroup = (props: PropsWithChildren) => { const [controlGroup, setControlGroup] = useState(); const localStoragePageFilterKey = useMemo( - () => `${featureIds.join(',')}.${spaceId}.${URL_PARAM_KEY}`, - [featureIds, spaceId] + () => storageKey ?? `${featureIds.join(',')}.${spaceId}.${URL_PARAM_KEY}`, + [featureIds, spaceId, storageKey] ); const currentFiltersRef = useRef(); diff --git a/packages/kbn-alerts-ui-shared/src/alert_filter_controls/types.ts b/packages/kbn-alerts-ui-shared/src/alert_filter_controls/types.ts index 75dcad2acb5c2..71e8e552eeeb1 100644 --- a/packages/kbn-alerts-ui-shared/src/alert_filter_controls/types.ts +++ b/packages/kbn-alerts-ui-shared/src/alert_filter_controls/types.ts @@ -70,4 +70,5 @@ export interface FilterGroupProps */ ControlGroupRenderer: typeof ControlGroupRenderer; Storage: typeof Storage; + storageKey?: string; } diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_search_bar/url_synced_alerts_search_bar.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_search_bar/url_synced_alerts_search_bar.tsx index 71594e3206ffd..de89eb9715733 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_search_bar/url_synced_alerts_search_bar.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_search_bar/url_synced_alerts_search_bar.tsx @@ -5,7 +5,7 @@ * 2.0. */ -import React, { useCallback, useEffect, useState } from 'react'; +import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { BoolQuery } from '@kbn/es-query'; import { AlertConsumers } from '@kbn/rule-data-utils'; import { i18n } from '@kbn/i18n'; @@ -61,17 +61,23 @@ export const UrlSyncedAlertsSearchBar = ({ const [spaceId, setSpaceId] = useState(); const { + // KQL bar query kuery, onKueryChange, + // KQL bar filters filters, onFiltersChange, + // Controls bar filters controlFilters, onControlFiltersChange, + // Time range rangeFrom, onRangeFromChange, rangeTo, onRangeToChange, + // Controls bar configuration filterControls, + // Saved KQL query savedQuery, setSavedQuery, clearSavedQuery, @@ -131,6 +137,11 @@ export const UrlSyncedAlertsSearchBar = ({ [onKueryChange, onRangeFromChange, onRangeToChange, setSavedQuery, timeFilterService] ); + const filterControlsStorageKey = useMemo( + () => ['alertsSearchBar', spaceId, 'filterControls'].filter(Boolean).join('.'), + [spaceId] + ); + return ( <>