Add possibility to disable syncing controls with local storage

This commit is contained in:
Maryam Saeidi 2025-01-10 12:37:16 +01:00
parent bc0970e8ce
commit 24bab210b0
6 changed files with 8 additions and 1 deletions

View file

@ -60,6 +60,7 @@ export const FilterGroup = (props: PropsWithChildren<FilterGroupProps>) => {
Storage, Storage,
ruleTypeIds, ruleTypeIds,
storageKey, storageKey,
disableLocalStorageSync = false,
} = props; } = props;
const filterChangedSubscription = useRef<Subscription>(); const filterChangedSubscription = useRef<Subscription>();
@ -105,7 +106,7 @@ export const FilterGroup = (props: PropsWithChildren<FilterGroupProps>) => {
} = useControlGroupSyncToLocalStorage({ } = useControlGroupSyncToLocalStorage({
Storage, Storage,
storageKey: localStoragePageFilterKey, storageKey: localStoragePageFilterKey,
shouldSync: isViewMode, shouldSync: !disableLocalStorageSync && isViewMode,
}); });
useEffect(() => { useEffect(() => {

View file

@ -74,4 +74,5 @@ export interface FilterGroupProps extends Pick<ControlGroupRuntimeState, 'chaini
ControlGroupRenderer: typeof ControlGroupRenderer; ControlGroupRenderer: typeof ControlGroupRenderer;
Storage: typeof Storage; Storage: typeof Storage;
storageKey?: string; storageKey?: string;
disableLocalStorageSync?: boolean;
} }

View file

@ -25,6 +25,7 @@ const toastTitle = i18n.translate('xpack.observability.alerts.searchBar.invalidQ
export function ObservabilityAlertSearchBar({ export function ObservabilityAlertSearchBar({
appName, appName,
defaultFilters = EMPTY_FILTERS, defaultFilters = EMPTY_FILTERS,
disableLocalStorageSync,
onEsQueryChange, onEsQueryChange,
onKueryChange, onKueryChange,
onRangeFromChange, onRangeFromChange,
@ -168,6 +169,7 @@ export function ObservabilityAlertSearchBar({
filters={[...filters, ...defaultFilters]} filters={[...filters, ...defaultFilters]}
onFiltersChange={onFilterControlsChange} onFiltersChange={onFilterControlsChange}
storageKey={filterControlsStorageKey} storageKey={filterControlsStorageKey}
disableLocalStorageSync={disableLocalStorageSync}
services={{ services={{
http, http,
notifications, notifications,

View file

@ -63,6 +63,7 @@ export interface ObservabilityAlertSearchBarProps
onFilterControlsChange: (controlConfigs: Filter[]) => void; onFilterControlsChange: (controlConfigs: Filter[]) => void;
savedQuery?: SavedQuery; savedQuery?: SavedQuery;
showFilterBar?: boolean; showFilterBar?: boolean;
disableLocalStorageSync?: boolean;
} }
export interface AlertSearchBarContainerState { export interface AlertSearchBarContainerState {

View file

@ -129,6 +129,7 @@ export function InternalRelatedAlerts({ alert }: Props) {
onEsQueryChange={setEsQuery} onEsQueryChange={setEsQuery}
urlStorageKey={SEARCH_BAR_URL_STORAGE_KEY} urlStorageKey={SEARCH_BAR_URL_STORAGE_KEY}
defaultFilters={defaultFilters.current} defaultFilters={defaultFilters.current}
disableLocalStorageSync={true}
defaultState={{ defaultState={{
...defaultState, ...defaultState,
kuery, kuery,

View file

@ -92,6 +92,7 @@ export function RuleDetailsTabs({
onEsQueryChange={onEsQueryChange} onEsQueryChange={onEsQueryChange}
urlStorageKey={RULE_DETAILS_SEARCH_BAR_URL_STORAGE_KEY} urlStorageKey={RULE_DETAILS_SEARCH_BAR_URL_STORAGE_KEY}
defaultFilters={ruleFilters.current} defaultFilters={ruleFilters.current}
disableLocalStorageSync={true}
/> />
<EuiSpacer size="s" /> <EuiSpacer size="s" />