diff --git a/src/plugins/data_views/common/data_views/data_views.test.ts b/src/plugins/data_views/common/data_views/data_views.test.ts index 05ca95b1adfe2..e5e9b2d83faf7 100644 --- a/src/plugins/data_views/common/data_views/data_views.test.ts +++ b/src/plugins/data_views/common/data_views/data_views.test.ts @@ -23,7 +23,7 @@ import { DataViewMissingIndices } from '../lib'; const createFieldsFetcher = () => ({ - getFieldsForWildcard: jest.fn(async () => ({ fields: [], indices: [] })), + getFieldsForWildcard: jest.fn(async () => ({ fields: [], indices: ['test'] })), } as any as IDataViewsApiClient); const fieldFormats = fieldFormatsMock; @@ -70,7 +70,6 @@ describe('IndexPatterns', () => { remove: jest.fn(), } as any as UiSettingsCommon; const indexPatternObj = { id: 'id', version: 'a', attributes: { title: 'title' } }; - const onMissingIndices = jest.fn(); beforeEach(() => { jest.clearAllMocks(); @@ -114,7 +113,6 @@ describe('IndexPatterns', () => { apiClient, fieldFormats, onNotification: () => {}, - onMissingIndices, onError: () => {}, onRedirectNoIndexPattern: () => {}, getCanSave: () => Promise.resolve(true), @@ -127,7 +125,6 @@ describe('IndexPatterns', () => { apiClient, fieldFormats, onNotification: () => {}, - onMissingIndices, onError: () => {}, onRedirectNoIndexPattern: () => {}, getCanSave: () => Promise.resolve(false), @@ -225,7 +222,20 @@ describe('IndexPatterns', () => { expect((await indexPatterns.get(id)).fields.length).toBe(1); }); - test('missing indices triggering onMissingIndices fn', async () => { + test('existing indices, so dataView.matchedIndices.length equals 1 ', async () => { + const id = '1'; + setDocsourcePayload(id, { + id: 'foo', + version: 'foo', + attributes: { + title: 'something', + }, + }); + const dataView = await indexPatterns.get(id); + expect(dataView.matchedIndices.length).toBe(1); + }); + + test('missing indices, so dataView.matchedIndices.length equals 0 ', async () => { const id = '1'; setDocsourcePayload(id, { id: 'foo', @@ -237,8 +247,8 @@ describe('IndexPatterns', () => { apiClient.getFieldsForWildcard = jest.fn().mockImplementation(async () => { throw new DataViewMissingIndices('Catch me if you can!'); }); - await indexPatterns.get(id); - expect(onMissingIndices).toHaveBeenCalled(); + const dataView = await indexPatterns.get(id); + expect(dataView.matchedIndices.length).toBe(0); }); test('savedObjectCache pre-fetches title, type, typeMeta', async () => { diff --git a/src/plugins/data_views/common/data_views/data_views.ts b/src/plugins/data_views/common/data_views/data_views.ts index abfcd5d5f83ac..afccfdcee79fc 100644 --- a/src/plugins/data_views/common/data_views/data_views.ts +++ b/src/plugins/data_views/common/data_views/data_views.ts @@ -103,11 +103,6 @@ export interface DataViewsServiceDeps { * Handler for service notifications */ onNotification: OnNotification; - /** - * Handler triggered when there are no indices - * @param error Error object - */ - onMissingIndices?: (error: Error) => void; /** * Handler for service errors */ @@ -308,11 +303,6 @@ export class DataViewsService { * @param key used to indicate uniqueness of the notification */ private onNotification: OnNotification; - /** - * Handler triggered when there are no indices - * @param error Error object - */ - private onMissingIndices?: (error: Error) => void; /* * Handler for service errors * @param error notification content in toast format @@ -339,7 +329,6 @@ export class DataViewsService { apiClient, fieldFormats, onNotification, - onMissingIndices, onError, getCanSave = () => Promise.resolve(false), getCanSaveAdvancedSettings, @@ -350,7 +339,6 @@ export class DataViewsService { this.fieldFormats = fieldFormats; this.onNotification = onNotification; this.onError = onError; - this.onMissingIndices = onMissingIndices; this.getCanSave = getCanSave; this.getCanSaveAdvancedSettings = getCanSaveAdvancedSettings; @@ -594,7 +582,7 @@ export class DataViewsService { await this.refreshFieldsFn(dataView); } catch (err) { if (err instanceof DataViewMissingIndices) { - this.onMissingIndices?.(err); + // not considered an error, check dataView.matchedIndices.length to be 0 } else { this.onError( err, @@ -644,7 +632,7 @@ export class DataViewsService { return { fields: this.fieldArrayToMap(updatedFieldList, fieldAttrs), indices }; } catch (err) { if (err instanceof DataViewMissingIndices) { - this.onMissingIndices?.(err); + // not considered an error, check dataView.matchedIndices.length to be 0 return {}; } if (!displayErrors) { @@ -805,12 +793,13 @@ export class DataViewsService { const fieldsAndIndices = await this.initFromSavedObjectLoadFields({ savedObjectId: savedObject.id, spec, + displayErrors, }); fields = fieldsAndIndices.fields; indices = fieldsAndIndices.indices; } catch (err) { if (err instanceof DataViewMissingIndices) { - this.onMissingIndices?.(err); + // not considered an error, check dataView.matchedIndices.length to be 0 } else { this.onError( err,