-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution] Filter by rule execution status (last response) o…
…n Rule Management page (#159865) **Resolves**: #138903 ## Summary Adds a dropdown that allows you to filter rules by their rule execution status to the Rule Management page. <img width="1583" alt="Screenshot 2023-06-16 at 16 34 23" src="https://github.com/elastic/kibana/assets/15949146/abc8234a-4c05-4195-bc15-86b76a108663"> ### Checklist Delete any items that are not applicable to this PR. - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [x] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [x] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) - [x] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers)
- Loading branch information
1 parent
2312705
commit 6ca5e59
Showing
11 changed files
with
220 additions
and
12 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
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
135 changes: 135 additions & 0 deletions
135
...nagement_ui/components/rules_table/rules_table_filters/rule_execution_status_selector.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,135 @@ | ||
/* | ||
* 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, { useState } from 'react'; | ||
import type { EuiSelectableOption } from '@elastic/eui'; | ||
import { EuiFilterButton, EuiPopover, EuiSelectable } from '@elastic/eui'; | ||
import * as i18n from '../../../../../detections/pages/detection_engine/rules/translations'; | ||
import { RuleExecutionStatus } from '../../../../../../common/detection_engine/rule_monitoring/model/execution_status'; | ||
import { getCapitalizedStatusText } from '../../../../../detections/components/rules/rule_execution_status/utils'; | ||
import { RuleStatusBadge } from '../../../../../detections/components/rules/rule_execution_status/rule_status_badge'; | ||
|
||
interface OptionData { | ||
status: RuleExecutionStatus; | ||
} | ||
|
||
interface RuleExecutionStatusSelectorProps { | ||
selectedStatus?: RuleExecutionStatus; | ||
onSelectedStatusChanged: (newStatus?: RuleExecutionStatus) => void; | ||
} | ||
|
||
/** | ||
* Selector for selecting last rule execution status to filter on | ||
* | ||
* @param selectedStatus Selected rule execution status | ||
* @param onSelectedStatusChanged change listener to be notified when rule execution status selection changes | ||
*/ | ||
const RuleExecutionStatusSelectorComponent = ({ | ||
selectedStatus, | ||
onSelectedStatusChanged, | ||
}: RuleExecutionStatusSelectorProps) => { | ||
const [isExecutionStatusPopoverOpen, setIsExecutionStatusPopoverOpen] = useState(false); | ||
|
||
const selectableOptions: EuiSelectableOption[] = [ | ||
{ | ||
label: getCapitalizedStatusText(RuleExecutionStatus.succeeded) || '', | ||
data: { status: RuleExecutionStatus.succeeded }, | ||
checked: selectedStatus === RuleExecutionStatus.succeeded ? 'on' : undefined, | ||
}, | ||
{ | ||
label: getCapitalizedStatusText(RuleExecutionStatus['partial failure']) || '', | ||
data: { status: RuleExecutionStatus['partial failure'] }, | ||
checked: selectedStatus === RuleExecutionStatus['partial failure'] ? 'on' : undefined, | ||
}, | ||
{ | ||
label: getCapitalizedStatusText(RuleExecutionStatus.failed) || '', | ||
data: { status: RuleExecutionStatus.failed }, | ||
checked: selectedStatus === RuleExecutionStatus.failed ? 'on' : undefined, | ||
}, | ||
]; | ||
|
||
const handleSelectableOptionsChange = ( | ||
newOptions: EuiSelectableOption[], | ||
_: unknown, | ||
changedOption: EuiSelectableOption | ||
) => { | ||
setIsExecutionStatusPopoverOpen(false); | ||
|
||
if (changedOption.checked && changedOption?.data?.status) { | ||
onSelectedStatusChanged(changedOption.data.status as RuleExecutionStatus); | ||
} else if (!changedOption.checked) { | ||
onSelectedStatusChanged(); | ||
} | ||
}; | ||
|
||
const triggerButton = ( | ||
<EuiFilterButton | ||
grow | ||
iconType="arrowDown" | ||
onClick={() => { | ||
setIsExecutionStatusPopoverOpen(!isExecutionStatusPopoverOpen); | ||
}} | ||
numFilters={selectableOptions.length} | ||
isSelected={isExecutionStatusPopoverOpen} | ||
hasActiveFilters={selectedStatus !== undefined} | ||
numActiveFilters={selectedStatus !== undefined ? 1 : 0} | ||
> | ||
{i18n.COLUMN_LAST_RESPONSE} | ||
</EuiFilterButton> | ||
); | ||
|
||
return ( | ||
<EuiPopover | ||
ownFocus | ||
button={triggerButton} | ||
isOpen={isExecutionStatusPopoverOpen} | ||
closePopover={() => { | ||
setIsExecutionStatusPopoverOpen(!isExecutionStatusPopoverOpen); | ||
}} | ||
panelPaddingSize="none" | ||
repositionOnScroll | ||
> | ||
<EuiSelectable | ||
aria-label={i18n.RULE_EXECTION_STATUS_FILTER} | ||
options={selectableOptions} | ||
onChange={handleSelectableOptionsChange} | ||
singleSelection | ||
listProps={{ | ||
isVirtualized: false, | ||
}} | ||
renderOption={(option) => { | ||
const status = (option as EuiSelectableOption<OptionData>).status; | ||
return ( | ||
<div | ||
css={` | ||
margin-top: 4px; // aligns the badge within the option | ||
`} | ||
> | ||
<RuleStatusBadge status={status} showTooltip={false} /> | ||
</div> | ||
); | ||
}} | ||
> | ||
{(list) => ( | ||
<div | ||
css={` | ||
width: 200px; | ||
`} | ||
> | ||
{list} | ||
</div> | ||
)} | ||
</EuiSelectable> | ||
</EuiPopover> | ||
); | ||
}; | ||
|
||
RuleExecutionStatusSelectorComponent.displayName = 'RuleExecutionStatusSelectorComponent'; | ||
|
||
export const RuleExecutionStatusSelector = React.memo(RuleExecutionStatusSelectorComponent); | ||
|
||
RuleExecutionStatusSelector.displayName = 'RuleExecutionStatusSelector'; |
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