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..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,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/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..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,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('../../../rule_management/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 90f1d38f69774..211321618068f 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 '../../../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. @@ -559,7 +559,7 @@ const RuleDetailsPageComponent: React.FC = ({ )} - + ); 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..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 @@ -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,17 @@ export const fetchRulesSnoozeSettings = async ({ } ); + 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, + })); +}; + 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/index.ts b/x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_snooze_badge/index.ts new file mode 100644 index 0000000000000..8e231398688f0 --- /dev/null +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_management/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/rule_management/components/rule_snooze_badge/rule_snooze_badge.tsx similarity index 55% 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/rule_management/components/rule_snooze_badge/rule_snooze_badge.tsx index 7fa16826eec60..e488127c25691 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge.tsx +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_snooze_badge/rule_snooze_badge.tsx @@ -7,46 +7,44 @@ 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 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'; +import { useInvalidateFetchRulesSnoozeSettingsQuery } from '../../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; + ruleId: RuleObjectId; showTooltipInline?: boolean; } export function RuleSnoozeBadge({ - snoozeSettings, - error, + ruleId, showTooltipInline = false, }: RuleSnoozeBadgeProps): JSX.Element { const RulesListNotifyBadge = useKibana().services.triggersActionsUi.getRulesListNotifyBadge; + const { snoozeSettings, error } = useRuleSnoozeSettings(ruleId); const [{ canUserCRUD }] = useUserData(); const hasCRUDPermissions = hasUserCRUDPermission(canUserCRUD); const invalidateFetchRuleSnoozeSettings = useInvalidateFetchRulesSnoozeSettingsQuery(); const isLoading = !snoozeSettings; - const rule = useMemo(() => { - return { + const rule = useMemo( + () => ({ id: snoozeSettings?.id ?? '', - muteAll: snoozeSettings?.mute_all ?? false, - activeSnoozes: snoozeSettings?.active_snoozes ?? [], - isSnoozedUntil: snoozeSettings?.is_snoozed_until - ? new Date(snoozeSettings.is_snoozed_until) + muteAll: snoozeSettings?.muteAll ?? false, + activeSnoozes: snoozeSettings?.activeSnoozes ?? [], + isSnoozedUntil: snoozeSettings?.isSnoozedUntil + ? new Date(snoozeSettings.isSnoozedUntil) : undefined, - snoozeSchedule: snoozeSettings?.snooze_schedule, + snoozeSchedule: snoozeSettings?.snoozeSchedule, isEditable: hasCRUDPermissions, - }; - }, [snoozeSettings, hasCRUDPermissions]); + }), + [snoozeSettings, hasCRUDPermissions] + ); if (error) { return ( 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/rule_management/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/rule_management/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/rule_management/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/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 new file mode 100644 index 0000000000000..94a857b1e9842 --- /dev/null +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_snooze_badge/use_rule_snooze_settings.ts @@ -0,0 +1,40 @@ +/* + * 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 '../../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 { + 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], { + enabled: !rulesTableSnoozeSettings?.data[id] && !rulesTableSnoozeSettings?.isFetching, + }); + 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_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; 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: [], }, }); }); 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..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 @@ -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'; @@ -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/index.tsx b/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/index.tsx index 86bbb7604add2..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'; @@ -35,8 +36,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 { + ruleId?: RuleObjectId; // Rule SO's id (not ruleId) defaultValues?: ActionsStepRule | null; actionMessageParams: ActionVariables; ruleType?: Type; @@ -68,6 +71,7 @@ const DisplayActionsHeader = () => { }; const StepRuleActionsComponent: FC = ({ + ruleId, addPadding = false, defaultValues, isReadOnlyView, @@ -166,9 +170,9 @@ const StepRuleActionsComponent: FC = ({ return application.capabilities.actions.show ? ( <> + {ruleId && } {displayActionsOptions} {responseActionsEnabled && displayResponseActionsOptions} - @@ -178,6 +182,7 @@ const StepRuleActionsComponent: FC = ({ ); }, [ + 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 new file mode 100644 index 0000000000000..d9586f80f3e93 --- /dev/null +++ b/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/rule_snooze_section.tsx @@ -0,0 +1,42 @@ +/* + * 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 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 { + ruleId: RuleObjectId; // Rule SO's id (not ruleId) +} + +export function RuleSnoozeSection({ ruleId }: 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.', + } +);