Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

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 @@ -56,6 +56,7 @@ const PageWrapper: FC<PageProps> = ({ location }) => {
services: {
data: { dataViews: dataViewsService },
savedSearch: savedSearchService,
notifications,
},
} = useMlKibana();
const mlApi = useMlApi();
Expand All @@ -72,7 +73,8 @@ const PageWrapper: FC<PageProps> = ({ location }) => {
mlApi,
dataViewsService,
savedSearchService,
DATA_FRAME_ANALYTICS
DATA_FRAME_ANALYTICS,
notifications
),
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ const PageWrapper: FC<WizardPageProps> = ({ location, jobType }) => {
data: { dataViews: dataViewsService },
savedSearch: savedSearchService,
mlServices: { mlApi },
notifications,
},
} = useMlKibana();
const { context, results } = useRouteResolver('full', ['canGetJobs', 'canCreateJob'], {
Expand All @@ -211,7 +212,8 @@ const PageWrapper: FC<WizardPageProps> = ({ location, jobType }) => {
mlApi,
dataViewsService,
savedSearchService,
ANOMALY_DETECTOR
ANOMALY_DETECTOR,
notifications
),
existingJobsAndGroups: () => mlApi.jobs.getAllJobAndGroupIds(),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@

import type { DataView, DataViewsContract } from '@kbn/data-views-plugin/public';
import type { SavedSearchPublicPluginStart } from '@kbn/saved-search-plugin/public';
import type { NotificationsStart } from '@kbn/core/public';
import { i18n } from '@kbn/i18n';
import { getDataViewAndSavedSearchCallback } from '../../util/index_utils';
import type { JobType } from '../../../../common/types/saved_objects';
import type { MlApi } from '../ml_api_service';
import { mlJobCapsServiceAnalyticsFactory } from './new_job_capabilities_service_analytics';
import { mlJobCapsServiceFactory } from './new_job_capabilities_service';
import { toastNotificationServiceProvider } from '../toast_notification_service/toast_notification_service';

export const ANOMALY_DETECTOR = 'anomaly-detector';
export const DATA_FRAME_ANALYTICS = 'data-frame-analytics';
Expand All @@ -24,7 +27,8 @@ export function loadNewJobCapabilities(
mlApi: MlApi,
dataViewsService: DataViewsContract,
savedSearchService: SavedSearchPublicPluginStart,
jobType: JobType
jobType: JobType,
notifications: NotificationsStart
) {
return new Promise(async (resolve, reject) => {
try {
Expand Down Expand Up @@ -58,6 +62,12 @@ export function loadNewJobCapabilities(
reject();
}
} catch (error) {
toastNotificationServiceProvider(notifications.toasts).displayErrorToast(
error,
i18n.translate('xpack.ml.newJob.capabilities.loadErrorTitle', {
defaultMessage: 'Failed to load job capabilities',
})
);
reject(error);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { SavedSearch, SavedSearchPublicPluginStart } from '@kbn/saved-searc
import { isCCSRemoteIndexName } from '@kbn/es-query';
import type { Query, Filter } from '@kbn/es-query';
import type { DataView, DataViewField, DataViewsContract } from '@kbn/data-views-plugin/common';
import type { SearchSourceFields } from '@kbn/data-plugin/public';

export interface DataViewAndSavedSearch {
savedSearch: SavedSearch | null;
Expand All @@ -35,7 +36,28 @@ export const getDataViewAndSavedSearchCallback =
return resp;
}
const dataViewId = ss.references?.find((r) => r.type === 'index-pattern')?.id;
resp.dataView = await deps.dataViewsService.get(dataViewId!);
if (dataViewId) {
resp.dataView = await deps.dataViewsService.get(dataViewId);
} else {
try {
const json: SearchSourceFields = JSON.parse(
ss.tabs![0].attributes.kibanaSavedObjectMeta.searchSourceJSON
);
if (!json.index) {
throw new Error('No data view found in Discover session');
}
resp.dataView = await deps.dataViewsService.create({
id: undefined,
title: json.index.title,
name: json.index.name,
timeFieldName: json.index.timeFieldName,
});
} catch (error) {
// eslint-disable-next-line no-console
console.error('No data view found in Discover session', error);
throw new Error('No data view found in Discover session');
}
}
resp.savedSearch = ss;
return resp;
};
Expand Down