From 298568ac3ffa59ecee83a805d9ee7a24b24fb7c0 Mon Sep 17 00:00:00 2001 From: Maxim Palenov Date: Mon, 24 Apr 2023 13:31:43 +0200 Subject: [PATCH 01/13] add rule snoozing on the rule editing page --- .../pages/rule_editing/index.tsx | 2 + .../rules/step_rule_actions/index.tsx | 6 ++- .../step_rule_actions/rule_snooze_section.tsx | 41 +++++++++++++++++++ .../rules/step_rule_actions/translations.tsx | 15 +++++++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/rule_snooze_section.tsx diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_creation_ui/pages/rule_editing/index.tsx b/x-pack/plugins/security_solution/public/detection_engine/rule_creation_ui/pages/rule_editing/index.tsx index 829a6688f4b60..58ccebb3dd124 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_creation_ui/pages/rule_editing/index.tsx +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_creation_ui/pages/rule_editing/index.tsx @@ -303,6 +303,7 @@ const EditRulePageComponent: FC = () => { {actionsStep.data != null && ( { }, ], [ + rule?.id, rule?.immutable, rule?.type, loading, diff --git a/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/index.tsx b/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/index.tsx index 86bbb7604add2..3c5356406a6b0 100644 --- a/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/index.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/index.tsx @@ -35,8 +35,10 @@ import { useKibana } from '../../../../common/lib/kibana'; import { getSchema } from './get_schema'; import * as I18n from './translations'; import { APP_UI_ID } from '../../../../../common/constants'; +import { RuleSnoozeSection } from './rule_snooze_section'; interface StepRuleActionsProps extends RuleStepProps { + id?: string; // Rule SO's id (not ruleId) defaultValues?: ActionsStepRule | null; actionMessageParams: ActionVariables; ruleType?: Type; @@ -68,6 +70,7 @@ const DisplayActionsHeader = () => { }; const StepRuleActionsComponent: FC = ({ + id, addPadding = false, defaultValues, isReadOnlyView, @@ -166,9 +169,9 @@ const StepRuleActionsComponent: FC = ({ return application.capabilities.actions.show ? ( <> + {id && } {displayActionsOptions} {responseActionsEnabled && displayResponseActionsOptions} - @@ -178,6 +181,7 @@ const StepRuleActionsComponent: FC = ({ ); }, [ + id, application.capabilities.actions.show, displayActionsOptions, displayResponseActionsOptions, diff --git a/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/rule_snooze_section.tsx b/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/rule_snooze_section.tsx new file mode 100644 index 0000000000000..067facb994f0c --- /dev/null +++ b/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/rule_snooze_section.tsx @@ -0,0 +1,41 @@ +/* + * 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 from 'react'; +import { css } from '@emotion/react'; +import { EuiFlexGroup, EuiFlexItem, EuiText, useEuiTheme } from '@elastic/eui'; +import { RuleDetailsSnoozeSettings } from '../../../../detection_engine/rule_details_ui/pages/rule_details/components/rule_details_snooze_settings'; +import * as i18n from './translations'; + +interface RuleSnoozeSectionProps { + id: string; // Rule SO's id (not ruleId) +} + +export function RuleSnoozeSection({ id }: RuleSnoozeSectionProps): JSX.Element { + const { euiTheme } = useEuiTheme(); + + return ( +
+ {i18n.RULE_SNOOZE_DESCRIPTION} + + + + + + + {i18n.SNOOZED_ACTIONS_WARNING} + + + +
+ ); +} diff --git a/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/translations.tsx b/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/translations.tsx index d467c3af05f8f..06368eadc30df 100644 --- a/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/translations.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/translations.tsx @@ -28,3 +28,18 @@ export const NO_ACTIONS_READ_PERMISSIONS = i18n.translate( 'Cannot create rule actions. You do not have "Read" permissions for the "Actions" plugin.', } ); + +export const RULE_SNOOZE_DESCRIPTION = i18n.translate( + 'xpack.securitySolution.detectionEngine.createRule.stepRuleActions.snoozeDescription', + { + defaultMessage: + 'Select when automated actions should be performed if a rule evaluates as true.', + } +); + +export const SNOOZED_ACTIONS_WARNING = i18n.translate( + 'xpack.securitySolution.detectionEngine.createRule.stepRuleActions.snoozedActionsWarning', + { + defaultMessage: 'Actions will not be preformed until it is unsnoozed.', + } +); From b98ad2bb8cbc85f96ccb508d6ae6f13cf54b9c12 Mon Sep 17 00:00:00 2001 From: Maxim Palenov Date: Mon, 24 Apr 2023 15:41:43 +0200 Subject: [PATCH 02/13] move rule snooze settings fetching functionality to a hook --- .../components/rule_snooze_badge/index.ts | 8 ++++ .../rule_snooze_badge.tsx | 22 +++++------ .../rule_snooze_badge}/translations.ts | 4 +- .../use_rule_snooze_settings.ts | 38 +++++++++++++++++++ .../rule_details_snooze_settings/index.tsx | 35 ----------------- .../pages/rule_details/index.test.tsx | 4 +- .../pages/rule_details/index.tsx | 4 +- .../components/rules_table/translations.ts | 7 ---- .../components/rules_table/use_columns.tsx | 23 +---------- .../step_rule_actions/rule_snooze_section.tsx | 4 +- 10 files changed, 65 insertions(+), 84 deletions(-) create mode 100644 x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge/index.ts rename x-pack/plugins/security_solution/public/detection_engine/components/{ => rule_snooze_badge}/rule_snooze_badge.tsx (71%) rename x-pack/plugins/security_solution/public/detection_engine/{rule_details_ui/pages/rule_details/components/rule_details_snooze_settings => components/rule_snooze_badge}/translations.ts (68%) create mode 100644 x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge/use_rule_snooze_settings.ts delete mode 100644 x-pack/plugins/security_solution/public/detection_engine/rule_details_ui/pages/rule_details/components/rule_details_snooze_settings/index.tsx diff --git a/x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge/index.ts b/x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge/index.ts new file mode 100644 index 0000000000000..8e231398688f0 --- /dev/null +++ b/x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge/index.ts @@ -0,0 +1,8 @@ +/* + * 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. + */ + +export * from './rule_snooze_badge'; diff --git a/x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge.tsx b/x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge/rule_snooze_badge.tsx similarity index 71% rename from x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge.tsx rename to x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge/rule_snooze_badge.tsx index 7fa16826eec60..2599bbc521d7c 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge.tsx +++ b/x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge/rule_snooze_badge.tsx @@ -7,30 +7,26 @@ import { EuiButtonIcon, EuiToolTip } from '@elastic/eui'; import React, { useMemo } from 'react'; -import { useUserData } from '../../detections/components/user_info'; -import { hasUserCRUDPermission } from '../../common/utils/privileges'; -import { useKibana } from '../../common/lib/kibana'; -import type { RuleSnoozeSettings } from '../rule_management/logic'; -import { useInvalidateFetchRulesSnoozeSettingsQuery } from '../rule_management/api/hooks/use_fetch_rules_snooze_settings'; +import { useUserData } from '../../../detections/components/user_info'; +import { hasUserCRUDPermission } from '../../../common/utils/privileges'; +import { useKibana } from '../../../common/lib/kibana'; +import { useInvalidateFetchRulesSnoozeSettingsQuery } from '../../rule_management/api/hooks/use_fetch_rules_snooze_settings'; +import { useRuleSnoozeSettings } from './use_rule_snooze_settings'; interface RuleSnoozeBadgeProps { /** - * Rule's snooze settings, when set to `undefined` considered as a loading state + * Rule's SO id (not ruleId) */ - snoozeSettings: RuleSnoozeSettings | undefined; - /** - * It should represent a user readable error message happened during data snooze settings fetching - */ - error?: string; + id: string; showTooltipInline?: boolean; } export function RuleSnoozeBadge({ - snoozeSettings, - error, + id, showTooltipInline = false, }: RuleSnoozeBadgeProps): JSX.Element { const RulesListNotifyBadge = useKibana().services.triggersActionsUi.getRulesListNotifyBadge; + const { snoozeSettings, error } = useRuleSnoozeSettings(id); const [{ canUserCRUD }] = useUserData(); const hasCRUDPermissions = hasUserCRUDPermission(canUserCRUD); const invalidateFetchRuleSnoozeSettings = useInvalidateFetchRulesSnoozeSettingsQuery(); diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_details_ui/pages/rule_details/components/rule_details_snooze_settings/translations.ts b/x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge/translations.ts similarity index 68% rename from x-pack/plugins/security_solution/public/detection_engine/rule_details_ui/pages/rule_details/components/rule_details_snooze_settings/translations.ts rename to x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge/translations.ts index 37b3b6c75ba6e..2c67bdab2744f 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_details_ui/pages/rule_details/components/rule_details_snooze_settings/translations.ts +++ b/x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge/translations.ts @@ -7,8 +7,8 @@ import { i18n } from '@kbn/i18n'; -export const UNABLE_TO_FETCH_RULE_SNOOZE_SETTINGS = i18n.translate( - 'xpack.securitySolution.detectionEngine.ruleDetails.rulesSnoozeSettings.error.unableToFetch', +export const UNABLE_TO_FETCH_RULES_SNOOZE_SETTINGS = i18n.translate( + 'xpack.securitySolution.detectionEngine.rulesSnoozeBadge.error.unableToFetch', { defaultMessage: 'Unable to fetch snooze settings', } diff --git a/x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge/use_rule_snooze_settings.ts b/x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge/use_rule_snooze_settings.ts new file mode 100644 index 0000000000000..0de53dadcd5f5 --- /dev/null +++ b/x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge/use_rule_snooze_settings.ts @@ -0,0 +1,38 @@ +/* + * 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 { RuleSnoozeSettings } from '../../rule_management/logic'; +import { useFetchRulesSnoozeSettings } from '../../rule_management/api/hooks/use_fetch_rules_snooze_settings'; +import { useRulesTableContextOptional } from '../../rule_management_ui/components/rules_table/rules_table/rules_table_context'; +import * as i18n from './translations'; + +interface UseRuleSnoozeSettingsResult { + snoozeSettings?: RuleSnoozeSettings; + error?: string; +} + +export function useRuleSnoozeSettings(id: string): UseRuleSnoozeSettingsResult { + const { + state: { rulesSnoozeSettings: rulesTableSnoozeSettings }, + } = useRulesTableContextOptional() ?? { state: {} }; + const { + data: rulesSnoozeSettings, + isFetching: isSingleSnoozeSettingsFetching, + isError: isSingleSnoozeSettingsError, + } = useFetchRulesSnoozeSettings([id]); + const snoozeSettings = rulesTableSnoozeSettings?.data[id] ?? rulesSnoozeSettings?.[0]; + const isFetching = rulesTableSnoozeSettings?.isFetching || isSingleSnoozeSettingsFetching; + const isError = rulesTableSnoozeSettings?.isError || isSingleSnoozeSettingsError; + + return { + snoozeSettings, + error: + isError || (!snoozeSettings && !isFetching) + ? i18n.UNABLE_TO_FETCH_RULES_SNOOZE_SETTINGS + : undefined, + }; +} diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_details_ui/pages/rule_details/components/rule_details_snooze_settings/index.tsx b/x-pack/plugins/security_solution/public/detection_engine/rule_details_ui/pages/rule_details/components/rule_details_snooze_settings/index.tsx deleted file mode 100644 index e610715d676ce..0000000000000 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_details_ui/pages/rule_details/components/rule_details_snooze_settings/index.tsx +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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 from 'react'; -import { useFetchRulesSnoozeSettings } from '../../../../../rule_management/api/hooks/use_fetch_rules_snooze_settings'; -import { RuleSnoozeBadge } from '../../../../../components/rule_snooze_badge'; -import * as i18n from './translations'; - -interface RuleDetailsSnoozeBadge { - /** - * Rule's SO id (not ruleId) - */ - id: string; -} - -export function RuleDetailsSnoozeSettings({ id }: RuleDetailsSnoozeBadge): JSX.Element { - const { data: rulesSnoozeSettings, isFetching, isError } = useFetchRulesSnoozeSettings([id]); - const snoozeSettings = rulesSnoozeSettings?.[0]; - - return ( - - ); -} diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_details_ui/pages/rule_details/index.test.tsx b/x-pack/plugins/security_solution/public/detection_engine/rule_details_ui/pages/rule_details/index.test.tsx index 07cbd4294cb22..8edd495393c09 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_details_ui/pages/rule_details/index.test.tsx +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_details_ui/pages/rule_details/index.test.tsx @@ -87,8 +87,8 @@ jest.mock('react-router-dom', () => { }); // RuleDetailsSnoozeSettings is an isolated component and not essential for existing tests -jest.mock('./components/rule_details_snooze_settings', () => ({ - RuleDetailsSnoozeSettings: () => <>, +jest.mock('../../../components/rule_snooze_badge', () => ({ + RuleSnoozeBadge: () => <>, })); const mockRedirectLegacyUrl = jest.fn(); diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_details_ui/pages/rule_details/index.tsx b/x-pack/plugins/security_solution/public/detection_engine/rule_details_ui/pages/rule_details/index.tsx index 6e1b4fddbd167..a8ca60478323a 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_details_ui/pages/rule_details/index.tsx +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_details_ui/pages/rule_details/index.tsx @@ -140,7 +140,7 @@ import { EditRuleSettingButtonLink } from '../../../../detections/pages/detectio import { useStartMlJobs } from '../../../rule_management/logic/use_start_ml_jobs'; import { useBulkDuplicateExceptionsConfirmation } from '../../../rule_management_ui/components/rules_table/bulk_actions/use_bulk_duplicate_confirmation'; import { BulkActionDuplicateExceptionsConfirmation } from '../../../rule_management_ui/components/rules_table/bulk_actions/bulk_duplicate_exceptions_confirmation'; -import { RuleDetailsSnoozeSettings } from './components/rule_details_snooze_settings'; +import { RuleSnoozeBadge } from '../../../components/rule_snooze_badge'; /** * Need a 100% height here to account for the graph/analyze tool, which sets no explicit height parameters, but fills the available space. @@ -559,7 +559,7 @@ const RuleDetailsPageComponent: React.FC = ({ )} - + ); diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_management_ui/components/rules_table/translations.ts b/x-pack/plugins/security_solution/public/detection_engine/rule_management_ui/components/rules_table/translations.ts index ad3cd89604030..52b4a5d4ba622 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_management_ui/components/rules_table/translations.ts +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_management_ui/components/rules_table/translations.ts @@ -21,10 +21,3 @@ export const ML_RULE_JOBS_WARNING_BUTTON_LABEL = i18n.translate( defaultMessage: 'Visit rule details page to investigate', } ); - -export const UNABLE_TO_FETCH_RULES_SNOOZE_SETTINGS = i18n.translate( - 'xpack.securitySolution.detectionEngine.ruleManagement.rulesSnoozeSettings.error.unableToFetch', - { - defaultMessage: 'Unable to fetch snooze settings', - } -); diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_management_ui/components/rules_table/use_columns.tsx b/x-pack/plugins/security_solution/public/detection_engine/rule_management_ui/components/rules_table/use_columns.tsx index 0ffb0ac7574a6..b37f2e0a6b4b4 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_management_ui/components/rules_table/use_columns.tsx +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_management_ui/components/rules_table/use_columns.tsx @@ -46,7 +46,6 @@ import { useHasActionsPrivileges } from './use_has_actions_privileges'; import { useHasMlPermissions } from './use_has_ml_permissions'; import { useRulesTableActions } from './use_rules_table_actions'; import { MlRuleWarningPopover } from './ml_rule_warning_popover'; -import * as rulesTableI18n from './translations'; export type TableColumn = EuiBasicTableColumn | EuiTableActionsColumnType; @@ -109,33 +108,15 @@ const useEnabledColumn = ({ hasCRUDPermissions, startMlJobs }: ColumnsProps): Ta }; const useRuleSnoozeColumn = (): TableColumn => { - const { - state: { rulesSnoozeSettings }, - } = useRulesTableContext(); - return useMemo( () => ({ field: 'snooze', name: i18n.COLUMN_SNOOZE, - render: (_, rule: Rule) => { - const snoozeSettings = rulesSnoozeSettings.data[rule.id]; - const { isFetching, isError } = rulesSnoozeSettings; - - return ( - - ); - }, + render: (_, rule: Rule) => , width: '100px', sortable: false, }), - [rulesSnoozeSettings] + [] ); }; diff --git a/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/rule_snooze_section.tsx b/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/rule_snooze_section.tsx index 067facb994f0c..44352e85c423b 100644 --- a/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/rule_snooze_section.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/rule_snooze_section.tsx @@ -8,7 +8,7 @@ import React from 'react'; import { css } from '@emotion/react'; import { EuiFlexGroup, EuiFlexItem, EuiText, useEuiTheme } from '@elastic/eui'; -import { RuleDetailsSnoozeSettings } from '../../../../detection_engine/rule_details_ui/pages/rule_details/components/rule_details_snooze_settings'; +import { RuleSnoozeBadge } from '../../../../detection_engine/components/rule_snooze_badge'; import * as i18n from './translations'; interface RuleSnoozeSectionProps { @@ -28,7 +28,7 @@ export function RuleSnoozeSection({ id }: RuleSnoozeSectionProps): JSX.Element { `} > - + From b70f92b77e4d5624e118b09cb4aebe6bc8d9d118 Mon Sep 17 00:00:00 2001 From: Maxim Palenov Date: Mon, 24 Apr 2023 18:41:02 +0200 Subject: [PATCH 03/13] avoid sending an unnecessary request if snooze data is found in rules table context --- .../components/rule_snooze_badge/use_rule_snooze_settings.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge/use_rule_snooze_settings.ts b/x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge/use_rule_snooze_settings.ts index 0de53dadcd5f5..d0cea2240c0ae 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge/use_rule_snooze_settings.ts +++ b/x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge/use_rule_snooze_settings.ts @@ -23,7 +23,7 @@ export function useRuleSnoozeSettings(id: string): UseRuleSnoozeSettingsResult { data: rulesSnoozeSettings, isFetching: isSingleSnoozeSettingsFetching, isError: isSingleSnoozeSettingsError, - } = useFetchRulesSnoozeSettings([id]); + } = useFetchRulesSnoozeSettings([id], { enabled: !rulesTableSnoozeSettings?.data[id] }); const snoozeSettings = rulesTableSnoozeSettings?.data[id] ?? rulesSnoozeSettings?.[0]; const isFetching = rulesTableSnoozeSettings?.isFetching || isSingleSnoozeSettingsFetching; const isError = rulesTableSnoozeSettings?.isError || isSingleSnoozeSettingsError; From 870e138f402e6ee3927e710d52e5f031ecce3454 Mon Sep 17 00:00:00 2001 From: Maxim Palenov Date: Mon, 24 Apr 2023 19:58:47 +0200 Subject: [PATCH 04/13] move RuleSnoozeBadge component to rule_management sub domain --- .../rule_details_ui/pages/rule_details/index.tsx | 2 +- .../components/rule_snooze_badge/index.ts | 0 .../components/rule_snooze_badge/rule_snooze_badge.tsx | 8 ++++---- .../components/rule_snooze_badge/translations.ts | 0 .../rule_snooze_badge/use_rule_snooze_settings.ts | 6 +++--- .../components/rules_table/use_columns.tsx | 2 +- .../rules/step_rule_actions/rule_snooze_section.tsx | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) rename x-pack/plugins/security_solution/public/detection_engine/{ => rule_management}/components/rule_snooze_badge/index.ts (100%) rename x-pack/plugins/security_solution/public/detection_engine/{ => rule_management}/components/rule_snooze_badge/rule_snooze_badge.tsx (87%) rename x-pack/plugins/security_solution/public/detection_engine/{ => rule_management}/components/rule_snooze_badge/translations.ts (100%) rename x-pack/plugins/security_solution/public/detection_engine/{ => rule_management}/components/rule_snooze_badge/use_rule_snooze_settings.ts (80%) diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_details_ui/pages/rule_details/index.tsx b/x-pack/plugins/security_solution/public/detection_engine/rule_details_ui/pages/rule_details/index.tsx index a8ca60478323a..d9181214afd6c 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_details_ui/pages/rule_details/index.tsx +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_details_ui/pages/rule_details/index.tsx @@ -140,7 +140,7 @@ import { EditRuleSettingButtonLink } from '../../../../detections/pages/detectio import { useStartMlJobs } from '../../../rule_management/logic/use_start_ml_jobs'; import { useBulkDuplicateExceptionsConfirmation } from '../../../rule_management_ui/components/rules_table/bulk_actions/use_bulk_duplicate_confirmation'; import { BulkActionDuplicateExceptionsConfirmation } from '../../../rule_management_ui/components/rules_table/bulk_actions/bulk_duplicate_exceptions_confirmation'; -import { RuleSnoozeBadge } from '../../../components/rule_snooze_badge'; +import { RuleSnoozeBadge } from '../../../rule_management/components/rule_snooze_badge'; /** * Need a 100% height here to account for the graph/analyze tool, which sets no explicit height parameters, but fills the available space. diff --git a/x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge/index.ts b/x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_snooze_badge/index.ts similarity index 100% rename from x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge/index.ts rename to x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_snooze_badge/index.ts diff --git a/x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge/rule_snooze_badge.tsx b/x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_snooze_badge/rule_snooze_badge.tsx similarity index 87% rename from x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge/rule_snooze_badge.tsx rename to x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_snooze_badge/rule_snooze_badge.tsx index 2599bbc521d7c..8f8c67e2ef074 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge/rule_snooze_badge.tsx +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_snooze_badge/rule_snooze_badge.tsx @@ -7,10 +7,10 @@ import { EuiButtonIcon, EuiToolTip } from '@elastic/eui'; import React, { useMemo } from 'react'; -import { useUserData } from '../../../detections/components/user_info'; -import { hasUserCRUDPermission } from '../../../common/utils/privileges'; -import { useKibana } from '../../../common/lib/kibana'; -import { useInvalidateFetchRulesSnoozeSettingsQuery } from '../../rule_management/api/hooks/use_fetch_rules_snooze_settings'; +import { useUserData } from '../../../../detections/components/user_info'; +import { hasUserCRUDPermission } from '../../../../common/utils/privileges'; +import { useKibana } from '../../../../common/lib/kibana'; +import { useInvalidateFetchRulesSnoozeSettingsQuery } from '../../api/hooks/use_fetch_rules_snooze_settings'; import { useRuleSnoozeSettings } from './use_rule_snooze_settings'; interface RuleSnoozeBadgeProps { diff --git a/x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge/translations.ts b/x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_snooze_badge/translations.ts similarity index 100% rename from x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge/translations.ts rename to x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_snooze_badge/translations.ts diff --git a/x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge/use_rule_snooze_settings.ts b/x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_snooze_badge/use_rule_snooze_settings.ts similarity index 80% rename from x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge/use_rule_snooze_settings.ts rename to x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_snooze_badge/use_rule_snooze_settings.ts index d0cea2240c0ae..a09db8b281591 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge/use_rule_snooze_settings.ts +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_snooze_badge/use_rule_snooze_settings.ts @@ -5,9 +5,9 @@ * 2.0. */ -import type { RuleSnoozeSettings } from '../../rule_management/logic'; -import { useFetchRulesSnoozeSettings } from '../../rule_management/api/hooks/use_fetch_rules_snooze_settings'; -import { useRulesTableContextOptional } from '../../rule_management_ui/components/rules_table/rules_table/rules_table_context'; +import type { RuleSnoozeSettings } from '../../logic'; +import { useFetchRulesSnoozeSettings } from '../../api/hooks/use_fetch_rules_snooze_settings'; +import { useRulesTableContextOptional } from '../../../rule_management_ui/components/rules_table/rules_table/rules_table_context'; import * as i18n from './translations'; interface UseRuleSnoozeSettingsResult { diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_management_ui/components/rules_table/use_columns.tsx b/x-pack/plugins/security_solution/public/detection_engine/rule_management_ui/components/rules_table/use_columns.tsx index b37f2e0a6b4b4..e20a2f2c70e4f 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_management_ui/components/rules_table/use_columns.tsx +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_management_ui/components/rules_table/use_columns.tsx @@ -22,7 +22,7 @@ import type { } from '../../../../../common/detection_engine/rule_monitoring'; import { isMlRule } from '../../../../../common/machine_learning/helpers'; import { getEmptyTagValue } from '../../../../common/components/empty_value'; -import { RuleSnoozeBadge } from '../../../components/rule_snooze_badge'; +import { RuleSnoozeBadge } from '../../../rule_management/components/rule_snooze_badge'; import { FormattedRelativePreferenceDate } from '../../../../common/components/formatted_date'; import { SecuritySolutionLinkAnchor } from '../../../../common/components/links'; import { getRuleDetailsTabUrl } from '../../../../common/components/link_to/redirect_to_detection_engine'; diff --git a/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/rule_snooze_section.tsx b/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/rule_snooze_section.tsx index 44352e85c423b..a6c9a03b26deb 100644 --- a/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/rule_snooze_section.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/rule_snooze_section.tsx @@ -8,7 +8,7 @@ import React from 'react'; import { css } from '@emotion/react'; import { EuiFlexGroup, EuiFlexItem, EuiText, useEuiTheme } from '@elastic/eui'; -import { RuleSnoozeBadge } from '../../../../detection_engine/components/rule_snooze_badge'; +import { RuleSnoozeBadge } from '../../../../detection_engine/rule_management/components/rule_snooze_badge'; import * as i18n from './translations'; interface RuleSnoozeSectionProps { From 583c096f7ddcc5ceb3140a3d40b4204dfc50e72e Mon Sep 17 00:00:00 2001 From: Maxim Palenov Date: Mon, 24 Apr 2023 20:09:14 +0200 Subject: [PATCH 05/13] avoid sending N+1 requests on the rules table --- .../components/rule_snooze_badge/use_rule_snooze_settings.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_snooze_badge/use_rule_snooze_settings.ts b/x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_snooze_badge/use_rule_snooze_settings.ts index a09db8b281591..94a857b1e9842 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_snooze_badge/use_rule_snooze_settings.ts +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_snooze_badge/use_rule_snooze_settings.ts @@ -23,7 +23,9 @@ export function useRuleSnoozeSettings(id: string): UseRuleSnoozeSettingsResult { data: rulesSnoozeSettings, isFetching: isSingleSnoozeSettingsFetching, isError: isSingleSnoozeSettingsError, - } = useFetchRulesSnoozeSettings([id], { enabled: !rulesTableSnoozeSettings?.data[id] }); + } = useFetchRulesSnoozeSettings([id], { + enabled: !rulesTableSnoozeSettings?.data[id] && !rulesTableSnoozeSettings?.isFetching, + }); const snoozeSettings = rulesTableSnoozeSettings?.data[id] ?? rulesSnoozeSettings?.[0]; const isFetching = rulesTableSnoozeSettings?.isFetching || isSingleSnoozeSettingsFetching; const isError = rulesTableSnoozeSettings?.isError || isSingleSnoozeSettingsError; From e777475bc92d75f963d5919a3d23cea41a34a15b Mon Sep 17 00:00:00 2001 From: Maxim Palenov Date: Mon, 24 Apr 2023 20:17:51 +0200 Subject: [PATCH 06/13] use RuleObjectId type for rule id --- .../components/rule_snooze_badge/rule_snooze_badge.tsx | 7 ++++--- .../components/rules/step_rule_actions/index.tsx | 9 +++++---- .../rules/step_rule_actions/rule_snooze_section.tsx | 7 ++++--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_snooze_badge/rule_snooze_badge.tsx b/x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_snooze_badge/rule_snooze_badge.tsx index 8f8c67e2ef074..6e0917b1fea7b 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_snooze_badge/rule_snooze_badge.tsx +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_snooze_badge/rule_snooze_badge.tsx @@ -7,6 +7,7 @@ import { EuiButtonIcon, EuiToolTip } from '@elastic/eui'; import React, { useMemo } from 'react'; +import type { RuleObjectId } from '../../../../../common/detection_engine/rule_schema'; import { useUserData } from '../../../../detections/components/user_info'; import { hasUserCRUDPermission } from '../../../../common/utils/privileges'; import { useKibana } from '../../../../common/lib/kibana'; @@ -17,16 +18,16 @@ interface RuleSnoozeBadgeProps { /** * Rule's SO id (not ruleId) */ - id: string; + ruleId: RuleObjectId; showTooltipInline?: boolean; } export function RuleSnoozeBadge({ - id, + ruleId, showTooltipInline = false, }: RuleSnoozeBadgeProps): JSX.Element { const RulesListNotifyBadge = useKibana().services.triggersActionsUi.getRulesListNotifyBadge; - const { snoozeSettings, error } = useRuleSnoozeSettings(id); + const { snoozeSettings, error } = useRuleSnoozeSettings(ruleId); const [{ canUserCRUD }] = useUserData(); const hasCRUDPermissions = hasUserCRUDPermission(canUserCRUD); const invalidateFetchRuleSnoozeSettings = useInvalidateFetchRulesSnoozeSettingsQuery(); diff --git a/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/index.tsx b/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/index.tsx index 3c5356406a6b0..47c33f9282572 100644 --- a/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/index.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/index.tsx @@ -22,6 +22,7 @@ import { FormattedMessage } from '@kbn/i18n-react'; import type { ActionVariables } from '@kbn/triggers-actions-ui-plugin/public'; import { UseArray } from '@kbn/es-ui-shared-plugin/static/forms/hook_form_lib'; import type { Type } from '@kbn/securitysolution-io-ts-alerting-types'; +import type { RuleObjectId } from '../../../../../common/detection_engine/rule_schema'; import { isQueryRule } from '../../../../../common/detection_engine/utils'; import { useIsExperimentalFeatureEnabled } from '../../../../common/hooks/use_experimental_features'; import { ResponseActionsForm } from '../../../../detection_engine/rule_response_actions/response_actions_form'; @@ -38,7 +39,7 @@ import { APP_UI_ID } from '../../../../../common/constants'; import { RuleSnoozeSection } from './rule_snooze_section'; interface StepRuleActionsProps extends RuleStepProps { - id?: string; // Rule SO's id (not ruleId) + ruleId?: RuleObjectId; // Rule SO's id (not ruleId) defaultValues?: ActionsStepRule | null; actionMessageParams: ActionVariables; ruleType?: Type; @@ -70,7 +71,7 @@ const DisplayActionsHeader = () => { }; const StepRuleActionsComponent: FC = ({ - id, + ruleId, addPadding = false, defaultValues, isReadOnlyView, @@ -169,7 +170,7 @@ const StepRuleActionsComponent: FC = ({ return application.capabilities.actions.show ? ( <> - {id && } + {ruleId && } {displayActionsOptions} {responseActionsEnabled && displayResponseActionsOptions} @@ -181,7 +182,7 @@ const StepRuleActionsComponent: FC = ({ ); }, [ - id, + ruleId, application.capabilities.actions.show, displayActionsOptions, displayResponseActionsOptions, diff --git a/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/rule_snooze_section.tsx b/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/rule_snooze_section.tsx index a6c9a03b26deb..d9586f80f3e93 100644 --- a/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/rule_snooze_section.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/rule_snooze_section.tsx @@ -8,14 +8,15 @@ import React from 'react'; import { css } from '@emotion/react'; import { EuiFlexGroup, EuiFlexItem, EuiText, useEuiTheme } from '@elastic/eui'; +import type { RuleObjectId } from '../../../../../common/detection_engine/rule_schema'; import { RuleSnoozeBadge } from '../../../../detection_engine/rule_management/components/rule_snooze_badge'; import * as i18n from './translations'; interface RuleSnoozeSectionProps { - id: string; // Rule SO's id (not ruleId) + ruleId: RuleObjectId; // Rule SO's id (not ruleId) } -export function RuleSnoozeSection({ id }: RuleSnoozeSectionProps): JSX.Element { +export function RuleSnoozeSection({ ruleId }: RuleSnoozeSectionProps): JSX.Element { const { euiTheme } = useEuiTheme(); return ( @@ -28,7 +29,7 @@ export function RuleSnoozeSection({ id }: RuleSnoozeSectionProps): JSX.Element { `} > - + From ed947aafa7691ed4446a21ad47da7a1fbc3a71ab Mon Sep 17 00:00:00 2001 From: Maxim Palenov Date: Mon, 24 Apr 2023 20:45:34 +0200 Subject: [PATCH 07/13] use RuleObjectId type for rule id --- .../rule_creation_ui/pages/rule_editing/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_creation_ui/pages/rule_editing/index.tsx b/x-pack/plugins/security_solution/public/detection_engine/rule_creation_ui/pages/rule_editing/index.tsx index 58ccebb3dd124..e07848c145d08 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_creation_ui/pages/rule_editing/index.tsx +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_creation_ui/pages/rule_editing/index.tsx @@ -303,7 +303,7 @@ const EditRulePageComponent: FC = () => { {actionsStep.data != null && ( Date: Mon, 24 Apr 2023 21:48:33 +0200 Subject: [PATCH 08/13] add API data mapping --- .../rule_management/api/api.test.ts | 36 +++++++++++++++++++ .../rule_management/api/api.ts | 16 +++++++-- .../hooks/use_fetch_rules_snooze_settings.ts | 6 +--- .../rule_snooze_badge/rule_snooze_badge.tsx | 8 +---- .../rule_management/logic/types.ts | 12 +++++-- 5 files changed, 61 insertions(+), 17 deletions(-) diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_management/api/api.test.ts b/x-pack/plugins/security_solution/public/detection_engine/rule_management/api/api.test.ts index b1a2d0f95417a..5e3248818bf4e 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_management/api/api.test.ts +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_management/api/api.test.ts @@ -791,6 +791,9 @@ describe('Detections Rules API', () => { describe('fetchRulesSnoozeSettings', () => { beforeEach(() => { fetchMock.mockClear(); + fetchMock.mockResolvedValue({ + data: [], + }); }); test('requests snooze settings of multiple rules by their IDs', () => { @@ -836,5 +839,38 @@ describe('Detections Rules API', () => { }) ); }); + + test('returns mapped data', async () => { + fetchMock.mockResolvedValue({ + data: [ + { + id: '1', + mute_all: false, + }, + { + id: '1', + mute_all: false, + active_snoozes: [], + is_snoozed_until: '2023-04-24T19:31:46.765Z', + }, + ], + }); + + const result = await fetchRulesSnoozeSettings({ ids: ['id1'] }); + + expect(result).toEqual([ + { + id: '1', + muteAll: false, + activeSnoozes: [], + }, + { + id: '1', + muteAll: false, + activeSnoozes: [], + isSnoozedUntil: new Date('2023-04-24T19:31:46.765Z'), + }, + ]); + }); }); }); diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_management/api/api.ts b/x-pack/plugins/security_solution/public/detection_engine/rule_management/api/api.ts index b8078421ce683..97bcaced4ca4c 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_management/api/api.ts +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_management/api/api.ts @@ -57,7 +57,8 @@ import type { PrePackagedRulesStatusResponse, PreviewRulesProps, Rule, - RulesSnoozeSettingsResponse, + RuleSnoozeSettings, + RulesSnoozeSettingsBatchResponse, UpdateRulesProps, } from '../logic/types'; import { convertRulesFilterToKQL } from '../logic/utils'; @@ -197,8 +198,8 @@ export const fetchRuleById = async ({ id, signal }: FetchRuleProps): Promise => - KibanaServices.get().http.fetch( +}: FetchRuleSnoozingProps): Promise => { + const response = await KibanaServices.get().http.fetch( INTERNAL_ALERTING_API_FIND_RULES_PATH, { method: 'GET', @@ -211,6 +212,15 @@ export const fetchRulesSnoozeSettings = async ({ } ); + return response.data?.map((x) => ({ + id: x?.id ?? '', + muteAll: x?.mute_all ?? false, + activeSnoozes: x?.active_snoozes ?? [], + isSnoozedUntil: x?.is_snoozed_until ? new Date(x.is_snoozed_until) : undefined, + snoozeSchedule: x?.snooze_schedule, + })); +}; + export interface BulkActionSummary { failed: number; skipped: number; diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_management/api/hooks/use_fetch_rules_snooze_settings.ts b/x-pack/plugins/security_solution/public/detection_engine/rule_management/api/hooks/use_fetch_rules_snooze_settings.ts index bdc101fe18644..8e0ef31871826 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_management/api/hooks/use_fetch_rules_snooze_settings.ts +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_management/api/hooks/use_fetch_rules_snooze_settings.ts @@ -29,11 +29,7 @@ export const useFetchRulesSnoozeSettings = ( ) => { return useQuery( [...FETCH_RULE_SNOOZE_SETTINGS_QUERY_KEY, ...ids], - async ({ signal }) => { - const response = await fetchRulesSnoozeSettings({ ids, signal }); - - return response.data; - }, + ({ signal }) => fetchRulesSnoozeSettings({ ids, signal }), { ...DEFAULT_QUERY_OPTIONS, ...queryOptions, diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_snooze_badge/rule_snooze_badge.tsx b/x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_snooze_badge/rule_snooze_badge.tsx index 6e0917b1fea7b..76c5d5bc2fece 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_snooze_badge/rule_snooze_badge.tsx +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_snooze_badge/rule_snooze_badge.tsx @@ -34,13 +34,7 @@ export function RuleSnoozeBadge({ const isLoading = !snoozeSettings; const rule = useMemo(() => { return { - id: snoozeSettings?.id ?? '', - muteAll: snoozeSettings?.mute_all ?? false, - activeSnoozes: snoozeSettings?.active_snoozes ?? [], - isSnoozedUntil: snoozeSettings?.is_snoozed_until - ? new Date(snoozeSettings.is_snoozed_until) - : undefined, - snoozeSchedule: snoozeSettings?.snooze_schedule, + ...snoozeSettings, isEditable: hasCRUDPermissions, }; }, [snoozeSettings, hasCRUDPermissions]); diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_management/logic/types.ts b/x-pack/plugins/security_solution/public/detection_engine/rule_management/logic/types.ts index ca71fa2680f17..e22be9467c6a1 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_management/logic/types.ts +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_management/logic/types.ts @@ -219,6 +219,14 @@ export interface FetchRulesProps { } export interface RuleSnoozeSettings { + id: string; + muteAll: boolean; + snoozeSchedule?: RuleSnooze; + activeSnoozes?: string[]; + isSnoozedUntil?: Date; +} + +interface RuleSnoozeSettingsResponse { id: string; mute_all: boolean; snooze_schedule?: RuleSnooze; @@ -226,8 +234,8 @@ export interface RuleSnoozeSettings { is_snoozed_until?: string; } -export interface RulesSnoozeSettingsResponse { - data: RuleSnoozeSettings[]; +export interface RulesSnoozeSettingsBatchResponse { + data: RuleSnoozeSettingsResponse[]; } export type SortingOptions = t.TypeOf; From 091106d8eaa6632f6033907aed39a498bc132255 Mon Sep 17 00:00:00 2001 From: Maxim Palenov Date: Mon, 24 Apr 2023 21:49:15 +0200 Subject: [PATCH 09/13] fix wrong mock --- .../rule_details_ui/pages/rule_details/index.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_details_ui/pages/rule_details/index.test.tsx b/x-pack/plugins/security_solution/public/detection_engine/rule_details_ui/pages/rule_details/index.test.tsx index 8edd495393c09..67a156e31edf2 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_details_ui/pages/rule_details/index.test.tsx +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_details_ui/pages/rule_details/index.test.tsx @@ -87,7 +87,7 @@ jest.mock('react-router-dom', () => { }); // RuleDetailsSnoozeSettings is an isolated component and not essential for existing tests -jest.mock('../../../components/rule_snooze_badge', () => ({ +jest.mock('../../../rule_management/components/rule_snooze_badge', () => ({ RuleSnoozeBadge: () => <>, })); From 1ac3838e3529ec21e1720fc7642beca71d357ae8 Mon Sep 17 00:00:00 2001 From: Maxim Palenov Date: Mon, 24 Apr 2023 21:51:38 +0200 Subject: [PATCH 10/13] rename missing props --- .../rule_details_ui/pages/rule_details/index.tsx | 2 +- .../rule_management_ui/components/rules_table/use_columns.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_details_ui/pages/rule_details/index.tsx b/x-pack/plugins/security_solution/public/detection_engine/rule_details_ui/pages/rule_details/index.tsx index d9181214afd6c..8be787c5c381b 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_details_ui/pages/rule_details/index.tsx +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_details_ui/pages/rule_details/index.tsx @@ -559,7 +559,7 @@ const RuleDetailsPageComponent: React.FC = ({ )} - + ); diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_management_ui/components/rules_table/use_columns.tsx b/x-pack/plugins/security_solution/public/detection_engine/rule_management_ui/components/rules_table/use_columns.tsx index e20a2f2c70e4f..cccd9f394d65e 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_management_ui/components/rules_table/use_columns.tsx +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_management_ui/components/rules_table/use_columns.tsx @@ -112,7 +112,7 @@ const useRuleSnoozeColumn = (): TableColumn => { () => ({ field: 'snooze', name: i18n.COLUMN_SNOOZE, - render: (_, rule: Rule) => , + render: (_, rule: Rule) => , width: '100px', sortable: false, }), From 249ce32d08918db8f1898043fcc9646a1443e150 Mon Sep 17 00:00:00 2001 From: Maxim Palenov Date: Mon, 24 Apr 2023 23:07:33 +0200 Subject: [PATCH 11/13] fix typings --- .../rule_snooze_badge/rule_snooze_badge.tsx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_snooze_badge/rule_snooze_badge.tsx b/x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_snooze_badge/rule_snooze_badge.tsx index 76c5d5bc2fece..e488127c25691 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_snooze_badge/rule_snooze_badge.tsx +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_snooze_badge/rule_snooze_badge.tsx @@ -32,12 +32,19 @@ export function RuleSnoozeBadge({ const hasCRUDPermissions = hasUserCRUDPermission(canUserCRUD); const invalidateFetchRuleSnoozeSettings = useInvalidateFetchRulesSnoozeSettingsQuery(); const isLoading = !snoozeSettings; - const rule = useMemo(() => { - return { - ...snoozeSettings, + const rule = useMemo( + () => ({ + id: snoozeSettings?.id ?? '', + muteAll: snoozeSettings?.muteAll ?? false, + activeSnoozes: snoozeSettings?.activeSnoozes ?? [], + isSnoozedUntil: snoozeSettings?.isSnoozedUntil + ? new Date(snoozeSettings.isSnoozedUntil) + : undefined, + snoozeSchedule: snoozeSettings?.snoozeSchedule, isEditable: hasCRUDPermissions, - }; - }, [snoozeSettings, hasCRUDPermissions]); + }), + [snoozeSettings, hasCRUDPermissions] + ); if (error) { return ( From 055540031dca3ac11bbf5f972785a033ae615ebd Mon Sep 17 00:00:00 2001 From: Maxim Palenov Date: Mon, 24 Apr 2023 23:45:31 +0200 Subject: [PATCH 12/13] fix typings --- .../rules_table/rules_table_context.test.tsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_management_ui/components/rules_table/rules_table/rules_table_context.test.tsx b/x-pack/plugins/security_solution/public/detection_engine/rule_management_ui/components/rules_table/rules_table/rules_table_context.test.tsx index 22a3af8ff0814..abc384cea3bfb 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_management_ui/components/rules_table/rules_table/rules_table_context.test.tsx +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_management_ui/components/rules_table/rules_table/rules_table_context.test.tsx @@ -190,8 +190,8 @@ describe('RulesTableContextProvider', () => { { id: '2', name: 'rule 2' }, ] as Rule[], rulesSnoozeSettings: [ - { id: '1', mute_all: true, snooze_schedule: [] }, - { id: '2', mute_all: false, snooze_schedule: [] }, + { id: '1', muteAll: true, snoozeSchedule: [] }, + { id: '2', muteAll: false, snoozeSchedule: [] }, ], }); @@ -216,21 +216,21 @@ describe('RulesTableContextProvider', () => { { id: '2', name: 'rule 2' }, ] as Rule[], rulesSnoozeSettings: [ - { id: '1', mute_all: true, snooze_schedule: [] }, - { id: '2', mute_all: false, snooze_schedule: [] }, + { id: '1', muteAll: true, snoozeSchedule: [] }, + { id: '2', muteAll: false, snoozeSchedule: [] }, ], }); expect(state.rulesSnoozeSettings.data).toEqual({ '1': { id: '1', - mute_all: true, - snooze_schedule: [], + muteAll: true, + snoozeSchedule: [], }, '2': { id: '2', - mute_all: false, - snooze_schedule: [], + muteAll: false, + snoozeSchedule: [], }, }); }); From 48064b1b59b39e8106762795eb173d8b70c46ce9 Mon Sep 17 00:00:00 2001 From: Maxim Palenov Date: Tue, 25 Apr 2023 11:28:49 +0200 Subject: [PATCH 13/13] rename an internal variable --- .../detection_engine/rule_management/api/api.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_management/api/api.ts b/x-pack/plugins/security_solution/public/detection_engine/rule_management/api/api.ts index 97bcaced4ca4c..24b66cada346c 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_management/api/api.ts +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_management/api/api.ts @@ -212,12 +212,14 @@ export const fetchRulesSnoozeSettings = async ({ } ); - return response.data?.map((x) => ({ - id: x?.id ?? '', - muteAll: x?.mute_all ?? false, - activeSnoozes: x?.active_snoozes ?? [], - isSnoozedUntil: x?.is_snoozed_until ? new Date(x.is_snoozed_until) : undefined, - snoozeSchedule: x?.snooze_schedule, + return response.data?.map((snoozeSettings) => ({ + id: snoozeSettings?.id ?? '', + muteAll: snoozeSettings?.mute_all ?? false, + activeSnoozes: snoozeSettings?.active_snoozes ?? [], + isSnoozedUntil: snoozeSettings?.is_snoozed_until + ? new Date(snoozeSettings.is_snoozed_until) + : undefined, + snoozeSchedule: snoozeSettings?.snooze_schedule, })); };