From d8ec4133c20089e6c5a010cb08aee9286b136334 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Mon, 3 Mar 2025 14:26:07 -0700 Subject: [PATCH] ml tslint --- .../custom_urls/custom_url_editor/utils.ts | 8 ++- .../components/custom_urls/custom_urls.tsx | 60 ++++++++++--------- .../quick_create_job_base.ts | 14 ++--- .../new_job/job_from_lens/quick_create_job.ts | 6 +- .../new_job/job_from_lens/route_resolver.ts | 8 +-- .../new_job/job_from_map/quick_create_job.ts | 6 +- .../new_job/job_from_map/route_resolver.ts | 14 ++--- .../quick_create_job.ts | 6 +- .../route_resolver.ts | 8 +-- .../routing/routes/new_job/from_lens.tsx | 4 +- .../routing/routes/new_job/from_map.tsx | 4 +- .../routes/new_job/from_pattern_analysis.tsx | 4 +- .../services/dashboard_service.test.ts | 17 +++++- .../application/services/dashboard_service.ts | 13 ++-- .../job_creation/aiops/flyout/create_job.tsx | 5 +- .../job_creation/common/context.ts | 2 - .../layer/compatible_layer.tsx | 3 +- .../layer/compatible_layer.tsx | 3 +- .../plugins/shared/ml/public/plugin.ts | 3 +- 19 files changed, 100 insertions(+), 88 deletions(-) diff --git a/x-pack/platform/plugins/shared/ml/public/application/components/custom_urls/custom_url_editor/utils.ts b/x-pack/platform/plugins/shared/ml/public/application/components/custom_urls/custom_url_editor/utils.ts index a55d4ffe343c8..6b020bed5f992 100644 --- a/x-pack/platform/plugins/shared/ml/public/application/components/custom_urls/custom_url_editor/utils.ts +++ b/x-pack/platform/plugins/shared/ml/public/application/components/custom_urls/custom_url_editor/utils.ts @@ -28,6 +28,8 @@ import { import { isDefined } from '@kbn/ml-is-defined'; import { parseInterval } from '@kbn/ml-parse-interval'; +import type { SharePluginStart } from '@kbn/share-plugin/public'; +import { DASHBOARD_APP_LOCATOR } from '@kbn/deeplinks-analytics'; import type { DashboardItems } from '../../../services/dashboard_service'; import { categoryFieldTypes } from '../../../../../common/util/fields_utils'; import { TIME_RANGE_TYPE, URL_TYPE } from './constants'; @@ -221,12 +223,13 @@ export function isValidCustomUrlSettings( export function buildCustomUrlFromSettings( dashboardService: DashboardStart, + share: SharePluginStart, settings: CustomUrlSettings ): Promise { // Dashboard URL returns a Promise as a query is made to obtain the full dashboard config. // So wrap the other two return types in a Promise for consistent return type. if (settings.type === URL_TYPE.KIBANA_DASHBOARD) { - return buildDashboardUrlFromSettings(dashboardService, settings); + return buildDashboardUrlFromSettings(dashboardService, share, settings); } else if (settings.type === URL_TYPE.KIBANA_DISCOVER) { return Promise.resolve(buildDiscoverUrlFromSettings(settings)); } else { @@ -256,6 +259,7 @@ function getUrlRangeFromSettings(settings: CustomUrlSettings) { async function buildDashboardUrlFromSettings( dashboardService: DashboardStart, + share: SharePluginStart, settings: CustomUrlSettings, isPartialDFAJob?: boolean ): Promise { @@ -300,7 +304,7 @@ async function buildDashboardUrlFromSettings( const { from, to } = getUrlRangeFromSettings(settings); - const location = await dashboardService.locator?.getLocation({ + const location = await share.url.locators.get(DASHBOARD_APP_LOCATOR)?.getLocation({ dashboardId, timeRange: { from, diff --git a/x-pack/platform/plugins/shared/ml/public/application/components/custom_urls/custom_urls.tsx b/x-pack/platform/plugins/shared/ml/public/application/components/custom_urls/custom_urls.tsx index 7bec64f3bf6b3..8dcf7b15ad544 100644 --- a/x-pack/platform/plugins/shared/ml/public/application/components/custom_urls/custom_urls.tsx +++ b/x-pack/platform/plugins/shared/ml/public/application/components/custom_urls/custom_urls.tsx @@ -151,9 +151,9 @@ export class CustomUrls extends Component { }; addNewCustomUrl = () => { - const { dashboard } = this.context.services; + const { dashboard, share } = this.context.services; - buildCustomUrlFromSettings(dashboard, this.state.editorSettings as CustomUrlSettings) + buildCustomUrlFromSettings(dashboard, share, this.state.editorSettings as CustomUrlSettings) .then((customUrl) => { const customUrls = [...this.state.customUrls, customUrl]; this.props.setCustomUrls(customUrls); @@ -179,6 +179,7 @@ export class CustomUrls extends Component { data: { dataViews }, dashboard, mlServices: { mlApi }, + share, } = this.context.services; const dataViewId = this.state?.editorSettings?.kibanaSettings?.discoverIndexPatternId; const job = this.props.job; @@ -191,33 +192,34 @@ export class CustomUrls extends Component { }) .then((dataView) => { const timefieldName = dataView?.timeFieldName ?? null; - buildCustomUrlFromSettings(dashboard, this.state.editorSettings as CustomUrlSettings).then( - (customUrl) => { - getTestUrl( - mlApi, - job, - customUrl, - timefieldName, - this.props.currentTimeFilter, - this.props.isPartialDFAJob - ) - .then((testUrl) => { - openCustomUrlWindow(testUrl, customUrl, basePath.get()); - }) - .catch((error) => { - this.toastNotificationService!.displayErrorToast( - error, - i18n.translate( - 'xpack.ml.jobsList.editJobFlyout.customUrls.getTestUrlErrorNotificationMessage', - { - defaultMessage: - 'An error occurred obtaining the URL to test the configuration', - } - ) - ); - }); - } - ); + buildCustomUrlFromSettings( + dashboard, + share, + this.state.editorSettings as CustomUrlSettings + ).then((customUrl) => { + getTestUrl( + mlApi, + job, + customUrl, + timefieldName, + this.props.currentTimeFilter, + this.props.isPartialDFAJob + ) + .then((testUrl) => { + openCustomUrlWindow(testUrl, customUrl, basePath.get()); + }) + .catch((error) => { + this.toastNotificationService!.displayErrorToast( + error, + i18n.translate( + 'xpack.ml.jobsList.editJobFlyout.customUrls.getTestUrlErrorNotificationMessage', + { + defaultMessage: 'An error occurred obtaining the URL to test the configuration', + } + ) + ); + }); + }); }) .catch((error) => { this.toastNotificationService!.displayErrorToast( diff --git a/x-pack/platform/plugins/shared/ml/public/application/jobs/new_job/job_from_dashboard/quick_create_job_base.ts b/x-pack/platform/plugins/shared/ml/public/application/jobs/new_job/job_from_dashboard/quick_create_job_base.ts index 0cf35e1a2128c..391280e365995 100644 --- a/x-pack/platform/plugins/shared/ml/public/application/jobs/new_job/job_from_dashboard/quick_create_job_base.ts +++ b/x-pack/platform/plugins/shared/ml/public/application/jobs/new_job/job_from_dashboard/quick_create_job_base.ts @@ -11,16 +11,14 @@ import type { IUiSettingsClient } from '@kbn/core/public'; import type { TimefilterContract } from '@kbn/data-plugin/public'; import { firstValueFrom } from 'rxjs'; import type { estypes } from '@elastic/elasticsearch'; -import type { - DashboardApi, - DashboardLocatorParams, - DashboardStart, -} from '@kbn/dashboard-plugin/public'; +import type { DashboardApi, DashboardLocatorParams } from '@kbn/dashboard-plugin/public'; import { getTitle } from '@kbn/presentation-publishing'; import type { Filter, Query, DataViewBase } from '@kbn/es-query'; import { FilterStateStore } from '@kbn/es-query'; import type { ErrorType } from '@kbn/ml-error-utils'; import type { DataViewsContract } from '@kbn/data-views-plugin/public'; +import type { SharePluginStart } from '@kbn/share-plugin/public'; +import { DASHBOARD_APP_LOCATOR } from '@kbn/deeplinks-analytics'; import type { MlApi } from '../../../services/ml_api_service'; import type { Job, Datafeed } from '../../../../../common/types/anomaly_detection_jobs'; import { getFiltersForDSLQuery } from '../../../../../common/util/job_utils'; @@ -55,7 +53,7 @@ export class QuickJobCreatorBase { protected readonly dataViews: DataViewsContract, protected readonly kibanaConfig: IUiSettingsClient, protected readonly timeFilter: TimefilterContract, - protected readonly dashboardService: DashboardStart, + protected readonly shareService: SharePluginStart, protected readonly mlApi: MlApi ) {} @@ -246,7 +244,9 @@ export class QuickJobCreatorBase { ), }; - const location = await this.dashboardService.locator?.getLocation(params); + const location = await this.shareService.url.locators + .get(DASHBOARD_APP_LOCATOR) + ?.getLocation(params); if (location === undefined) { return null; } diff --git a/x-pack/platform/plugins/shared/ml/public/application/jobs/new_job/job_from_lens/quick_create_job.ts b/x-pack/platform/plugins/shared/ml/public/application/jobs/new_job/job_from_lens/quick_create_job.ts index cda0e842f2c95..20d5f3ab9f745 100644 --- a/x-pack/platform/plugins/shared/ml/public/application/jobs/new_job/job_from_lens/quick_create_job.ts +++ b/x-pack/platform/plugins/shared/ml/public/application/jobs/new_job/job_from_lens/quick_create_job.ts @@ -15,7 +15,7 @@ import type { IUiSettingsClient } from '@kbn/core/public'; import type { TimefilterContract } from '@kbn/data-plugin/public'; import type { DataViewsContract } from '@kbn/data-views-plugin/public'; import { isOfAggregateQueryType, type Filter, type Query } from '@kbn/es-query'; -import type { DashboardStart } from '@kbn/dashboard-plugin/public'; +import type { SharePluginStart } from '@kbn/share-plugin/public'; import type { LensApi } from '@kbn/lens-plugin/public'; import type { JobCreatorType } from '../common/job_creator'; import { createEmptyJob, createEmptyDatafeed } from '../common/job_creator/util/default_configs'; @@ -41,10 +41,10 @@ export class QuickLensJobCreator extends QuickJobCreatorBase { dataViews: DataViewsContract, kibanaConfig: IUiSettingsClient, timeFilter: TimefilterContract, - dashboardService: DashboardStart, + shareService: SharePluginStart, mlApi: MlApi ) { - super(dataViews, kibanaConfig, timeFilter, dashboardService, mlApi); + super(dataViews, kibanaConfig, timeFilter, shareService, mlApi); } public async createAndSaveJob( diff --git a/x-pack/platform/plugins/shared/ml/public/application/jobs/new_job/job_from_lens/route_resolver.ts b/x-pack/platform/plugins/shared/ml/public/application/jobs/new_job/job_from_lens/route_resolver.ts index 45d54593ab237..b33e374e4c0f3 100644 --- a/x-pack/platform/plugins/shared/ml/public/application/jobs/new_job/job_from_lens/route_resolver.ts +++ b/x-pack/platform/plugins/shared/ml/public/application/jobs/new_job/job_from_lens/route_resolver.ts @@ -11,7 +11,7 @@ import type { Filter } from '@kbn/es-query'; import type { LensPublicStart, LensSavedObjectAttributes } from '@kbn/lens-plugin/public'; import type { IUiSettingsClient } from '@kbn/core-ui-settings-browser'; import type { TimefilterContract } from '@kbn/data-plugin/public'; -import type { DashboardStart } from '@kbn/dashboard-plugin/public'; +import type { SharePluginStart } from '@kbn/share-plugin/public'; import type { DataViewsContract } from '@kbn/data-views-plugin/public'; import { QuickLensJobCreator } from './quick_create_job'; import type { MlApi } from '../../../services/ml_api_service'; @@ -23,7 +23,7 @@ interface Dependencies { dataViews: DataViewsContract; kibanaConfig: IUiSettingsClient; timeFilter: TimefilterContract; - dashboardService: DashboardStart; + share: SharePluginStart; mlApi: MlApi; } export async function resolver( @@ -35,7 +35,7 @@ export async function resolver( filtersRisonString: string, layerIndexRisonString: string ) { - const { dataViews, lens, mlApi, timeFilter, kibanaConfig, dashboardService } = deps; + const { dataViews, lens, mlApi, timeFilter, kibanaConfig, share } = deps; if (lensSavedObjectRisonString === undefined) { throw new Error('Cannot create visualization'); } @@ -56,7 +56,7 @@ export async function resolver( dataViews, kibanaConfig, timeFilter, - dashboardService, + share, mlApi ); await jobCreator.createAndStashADJob(vis, from, to, query, filters, layerIndex); diff --git a/x-pack/platform/plugins/shared/ml/public/application/jobs/new_job/job_from_map/quick_create_job.ts b/x-pack/platform/plugins/shared/ml/public/application/jobs/new_job/job_from_map/quick_create_job.ts index a507eb53116af..fa5008755bc46 100644 --- a/x-pack/platform/plugins/shared/ml/public/application/jobs/new_job/job_from_map/quick_create_job.ts +++ b/x-pack/platform/plugins/shared/ml/public/application/jobs/new_job/job_from_map/quick_create_job.ts @@ -10,7 +10,7 @@ import type { IUiSettingsClient } from '@kbn/core/public'; import type { TimefilterContract } from '@kbn/data-plugin/public'; import type { Filter, Query } from '@kbn/es-query'; import type { DataView, DataViewsContract } from '@kbn/data-views-plugin/public'; -import type { DashboardStart } from '@kbn/dashboard-plugin/public'; +import type { SharePluginStart } from '@kbn/share-plugin/public'; import type { MapApi } from '@kbn/maps-plugin/public'; import type { MlApi } from '../../../services/ml_api_service'; import { @@ -42,10 +42,10 @@ export class QuickGeoJobCreator extends QuickJobCreatorBase { dataViews: DataViewsContract, kibanaConfig: IUiSettingsClient, timeFilter: TimefilterContract, - dashboardService: DashboardStart, + shareService: SharePluginStart, mlApi: MlApi ) { - super(dataViews, kibanaConfig, timeFilter, dashboardService, mlApi); + super(dataViews, kibanaConfig, timeFilter, shareService, mlApi); } public async createAndSaveGeoJob({ diff --git a/x-pack/platform/plugins/shared/ml/public/application/jobs/new_job/job_from_map/route_resolver.ts b/x-pack/platform/plugins/shared/ml/public/application/jobs/new_job/job_from_map/route_resolver.ts index efc69e324de3d..14d07ce464809 100644 --- a/x-pack/platform/plugins/shared/ml/public/application/jobs/new_job/job_from_map/route_resolver.ts +++ b/x-pack/platform/plugins/shared/ml/public/application/jobs/new_job/job_from_map/route_resolver.ts @@ -7,7 +7,7 @@ import type { IUiSettingsClient } from '@kbn/core-ui-settings-browser'; import type { TimefilterContract } from '@kbn/data-plugin/public'; -import type { DashboardStart } from '@kbn/dashboard-plugin/public'; +import type { SharePluginStart } from '@kbn/share-plugin/public'; import type { DataViewsContract } from '@kbn/data-views-plugin/public'; import type { MlApi } from '../../../services/ml_api_service'; import { QuickGeoJobCreator } from './quick_create_job'; @@ -18,7 +18,7 @@ interface Dependencies { dataViews: DataViewsContract; kibanaConfig: IUiSettingsClient; timeFilter: TimefilterContract; - dashboardService: DashboardStart; + share: SharePluginStart; mlApi: MlApi; } export async function resolver( @@ -32,7 +32,7 @@ export async function resolver( toRisonString: string, layerRisonString?: string ) { - const { dataViews, kibanaConfig, timeFilter, dashboardService, mlApi } = deps; + const { dataViews, kibanaConfig, timeFilter, share, mlApi } = deps; const defaultLayer = { query: getDefaultQuery(), filters: [] }; const dashboard = getRisonValue(dashboardRisonString, defaultLayer); @@ -50,13 +50,7 @@ export async function resolver( const from = getRisonValue(fromRisonString, ''); const to = getRisonValue(toRisonString, ''); - const jobCreator = new QuickGeoJobCreator( - dataViews, - kibanaConfig, - timeFilter, - dashboardService, - mlApi - ); + const jobCreator = new QuickGeoJobCreator(dataViews, kibanaConfig, timeFilter, share, mlApi); await jobCreator.createAndStashGeoJob( dataViewId, diff --git a/x-pack/platform/plugins/shared/ml/public/application/jobs/new_job/job_from_pattern_analysis/quick_create_job.ts b/x-pack/platform/plugins/shared/ml/public/application/jobs/new_job/job_from_pattern_analysis/quick_create_job.ts index 28e5ddd01f439..eae64ffbda5c1 100644 --- a/x-pack/platform/plugins/shared/ml/public/application/jobs/new_job/job_from_pattern_analysis/quick_create_job.ts +++ b/x-pack/platform/plugins/shared/ml/public/application/jobs/new_job/job_from_pattern_analysis/quick_create_job.ts @@ -7,7 +7,7 @@ import type { IUiSettingsClient } from '@kbn/core/public'; import type { DataPublicPluginStart, TimefilterContract } from '@kbn/data-plugin/public'; -import type { DashboardStart } from '@kbn/dashboard-plugin/public'; +import type { SharePluginStart } from '@kbn/share-plugin/public'; import type { DataViewField, DataView } from '@kbn/data-views-plugin/common'; import type { DataViewsContract } from '@kbn/data-views-plugin/public'; import type { TimeRange } from '@kbn/es-query'; @@ -34,11 +34,11 @@ export class QuickCategorizationJobCreator extends QuickJobCreatorBase { dataViews: DataViewsContract, kibanaConfig: IUiSettingsClient, timeFilter: TimefilterContract, - dashboardService: DashboardStart, + shareService: SharePluginStart, private data: DataPublicPluginStart, mlApi: MlApi ) { - super(dataViews, kibanaConfig, timeFilter, dashboardService, mlApi); + super(dataViews, kibanaConfig, timeFilter, shareService, mlApi); } public async createAndSaveJob( diff --git a/x-pack/platform/plugins/shared/ml/public/application/jobs/new_job/job_from_pattern_analysis/route_resolver.ts b/x-pack/platform/plugins/shared/ml/public/application/jobs/new_job/job_from_pattern_analysis/route_resolver.ts index 1ed579a1838cc..bf8c43a53888e 100644 --- a/x-pack/platform/plugins/shared/ml/public/application/jobs/new_job/job_from_pattern_analysis/route_resolver.ts +++ b/x-pack/platform/plugins/shared/ml/public/application/jobs/new_job/job_from_pattern_analysis/route_resolver.ts @@ -7,7 +7,7 @@ import type { IUiSettingsClient } from '@kbn/core-ui-settings-browser'; import type { DataPublicPluginStart, TimefilterContract } from '@kbn/data-plugin/public'; -import type { DashboardStart } from '@kbn/dashboard-plugin/public'; +import type { SharePluginStart } from '@kbn/share-plugin/public'; import type { QueryDslQueryContainer } from '@kbn/data-views-plugin/common/types'; import { type CategorizationType, @@ -21,9 +21,9 @@ import { getDefaultDatafeedQuery, getRisonValue } from '../utils/new_job_utils'; interface Dependencies { kibanaConfig: IUiSettingsClient; timeFilter: TimefilterContract; - dashboardService: DashboardStart; data: DataPublicPluginStart; mlApi: MlApi; + share: SharePluginStart; } export async function resolver( deps: Dependencies, @@ -36,7 +36,7 @@ export async function resolver( toRisonString: string, queryRisonString: string ) { - const { mlApi, timeFilter, kibanaConfig, dashboardService, data } = deps; + const { mlApi, timeFilter, kibanaConfig, share, data } = deps; const query = getRisonValue(queryRisonString, getDefaultDatafeedQuery()); const from = getRisonValue(fromRisonString, ''); @@ -55,7 +55,7 @@ export async function resolver( data.dataViews, kibanaConfig, timeFilter, - dashboardService, + share, data, mlApi ); diff --git a/x-pack/platform/plugins/shared/ml/public/application/routing/routes/new_job/from_lens.tsx b/x-pack/platform/plugins/shared/ml/public/application/routing/routes/new_job/from_lens.tsx index 74b61559d9f3f..d68b94943f5a2 100644 --- a/x-pack/platform/plugins/shared/ml/public/application/routing/routes/new_job/from_lens.tsx +++ b/x-pack/platform/plugins/shared/ml/public/application/routing/routes/new_job/from_lens.tsx @@ -37,10 +37,10 @@ const PageWrapper: FC = ({ location }) => { timefilter: { timefilter: timeFilter }, }, }, - dashboard: dashboardService, uiSettings: kibanaConfig, mlServices: { mlApi }, lens, + share, }, } = useMlKibana(); @@ -53,7 +53,7 @@ const PageWrapper: FC = ({ location }) => { mlApi, timeFilter, kibanaConfig, - dashboardService, + share, }, vis, from, diff --git a/x-pack/platform/plugins/shared/ml/public/application/routing/routes/new_job/from_map.tsx b/x-pack/platform/plugins/shared/ml/public/application/routing/routes/new_job/from_map.tsx index 026f219e5104f..833c9811e8d06 100644 --- a/x-pack/platform/plugins/shared/ml/public/application/routing/routes/new_job/from_map.tsx +++ b/x-pack/platform/plugins/shared/ml/public/application/routing/routes/new_job/from_map.tsx @@ -44,16 +44,16 @@ const PageWrapper: FC = ({ location }) => { timefilter: { timefilter: timeFilter }, }, }, - dashboard: dashboardService, uiSettings: kibanaConfig, mlServices: { mlApi }, + share, }, } = useMlKibana(); const { context } = useRouteResolver('full', ['canCreateJob'], { redirect: () => resolver( - { dataViews, mlApi, timeFilter, kibanaConfig, dashboardService }, + { dataViews, mlApi, timeFilter, kibanaConfig, share }, dashboard, dataViewId, embeddable, diff --git a/x-pack/platform/plugins/shared/ml/public/application/routing/routes/new_job/from_pattern_analysis.tsx b/x-pack/platform/plugins/shared/ml/public/application/routing/routes/new_job/from_pattern_analysis.tsx index 6252e54d6ae7e..2f2725dc785f1 100644 --- a/x-pack/platform/plugins/shared/ml/public/application/routing/routes/new_job/from_pattern_analysis.tsx +++ b/x-pack/platform/plugins/shared/ml/public/application/routing/routes/new_job/from_pattern_analysis.tsx @@ -38,9 +38,9 @@ const PageWrapper: FC = ({ location }) => { const { services: { data, - dashboard: dashboardService, uiSettings: kibanaConfig, mlServices: { mlApi }, + share, }, } = useMlKibana(); @@ -51,7 +51,7 @@ const PageWrapper: FC = ({ location }) => { mlApi, timeFilter: data.query.timefilter.timefilter, kibanaConfig, - dashboardService, + share, data, }, categorizationType, diff --git a/x-pack/platform/plugins/shared/ml/public/application/services/dashboard_service.test.ts b/x-pack/platform/plugins/shared/ml/public/application/services/dashboard_service.test.ts index e3ff58510374d..e51fdf0e0dc6c 100644 --- a/x-pack/platform/plugins/shared/ml/public/application/services/dashboard_service.test.ts +++ b/x-pack/platform/plugins/shared/ml/public/application/services/dashboard_service.test.ts @@ -5,10 +5,12 @@ * 2.0. */ +import type { SharePluginStart } from '@kbn/share-plugin/public'; import { dashboardServiceProvider } from './dashboard_service'; import type { DashboardStart } from '@kbn/dashboard-plugin/public'; describe('DashboardService', () => { + const getUrlMock = jest.fn(); const dashboard: DashboardStart = { // @ts-expect-error Only partial mock of full plugin locator: { @@ -22,7 +24,18 @@ describe('DashboardService', () => { }), }; - const dashboardService = dashboardServiceProvider(dashboard); + const share: SharePluginStart = { + url: { + locators: { + // @ts-expect-error Only partial mock of full plugin + get: () => ({ + getUrl: getUrlMock, + }), + }, + }, + }; + + const dashboardService = dashboardServiceProvider(dashboard, share); test('should fetch dashboard', async () => { // act @@ -37,7 +50,7 @@ describe('DashboardService', () => { }); test('should generate url to the dashboard', () => { dashboardService.getDashboardUrl('test-id'); - expect(dashboard.locator?.getUrl).toHaveBeenCalledWith({ + expect(getUrlMock).toHaveBeenCalledWith({ dashboardId: 'test-id', useHash: false, viewMode: 'edit', diff --git a/x-pack/platform/plugins/shared/ml/public/application/services/dashboard_service.ts b/x-pack/platform/plugins/shared/ml/public/application/services/dashboard_service.ts index ffa6f6a5d3ede..c687efe1d4cfe 100644 --- a/x-pack/platform/plugins/shared/ml/public/application/services/dashboard_service.ts +++ b/x-pack/platform/plugins/shared/ml/public/application/services/dashboard_service.ts @@ -8,12 +8,17 @@ import { useMemo } from 'react'; import type { DashboardStart } from '@kbn/dashboard-plugin/public'; import { ViewMode } from '@kbn/embeddable-plugin/public'; +import type { SharePluginStart } from '@kbn/share-plugin/public'; +import { DASHBOARD_APP_LOCATOR } from '@kbn/deeplinks-analytics'; import { useMlKibana } from '../contexts/kibana'; export type DashboardService = ReturnType; export type DashboardItems = Awaited>; -export function dashboardServiceProvider(dashboardService: DashboardStart) { +export function dashboardServiceProvider( + dashboardService: DashboardStart, + share: SharePluginStart +) { return { /** * Fetches dashboards @@ -39,7 +44,7 @@ export function dashboardServiceProvider(dashboardService: DashboardStart) { * Generates dashboard url */ async getDashboardUrl(dashboardId: string, viewMode: ViewMode = ViewMode.EDIT) { - return await dashboardService.locator?.getUrl({ + return await share.url.locators.get(DASHBOARD_APP_LOCATOR)?.getUrl({ dashboardId, viewMode: ViewMode.EDIT, useHash: false, @@ -53,8 +58,8 @@ export function dashboardServiceProvider(dashboardService: DashboardStart) { */ export function useDashboardService(): DashboardService { const { - services: { dashboard }, + services: { dashboard, share }, } = useMlKibana(); - return useMemo(() => dashboardServiceProvider(dashboard), [dashboard]); + return useMemo(() => dashboardServiceProvider(dashboard, share), [dashboard, share]); } diff --git a/x-pack/platform/plugins/shared/ml/public/embeddables/job_creation/aiops/flyout/create_job.tsx b/x-pack/platform/plugins/shared/ml/public/embeddables/job_creation/aiops/flyout/create_job.tsx index 3bf418d2c9db3..68c9b72567fee 100644 --- a/x-pack/platform/plugins/shared/ml/public/embeddables/job_creation/aiops/flyout/create_job.tsx +++ b/x-pack/platform/plugins/shared/ml/public/embeddables/job_creation/aiops/flyout/create_job.tsx @@ -48,7 +48,6 @@ export const CreateJob: FC = ({ dataView, field, query, timeRange }) => { data, share, uiSettings, - dashboardService, mlServices: { mlApi }, }, } = useMlFromLensKibanaContext(); @@ -88,11 +87,11 @@ export const CreateJob: FC = ({ dataView, field, query, timeRange }) => { data.dataViews, uiSettings, data.query.timefilter.timefilter, - dashboardService, + share, data, mlApi ), - [dashboardService, data, mlApi, uiSettings] + [share, data, mlApi, uiSettings] ); function createADJobInWizard() { diff --git a/x-pack/platform/plugins/shared/ml/public/embeddables/job_creation/common/context.ts b/x-pack/platform/plugins/shared/ml/public/embeddables/job_creation/common/context.ts index 5f94b7c3030f9..7b6ffa30fe629 100644 --- a/x-pack/platform/plugins/shared/ml/public/embeddables/job_creation/common/context.ts +++ b/x-pack/platform/plugins/shared/ml/public/embeddables/job_creation/common/context.ts @@ -12,14 +12,12 @@ import { useKibana } from '@kbn/kibana-react-plugin/public'; import type { SharePluginStart } from '@kbn/share-plugin/public'; import type { LensPublicStart } from '@kbn/lens-plugin/public'; -import type { DashboardStart } from '@kbn/dashboard-plugin/public'; import type { MlServicesContext } from '../../../application/app'; interface StartPlugins { data: DataPublicPluginStart; share: SharePluginStart; lens: LensPublicStart; - dashboardService: DashboardStart; } export type StartServices = CoreStart & StartPlugins & MlServicesContext; export const useMlFromLensKibanaContext = () => useKibana(); diff --git a/x-pack/platform/plugins/shared/ml/public/embeddables/job_creation/lens/lens_vis_layer_selection_flyout/layer/compatible_layer.tsx b/x-pack/platform/plugins/shared/ml/public/embeddables/job_creation/lens/lens_vis_layer_selection_flyout/layer/compatible_layer.tsx index 463f432db28b5..b55c85821adf7 100644 --- a/x-pack/platform/plugins/shared/ml/public/embeddables/job_creation/lens/lens_vis_layer_selection_flyout/layer/compatible_layer.tsx +++ b/x-pack/platform/plugins/shared/ml/public/embeddables/job_creation/lens/lens_vis_layer_selection_flyout/layer/compatible_layer.tsx @@ -33,7 +33,6 @@ export const CompatibleLayer: FC = ({ layer, layerIndex, embeddable }) => share, uiSettings, lens, - dashboardService, mlServices: { mlApi }, }, } = useMlFromLensKibanaContext(); @@ -45,7 +44,7 @@ export const CompatibleLayer: FC = ({ layer, layerIndex, embeddable }) => data.dataViews, uiSettings, data.query.timefilter.timefilter, - dashboardService, + share, mlApi ), // eslint-disable-next-line react-hooks/exhaustive-deps diff --git a/x-pack/platform/plugins/shared/ml/public/embeddables/job_creation/map/map_vis_layer_selection_flyout/layer/compatible_layer.tsx b/x-pack/platform/plugins/shared/ml/public/embeddables/job_creation/map/map_vis_layer_selection_flyout/layer/compatible_layer.tsx index 8847d21b2f4e3..92fbc56c98c76 100644 --- a/x-pack/platform/plugins/shared/ml/public/embeddables/job_creation/map/map_vis_layer_selection_flyout/layer/compatible_layer.tsx +++ b/x-pack/platform/plugins/shared/ml/public/embeddables/job_creation/map/map_vis_layer_selection_flyout/layer/compatible_layer.tsx @@ -50,7 +50,6 @@ export const CompatibleLayer: FC = ({ embeddable, layer, layerIndex }) => data, share, uiSettings, - dashboardService, mlServices: { mlApi }, }, } = useMlFromLensKibanaContext(); @@ -61,7 +60,7 @@ export const CompatibleLayer: FC = ({ embeddable, layer, layerIndex }) => data.dataViews, uiSettings, data.query.timefilter.timefilter, - dashboardService, + share, mlApi ), // eslint-disable-next-line react-hooks/exhaustive-deps diff --git a/x-pack/platform/plugins/shared/ml/public/plugin.ts b/x-pack/platform/plugins/shared/ml/public/plugin.ts index 9f634ca9cbcbd..a06f0470a80d4 100644 --- a/x-pack/platform/plugins/shared/ml/public/plugin.ts +++ b/x-pack/platform/plugins/shared/ml/public/plugin.ts @@ -44,7 +44,7 @@ import type { DataVisualizerPluginStart } from '@kbn/data-visualizer-plugin/publ import type { PluginSetupContract as AlertingSetup } from '@kbn/alerting-plugin/public'; import type { UsageCollectionSetup } from '@kbn/usage-collection-plugin/public'; import type { FieldFormatsSetup } from '@kbn/field-formats-plugin/public'; -import type { DashboardSetup, DashboardStart } from '@kbn/dashboard-plugin/public'; +import type { DashboardStart } from '@kbn/dashboard-plugin/public'; import type { ChartsPluginStart } from '@kbn/charts-plugin/public'; import type { CasesPublicSetup, CasesPublicStart } from '@kbn/cases-plugin/public'; import type { SavedSearchPublicPluginStart } from '@kbn/saved-search-plugin/public'; @@ -107,7 +107,6 @@ export interface MlStartDependencies { export interface MlSetupDependencies { alerting?: AlertingSetup; cases?: CasesPublicSetup; - dashboard: DashboardSetup; embeddable: EmbeddableSetup; fieldFormats: FieldFormatsSetup; home?: HomePublicPluginSetup;