Skip to content

Commit a6d386f

Browse files
[Embeddables] Decouple fetching from search sessions (#240333)
Closes #239610 ## Summary This PR decouples fetching from search session IDs - i.e. we no longer need the search session ID to change in order to trigger a refetch. This unblocks #233124, since making a selection in a section-scoped control should **not** trigger a new search session but it **should** cause a refetch for the targeted panels. This is also just a cleaner implementation overall, since search sessions should **not** drive fetching. Note that, in order to ensure that fetching still happens **after** the search session ID changes (so that embeddables receive the up-to-date ID and no double fetch happens), I had to add an async callback that allows the Dashboard to let the `fetch$` observable know when the search session ID is stable. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) - [x] Review the [backport guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing) and apply applicable `backport:*` labels. --------- Co-authored-by: kibanamachine <[email protected]>
1 parent b7cf75a commit a6d386f

File tree

21 files changed

+297
-250
lines changed

21 files changed

+297
-250
lines changed

src/platform/packages/shared/kbn-unified-histogram/components/chart/chart.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export interface UnifiedHistogramChartProps {
7272
isPlainRecord?: boolean;
7373
lensVisService: LensVisService;
7474
relativeTimeRange?: TimeRange;
75+
lastReloadRequestTime?: number;
7576
request?: UnifiedHistogramRequestContext;
7677
hits?: UnifiedHistogramHitsContext;
7778
chart?: UnifiedHistogramChartContext;
@@ -104,6 +105,7 @@ export function UnifiedHistogramChart({
104105
dataView,
105106
requestParams,
106107
relativeTimeRange: originalRelativeTimeRange,
108+
lastReloadRequestTime,
107109
request,
108110
hits,
109111
chart,
@@ -223,6 +225,7 @@ export function UnifiedHistogramChart({
223225
visContext,
224226
esqlVariables,
225227
onLoad,
228+
lastReloadRequestTime,
226229
});
227230

228231
const { chartToolbarCss, histogramCss } = useChartStyles(chartVisible);

src/platform/packages/shared/kbn-unified-histogram/components/chart/hooks/use_lens_props.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export type LensProps = Pick<
3131
| 'searchSessionId'
3232
| 'executionContext'
3333
| 'onLoad'
34+
| 'lastReloadRequestTime'
3435
>;
3536

3637
export const useLensProps = ({
@@ -40,13 +41,15 @@ export const useLensProps = ({
4041
visContext,
4142
esqlVariables,
4243
onLoad,
44+
lastReloadRequestTime,
4345
}: {
4446
request?: UnifiedHistogramRequestContext;
4547
getTimeRange: () => TimeRange;
4648
fetch$: Observable<UnifiedHistogramInputMessage>;
4749
visContext?: UnifiedHistogramVisContext;
4850
esqlVariables?: ESQLControlVariable[];
4951
onLoad: (isLoading: boolean, adapters: Partial<DefaultInspectorAdapters> | undefined) => void;
52+
lastReloadRequestTime?: number;
5053
}) => {
5154
const buildLensProps = useCallback(() => {
5255
if (!visContext) {
@@ -63,9 +66,17 @@ export const useLensProps = ({
6366
attributes,
6467
esqlVariables,
6568
onLoad,
69+
lastReloadRequestTime,
6670
}),
6771
};
68-
}, [visContext, request?.searchSessionId, getTimeRange, esqlVariables, onLoad]);
72+
}, [
73+
visContext,
74+
request?.searchSessionId,
75+
getTimeRange,
76+
esqlVariables,
77+
onLoad,
78+
lastReloadRequestTime,
79+
]);
6980

7081
// Initialize with undefined to avoid rendering Lens until a fetch has been triggered
7182
const [lensPropsContext, setLensPropsContext] = useState<ReturnType<typeof buildLensProps>>();
@@ -85,12 +96,14 @@ export const getLensProps = ({
8596
attributes,
8697
esqlVariables,
8798
onLoad,
99+
lastReloadRequestTime,
88100
}: {
89101
searchSessionId?: string;
90102
getTimeRange: () => TimeRange;
91103
attributes: TypedLensByValueInput['attributes'];
92104
esqlVariables?: ESQLControlVariable[];
93105
onLoad: (isLoading: boolean, adapters: Partial<DefaultInspectorAdapters> | undefined) => void;
106+
lastReloadRequestTime?: number;
94107
}): LensProps => ({
95108
id: 'unifiedHistogramLensComponent',
96109
viewMode: 'view',
@@ -103,4 +116,5 @@ export const getLensProps = ({
103116
description: 'fetch chart data and total hits',
104117
},
105118
onLoad,
119+
lastReloadRequestTime,
106120
});

src/platform/packages/shared/kbn-unified-histogram/hooks/use_unified_histogram.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ export type UseUnifiedHistogramProps = Omit<UnifiedHistogramStateOptions, 'servi
9595
* The relative time range, used when timeRange is an absolute range (e.g. for edit visualization button)
9696
*/
9797
relativeTimeRange?: TimeRange;
98+
/**
99+
* The timestamp of the last data request
100+
*/
101+
lastReloadRequestTime?: number;
98102
/**
99103
* The current columns
100104
*/

0 commit comments

Comments
 (0)