Skip to content

Commit

Permalink
Update detection pages to display jobs friendly names
Browse files Browse the repository at this point in the history
  • Loading branch information
machadoum committed Jan 16, 2023
1 parent 1407d85 commit a1aced6
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const MlRuleWarningPopoverComponent: React.FC<MlRuleWarningPopoverComponentProps
</div>
<EuiSpacer size="s" />
{notRunningJobs.map((job) => (
<EuiText>{job.id}</EuiText>
<EuiText>{job.customSettings?.security_app_display_name ?? job.id}</EuiText>
))}
<EuiPopoverFooter>
<SecuritySolutionLinkButton
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import React from 'react';
import { render } from '@testing-library/react';

import { MlJobLink } from './ml_job_link';
import { TestProviders } from '../../../../common/mock';

jest.mock('../../../../common/lib/kibana', () => {
const originalModule = jest.requireActual('../../../../common/lib/kibana');
return {
...originalModule,
useKibana: jest.fn().mockReturnValue({
services: { theme: { theme$: {} }, http: { basePath: { get: jest.fn(() => {}) } } },
}),
};
});

describe('MlJobLink', () => {
it('renders job name when available', () => {
const jobName = 'test_job_name';
const { getByTestId } = render(<MlJobLink jobId={'test_job_id'} jobName={jobName} />, {
wrapper: TestProviders,
});

expect(getByTestId('machineLearningJobLink')).toHaveTextContent(jobName);
});

it('renders job id when job name is unavailable', () => {
const jobId = 'test_job_id';
const { getByTestId } = render(<MlJobLink jobId={jobId} jobName={undefined} />, {
wrapper: TestProviders,
});

expect(getByTestId('machineLearningJobLink')).toHaveTextContent(jobId);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ const StyledJobEuiLInk = styled(EuiLink)`

interface MlJobLinkProps {
jobId: string;
jobName: string | undefined;
}

const MlJobLinkComponent: React.FC<MlJobLinkProps> = ({ jobId }) => {
const MlJobLinkComponent: React.FC<MlJobLinkProps> = ({ jobId, jobName }) => {
const {
services: { http, ml },
} = useKibana();
Expand All @@ -33,7 +34,7 @@ const MlJobLinkComponent: React.FC<MlJobLinkProps> = ({ jobId }) => {

return (
<StyledJobEuiLInk data-test-subj="machineLearningJobLink" href={jobUrl} target="_blank">
<span data-test-subj="machineLearningJobId">{jobId}</span>
<span data-test-subj="machineLearningJobId">{jobName ?? jobId}</span>
</StyledJobEuiLInk>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ const MlJobEuiButton = styled(EuiButton)`
margin-top: 20px;
`;

const JobDisplay: React.FC<MlJobValue> = ({ id, description }) => (
const JobDisplay: React.FC<{ description: string; label: string }> = ({ description, label }) => (
<JobDisplayContainer>
<strong>{id}</strong>
<strong>{label}</strong>
<EuiToolTip content={description}>
<EuiText size="xs" color="subdued">
<p>{description}</p>
Expand All @@ -68,7 +68,7 @@ interface MlJobSelectProps {

const renderJobOption = (option: MlJobOption) => (
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
<JobDisplay id={option.value!.id} description={option.value!.description} />
<JobDisplay description={option.value!.description} label={option.label} />
);

export const MlJobSelect: React.FC<MlJobSelectProps> = ({ describedByIds = [], field }) => {
Expand All @@ -91,7 +91,7 @@ export const MlJobSelect: React.FC<MlJobSelectProps> = ({ describedByIds = [], f
id: job.id,
description: job.description,
},
label: job.id,
label: job.customSettings?.security_app_display_name ?? job.id,
}));

const selectedJobOptions = jobOptions.filter((option) => jobIds.includes(option.value.id));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const MlJobItemComponent: FC<{
return (
<Wrapper {...props}>
<div>
<MlJobLink jobId={job.id} />
<MlJobLink jobId={job.id} jobName={job.customSettings?.security_app_display_name} />
<MlAuditIcon message={job.auditMessage} />
</div>
<EuiFlexGroup justifyContent="flexStart">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const mlExecutor = async ({
...jobSummaries.map((job) =>
[
`job id: "${job.id}"`,
`job name: "${job?.customSettings?.security_app_display_name ?? job.id}"`,
`job status: "${job.jobState}"`,
`datafeed status: "${job.datafeedState}"`,
].join(', ')
Expand Down

0 comments on commit a1aced6

Please sign in to comment.