[9.0] [Detection Engine] Rule Data View select uses Data View name for display (#214495) (#215355)

# Backport

This will backport the following commits from `main` to `9.0`:
- [[Detection Engine] Rule Data View select uses Data View name for
display (#214495)](https://github.com/elastic/kibana/pull/214495)

<!--- Backport version: 9.6.6 -->

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

<!--BACKPORT [{"author":{"name":"Ryland
Herrick","email":"ryalnd@gmail.com"},"sourceCommit":{"committedDate":"2025-03-20T15:01:26Z","message":"[Detection
Engine] Rule Data View select uses Data View name for display
(#214495)\n\n## Summary\n\nSupersedes #190936, and also
addresses\nhttps://github.com/elastic/kibana/issues/137823. This mainly
just\nrebases the changes introduced there to the latest `main`. I
also\nnoticed that it originally had some unit tests, so I resurrected
those\nas well. ~~I modified the copy as well, so nota bene
@ARWNightingale~~\nAfter some discussion, we determined that an explicit
UI note about this\nbehavior was unnecessary.\n\n\n##
Screenshots\n\n<kbd>\n<img width=\"979\" alt=\"Screenshot 2025-03-13 at
5 24
42 PM\"\nsrc=\"https://github.com/user-attachments/assets/69da29bf-5504-461e-b797-d016adcd4b59\"\n/></kbd>\n\n<kbd><img
width=\"1052\" alt=\"Screenshot 2025-03-18 at 4 37
58 PM\"\nsrc=\"https://github.com/user-attachments/assets/8ee5e55e-2413-4936-aa87-7dadb3d7cbb1\"\n/></kbd>\n\n\n\n\n###
Checklist\n\n\n- [x] Any text added follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n-
[x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common
scenarios\n\n---------\n\nCo-authored-by: Yara Tercero
<yara.tercero@elastic.co>","sha":"07acd2480aea52d22a5c5454740cd2a1fa7a70e8","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:enhancement","Feature:Rule
Creation","backport:all-open","Team:Detection Engine","Feature:Rule
Edit","v9.1.0"],"title":"[Detection Engine] Rule Data View select uses
Data View name for
display","number":214495,"url":"https://github.com/elastic/kibana/pull/214495","mergeCommit":{"message":"[Detection
Engine] Rule Data View select uses Data View name for display
(#214495)\n\n## Summary\n\nSupersedes #190936, and also
addresses\nhttps://github.com/elastic/kibana/issues/137823. This mainly
just\nrebases the changes introduced there to the latest `main`. I
also\nnoticed that it originally had some unit tests, so I resurrected
those\nas well. ~~I modified the copy as well, so nota bene
@ARWNightingale~~\nAfter some discussion, we determined that an explicit
UI note about this\nbehavior was unnecessary.\n\n\n##
Screenshots\n\n<kbd>\n<img width=\"979\" alt=\"Screenshot 2025-03-13 at
5 24
42 PM\"\nsrc=\"https://github.com/user-attachments/assets/69da29bf-5504-461e-b797-d016adcd4b59\"\n/></kbd>\n\n<kbd><img
width=\"1052\" alt=\"Screenshot 2025-03-18 at 4 37
58 PM\"\nsrc=\"https://github.com/user-attachments/assets/8ee5e55e-2413-4936-aa87-7dadb3d7cbb1\"\n/></kbd>\n\n\n\n\n###
Checklist\n\n\n- [x] Any text added follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n-
[x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common
scenarios\n\n---------\n\nCo-authored-by: Yara Tercero
<yara.tercero@elastic.co>","sha":"07acd2480aea52d22a5c5454740cd2a1fa7a70e8"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/214495","number":214495,"mergeCommit":{"message":"[Detection
Engine] Rule Data View select uses Data View name for display
(#214495)\n\n## Summary\n\nSupersedes #190936, and also
addresses\nhttps://github.com/elastic/kibana/issues/137823. This mainly
just\nrebases the changes introduced there to the latest `main`. I
also\nnoticed that it originally had some unit tests, so I resurrected
those\nas well. ~~I modified the copy as well, so nota bene
@ARWNightingale~~\nAfter some discussion, we determined that an explicit
UI note about this\nbehavior was unnecessary.\n\n\n##
Screenshots\n\n<kbd>\n<img width=\"979\" alt=\"Screenshot 2025-03-13 at
5 24
42 PM\"\nsrc=\"https://github.com/user-attachments/assets/69da29bf-5504-461e-b797-d016adcd4b59\"\n/></kbd>\n\n<kbd><img
width=\"1052\" alt=\"Screenshot 2025-03-18 at 4 37
58 PM\"\nsrc=\"https://github.com/user-attachments/assets/8ee5e55e-2413-4936-aa87-7dadb3d7cbb1\"\n/></kbd>\n\n\n\n\n###
Checklist\n\n\n- [x] Any text added follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n-
[x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common
scenarios\n\n---------\n\nCo-authored-by: Yara Tercero
<yara.tercero@elastic.co>","sha":"07acd2480aea52d22a5c5454740cd2a1fa7a70e8"}}]}]
BACKPORT-->

Co-authored-by: Ryland Herrick <ryalnd@gmail.com>
This commit is contained in:
Kibana Machine 2025-03-20 17:59:35 +01:00 committed by GitHub
parent bc9c01a0e0
commit da3bedee1c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 3 deletions

View file

@ -6,7 +6,7 @@
*/
import React from 'react';
import { screen, render } from '@testing-library/react';
import { screen, render, fireEvent } from '@testing-library/react';
import { TestProviders, useFormFieldMock } from '../../../../common/mock';
import { DataViewSelectorField } from './data_view_selector_field';
import { useDataViewListItems } from './use_data_view_list_items';
@ -45,6 +45,35 @@ describe('data_view_selector', () => {
expect(screen.getByRole('combobox')).toBeDisabled();
});
it('displays the selected dataview by name, if specified', () => {
const dataViews = [
{
id: 'security-solution-default',
title:
'-*elastic-cloud-logs-*,.alerts-security.alerts-default,apm-*-transaction*,auditbeat-*,endgame-*,filebeat-*,logs-*,packetbeat-*,traces-apm*,winlogbeat-*',
},
{
id: '1234',
title: 'logs-*',
name: 'dataview-name',
},
];
(useDataViewListItems as jest.Mock).mockReturnValue({ data: dataViews, isFetching: false });
render(
<DataViewSelectorField
field={useFormFieldMock<string | undefined>({
value: 'security-solution-default',
})}
/>,
{ wrapper: TestProviders }
);
expect(screen.queryByText('dataview-name')).not.toBeInTheDocument();
fireEvent.change(screen.getByRole('combobox'), { target: { value: 'dataview-name' } });
expect(screen.getByText('dataview-name')).toBeInTheDocument();
});
it('displays alerts on alerts warning when default security view selected', () => {
const dataViews = [
{

View file

@ -27,9 +27,9 @@ export function DataViewSelectorField({ field }: DataViewSelectorProps): JSX.Ele
const errorMessage = fieldAndError?.errorMessage;
const comboBoxOptions = useMemo(
() =>
dataViews.map(({ id, title: label }) => ({
dataViews.map(({ id, title, name }) => ({
id,
label,
label: name ?? title,
})),
[dataViews]
);