mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Security Solution] [Dashboards] [137956] add regex filter for search queries to remove special characters (#138450) (#138462)
* add regex filter for search queries
* Add tests for filtering and update regex
* unskip tests
Co-authored-by: Kristof-Pierre Cummings <kristofpierre.cummings@elastic.co>
(cherry picked from commit f41fbcda3f
)
Co-authored-by: Kristof C <kpac.ja@gmail.com>
This commit is contained in:
parent
1595daa933
commit
87c3ad3e91
2 changed files with 22 additions and 5 deletions
|
@ -21,13 +21,13 @@ const DASHBOARD_TABLE_ITEMS = [
|
|||
},
|
||||
{
|
||||
id: 'id 2',
|
||||
title: 'second dashboard title',
|
||||
title: 'second dashboard_title',
|
||||
description: 'desc 2',
|
||||
},
|
||||
{
|
||||
id: 'id 3',
|
||||
title: 'different title',
|
||||
description: 'different desc',
|
||||
description: 'different-desc',
|
||||
},
|
||||
];
|
||||
|
||||
|
@ -109,4 +109,21 @@ describe('Dashboards table', () => {
|
|||
expect(result.queryByText(DASHBOARD_TABLE_ITEMS[0].title)).toBeInTheDocument();
|
||||
expect(result.queryByText(DASHBOARD_TABLE_ITEMS[0].description)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should filter out special characters except hyphens & underscores', () => {
|
||||
const result = renderDashboardTable();
|
||||
|
||||
const input = result.getByRole('searchbox');
|
||||
fireEvent.change(input, { target: { value: '"_title"' } });
|
||||
|
||||
expect(result.queryAllByTestId('dashboardTableTitleCell')).toHaveLength(1);
|
||||
expect(result.queryByText(DASHBOARD_TABLE_ITEMS[1].title)).toBeInTheDocument();
|
||||
expect(result.queryByText(DASHBOARD_TABLE_ITEMS[1].description)).toBeInTheDocument();
|
||||
|
||||
fireEvent.change(input, { target: { value: "'-desc'" } });
|
||||
|
||||
expect(result.queryAllByTestId('dashboardTableTitleCell')).toHaveLength(1);
|
||||
expect(result.queryByText(DASHBOARD_TABLE_ITEMS[2].title)).toBeInTheDocument();
|
||||
expect(result.queryByText(DASHBOARD_TABLE_ITEMS[2].description)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -30,8 +30,8 @@ export const DashboardsTable: React.FC = () => {
|
|||
const debouncedSetSearchQuery = debounce(setSearchQuery, INPUT_TIMEOUT);
|
||||
|
||||
return {
|
||||
onChange: ({ query }) => {
|
||||
debouncedSetSearchQuery(query?.text.toLowerCase() ?? '');
|
||||
onChange: ({ queryText }) => {
|
||||
debouncedSetSearchQuery(queryText.toLowerCase() ?? '');
|
||||
},
|
||||
box: {
|
||||
incremental: true,
|
||||
|
@ -46,7 +46,7 @@ export const DashboardsTable: React.FC = () => {
|
|||
setFilteredItems(
|
||||
items.filter(({ title, description }) => {
|
||||
const normalizedName = `${title} ${description}`.toLowerCase();
|
||||
return normalizedName.includes(searchQuery);
|
||||
return normalizedName.includes(searchQuery.replace(/[^\w- ]/g, ''));
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue