From 2578ac3ba4eb35c13a4cdf97174378760342dced Mon Sep 17 00:00:00 2001 From: Achyut Jhunjhunwala Date: Wed, 14 Jan 2026 14:23:56 +0100 Subject: [PATCH] [Obs Explorations] Fix incorrect extraction of time range from wrong context (#248939) ## Summary Original issue - https://github.com/elastic/kibana/pull/248795 As part of the original issue it was found that in 8.19 it provides a completely broken experience but 9.1 onwards, we don't access the undefined object inside the react component and straight away were passing it to the Discover Locator which was getting `undefined` for `dateRange` and thus was defaulting to `now to now-15m` With this PR we fix passing the correct `dateRange`. Now when user open `View in Context` and then clicks Open in Discover from the modal, it does passes the actual timerange from the Logs Categories page to Discover ## Release Note Fixes broken links from View In Context Modal to Discover which was not respecting the DateRange (cherry picked from commit 6302c6b9a02a26e533f805926752d28a0c0b0144) --- .../logs/stream/page_view_log_in_context.tsx | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/x-pack/solutions/observability/plugins/infra/public/pages/logs/stream/page_view_log_in_context.tsx b/x-pack/solutions/observability/plugins/infra/public/pages/logs/stream/page_view_log_in_context.tsx index d928788e3da04..ebd88d313d643 100644 --- a/x-pack/solutions/observability/plugins/infra/public/pages/logs/stream/page_view_log_in_context.tsx +++ b/x-pack/solutions/observability/plugins/infra/public/pages/logs/stream/page_view_log_in_context.tsx @@ -25,7 +25,6 @@ import { LazySavedSearchComponent } from '@kbn/saved-search-component'; import { i18n } from '@kbn/i18n'; import { Global, css } from '@emotion/react'; import { useKibanaContextForPlugin } from '../../../hooks/use_kibana'; -import { useDatePickerContext } from '../../../components/asset_details/hooks/use_date_picker'; import { useViewLogInProviderContext } from '../../../containers/logs/view_log_in_context'; import { useViewportDimensions } from '../../../hooks/use_viewport_dimensions'; @@ -46,14 +45,23 @@ export const PageViewLogInContext: React.FC = () => { }, } = useKibanaContextForPlugin(); - const { dateRange } = useDatePickerContext(); const logsLocator = getLogsLocatorFromUrlService(url); const logSources = useAsync(logSourcesService.getFlattenedLogSources); - const [{ contextEntry }, { setContextEntry }] = useViewLogInProviderContext(); + const [{ contextEntry, startTimestamp, endTimestamp }, { setContextEntry }] = + useViewLogInProviderContext(); const closeModal = useCallback(() => setContextEntry(undefined), [setContextEntry]); const { width: vw, height: vh } = useViewportDimensions(); + // Convert timestamps to TimeRange format for LazySavedSearchComponent + const timeRange = useMemo( + () => ({ + from: new Date(startTimestamp).toISOString(), + to: new Date(endTimestamp).toISOString(), + }), + [startTimestamp, endTimestamp] + ); + const contextQuery = useMemo(() => { if (contextEntry && !isEmpty(contextEntry.context)) { return { @@ -75,7 +83,7 @@ export const PageViewLogInContext: React.FC = () => { } const discoverLink = logsLocator?.getRedirectUrl({ - timeRange: dateRange, + timeRange, query: contextQuery, }); @@ -100,7 +108,7 @@ export const PageViewLogInContext: React.FC = () => {