Skip to content

Commit

Permalink
[Security Solution] Fix rule severity sorting in inMemory tables (#16…
Browse files Browse the repository at this point in the history
…0075)

## Summary

- Fix rule severity sorting in in-memory tables (Add Rules table and
Rule Upgrade table) so that rows are filtered by the semantic meaning of
severity.


### Checklist

Delete any items that are not applicable to this PR.

- [ ] 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
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] 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))
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] 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))
- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)


### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
  • Loading branch information
jpdjere committed Jun 21, 2023
1 parent 0b91e6d commit 5bac117
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
Expand Up @@ -21,6 +21,7 @@ import { hasUserCRUDPermission } from '../../../../../common/utils/privileges';
import type { AddPrebuiltRulesTableActions } from './add_prebuilt_rules_table_context';
import { useAddPrebuiltRulesTableContext } from './add_prebuilt_rules_table_context';
import type { RuleSignatureId } from '../../../../../../common/detection_engine/rule_schema';
import { getNormalizedSeverity } from '../helpers';

export type TableColumn = EuiBasicTableColumn<RuleInstallationInfoForReview>;

Expand Down Expand Up @@ -130,7 +131,7 @@ export const useAddPrebuiltRulesTableColumns = (): TableColumn[] => {
field: 'severity',
name: i18n.COLUMN_SEVERITY,
render: (value: Rule['severity']) => <SeverityBadge value={value} />,
sortable: true,
sortable: ({ severity }: RuleInstallationInfoForReview) => getNormalizedSeverity(severity),
truncateText: true,
width: '12%',
},
Expand Down
Expand Up @@ -6,6 +6,7 @@
*/

import type { Query } from '@elastic/eui';
import type { Severity } from '@kbn/securitysolution-io-ts-alerting-types';
import type { ExportRulesDetails } from '../../../../../common/detection_engine/rule_management';
import type { BulkActionSummary } from '../../../rule_management/logic';

Expand Down Expand Up @@ -75,3 +76,14 @@ export const getExportedRulesCounts = async (blob: Blob): Promise<BulkActionSumm
total: details.exported_rules_count + details.missing_rules_count,
};
};

const NormalizedSeverity: Record<Severity, number> = {
low: 0,
medium: 1,
high: 2,
critical: 3,
};

export const getNormalizedSeverity = (severity: Severity): number => {
return NormalizedSeverity[severity] ?? -1;
};
Expand Up @@ -19,6 +19,7 @@ import { SeverityBadge } from '../../../../../detections/components/rules/severi
import { useUserData } from '../../../../../detections/components/user_info';
import * as i18n from '../../../../../detections/pages/detection_engine/rules/translations';
import type { Rule } from '../../../../rule_management/logic';
import { getNormalizedSeverity } from '../helpers';
import type { UpgradePrebuiltRulesTableActions } from './upgrade_prebuilt_rules_table_context';
import { useUpgradePrebuiltRulesTableContext } from './upgrade_prebuilt_rules_table_context';

Expand Down Expand Up @@ -130,7 +131,8 @@ export const useUpgradePrebuiltRulesTableColumns = (): TableColumn[] => {
field: 'rule.severity',
name: i18n.COLUMN_SEVERITY,
render: (value: Rule['severity']) => <SeverityBadge value={value} />,
sortable: true,
sortable: ({ rule: { severity } }: RuleUpgradeInfoForReview) =>
getNormalizedSeverity(severity),
truncateText: true,
width: '12%',
},
Expand Down

0 comments on commit 5bac117

Please sign in to comment.