forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Rules migration] Add migration rules filters (elastic#11386) (elasti…
…c#206089) ## Summary [Internal link](elastic/security-team#10820) to the feature details These changes add a migration rules filtering functionality and allows user to filter rules by `Status` and `Author`. > [!NOTE] > This feature needs `siemMigrationsEnabled` experimental flag enabled to work. ## Screenshots ### Filter by `Status` <img width="1775" alt="Screenshot 2025-01-09 at 15 38 28" src="https://github.com/user-attachments/assets/02f2a916-e0a1-4741-a602-50a032600c39" /> ### Filter by `Author` <img width="1774" alt="Screenshot 2025-01-09 at 15 38 38" src="https://github.com/user-attachments/assets/4a44af77-4665-4c7c-86c4-c9f08918ea1f" />
- Loading branch information
Showing
20 changed files
with
575 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
.../security_solution/public/siem_migrations/rules/components/rules_table/filters/author.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* 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, { useCallback, useMemo, useState } from 'react'; | ||
import type { EuiSelectableOption } from '@elastic/eui'; | ||
import { EuiFilterButton, EuiPopover, EuiSelectable } from '@elastic/eui'; | ||
import type { EuiSelectableOnChangeEvent } from '@elastic/eui/src/components/selectable/selectable'; | ||
import { AuthorFilter } from '../../../../../../common/siem_migrations/constants'; | ||
import * as i18n from './translations'; | ||
|
||
const AUTHOR_FILTER_POPOVER_WIDTH = 150; | ||
|
||
export interface AuthorFilterButtonProps { | ||
author?: AuthorFilter; | ||
onAuthorChanged: (newAuthor?: AuthorFilter) => void; | ||
} | ||
|
||
export const AuthorFilterButton: React.FC<AuthorFilterButtonProps> = React.memo( | ||
({ author, onAuthorChanged }) => { | ||
const [isPopoverOpen, setIsPopoverOpen] = useState(false); | ||
|
||
const selectableOptions: EuiSelectableOption[] = useMemo( | ||
() => [ | ||
{ | ||
label: i18n.ELASTIC_AUTHOR_FILTER_OPTION, | ||
data: { author: AuthorFilter.ELASTIC }, | ||
checked: author === AuthorFilter.ELASTIC ? 'on' : undefined, | ||
}, | ||
{ | ||
label: i18n.CUSTOM_AUTHOR_FILTER_OPTION, | ||
data: { author: AuthorFilter.CUSTOM }, | ||
checked: author === AuthorFilter.CUSTOM ? 'on' : undefined, | ||
}, | ||
], | ||
[author] | ||
); | ||
|
||
const handleOptionsChange = useCallback( | ||
( | ||
_options: EuiSelectableOption[], | ||
_event: EuiSelectableOnChangeEvent, | ||
changedOption: EuiSelectableOption | ||
) => { | ||
setIsPopoverOpen(false); | ||
|
||
if (changedOption.checked && changedOption?.data?.author) { | ||
onAuthorChanged(changedOption.data.author); | ||
} else if (!changedOption.checked) { | ||
onAuthorChanged(); | ||
} | ||
}, | ||
[onAuthorChanged] | ||
); | ||
|
||
const triggerButton = ( | ||
<EuiFilterButton | ||
grow | ||
iconType="arrowDown" | ||
onClick={() => { | ||
setIsPopoverOpen(!isPopoverOpen); | ||
}} | ||
isSelected={isPopoverOpen} | ||
hasActiveFilters={author !== undefined} | ||
data-test-subj="authorFilterButton" | ||
> | ||
{i18n.AUTHOR_BUTTON_TITLE} | ||
</EuiFilterButton> | ||
); | ||
|
||
return ( | ||
<EuiPopover | ||
ownFocus | ||
button={triggerButton} | ||
isOpen={isPopoverOpen} | ||
closePopover={() => { | ||
setIsPopoverOpen(!isPopoverOpen); | ||
}} | ||
panelPaddingSize="none" | ||
repositionOnScroll | ||
> | ||
<EuiSelectable | ||
aria-label={i18n.AUTHOR_FILTER_ARIAL_LABEL} | ||
options={selectableOptions} | ||
onChange={handleOptionsChange} | ||
singleSelection | ||
data-test-subj="authorFilterSelectableList" | ||
> | ||
{(list) => <div style={{ width: AUTHOR_FILTER_POPOVER_WIDTH }}>{list}</div>} | ||
</EuiSelectable> | ||
</EuiPopover> | ||
); | ||
} | ||
); | ||
AuthorFilterButton.displayName = 'AuthorFilterButton'; |
57 changes: 57 additions & 0 deletions
57
...s/security_solution/public/siem_migrations/rules/components/rules_table/filters/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* 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, { useCallback } from 'react'; | ||
import { EuiFilterGroup } from '@elastic/eui'; | ||
import type { | ||
AuthorFilter, | ||
StatusFilter, | ||
} from '../../../../../../common/siem_migrations/constants'; | ||
import { StatusFilterButton } from './status'; | ||
import { AuthorFilterButton } from './author'; | ||
|
||
export interface FilterOptions { | ||
status?: StatusFilter; | ||
author?: AuthorFilter; | ||
} | ||
|
||
export interface MigrationRulesFilterProps { | ||
filterOptions?: FilterOptions; | ||
onFilterOptionsChanged: (filterOptions?: FilterOptions) => void; | ||
} | ||
|
||
export const MigrationRulesFilter: React.FC<MigrationRulesFilterProps> = React.memo( | ||
({ filterOptions, onFilterOptionsChanged }) => { | ||
const handleOnStatusChanged = useCallback( | ||
(newStatus?: StatusFilter) => { | ||
onFilterOptionsChanged({ ...filterOptions, ...{ status: newStatus } }); | ||
}, | ||
[filterOptions, onFilterOptionsChanged] | ||
); | ||
|
||
const handleOnAuthorChanged = useCallback( | ||
(newAuthor?: AuthorFilter) => { | ||
onFilterOptionsChanged({ ...filterOptions, ...{ author: newAuthor } }); | ||
}, | ||
[filterOptions, onFilterOptionsChanged] | ||
); | ||
|
||
return ( | ||
<EuiFilterGroup> | ||
<StatusFilterButton | ||
status={filterOptions?.status} | ||
onStatusChanged={handleOnStatusChanged} | ||
/> | ||
<AuthorFilterButton | ||
author={filterOptions?.author} | ||
onAuthorChanged={handleOnAuthorChanged} | ||
/> | ||
</EuiFilterGroup> | ||
); | ||
} | ||
); | ||
MigrationRulesFilter.displayName = 'MigrationRulesFilter'; |
Oops, something went wrong.