[8.6] Fix Notable Anomalies context visible under collapse (#145726) (#145958)

# Backport

This will backport the following commits from `main` to `8.6`:
- [Fix Notable Anomalies context visible under collapse
(#145726)](https://github.com/elastic/kibana/pull/145726)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Pablo
Machado","email":"pablo.nevesmachado@elastic.co"},"sourceCommit":{"committedDate":"2022-11-22T08:38:02Z","message":"Fix
Notable Anomalies context visible under collapse (#145726)\n\nissue:
https://github.com/elastic/kibana/issues/145534\r\n\r\n##
Summary\r\n\r\nHide warning messages when the card is
collapsed\r\n<img\r\nsrc=\"https://user-images.githubusercontent.com/59917825/202425479-d3cdc27d-3b72-4bc2-9bb5-9e09a35457fe.png\">\r\n\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"ab0cede59c6abe27eaf6c6d51b07232e2723b5e9","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Team:Threat
Hunting","Team: SecuritySolution","Team:Threat
Hunting:Explore","v8.6.0","v8.7.0"],"number":145726,"url":"https://github.com/elastic/kibana/pull/145726","mergeCommit":{"message":"Fix
Notable Anomalies context visible under collapse (#145726)\n\nissue:
https://github.com/elastic/kibana/issues/145534\r\n\r\n##
Summary\r\n\r\nHide warning messages when the card is
collapsed\r\n<img\r\nsrc=\"https://user-images.githubusercontent.com/59917825/202425479-d3cdc27d-3b72-4bc2-9bb5-9e09a35457fe.png\">\r\n\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"ab0cede59c6abe27eaf6c6d51b07232e2723b5e9"}},"sourceBranch":"main","suggestedTargetBranches":["8.6"],"targetPullRequestStates":[{"branch":"8.6","label":"v8.6.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/145726","number":145726,"mergeCommit":{"message":"Fix
Notable Anomalies context visible under collapse (#145726)\n\nissue:
https://github.com/elastic/kibana/issues/145534\r\n\r\n##
Summary\r\n\r\nHide warning messages when the card is
collapsed\r\n<img\r\nsrc=\"https://user-images.githubusercontent.com/59917825/202425479-d3cdc27d-3b72-4bc2-9bb5-9e09a35457fe.png\">\r\n\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"ab0cede59c6abe27eaf6c6d51b07232e2723b5e9"}}]}]
BACKPORT-->

Co-authored-by: Pablo Machado <pablo.nevesmachado@elastic.co>
This commit is contained in:
Kibana Machine 2022-11-22 06:22:18 -05:00 committed by GitHub
parent 25786e042f
commit db96bd0122
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 82 additions and 37 deletions

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import { render } from '@testing-library/react';
import { fireEvent, render } from '@testing-library/react';
import React from 'react';
import { EntityAnalyticsAnomalies } from '.';
import type { AnomaliesCount } from '../../../../common/components/ml/anomaly/use_anomalies_search';
@ -14,6 +14,15 @@ import { AnomalyEntity } from '../../../../common/components/ml/anomaly/use_anom
import { TestProviders } from '../../../../common/mock';
import type { SecurityJob } from '../../../../common/components/ml_popover/types';
// Query toggle only works if pageName.lenght > 0
jest.mock('../../../../common/utils/route/use_route_spy', () => ({
useRouteSpy: jest.fn().mockReturnValue([
{
pageName: 'not_empty',
},
]),
}));
const mockUseNotableAnomaliesSearch = jest.fn().mockReturnValue({
isLoading: false,
data: [],
@ -232,4 +241,34 @@ describe('EntityAnalyticsAnomalies', () => {
expect(getByTestId('incompatible_jobs_warnings')).toBeInTheDocument();
});
it("doesn't render the warning message when header is collapsed", () => {
const jobCount: AnomaliesCount = {
job: {
isInstalled: true,
datafeedState: 'started',
jobState: 'opened',
isCompatible: false,
} as SecurityJob,
name: 'v3_windows_anomalous_script',
count: 0,
entity: AnomalyEntity.User,
};
mockUseNotableAnomaliesSearch.mockReturnValue({
isLoading: false,
data: [jobCount],
refetch: jest.fn(),
});
const { queryByTestId, getByTestId } = render(
<TestProviders>
<EntityAnalyticsAnomalies />
</TestProviders>
);
fireEvent.click(getByTestId('query-toggle-header'));
expect(queryByTestId('incompatible_jobs_warnings')).not.toBeInTheDocument();
});
});

View file

@ -163,43 +163,49 @@ export const EntityAnalyticsAnomalies = () => {
</EuiFlexGroup>
</HeaderSection>
{incompatibleJobCount > 0 && (
<>
<EuiCallOut
title={i18n.MODULE_NOT_COMPATIBLE_TITLE(incompatibleJobCount)}
data-test-subj="incompatible_jobs_warnings"
color="warning"
iconType="alert"
size="s"
>
<p>
<FormattedMessage
defaultMessage="We could not find any data, see {mlDocs} for more information on Machine Learning job requirements."
id="xpack.securitySolution.components.mlPopup.moduleNotCompatibleDescription"
values={{
mlDocs: (
<a href={`${docLinks.links.siem.ml}`} rel="noopener noreferrer" target="_blank">
{i18n.ANOMALY_DETECTION_DOCS}
</a>
),
}}
/>
</p>
</EuiCallOut>
<EuiSpacer size="m" />
</>
)}
<MLJobsAwaitingNodeWarning jobIds={installedJobsIds} />
{toggleStatus && (
<EuiInMemoryTable
responsive={false}
items={data}
columns={columns}
loading={isSearchLoading}
id={TABLE_QUERY_ID}
sorting={TABLE_SORTING}
/>
<>
{incompatibleJobCount > 0 && (
<>
<EuiCallOut
title={i18n.MODULE_NOT_COMPATIBLE_TITLE(incompatibleJobCount)}
data-test-subj="incompatible_jobs_warnings"
color="warning"
iconType="alert"
size="s"
>
<p>
<FormattedMessage
defaultMessage="We could not find any data, see {mlDocs} for more information on Machine Learning job requirements."
id="xpack.securitySolution.components.mlPopup.moduleNotCompatibleDescription"
values={{
mlDocs: (
<a
href={`${docLinks.links.siem.ml}`}
rel="noopener noreferrer"
target="_blank"
>
{i18n.ANOMALY_DETECTION_DOCS}
</a>
),
}}
/>
</p>
</EuiCallOut>
<EuiSpacer size="m" />
</>
)}
<MLJobsAwaitingNodeWarning jobIds={installedJobsIds} />
<EuiInMemoryTable
responsive={false}
items={data}
columns={columns}
loading={isSearchLoading}
id={TABLE_QUERY_ID}
sorting={TABLE_SORTING}
/>
</>
)}
</EuiPanel>
);