-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution] Add rule snooze settings on the rule details page (…
…#155407) **Addresses:** #155406 ## Summary This PR adds rule snoozing support on the Rule Details page. https://user-images.githubusercontent.com/3775283/233387056-47a29066-f2af-4bbe-ad4f-f1002b216d7e.mov ### Checklist - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
- Loading branch information
Showing
10 changed files
with
176 additions
and
80 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
x-pack/plugins/security_solution/public/detection_engine/components/rule_snooze_badge.tsx
This file contains 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,67 @@ | ||
/* | ||
* 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 { 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'; | ||
|
||
interface RuleSnoozeBadgeProps { | ||
/** | ||
* Rule's snooze settings, when set to `undefined` considered as a loading state | ||
*/ | ||
snoozeSettings: RuleSnoozeSettings | undefined; | ||
/** | ||
* It should represent a user readable error message happened during data snooze settings fetching | ||
*/ | ||
error?: string; | ||
showTooltipInline?: boolean; | ||
} | ||
|
||
export function RuleSnoozeBadge({ | ||
snoozeSettings, | ||
error, | ||
showTooltipInline = false, | ||
}: RuleSnoozeBadgeProps): JSX.Element { | ||
const RulesListNotifyBadge = useKibana().services.triggersActionsUi.getRulesListNotifyBadge; | ||
const [{ canUserCRUD }] = useUserData(); | ||
const hasCRUDPermissions = hasUserCRUDPermission(canUserCRUD); | ||
const invalidateFetchRuleSnoozeSettings = useInvalidateFetchRulesSnoozeSettingsQuery(); | ||
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, | ||
isEditable: hasCRUDPermissions, | ||
}; | ||
}, [snoozeSettings, hasCRUDPermissions]); | ||
|
||
if (error) { | ||
return ( | ||
<EuiToolTip content={error}> | ||
<EuiButtonIcon size="s" iconType="bellSlash" disabled /> | ||
</EuiToolTip> | ||
); | ||
} | ||
|
||
return ( | ||
<RulesListNotifyBadge | ||
rule={rule} | ||
isLoading={isLoading} | ||
showTooltipInline={showTooltipInline} | ||
onRuleChanged={invalidateFetchRuleSnoozeSettings} | ||
/> | ||
); | ||
} |
35 changes: 35 additions & 0 deletions
35
...gine/rule_details_ui/pages/rule_details/components/rule_details_snooze_settings/index.tsx
This file contains 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 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 ( | ||
<RuleSnoozeBadge | ||
snoozeSettings={snoozeSettings} | ||
error={ | ||
isError || (!snoozeSettings && !isFetching) | ||
? i18n.UNABLE_TO_FETCH_RULE_SNOOZE_SETTINGS | ||
: undefined | ||
} | ||
showTooltipInline={true} | ||
/> | ||
); | ||
} |
This file contains 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
This file contains 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
This file contains 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
59 changes: 0 additions & 59 deletions
59
...ecurity_solution/public/detection_engine/rule_management/components/rule_snooze_badge.tsx
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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