From 219ccb3396ed99e44eb1b6b609d30ce5d59ad8be Mon Sep 17 00:00:00 2001 From: Marco Vettorello Date: Mon, 9 Dec 2024 19:30:44 +0100 Subject: [PATCH] Update searchSessionId on setDateRange --- .../asset_details/hooks/use_date_picker.ts | 9 +++---- .../asset_details/hooks/use_loading_state.ts | 26 ++++--------------- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/x-pack/plugins/observability_solution/infra/public/components/asset_details/hooks/use_date_picker.ts b/x-pack/plugins/observability_solution/infra/public/components/asset_details/hooks/use_date_picker.ts index e6b69c1ddca8f..4cb20bfc4f3d5 100644 --- a/x-pack/plugins/observability_solution/infra/public/components/asset_details/hooks/use_date_picker.ts +++ b/x-pack/plugins/observability_solution/infra/public/components/asset_details/hooks/use_date_picker.ts @@ -52,8 +52,9 @@ export function useDatePicker({ (newDateRange: TimeRange) => { setUrlState({ dateRange: newDateRange }); setParsedDateRange(parseDateRange(newDateRange)); + updateSearchSessionId(); }, - [setUrlState] + [setUrlState, updateSearchSessionId] ); const onRefresh = useCallback( @@ -62,12 +63,10 @@ export function useDatePicker({ if (autoRefreshEnabled) { autoRefreshTick$.next(null); } else { - updateSearchSessionId(); + setDateRange(newDateRange); } - - setDateRange(newDateRange); }, - [autoRefreshEnabled, autoRefreshTick$, setDateRange, updateSearchSessionId] + [autoRefreshEnabled, autoRefreshTick$, setDateRange] ); const setAutoRefresh = useCallback( diff --git a/x-pack/plugins/observability_solution/infra/public/components/asset_details/hooks/use_loading_state.ts b/x-pack/plugins/observability_solution/infra/public/components/asset_details/hooks/use_loading_state.ts index f3098b6dca8f8..662723cccb420 100644 --- a/x-pack/plugins/observability_solution/infra/public/components/asset_details/hooks/use_loading_state.ts +++ b/x-pack/plugins/observability_solution/infra/public/components/asset_details/hooks/use_loading_state.ts @@ -26,7 +26,6 @@ import { useCallback, useEffect, useMemo } from 'react'; import { SearchSessionState, waitUntilNextSessionCompletes$ } from '@kbn/data-plugin/public'; import { useKibanaContextForPlugin } from '../../../hooks/use_kibana'; import { useDatePickerContext } from './use_date_picker'; -import { useSearchSessionContext } from '../../../hooks/use_search_session'; export type RequestState = 'running' | 'done' | 'error'; const WAIT_MS = 1000; @@ -37,16 +36,11 @@ export const useLoadingState = () => { const { data: { search }, } = services; - const { updateSearchSessionId } = useSearchSessionContext(); const isAutoRefreshRequestPending$ = useMemo(() => new BehaviorSubject(false), []); const requestsCount$ = useMemo(() => new BehaviorSubject(0), []); const requestState$ = useMemo(() => new BehaviorSubject(null), []); - useEffect(() => { - updateSearchSessionId(); - }, [updateSearchSessionId]); - const waitUntilRequestsCompletes$ = useCallback( () => requestsCount$.pipe( @@ -132,27 +126,17 @@ export const useLoadingState = () => { autoRefreshTick$.pipe( skipUntil(isAutoRefreshEnabled$()), - withLatestFrom(search.session.state$, isAutoRefreshRequestPending$), - switchMap(([_, state, isAutoRefreshRequestPending]) => { + withLatestFrom(search.session.state$), + switchMap(([_, state]) => { // if the current state$ value is not Completed if (state === SearchSessionState.Loading) { // Wait until queries using data.search complete before processing the next tick // This will only be called when Lens is used in the Asset Details page - return waitUntilNextSessionCompletes$(search.session).pipe( - tap(() => { - updateSearchSessionId(); - }) - ); + return waitUntilNextSessionCompletes$(search.session); } // Else immediately emit true if session state is already completed - return of(null).pipe( - tap(() => { - if (!isAutoRefreshRequestPending) { - updateSearchSessionId(); - } - }) - ); + return of(null); }) ) ).subscribe(); @@ -169,7 +153,7 @@ export const useLoadingState = () => { requestState$, requestsCount$, search.session, - updateSearchSessionId, + // updateSearchSessionId, waitUntilRequestsCompletes$, ]);