-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[AI4SOC] Add rules management table #219111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
12 changes: 0 additions & 12 deletions
12
...k/solutions/security/plugins/security_solution/public/configurations/tabs/basic_rules.tsx
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
...lutions/security/plugins/security_solution/public/configurations/tabs/promotion_rules.tsx
This file contains hidden or 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,23 @@ | ||
| /* | ||
| * 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 { EuiSpacer } from '@elastic/eui'; | ||
| import React from 'react'; | ||
| import { SecuritySolutionPageWrapper } from '../../common/components/page_wrapper'; | ||
| import { RulesTableContextProvider } from '../../detection_engine/rule_management_ui/components/rules_table/rules_table/rules_table_context'; | ||
| import { PromotionRulesTable } from './promotion_rules/promotion_rules_table'; | ||
|
|
||
| export const PromotionRules: React.FC = () => { | ||
| return ( | ||
| <RulesTableContextProvider> | ||
| <SecuritySolutionPageWrapper> | ||
| <EuiSpacer /> | ||
| <PromotionRulesTable /> | ||
| </SecuritySolutionPageWrapper> | ||
| </RulesTableContextProvider> | ||
| ); | ||
| }; |
228 changes: 228 additions & 0 deletions
228
...ns/security_solution/public/configurations/tabs/promotion_rules/promotion_rules_table.tsx
This file contains hidden or 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,228 @@ | ||||||||||||||||||||||||
| /* | ||||||||||||||||||||||||
| * 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 type { EuiBasicTableColumn } from '@elastic/eui'; | ||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||
| EuiBasicTable, | ||||||||||||||||||||||||
| EuiEmptyPrompt, | ||||||||||||||||||||||||
| EuiNotificationBadge, | ||||||||||||||||||||||||
| EuiProgress, | ||||||||||||||||||||||||
| EuiSpacer, | ||||||||||||||||||||||||
| EuiTab, | ||||||||||||||||||||||||
| EuiTabs, | ||||||||||||||||||||||||
| EuiText, | ||||||||||||||||||||||||
| } from '@elastic/eui'; | ||||||||||||||||||||||||
| import React, { useCallback, useMemo, useState } from 'react'; | ||||||||||||||||||||||||
| import type { FindRulesSortField } from '../../../../common/api/detection_engine'; | ||||||||||||||||||||||||
| import { Loader } from '../../../common/components/loader'; | ||||||||||||||||||||||||
| import { hasUserCRUDPermission } from '../../../common/utils/privileges'; | ||||||||||||||||||||||||
| import type { EuiBasicTableOnChange } from '../../../detection_engine/common/types'; | ||||||||||||||||||||||||
| import type { Rule } from '../../../detection_engine/rule_management/logic'; | ||||||||||||||||||||||||
| import { useRuleManagementFilters } from '../../../detection_engine/rule_management/logic/use_rule_management_filters'; | ||||||||||||||||||||||||
| import { useIsUpgradingSecurityPackages } from '../../../detection_engine/rule_management/logic/use_upgrade_security_packages'; | ||||||||||||||||||||||||
| import { RULES_TABLE_PAGE_SIZE_OPTIONS } from '../../../detection_engine/rule_management_ui/components/rules_table/constants'; | ||||||||||||||||||||||||
| import { useRulesTableContext } from '../../../detection_engine/rule_management_ui/components/rules_table/rules_table/rules_table_context'; | ||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||
| INDEXING_DURATION_COLUMN, | ||||||||||||||||||||||||
| LAST_EXECUTION_COLUMN, | ||||||||||||||||||||||||
| RULE_NAME_COLUMN, | ||||||||||||||||||||||||
| SEARCH_DURATION_COLUMN, | ||||||||||||||||||||||||
| TOTAL_UNFILLED_DURATION_COLUMN, | ||||||||||||||||||||||||
| useEnabledColumn, | ||||||||||||||||||||||||
| useGapDurationColumn, | ||||||||||||||||||||||||
| useRuleExecutionStatusColumn, | ||||||||||||||||||||||||
| } from '../../../detection_engine/rule_management_ui/components/rules_table/use_columns'; | ||||||||||||||||||||||||
| import { useUserData } from '../../../detections/components/user_info'; | ||||||||||||||||||||||||
| import * as i18n from './translations'; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const INITIAL_SORT_FIELD = 'name'; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const NO_ITEMS_MESSAGE = ( | ||||||||||||||||||||||||
| <EuiEmptyPrompt title={<h3>{i18n.NO_RULES}</h3>} titleSize="xs" body={i18n.NO_RULES_BODY} /> | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| export enum PromotionRuleTabs { | ||||||||||||||||||||||||
| management = 'management', | ||||||||||||||||||||||||
| monitoring = 'monitoring', | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| export const PromotionRulesTable = () => { | ||||||||||||||||||||||||
| const isUpgradingSecurityPackages = useIsUpgradingSecurityPackages(); | ||||||||||||||||||||||||
| const rulesTableContext = useRulesTableContext(); | ||||||||||||||||||||||||
| const { data: ruleManagementFilters } = useRuleManagementFilters(); | ||||||||||||||||||||||||
| const [currentTab, setCurrentTab] = useState(PromotionRuleTabs.management); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const { | ||||||||||||||||||||||||
| state: { rules, isFetched, isRefetching, pagination, sortingOptions }, | ||||||||||||||||||||||||
| actions: { setPage, setPerPage, setSortingOptions }, | ||||||||||||||||||||||||
| } = rulesTableContext; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const paginationMemo = useMemo(() => { | ||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||
| pageIndex: pagination.page - 1, | ||||||||||||||||||||||||
| pageSize: pagination.perPage, | ||||||||||||||||||||||||
| totalItemCount: pagination.total, | ||||||||||||||||||||||||
| pageSizeOptions: RULES_TABLE_PAGE_SIZE_OPTIONS, | ||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||
| }, [pagination.page, pagination.perPage, pagination.total]); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const tableOnChangeCallback = useCallback( | ||||||||||||||||||||||||
| ({ page, sort }: EuiBasicTableOnChange) => { | ||||||||||||||||||||||||
| setSortingOptions({ | ||||||||||||||||||||||||
| field: (sort?.field as FindRulesSortField) ?? INITIAL_SORT_FIELD, | ||||||||||||||||||||||||
| order: sort?.direction ?? 'desc', | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
| setPage(page.index + 1); | ||||||||||||||||||||||||
| setPerPage(page.size); | ||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||
| [setPage, setPerPage, setSortingOptions] | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const rulesColumns = useRulesColumns({ currentTab }); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const handleTabClick = useCallback( | ||||||||||||||||||||||||
| (tabId: PromotionRuleTabs) => { | ||||||||||||||||||||||||
| setCurrentTab(tabId); | ||||||||||||||||||||||||
| rulesTableContext.actions.setPage(1); | ||||||||||||||||||||||||
| rulesTableContext.actions.setPerPage(pagination.perPage); | ||||||||||||||||||||||||
| rulesTableContext.actions.setSortingOptions({ | ||||||||||||||||||||||||
| field: INITIAL_SORT_FIELD, | ||||||||||||||||||||||||
| order: 'desc', | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||
| [pagination.perPage, rulesTableContext.actions] | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const installedTotal = | ||||||||||||||||||||||||
| (ruleManagementFilters?.rules_summary.custom_count ?? 0) + | ||||||||||||||||||||||||
| (ruleManagementFilters?.rules_summary.prebuilt_installed_count ?? 0); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const ruleTabs = useMemo( | ||||||||||||||||||||||||
| () => [ | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| id: PromotionRuleTabs.management, | ||||||||||||||||||||||||
| name: i18n.INSTALLED_RULES_TAB, | ||||||||||||||||||||||||
| append: | ||||||||||||||||||||||||
| installedTotal > 0 ? ( | ||||||||||||||||||||||||
| <EuiNotificationBadge size="m" color="subdued"> | ||||||||||||||||||||||||
| {installedTotal} | ||||||||||||||||||||||||
| </EuiNotificationBadge> | ||||||||||||||||||||||||
| ) : undefined, | ||||||||||||||||||||||||
| isSelected: currentTab === PromotionRuleTabs.management, | ||||||||||||||||||||||||
| onClick: () => handleTabClick(PromotionRuleTabs.management), | ||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| id: PromotionRuleTabs.monitoring, | ||||||||||||||||||||||||
| name: i18n.RULE_MONITORING_TAB, | ||||||||||||||||||||||||
| append: | ||||||||||||||||||||||||
| installedTotal > 0 ? ( | ||||||||||||||||||||||||
| <EuiNotificationBadge size="m" color="subdued"> | ||||||||||||||||||||||||
| {installedTotal} | ||||||||||||||||||||||||
| </EuiNotificationBadge> | ||||||||||||||||||||||||
| ) : undefined, | ||||||||||||||||||||||||
|
Comment on lines
+121
to
+126
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||
| isSelected: currentTab === PromotionRuleTabs.monitoring, | ||||||||||||||||||||||||
| onClick: () => handleTabClick(PromotionRuleTabs.monitoring), | ||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||
| [currentTab, handleTabClick, installedTotal] | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const shouldShowLinearProgress = (isFetched && isRefetching) || isUpgradingSecurityPackages; | ||||||||||||||||||||||||
| const shouldShowLoadingOverlay = !isFetched && isRefetching; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||
| <> | ||||||||||||||||||||||||
| <EuiTabs size="m" bottomBorder> | ||||||||||||||||||||||||
| {ruleTabs.map((tab) => ( | ||||||||||||||||||||||||
| <EuiTab key={tab.id} {...tab}> | ||||||||||||||||||||||||
| {tab.name} | ||||||||||||||||||||||||
| </EuiTab> | ||||||||||||||||||||||||
| ))} | ||||||||||||||||||||||||
| </EuiTabs> | ||||||||||||||||||||||||
| <EuiSpacer size="s" /> | ||||||||||||||||||||||||
| {shouldShowLinearProgress && ( | ||||||||||||||||||||||||
| <EuiProgress | ||||||||||||||||||||||||
| data-test-subj="loadingRulesInfoProgress" | ||||||||||||||||||||||||
| size="xs" | ||||||||||||||||||||||||
| position="absolute" | ||||||||||||||||||||||||
| color="accent" | ||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||
| {shouldShowLoadingOverlay && ( | ||||||||||||||||||||||||
| <Loader data-test-subj="loadingPanelAllRulesTable" overlay size="xl" /> | ||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||
| <EuiBasicTable | ||||||||||||||||||||||||
| itemId="id" | ||||||||||||||||||||||||
| items={rules} | ||||||||||||||||||||||||
| noItemsMessage={NO_ITEMS_MESSAGE} | ||||||||||||||||||||||||
| onChange={tableOnChangeCallback} | ||||||||||||||||||||||||
| pagination={paginationMemo} | ||||||||||||||||||||||||
| sorting={{ | ||||||||||||||||||||||||
| sort: { | ||||||||||||||||||||||||
| // EuiBasicTable has incorrect `sort.field` types which accept only `keyof Item` and reject fields in dot notation | ||||||||||||||||||||||||
| field: sortingOptions.field as keyof Rule, | ||||||||||||||||||||||||
| direction: sortingOptions.order, | ||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||
| columns={rulesColumns} | ||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||
| </> | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| interface ColumnsProps { | ||||||||||||||||||||||||
| currentTab: PromotionRuleTabs; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const useRulesColumns = ({ currentTab }: ColumnsProps): Array<EuiBasicTableColumn<Rule>> => { | ||||||||||||||||||||||||
| const [{ canUserCRUD }] = useUserData(); | ||||||||||||||||||||||||
| const hasPermissions = hasUserCRUDPermission(canUserCRUD); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const enabledColumn = useEnabledColumn({ | ||||||||||||||||||||||||
| hasCRUDPermissions: hasPermissions, | ||||||||||||||||||||||||
| isLoadingJobs: false, | ||||||||||||||||||||||||
| mlJobs: [], | ||||||||||||||||||||||||
| startMlJobs: async (jobIds: string[] | undefined) => {}, | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
| const executionStatusColumn = useRuleExecutionStatusColumn({ | ||||||||||||||||||||||||
| sortable: true, | ||||||||||||||||||||||||
| width: '16%', | ||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||||
| isLoadingJobs: false, | ||||||||||||||||||||||||
| mlJobs: [], | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
| const gapDurationColumn = useGapDurationColumn(); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return useMemo(() => { | ||||||||||||||||||||||||
| if (currentTab === PromotionRuleTabs.monitoring) { | ||||||||||||||||||||||||
| return [ | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| ...RULE_NAME_COLUMN, | ||||||||||||||||||||||||
| render: (value: Rule['name']) => <EuiText size="s">{value}</EuiText>, | ||||||||||||||||||||||||
| width: '30%', | ||||||||||||||||||||||||
| } as EuiBasicTableColumn<Rule>, | ||||||||||||||||||||||||
| INDEXING_DURATION_COLUMN, | ||||||||||||||||||||||||
| SEARCH_DURATION_COLUMN, | ||||||||||||||||||||||||
| gapDurationColumn, | ||||||||||||||||||||||||
| TOTAL_UNFILLED_DURATION_COLUMN, | ||||||||||||||||||||||||
| LAST_EXECUTION_COLUMN, | ||||||||||||||||||||||||
| executionStatusColumn, | ||||||||||||||||||||||||
| enabledColumn, | ||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return [ | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| ...RULE_NAME_COLUMN, | ||||||||||||||||||||||||
| render: (value: Rule['name']) => <EuiText size="s">{value}</EuiText>, | ||||||||||||||||||||||||
| width: '100%', | ||||||||||||||||||||||||
| } as EuiBasicTableColumn<Rule>, | ||||||||||||||||||||||||
| LAST_EXECUTION_COLUMN, | ||||||||||||||||||||||||
| executionStatusColumn, | ||||||||||||||||||||||||
| enabledColumn, | ||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||
| }, [currentTab, enabledColumn, executionStatusColumn, gapDurationColumn]); | ||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||
35 changes: 35 additions & 0 deletions
35
...rity/plugins/security_solution/public/configurations/tabs/promotion_rules/translations.ts
This file contains hidden or 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,35 @@ | ||
| /* | ||
| * 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 { i18n } from '@kbn/i18n'; | ||
|
|
||
| export const NO_RULES = i18n.translate( | ||
| 'xpack.securitySolution.ai4soc.configurations.rulesTable.noRules', | ||
| { | ||
| defaultMessage: 'No rules found', | ||
| } | ||
| ); | ||
|
|
||
| export const NO_RULES_BODY = i18n.translate( | ||
| 'xpack.securitySolution.ai4soc.configurations.rulesTable.noRulesBody', | ||
| { | ||
| defaultMessage: 'No rules are currently installed. To get started, add an integration.', | ||
| } | ||
| ); | ||
|
|
||
| export const INSTALLED_RULES_TAB = i18n.translate( | ||
| 'xpack.securitySolution.ai4soc.configurations.promotionRules.installedRulesTab', | ||
| { | ||
| defaultMessage: 'Installed rules', | ||
| } | ||
| ); | ||
| export const RULE_MONITORING_TAB = i18n.translate( | ||
| 'xpack.securitySolution.ai4soc.configurations.promotionRules.ruleMonitoringTab', | ||
| { | ||
| defaultMessage: 'Rule monitoring', | ||
| } | ||
| ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.