diff --git a/src/platform/packages/shared/presentation/presentation_publishing/interfaces/publishes_data_views.ts b/src/platform/packages/shared/presentation/presentation_publishing/interfaces/publishes_data_views.ts index b3a9da716d6be..0518e1d6c2892 100644 --- a/src/platform/packages/shared/presentation/presentation_publishing/interfaces/publishes_data_views.ts +++ b/src/platform/packages/shared/presentation/presentation_publishing/interfaces/publishes_data_views.ts @@ -10,6 +10,10 @@ import { DataView } from '@kbn/data-views-plugin/common'; import { PublishingSubject } from '../publishing_subject'; +/** + * This API publishes a list of data views that it uses. Note that this should not contain any + * ad-hoc data views. + */ export interface PublishesDataViews { dataViews$: PublishingSubject; } diff --git a/src/platform/plugins/shared/controls/public/controls/data_controls/options_list_control/get_options_list_control_factory.tsx b/src/platform/plugins/shared/controls/public/controls/data_controls/options_list_control/get_options_list_control_factory.tsx index 1d0c786c23f06..5880e5487873b 100644 --- a/src/platform/plugins/shared/controls/public/controls/data_controls/options_list_control/get_options_list_control_factory.tsx +++ b/src/platform/plugins/shared/controls/public/controls/data_controls/options_list_control/get_options_list_control_factory.tsx @@ -153,6 +153,7 @@ export const getOptionsListControlFactory = (): DataControlFactory< }); /** Fetch the suggestions and perform validation */ + const suggestionLoadError$ = new BehaviorSubject(undefined); const loadMoreSubject = new Subject(); const fetchSubscription = fetchAndValidate$({ api: { @@ -169,13 +170,13 @@ export const getOptionsListControlFactory = (): DataControlFactory< sort$, controlFetch$: (onReload: () => void) => controlGroupApi.controlFetch$(uuid, onReload), }).subscribe((result) => { - // if there was an error during fetch, set blocking error and return early + // if there was an error during fetch, set suggestion load error and return early if (Object.hasOwn(result, 'error')) { - dataControlManager.api.setBlockingError((result as { error: Error }).error); + suggestionLoadError$.next((result as { error: Error }).error); return; - } else if (dataControlManager.api.blockingError$.getValue()) { + } else if (suggestionLoadError$.getValue()) { // otherwise, if there was a previous error, clear it - dataControlManager.api.setBlockingError(undefined); + suggestionLoadError$.next(undefined); } // fetch was successful so set all attributes from result @@ -305,9 +306,22 @@ export const getOptionsListControlFactory = (): DataControlFactory< }, }); + const blockingError$ = new BehaviorSubject(undefined); + const errorsSubscription = combineLatest([ + dataControlManager.api.blockingError$, + suggestionLoadError$, + ]) + .pipe( + map(([controlError, suggestionError]) => { + return controlError ?? suggestionError; + }) + ) + .subscribe((error) => blockingError$.next(error)); + const api = finalizeApi({ ...unsavedChangesApi, ...dataControlManager.api, + blockingError$, dataLoading$: temporaryStateManager.api.dataLoading$, getTypeDisplayName: OptionsListStrings.control.getDisplayName, serializeState, @@ -446,6 +460,7 @@ export const getOptionsListControlFactory = (): DataControlFactory< validSearchStringSubscription.unsubscribe(); hasSelectionsSubscription.unsubscribe(); selectionsSubscription.unsubscribe(); + errorsSubscription.unsubscribe(); }; }, []); diff --git a/src/platform/plugins/shared/dashboard/public/dashboard_api/data_views_manager.ts b/src/platform/plugins/shared/dashboard/public/dashboard_api/data_views_manager.ts index 34d2d10433292..ce1b799d3ee7c 100644 --- a/src/platform/plugins/shared/dashboard/public/dashboard_api/data_views_manager.ts +++ b/src/platform/plugins/shared/dashboard/public/dashboard_api/data_views_manager.ts @@ -42,7 +42,10 @@ export function initializeDataViewsManager( const dataViewsSubscription = combineLatest([controlGroupDataViewsPipe, childDataViewsPipe]) .pipe( switchMap(async ([controlGroupDataViews, childDataViews]) => { - const allDataViews = [...(controlGroupDataViews ?? []), ...childDataViews]; + const allDataViews = [...(controlGroupDataViews ?? []), ...childDataViews].filter( + (dataView) => dataView.isPersisted() + ); + if (allDataViews.length === 0) { try { const defaultDataView = await dataService.dataViews.getDefaultDataView(); diff --git a/src/platform/plugins/shared/data_views/common/data_views/abstract_data_views.ts b/src/platform/plugins/shared/data_views/common/data_views/abstract_data_views.ts index 6da94426c960d..ffb7c86f63c23 100644 --- a/src/platform/plugins/shared/data_views/common/data_views/abstract_data_views.ts +++ b/src/platform/plugins/shared/data_views/common/data_views/abstract_data_views.ts @@ -235,6 +235,9 @@ export abstract class AbstractDataView { this.originalSavedObjectBody = this.getAsSavedObjectBody(); }; + /** + * Returns true if the data view is persisted, and false if the dataview is adhoc. + */ isPersisted() { return typeof this.version === 'string'; }