From 9a59954a95380a592d3ee37df4c84417e7ce19e3 Mon Sep 17 00:00:00 2001 From: jennypavlova Date: Tue, 13 Jun 2023 10:07:58 +0200 Subject: [PATCH] [Infrastructure UI] Hosts View: Unified Search bar with auto-refresh enabled (#157011) Closes #156690 ## Summary This PR adds a flag (`isAutoRefreshDisabled`) to disable the default auto-refresh option in the unified search. ## Background The auto refresh is added by default when using a unified search bar in [defaultOnRefreshChange](https://github.com/elastic/kibana/blob/main/src/plugins/unified_search/public/search_bar/create_search_bar.tsx/#L59) and it appeared on the host view page when currently the auto-refresh option is not supported. | with `isAutoRefreshDisabled` (true) | without `isAutoRefreshDisabled` (false/undefined) | | ------------------------------------ | -------------------------------------------------- | | image | image | --------- Co-authored-by: Stratoula Kalafateli (cherry picked from commit 77d864e4ff04027f800789259fd6c6194b51c59a) --- .../public/__stories__/search_bar.stories.tsx | 11 +++++++++-- .../public/search_bar/create_search_bar.tsx | 6 +++++- .../unified_search/public/search_bar/search_bar.tsx | 2 ++ .../components/search_bar/unified_search_bar.tsx | 1 + 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/plugins/unified_search/public/__stories__/search_bar.stories.tsx b/src/plugins/unified_search/public/__stories__/search_bar.stories.tsx index bf2326604c308..2a03bb867105d 100644 --- a/src/plugins/unified_search/public/__stories__/search_bar.stories.tsx +++ b/src/plugins/unified_search/public/__stories__/search_bar.stories.tsx @@ -249,9 +249,16 @@ storiesOf('SearchBar', module) showDatePicker: false, } as SearchBarProps) ) - .add('with date picker off', () => + .add('with the default date picker auto refresh interval on', () => wrapSearchBarInContext({ - showDatePicker: false, + showDatePicker: true, + onRefreshChange: action('onRefreshChange'), + } as SearchBarProps) + ) + .add('with the default date picker auto refresh interval off', () => + wrapSearchBarInContext({ + showDatePicker: true, + isAutoRefreshDisabled: true, } as SearchBarProps) ) .add('with only the date picker on', () => diff --git a/src/plugins/unified_search/public/search_bar/create_search_bar.tsx b/src/plugins/unified_search/public/search_bar/create_search_bar.tsx index e319b64819a23..aa7aff184acb5 100644 --- a/src/plugins/unified_search/public/search_bar/create_search_bar.tsx +++ b/src/plugins/unified_search/public/search_bar/create_search_bar.tsx @@ -227,7 +227,11 @@ export function createSearchBar({ filters={filters} query={query} onFiltersUpdated={defaultFiltersUpdated(data.query, props.onFiltersUpdated)} - onRefreshChange={defaultOnRefreshChange(data.query, props.onRefreshChange)} + onRefreshChange={ + !props.isAutoRefreshDisabled + ? defaultOnRefreshChange(data.query, props.onRefreshChange) + : undefined + } savedQuery={savedQuery} onQuerySubmit={defaultOnQuerySubmit(props, data.query, query)} onRefresh={props.onRefresh} diff --git a/src/plugins/unified_search/public/search_bar/search_bar.tsx b/src/plugins/unified_search/public/search_bar/search_bar.tsx index 103150bc8b4e0..784ada4a95b42 100644 --- a/src/plugins/unified_search/public/search_bar/search_bar.tsx +++ b/src/plugins/unified_search/public/search_bar/search_bar.tsx @@ -84,6 +84,8 @@ export interface SearchBarOwnProps { // Autorefresh onRefreshChange?: (options: { isPaused: boolean; refreshInterval: number }) => void; indicateNoData?: boolean; + // Disables the default auto-refresh option inside the date picker + isAutoRefreshDisabled?: boolean; placeholder?: string; isClearable?: boolean; diff --git a/x-pack/plugins/infra/public/pages/metrics/hosts/components/search_bar/unified_search_bar.tsx b/x-pack/plugins/infra/public/pages/metrics/hosts/components/search_bar/unified_search_bar.tsx index a365d828d39ae..3319ca2f09fa1 100644 --- a/x-pack/plugins/infra/public/pages/metrics/hosts/components/search_bar/unified_search_bar.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/hosts/components/search_bar/unified_search_bar.tsx @@ -69,6 +69,7 @@ export const UnifiedSearchBar = () => { showQueryInput showQueryMenu useDefaultBehaviors + isAutoRefreshDisabled />