Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security Solutions] Fix link to ML Job is wrong when searching within ML Job Settings UI #150881

Merged
merged 3 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,26 @@ export const AnalyzeCategoryDatasetInMlAction: React.FunctionComponent<{
services: { ml, http, application },
} = useKibanaContextForPlugin();

const viewAnomalyInMachineLearningLink = useMlHref(ml, http.basePath.get(), {
page: ML_PAGES.SINGLE_METRIC_VIEWER,
pageState: {
jobIds: [categorizationJobId],
timeRange: {
from: moment(timeRange.startTime).format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
to: moment(timeRange.endTime).format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
mode: 'absolute',
},
entities: {
[partitionField]: dataset,
mlcategory: `${categoryId}`,
const viewAnomalyInMachineLearningLink = useMlHref(
ml,
http.basePath.get(),
{
page: ML_PAGES.SINGLE_METRIC_VIEWER,
pageState: {
jobIds: [categorizationJobId],
timeRange: {
from: moment(timeRange.startTime).format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
to: moment(timeRange.endTime).format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
mode: 'absolute',
},
entities: {
[partitionField]: dataset,
mlcategory: `${categoryId}`,
},
},
},
});
[categorizationJobId]
);

const handleClick = useCallback(
(e) => {
Expand Down
6 changes: 4 additions & 2 deletions x-pack/plugins/ml/public/locator/use_ml_href.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { DependencyList } from 'react';
import { MlPluginStart } from '..';
import { MlLocatorParams } from '../../common/types/locator';

Expand All @@ -15,10 +16,11 @@ import { MlLocatorParams } from '../../common/types/locator';
export const useMlHref = (
ml: MlPluginStart | undefined,
basePath: string | undefined,
params: MlLocatorParams
params: MlLocatorParams,
dependencies?: DependencyList
) => {
return ml && ml.locator
? ml.locator!.useUrl(params)
? ml.locator.useUrl(params, undefined, dependencies)
: basePath !== undefined
? `${basePath}/app/ml/${params.page}`
: '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,27 @@ export const ExplorerLink: React.FC<ExplorerLinkProps> = ({
services: { ml, http },
} = useKibana();

const explorerUrl = useMlHref(ml, http.basePath.get(), {
page: 'explorer',
pageState: {
jobIds: [score.jobId],
timeRange: {
from: new Date(startDate).toISOString(),
to: new Date(endDate).toISOString(),
mode: 'absolute',
},
refreshInterval: {
pause: true,
value: 0,
display: 'Off',
const explorerUrl = useMlHref(
ml,
http.basePath.get(),
{
page: 'explorer',
pageState: {
jobIds: [score.jobId],
timeRange: {
from: new Date(startDate).toISOString(),
to: new Date(endDate).toISOString(),
mode: 'absolute',
},
refreshInterval: {
pause: true,
value: 0,
display: 'Off',
},
},
},
});
[score.jobId]
);

if (!explorerUrl) return null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,17 @@ const JobName = ({ id, name, description, basePath }: JobNameProps) => {
services: { ml },
} = useKibana();

const jobUrl = useMlHref(ml, basePath, {
page: ML_PAGES.ANOMALY_DETECTION_JOBS_MANAGE,
pageState: {
jobId: id,
const jobUrl = useMlHref(
ml,
basePath,
{
page: ML_PAGES.ANOMALY_DETECTION_JOBS_MANAGE,
pageState: {
jobId: id,
},
},
});
[id]
);

return (
<JobNameWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@ const MlJobLinkComponent: React.FC<MlJobLinkProps> = ({ jobId, jobName }) => {
const {
services: { http, ml },
} = useKibana();
const jobUrl = useMlHref(ml, http.basePath.get(), {
page: ML_PAGES.ANOMALY_DETECTION_JOBS_MANAGE,
pageState: {
jobId: [jobId],
const jobUrl = useMlHref(
ml,
http.basePath.get(),
{
page: ML_PAGES.ANOMALY_DETECTION_JOBS_MANAGE,
pageState: {
jobId: [jobId],
},
},
});
[jobId]
);

return (
<StyledJobEuiLInk data-test-subj="machineLearningJobLink" href={jobUrl} target="_blank">
Expand Down