[8.10] [Security Solution] expandable flyout - correctly format alert and document count number in the prevalence details table (#165843) (#166192)

# Backport

This will backport the following commits from `main` to `8.10`:
- [[Security Solution] expandable flyout - correctly format alert and
document count number in the prevalence details table
(#165843)](https://github.com/elastic/kibana/pull/165843)

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

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

<!--BACKPORT [{"author":{"name":"Philippe
Oberti","email":"philippe.oberti@elastic.co"},"sourceCommit":{"committedDate":"2023-09-11T16:14:35Z","message":"[Security
Solution] expandable flyout - correctly format alert and document count
number in the prevalence details table
(#165843)","sha":"5b216c6ea94e739fea1f161f0bbce5a57ae44c02","branchLabelMapping":{"^v8.11.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:enhancement","Team:Threat
Hunting:Investigations","v8.10.0","v8.11.0"],"number":165843,"url":"https://github.com/elastic/kibana/pull/165843","mergeCommit":{"message":"[Security
Solution] expandable flyout - correctly format alert and document count
number in the prevalence details table
(#165843)","sha":"5b216c6ea94e739fea1f161f0bbce5a57ae44c02"}},"sourceBranch":"main","suggestedTargetBranches":["8.10"],"targetPullRequestStates":[{"branch":"8.10","label":"v8.10.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.11.0","labelRegex":"^v8.11.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/165843","number":165843,"mergeCommit":{"message":"[Security
Solution] expandable flyout - correctly format alert and document count
number in the prevalence details table
(#165843)","sha":"5b216c6ea94e739fea1f161f0bbce5a57ae44c02"}}]}]
BACKPORT-->

Co-authored-by: Philippe Oberti <philippe.oberti@elastic.co>
This commit is contained in:
Kibana Machine 2023-09-11 13:36:36 -04:00 committed by GitHub
parent cdc8242989
commit dc07a4d0db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 2 deletions

View file

@ -112,6 +112,43 @@ describe('PrevalenceDetails', () => {
expect(queryByTestId(`${PREVALENCE_DETAILS_TABLE_TEST_ID}UpSell`)).not.toBeInTheDocument();
});
it('should render formatted numbers for the alert and document count columns', () => {
(usePrevalence as jest.Mock).mockReturnValue({
loading: false,
error: false,
data: [
{
field: 'field1',
value: 'value1',
alertCount: 1000,
docCount: 2000000,
hostPrevalence: 0.05,
userPrevalence: 0.1,
},
],
});
const { getByTestId } = render(
<TestProviders>
<LeftPanelContext.Provider value={panelContextValue}>
<PrevalenceDetails />
</LeftPanelContext.Provider>
</TestProviders>
);
expect(getByTestId(PREVALENCE_DETAILS_TABLE_TEST_ID)).toBeInTheDocument();
expect(getByTestId(PREVALENCE_DETAILS_TABLE_FIELD_CELL_TEST_ID)).toHaveTextContent('field1');
expect(getByTestId(PREVALENCE_DETAILS_TABLE_VALUE_CELL_TEST_ID)).toHaveTextContent('value1');
expect(getByTestId(PREVALENCE_DETAILS_TABLE_ALERT_COUNT_CELL_TEST_ID)).toHaveTextContent('1k');
expect(getByTestId(PREVALENCE_DETAILS_TABLE_DOC_COUNT_CELL_TEST_ID)).toHaveTextContent('2M');
expect(getByTestId(PREVALENCE_DETAILS_TABLE_HOST_PREVALENCE_CELL_TEST_ID)).toHaveTextContent(
'5%'
);
expect(getByTestId(PREVALENCE_DETAILS_TABLE_USER_PREVALENCE_CELL_TEST_ID)).toHaveTextContent(
'10%'
);
});
it('should render the table with only basic columns if license is not platinum', () => {
const field1 = 'field1';
const field2 = 'field2';

View file

@ -23,6 +23,7 @@ import {
EuiToolTip,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { FormattedCount } from '../../../common/components/formatted_number';
import { useLicense } from '../../../common/hooks/use_license';
import { InvestigateInTimelineButton } from '../../../common/components/event_details/table/investigate_in_timeline_button';
import type { PrevalenceData } from '../../shared/hooks/use_prevalence';
@ -116,7 +117,7 @@ const columns: Array<EuiBasicTableColumn<PrevalenceDetailsRow>> = [
filters={[]}
timeRange={{ kind: 'absolute', from: data.from, to: data.to }}
>
<>{data.alertCount}</>
<FormattedCount count={data.alertCount} />
</InvestigateInTimelineButton>
) : (
getEmptyTagValue()
@ -161,7 +162,7 @@ const columns: Array<EuiBasicTableColumn<PrevalenceDetailsRow>> = [
timeRange={{ kind: 'absolute', from: data.from, to: data.to }}
keepDataView // changing dataview from only detections to include non-alerts docs
>
<>{data.docCount}</>
<FormattedCount count={data.docCount} />
</InvestigateInTimelineButton>
) : (
getEmptyTagValue()