-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Embeddable] Allow panels to pause data fetching #235266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4525467
2a17542
b7bf464
0fbc323
e20c6b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| import type { AggregateQuery, Filter, Query, TimeRange } from '@kbn/es-query'; | ||
| import { COMPARE_ALL_OPTIONS, onlyDisabledFiltersChanged } from '@kbn/es-query'; | ||
| import fastIsEqual from 'fast-deep-equal'; | ||
|
|
||
| export interface FetchContext { | ||
| isReload: boolean; | ||
| filters: Filter[] | undefined; | ||
| query: Query | AggregateQuery | undefined; | ||
| searchSessionId: string | undefined; | ||
| timeRange: TimeRange | undefined; | ||
| timeslice: [number, number] | undefined; | ||
| } | ||
|
|
||
| export interface ReloadTimeFetchContext extends Omit<FetchContext, 'isReload'> { | ||
| reloadTimestamp?: number; | ||
| } | ||
|
|
||
| export function isReloadTimeFetchContextEqual( | ||
| currentContext: ReloadTimeFetchContext, | ||
| lastContext: ReloadTimeFetchContext | ||
| ): boolean { | ||
| if (currentContext.searchSessionId !== lastContext.searchSessionId) return false; | ||
|
|
||
| return ( | ||
| isReloadTimestampEqualForFetch(currentContext.reloadTimestamp, lastContext.reloadTimestamp) && | ||
| areFiltersEqualForFetch(currentContext.filters, lastContext.filters) && | ||
| isQueryEqualForFetch(currentContext.query, lastContext.query) && | ||
| isTimeRangeEqualForFetch(currentContext.timeRange, lastContext.timeRange) && | ||
| isTimeSliceEqualForFetch(currentContext.timeslice, lastContext.timeslice) | ||
| ); | ||
| } | ||
|
|
||
| export const areFiltersEqualForFetch = (currentFilters?: Filter[], lastFilters?: Filter[]) => { | ||
| return onlyDisabledFiltersChanged(currentFilters, lastFilters, { | ||
| ...COMPARE_ALL_OPTIONS, | ||
| // do not compare $state to avoid refreshing when filter is pinned/unpinned (which does not impact results) | ||
| state: false, | ||
| }); | ||
| }; | ||
|
|
||
| export const isReloadTimestampEqualForFetch = ( | ||
| currentReloadTimestamp?: number, | ||
| lastReloadTimestamp?: number | ||
| ) => { | ||
| if (!currentReloadTimestamp) return true; // if current reload timestamp is not set, this is not a force refresh. | ||
| return currentReloadTimestamp === lastReloadTimestamp; | ||
| }; | ||
|
|
||
| export const isQueryEqualForFetch = ( | ||
| currentQuery: Query | AggregateQuery | undefined, | ||
| lastQuery: Query | AggregateQuery | undefined | ||
| ) => fastIsEqual(currentQuery, lastQuery); | ||
|
|
||
| export const isTimeRangeEqualForFetch = ( | ||
| currentTimeRange: TimeRange | undefined, | ||
| lastTimeRange: TimeRange | undefined | ||
| ) => fastIsEqual(currentTimeRange, lastTimeRange); | ||
|
|
||
| export const isTimeSliceEqualForFetch = ( | ||
| currentTimeslice: [number, number] | undefined, | ||
| lastTimeslice: [number, number] | undefined | ||
| ) => fastIsEqual(currentTimeslice, lastTimeslice); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| import type { Observable } from 'rxjs'; | ||
|
|
||
| export interface PublishesPauseFetch { | ||
| isFetchPaused$: Observable<boolean>; | ||
| } | ||
|
|
||
| export const apiPublishesPauseFetch = ( | ||
| unknownApi: null | unknown | ||
| ): unknownApi is PublishesPauseFetch => { | ||
| return Boolean(unknownApi && (unknownApi as PublishesPauseFetch)?.isFetchPaused$ !== undefined); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -285,7 +285,7 @@ describe('saved search embeddable', () => { | |
| expect(resolveDataSourceProfileSpy).not.toHaveBeenCalled(); | ||
|
|
||
| // trigger a refetch | ||
| dashboadFilters.next([]); | ||
| dashboadFilters.next([{ meta: {} }]); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR introduces diffing into the keys of the fetch context before firing the requests. Adding this blank filter object triggers a diff which makes the request fire again. In this test, firing an update with a blank array fails the diff and doesn't trigger a refetch. I thought that using filters here would retain the spirit of the test better than switching to reload, but either would work IMO.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the explanation. Makes sense and its only a test |
||
| await waitOneTick(); | ||
| expect(resolveDataSourceProfileSpy).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.