Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataView[] | undefined>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export const getOptionsListControlFactory = (): DataControlFactory<
});

/** Fetch the suggestions and perform validation */
const suggestionLoadError$ = new BehaviorSubject<Error | undefined>(undefined);
const loadMoreSubject = new Subject<void>();
const fetchSubscription = fetchAndValidate$({
api: {
Expand All @@ -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
Expand Down Expand Up @@ -305,9 +306,22 @@ export const getOptionsListControlFactory = (): DataControlFactory<
},
});

const blockingError$ = new BehaviorSubject<Error | undefined>(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,
Expand Down Expand Up @@ -446,6 +460,7 @@ export const getOptionsListControlFactory = (): DataControlFactory<
validSearchStringSubscription.unsubscribe();
hasSelectionsSubscription.unsubscribe();
selectionsSubscription.unsubscribe();
errorsSubscription.unsubscribe();
};
}, []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down