diff --git a/examples/controls_example/public/app/react_control_example/react_control_example.tsx b/examples/controls_example/public/app/react_control_example/react_control_example.tsx index 9436adc208ebd..690c33d0aad97 100644 --- a/examples/controls_example/public/app/react_control_example/react_control_example.tsx +++ b/examples/controls_example/public/app/react_control_example/react_control_example.tsx @@ -99,6 +99,9 @@ export const ReactControlExample = ({ const saveNotification$ = useMemo(() => { return new Subject(); }, []); + const reload$ = useMemo(() => { + return new Subject(); + }, []); const [dataLoading, timeRange, viewMode] = useBatchedPublishingSubjects( dataLoading$, timeRange$, @@ -138,6 +141,7 @@ export const ReactControlExample = ({ }, lastUsedDataViewId: new BehaviorSubject(WEB_LOGS_DATA_VIEW_ID), saveNotification$, + reload$, }; // eslint-disable-next-line react-hooks/exhaustive-deps }, []); @@ -381,6 +385,9 @@ export const ReactControlExample = ({ to: end, }); }} + onRefresh={() => { + reload$.next(); + }} /> & PublishesControlGroupDisplaySettings & PublishesTimeslice & - Partial & HasSaveNotification> & { + Partial & HasSaveNotification & PublishesReload> & { asyncResetUnsavedChanges: () => Promise; autoApplySelections$: PublishingSubject; controlFetch$: (controlUuid: string) => Observable; diff --git a/src/plugins/controls/public/react_controls/controls/data_controls/options_list_control/fetch_and_validate.tsx b/src/plugins/controls/public/react_controls/controls/data_controls/options_list_control/fetch_and_validate.tsx index 7b6db45a1ba2a..f3633b13d3d1a 100644 --- a/src/plugins/controls/public/react_controls/controls/data_controls/options_list_control/fetch_and_validate.tsx +++ b/src/plugins/controls/public/react_controls/controls/data_controls/options_list_control/fetch_and_validate.tsx @@ -11,12 +11,15 @@ import { combineLatest, debounceTime, Observable, + of, + startWith, switchMap, tap, withLatestFrom, } from 'rxjs'; import { PublishingSubject } from '@kbn/presentation-publishing'; +import { apiPublishesReload } from '@kbn/presentation-publishing/interfaces/fetch/publishes_reload'; import { OptionsListSuccessResponse } from '../../../../../common/options_list/types'; import { isValidSearch } from '../../../../../common/options_list/is_valid_search'; import { OptionsListSelection } from '../../../../../common/options_list/options_list_selections'; @@ -57,6 +60,12 @@ export function fetchAndValidate$({ stateManager.searchTechnique, // cannot use requestSize directly, because we need to be able to reset the size to the default without refetching api.loadMoreSubject.pipe(debounceTime(100)), // debounce load more so "loading" state briefly shows + apiPublishesReload(api.parentApi) + ? api.parentApi.reload$.pipe( + tap(() => requestCache.clearCache()), + startWith(undefined) + ) + : of(undefined), ]).pipe( tap(() => { // abort any in progress requests diff --git a/src/plugins/controls/public/react_controls/controls/data_controls/options_list_control/options_list_fetch_cache.ts b/src/plugins/controls/public/react_controls/controls/data_controls/options_list_control/options_list_fetch_cache.ts index 7b30504e3ab1c..6a4bc779a61a2 100644 --- a/src/plugins/controls/public/react_controls/controls/data_controls/options_list_control/options_list_fetch_cache.ts +++ b/src/plugins/controls/public/react_controls/controls/data_controls/options_list_control/options_list_fetch_cache.ts @@ -119,4 +119,8 @@ export class OptionsListFetchCache { return result; } } + + public clearCache = () => { + this.cache.reset(); + }; } diff --git a/src/plugins/controls/public/react_controls/controls/data_controls/range_slider/get_range_slider_control_factory.tsx b/src/plugins/controls/public/react_controls/controls/data_controls/range_slider/get_range_slider_control_factory.tsx index cc953e3109a07..a2819460d05c9 100644 --- a/src/plugins/controls/public/react_controls/controls/data_controls/range_slider/get_range_slider_control_factory.tsx +++ b/src/plugins/controls/public/react_controls/controls/data_controls/range_slider/get_range_slider_control_factory.tsx @@ -144,6 +144,7 @@ export const getRangesliderControlFactory = ( } loadingMinMax$.next(isLoading); }, + controlGroupApi, }).subscribe( ({ error, diff --git a/src/plugins/controls/public/react_controls/controls/data_controls/range_slider/min_max.ts b/src/plugins/controls/public/react_controls/controls/data_controls/range_slider/min_max.ts index 54ee8bf68031d..e68a83eaa4f13 100644 --- a/src/plugins/controls/public/react_controls/controls/data_controls/range_slider/min_max.ts +++ b/src/plugins/controls/public/react_controls/controls/data_controls/range_slider/min_max.ts @@ -11,24 +11,35 @@ import { DataPublicPluginStart } from '@kbn/data-plugin/public'; import { DataView, DataViewField } from '@kbn/data-views-plugin/public'; import { AggregateQuery, Filter, Query, TimeRange } from '@kbn/es-query'; import { PublishesDataViews, PublishingSubject } from '@kbn/presentation-publishing'; -import { combineLatest, lastValueFrom, Observable, switchMap, tap } from 'rxjs'; +import { combineLatest, lastValueFrom, Observable, of, startWith, switchMap, tap } from 'rxjs'; +import { apiPublishesReload } from '@kbn/presentation-publishing/interfaces/fetch/publishes_reload'; import { ControlFetchContext } from '../../../control_group/control_fetch'; +import { ControlGroupApi } from '../../../control_group/types'; export function minMax$({ controlFetch$, + controlGroupApi, data, dataViews$, fieldName$, setIsLoading, }: { controlFetch$: Observable; + controlGroupApi: ControlGroupApi; data: DataPublicPluginStart; dataViews$: PublishesDataViews['dataViews']; fieldName$: PublishingSubject; setIsLoading: (isLoading: boolean) => void; }) { let prevRequestAbortController: AbortController | undefined; - return combineLatest([controlFetch$, dataViews$, fieldName$]).pipe( + return combineLatest([ + controlFetch$, + dataViews$, + fieldName$, + apiPublishesReload(controlGroupApi) + ? controlGroupApi.reload$.pipe(startWith(undefined)) + : of(undefined), + ]).pipe( tap(() => { if (prevRequestAbortController) { prevRequestAbortController.abort();