diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/action_delete/use_delete_action.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/action_delete/use_delete_action.tsx index 0d2025c0d049a..67c44f041d401 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/action_delete/use_delete_action.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/action_delete/use_delete_action.tsx @@ -55,11 +55,13 @@ export const useDeleteAction = (canDeleteDataFrameAnalytics: boolean) => { const checkIndexPatternExists = async () => { try { - const dv = (await dataViews.find(indexName)).find(({ title }) => title === indexName); - if (dv !== undefined) { - setIndexPatternExists(true); - } else { - setIndexPatternExists(false); + if (indexName !== '') { + const dv = (await dataViews.find(indexName)).find(({ title }) => title === indexName); + if (dv !== undefined) { + setIndexPatternExists(true); + } else { + setIndexPatternExists(false); + } } setIsLoading(false); } catch (e) { diff --git a/x-pack/plugins/ml/public/application/jobs/components/custom_url_editor/editor.test.tsx b/x-pack/plugins/ml/public/application/jobs/components/custom_url_editor/editor.test.tsx index 11e4c14cd4ab2..9d6dc3f11d448 100644 --- a/x-pack/plugins/ml/public/application/jobs/components/custom_url_editor/editor.test.tsx +++ b/x-pack/plugins/ml/public/application/jobs/components/custom_url_editor/editor.test.tsx @@ -16,7 +16,7 @@ import React from 'react'; import { CustomUrlEditor } from './editor'; import { TIME_RANGE_TYPE, URL_TYPE } from './constants'; import { CustomUrlSettings } from './utils'; -import { DataView } from '../../../../../../../../src/plugins/data_views/common'; +import { DataViewListItem } from '../../../../../../../../src/plugins/data_views/common'; function prepareTest(customUrl: CustomUrlSettings, setEditCustomUrlFn: (url: UrlConfig) => void) { const savedCustomUrls = [ @@ -50,7 +50,7 @@ function prepareTest(customUrl: CustomUrlSettings, setEditCustomUrlFn: (url: Url const indexPatterns = [ { id: 'pattern1', title: 'Index Pattern 1' }, { id: 'pattern2', title: 'Index Pattern 2' }, - ] as DataView[]; + ] as DataViewListItem[]; const queryEntityFieldNames = ['airline']; diff --git a/x-pack/plugins/ml/public/application/jobs/components/custom_url_editor/editor.tsx b/x-pack/plugins/ml/public/application/jobs/components/custom_url_editor/editor.tsx index 7dd779ead7892..b674b2d59dbc6 100644 --- a/x-pack/plugins/ml/public/application/jobs/components/custom_url_editor/editor.tsx +++ b/x-pack/plugins/ml/public/application/jobs/components/custom_url_editor/editor.tsx @@ -29,7 +29,7 @@ import { isValidLabel } from '../../../util/custom_url_utils'; import { TIME_RANGE_TYPE, URL_TYPE } from './constants'; import { UrlConfig } from '../../../../../common/types/custom_urls'; -import { DataView } from '../../../../../../../../src/plugins/data_views/common'; +import { DataViewListItem } from '../../../../../../../../src/plugins/data_views/common'; function getLinkToOptions() { return [ @@ -59,7 +59,7 @@ interface CustomUrlEditorProps { setEditCustomUrl: (url: any) => void; savedCustomUrls: UrlConfig[]; dashboards: any[]; - indexPatterns: DataView[]; + indexPatterns: DataViewListItem[]; queryEntityFieldNames: string[]; } diff --git a/x-pack/plugins/ml/public/application/jobs/components/custom_url_editor/utils.d.ts b/x-pack/plugins/ml/public/application/jobs/components/custom_url_editor/utils.d.ts index 1f815759c6242..db613472d3f92 100644 --- a/x-pack/plugins/ml/public/application/jobs/components/custom_url_editor/utils.d.ts +++ b/x-pack/plugins/ml/public/application/jobs/components/custom_url_editor/utils.d.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { DataView } from '../../../../../../../../src/plugins/data_views/common'; +import { DataViewListItem } from '../../../../../../../../src/plugins/data_views/common'; import { UrlConfig } from '../../../../../common/types/custom_urls'; import { Job } from '../../../../../common/types/anomaly_detection_jobs'; import { TimeRangeType } from './constants'; @@ -34,7 +34,7 @@ export function isValidCustomUrlSettingsTimeRange(timeRangeSettings: any): boole export function getNewCustomUrlDefaults( job: Job, dashboards: any[], - indexPatterns: DataView[] + indexPatterns: DataViewListItem[] ): CustomUrlSettings; export function getQueryEntityFieldNames(job: Job): string[]; export function isValidCustomUrlSettings( diff --git a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/edit_utils.d.ts b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/edit_utils.d.ts index 32e99e3e433e0..114162e9a3c74 100644 --- a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/edit_utils.d.ts +++ b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/edit_utils.d.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type { DataView } from 'src/plugins/data_views/common'; +import type { DataViewListItem } from 'src/plugins/data_views/common'; export function loadSavedDashboards(maxNumber: number): Promise; -export function loadIndexPatterns(maxNumber: number): Promise; +export function loadIndexPatterns(): Promise; diff --git a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/edit_utils.js b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/edit_utils.js index ad192a738174e..ff5fb47cf24fc 100644 --- a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/edit_utils.js +++ b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/edit_utils.js @@ -102,14 +102,14 @@ export function loadSavedDashboards(maxNumber) { }); } -export function loadIndexPatterns(maxNumber) { +export function loadIndexPatterns() { // Loads the list of Kibana index patterns, as used in editing custom URLs. // TODO - amend loadIndexPatterns in index_utils.js to do the request, // without needing an Angular Provider. return new Promise((resolve, reject) => { const dataViewsContract = getDataViews(); dataViewsContract - .find('*', maxNumber) + .getIdsWithTitle() .then((dataViews) => { const sortedDataViews = dataViews.sort((a, b) => a.title.localeCompare(b.title)); resolve(sortedDataViews); diff --git a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/tabs/custom_urls.tsx b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/tabs/custom_urls.tsx index 46ac1dbd01b7f..8a39f832a88b7 100644 --- a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/tabs/custom_urls.tsx +++ b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/tabs/custom_urls.tsx @@ -37,11 +37,10 @@ import { loadSavedDashboards, loadIndexPatterns } from '../edit_utils'; import { openCustomUrlWindow } from '../../../../../util/custom_url_utils'; import { Job } from '../../../../../../../common/types/anomaly_detection_jobs'; import { UrlConfig } from '../../../../../../../common/types/custom_urls'; -import { DataView } from '../../../../../../../../../../src/plugins/data_views/common'; +import { DataViewListItem } from '../../../../../../../../../../src/plugins/data_views/common'; import { MlKibanaReactContextValue } from '../../../../../contexts/kibana'; const MAX_NUMBER_DASHBOARDS = 1000; -const MAX_NUMBER_INDEX_PATTERNS = 1000; interface CustomUrlsProps { job: Job; @@ -54,7 +53,7 @@ interface CustomUrlsProps { interface CustomUrlsState { customUrls: UrlConfig[]; dashboards: any[]; - indexPatterns: DataView[]; + indexPatterns: DataViewListItem[]; queryEntityFieldNames: string[]; editorOpen: boolean; editorSettings?: CustomUrlSettings; @@ -100,7 +99,7 @@ class CustomUrlsUI extends Component { ); }); - loadIndexPatterns(MAX_NUMBER_INDEX_PATTERNS) + loadIndexPatterns() .then((indexPatterns) => { this.setState({ indexPatterns }); }) diff --git a/x-pack/plugins/ml/public/application/util/index_utils.ts b/x-pack/plugins/ml/public/application/util/index_utils.ts index b4f46d4df0cbb..1a3bccd00eea8 100644 --- a/x-pack/plugins/ml/public/application/util/index_utils.ts +++ b/x-pack/plugins/ml/public/application/util/index_utils.ts @@ -18,7 +18,25 @@ let indexPatternsContract: DataViewsContract | null = null; export async function loadIndexPatterns(indexPatterns: DataViewsContract) { indexPatternsContract = indexPatterns; const dataViewsContract = getDataViews(); - indexPatternCache = await dataViewsContract.find('*', 10000); + const idsAndTitles = await dataViewsContract.getIdsWithTitle(); + + const dataViewsThatExist = ( + await Promise.allSettled( + // attempt to load the fields for every data view. + // if the index doesn't exist an error is thrown which we can catch. + // This is preferable to the get function which display an + // error toast for every missing index. + idsAndTitles.map(({ title }) => dataViewsContract.getFieldsForIndexPattern({ title })) + ) + ).reduce((acc, { status }, i) => { + if (status === 'fulfilled') { + acc.push(idsAndTitles[i].id); + } + return acc; + }, []); + + // load each data view which has a real index behind it. + indexPatternCache = await Promise.all(dataViewsThatExist.map(dataViewsContract.get)); return indexPatternCache; }