mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
react control group: implement reload (#190366)
PR adds reload implementation for react control group.
This commit is contained in:
parent
74d88580a5
commit
571fe047c1
7 changed files with 38 additions and 3 deletions
|
@ -99,6 +99,9 @@ export const ReactControlExample = ({
|
|||
const saveNotification$ = useMemo(() => {
|
||||
return new Subject<void>();
|
||||
}, []);
|
||||
const reload$ = useMemo(() => {
|
||||
return new Subject<void>();
|
||||
}, []);
|
||||
const [dataLoading, timeRange, viewMode] = useBatchedPublishingSubjects(
|
||||
dataLoading$,
|
||||
timeRange$,
|
||||
|
@ -138,6 +141,7 @@ export const ReactControlExample = ({
|
|||
},
|
||||
lastUsedDataViewId: new BehaviorSubject<string>(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();
|
||||
}}
|
||||
/>
|
||||
<EuiSpacer size="m" />
|
||||
<ReactEmbeddableRenderer
|
||||
|
|
|
@ -23,6 +23,7 @@ import {
|
|||
PublishesDataViews,
|
||||
useBatchedPublishingSubjects,
|
||||
} from '@kbn/presentation-publishing';
|
||||
import { apiPublishesReload } from '@kbn/presentation-publishing/interfaces/fetch/publishes_reload';
|
||||
import { ControlStyle, ParentIgnoreSettings } from '../..';
|
||||
import {
|
||||
ControlGroupChainingSystem,
|
||||
|
@ -205,6 +206,7 @@ export const getControlGroupEmbeddableFactory = (services: {
|
|||
saveNotification$: apiHasSaveNotification(parentApi)
|
||||
? parentApi.saveNotification$
|
||||
: undefined,
|
||||
reload$: apiPublishesReload(parentApi) ? parentApi.reload$ : undefined,
|
||||
});
|
||||
|
||||
/** Subscribe to all children's output data views, combine them, and output them */
|
||||
|
|
|
@ -27,6 +27,7 @@ import {
|
|||
} from '@kbn/presentation-publishing';
|
||||
import { PublishesDataViews } from '@kbn/presentation-publishing/interfaces/publishes_data_views';
|
||||
|
||||
import { PublishesReload } from '@kbn/presentation-publishing/interfaces/fetch/publishes_reload';
|
||||
import { ParentIgnoreSettings } from '../..';
|
||||
import { ControlInputTransform } from '../../../common';
|
||||
import { ControlGroupChainingSystem } from '../../../common/control_group/types';
|
||||
|
@ -61,7 +62,7 @@ export type ControlGroupApi = PresentationContainer &
|
|||
Pick<PublishesUnsavedChanges, 'unsavedChanges'> &
|
||||
PublishesControlGroupDisplaySettings &
|
||||
PublishesTimeslice &
|
||||
Partial<HasParentApi<PublishesUnifiedSearch> & HasSaveNotification> & {
|
||||
Partial<HasParentApi<PublishesUnifiedSearch> & HasSaveNotification & PublishesReload> & {
|
||||
asyncResetUnsavedChanges: () => Promise<void>;
|
||||
autoApplySelections$: PublishingSubject<boolean>;
|
||||
controlFetch$: (controlUuid: string) => Observable<ControlFetchContext>;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -119,4 +119,8 @@ export class OptionsListFetchCache {
|
|||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public clearCache = () => {
|
||||
this.cache.reset();
|
||||
};
|
||||
}
|
||||
|
|
|
@ -144,6 +144,7 @@ export const getRangesliderControlFactory = (
|
|||
}
|
||||
loadingMinMax$.next(isLoading);
|
||||
},
|
||||
controlGroupApi,
|
||||
}).subscribe(
|
||||
({
|
||||
error,
|
||||
|
|
|
@ -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<ControlFetchContext>;
|
||||
controlGroupApi: ControlGroupApi;
|
||||
data: DataPublicPluginStart;
|
||||
dataViews$: PublishesDataViews['dataViews'];
|
||||
fieldName$: PublishingSubject<string>;
|
||||
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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue