Skip to content

Commit

Permalink
ml tslint
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Mar 3, 2025
1 parent fea861e commit d8ec413
Show file tree
Hide file tree
Showing 19 changed files with 100 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -221,12 +223,13 @@ export function isValidCustomUrlSettings(

export function buildCustomUrlFromSettings(
dashboardService: DashboardStart,
share: SharePluginStart,
settings: CustomUrlSettings
): Promise<MlUrlConfig> {
// 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 {
Expand Down Expand Up @@ -256,6 +259,7 @@ function getUrlRangeFromSettings(settings: CustomUrlSettings) {

async function buildDashboardUrlFromSettings(
dashboardService: DashboardStart,
share: SharePluginStart,
settings: CustomUrlSettings,
isPartialDFAJob?: boolean
): Promise<MlUrlConfig> {
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ export class CustomUrls extends Component<CustomUrlsProps, CustomUrlsState> {
};

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);
Expand All @@ -179,6 +179,7 @@ export class CustomUrls extends Component<CustomUrlsProps, CustomUrlsState> {
data: { dataViews },
dashboard,
mlServices: { mlApi },
share,
} = this.context.services;
const dataViewId = this.state?.editorSettings?.kibanaSettings?.discoverIndexPatternId;
const job = this.props.job;
Expand All @@ -191,33 +192,34 @@ export class CustomUrls extends Component<CustomUrlsProps, CustomUrlsState> {
})
.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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
) {}

Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -23,7 +23,7 @@ interface Dependencies {
dataViews: DataViewsContract;
kibanaConfig: IUiSettingsClient;
timeFilter: TimefilterContract;
dashboardService: DashboardStart;
share: SharePluginStart;
mlApi: MlApi;
}
export async function resolver(
Expand All @@ -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');
}
Expand All @@ -56,7 +56,7 @@ export async function resolver(
dataViews,
kibanaConfig,
timeFilter,
dashboardService,
share,
mlApi
);
await jobCreator.createAndStashADJob(vis, from, to, query, filters, layerIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -18,7 +18,7 @@ interface Dependencies {
dataViews: DataViewsContract;
kibanaConfig: IUiSettingsClient;
timeFilter: TimefilterContract;
dashboardService: DashboardStart;
share: SharePluginStart;
mlApi: MlApi;
}
export async function resolver(
Expand All @@ -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<typeof defaultLayer>(dashboardRisonString, defaultLayer);
Expand All @@ -50,13 +50,7 @@ export async function resolver(
const from = getRisonValue<string>(fromRisonString, '');
const to = getRisonValue<string>(toRisonString, '');

const jobCreator = new QuickGeoJobCreator(
dataViews,
kibanaConfig,
timeFilter,
dashboardService,
mlApi
);
const jobCreator = new QuickGeoJobCreator(dataViews, kibanaConfig, timeFilter, share, mlApi);

await jobCreator.createAndStashGeoJob(
dataViewId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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<QueryDslQueryContainer>(queryRisonString, getDefaultDatafeedQuery());
const from = getRisonValue<string>(fromRisonString, '');
Expand All @@ -55,7 +55,7 @@ export async function resolver(
data.dataViews,
kibanaConfig,
timeFilter,
dashboardService,
share,
data,
mlApi
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ const PageWrapper: FC<PageProps> = ({ location }) => {
timefilter: { timefilter: timeFilter },
},
},
dashboard: dashboardService,
uiSettings: kibanaConfig,
mlServices: { mlApi },
lens,
share,
},
} = useMlKibana();

Expand All @@ -53,7 +53,7 @@ const PageWrapper: FC<PageProps> = ({ location }) => {
mlApi,
timeFilter,
kibanaConfig,
dashboardService,
share,
},
vis,
from,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ const PageWrapper: FC<PageProps> = ({ 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,
Expand Down
Loading

0 comments on commit d8ec413

Please sign in to comment.