{
fireEvent.click(getByTestId('risk-filter-button'));
- fireEvent.click(getAllByTestId('risk-score').at(0)!);
+ fireEvent.click(getByTestId('risk-filter-item-Unknown'));
expect(mockedTelemetry.reportEntityRiskFiltered).toHaveBeenCalledTimes(0);
});
});
diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/severity/severity_filter_group.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/severity/severity_filter_group.tsx
index c5373199192a4..9ecb9d9cd6cdb 100644
--- a/x-pack/plugins/security_solution/public/entity_analytics/components/severity/severity_filter_group.tsx
+++ b/x-pack/plugins/security_solution/public/entity_analytics/components/severity/severity_filter_group.tsx
@@ -10,12 +10,11 @@ import type { FilterChecked } from '@elastic/eui';
import {
EuiFilterButton,
EuiFilterGroup,
- EuiFilterSelectItem,
EuiPopover,
useGeneratedHtmlId,
- useEuiTheme,
+ EuiSelectable,
} from '@elastic/eui';
-
+import { i18n } from '@kbn/i18n';
import { SEVERITY_UI_SORT_ORDER } from '../../common/utils';
import type { RiskScoreEntity, RiskSeverity } from '../../../../common/search_strategy';
import type { SeverityCount } from './types';
@@ -27,14 +26,22 @@ interface SeverityItems {
risk: RiskSeverity;
count: number;
checked?: FilterChecked;
+ label: string;
}
+
+const SEVERITY_FILTER_ARIA_LABEL = i18n.translate(
+ 'xpack.securitySolution.entityAnalytics.severityFilter.ariaLabel',
+ {
+ defaultMessage: 'Select the severity level to filter by',
+ }
+);
+
export const SeverityFilterGroup: React.FC<{
severityCount: SeverityCount;
selectedSeverities: RiskSeverity[];
onSelect: (newSelection: RiskSeverity[]) => void;
riskEntity: RiskScoreEntity;
}> = ({ severityCount, selectedSeverities, onSelect, riskEntity }) => {
- const { euiTheme } = useEuiTheme();
const { telemetry } = useKibana().services;
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
@@ -55,26 +62,27 @@ export const SeverityFilterGroup: React.FC<{
return SEVERITY_UI_SORT_ORDER.map((severity) => ({
risk: severity,
count: severityCount[severity],
+ label: severity,
checked: selectedSeverities.includes(severity) ? checked : undefined,
}));
}, [severityCount, selectedSeverities]);
const updateSeverityFilter = useCallback(
- (selectedSeverity: RiskSeverity) => {
- const currentSelection = selectedSeverities ?? [];
- const isAddingSeverity = !currentSelection.includes(selectedSeverity);
-
- const newSelection = isAddingSeverity
- ? [...currentSelection, selectedSeverity]
- : currentSelection.filter((s) => s !== selectedSeverity);
-
- if (isAddingSeverity) {
- telemetry.reportEntityRiskFiltered({ entity: riskEntity, selectedSeverity });
+ (newSelection: SeverityItems[], _, changedSeverity: SeverityItems) => {
+ if (changedSeverity.checked === 'on') {
+ telemetry.reportEntityRiskFiltered({
+ entity: riskEntity,
+ selectedSeverity: changedSeverity.risk,
+ });
}
- onSelect(newSelection);
+ const newSelectedSeverities = newSelection
+ .filter((item) => item.checked === 'on')
+ .map((item) => item.risk);
+
+ onSelect(newSelectedSeverities);
},
- [selectedSeverities, onSelect, telemetry, riskEntity]
+ [onSelect, riskEntity, telemetry]
);
const totalActiveItem = useMemo(
@@ -107,21 +115,17 @@ export const SeverityFilterGroup: React.FC<{
closePopover={closePopover}
panelPaddingSize="none"
>
- {/* EUI NOTE: Please use EuiSelectable (which already has height/scrolling built in)
- instead of EuiFilterSelectItem (which is pending deprecation).
- @see https://elastic.github.io/eui/#/forms/filter-group#multi-select */}
-
- {items.map((item, index) => (
- updateSeverityFilter(item.risk)}
- >
-
-
- ))}
-
+ (
+
+ )}
+ >
+ {(list) => {list}
}
+
);