diff --git a/x-pack/plugins/security_solution/public/cases/components/user_action_tree/helpers.tsx b/x-pack/plugins/security_solution/public/cases/components/user_action_tree/helpers.tsx
index 1a59dd06570ce..be32c1c5dd036 100644
--- a/x-pack/plugins/security_solution/public/cases/components/user_action_tree/helpers.tsx
+++ b/x-pack/plugins/security_solution/public/cases/components/user_action_tree/helpers.tsx
@@ -219,8 +219,8 @@ export const getAlertAttachment = ({
alertId: string;
index: string;
loadingAlertData: boolean;
- ruleId: string;
- ruleName: string;
+ ruleId?: string | null;
+ ruleName?: string | null;
}): EuiCommentProps => {
return {
username: (
diff --git a/x-pack/plugins/security_solution/public/cases/components/user_action_tree/index.tsx b/x-pack/plugins/security_solution/public/cases/components/user_action_tree/index.tsx
index bcb0b1515a252..b5338ef216ea5 100644
--- a/x-pack/plugins/security_solution/public/cases/components/user_action_tree/index.tsx
+++ b/x-pack/plugins/security_solution/public/cases/components/user_action_tree/index.tsx
@@ -377,11 +377,9 @@ export const UserActionTree = React.memo(
}
const ruleId =
- comment?.rule?.id ?? manualAlertsData[alertId]?.signal?.rule?.id?.[0] ?? '';
+ comment?.rule?.id ?? manualAlertsData[alertId]?.signal?.rule?.id?.[0] ?? null;
const ruleName =
- comment?.rule?.name ??
- manualAlertsData[alertId]?.signal?.rule?.name?.[0] ??
- i18n.UNKNOWN_RULE;
+ comment?.rule?.name ?? manualAlertsData[alertId]?.signal?.rule?.name?.[0] ?? null;
return [
...comments,
diff --git a/x-pack/plugins/security_solution/public/cases/components/user_action_tree/user_action_alert_comment_event.test.tsx b/x-pack/plugins/security_solution/public/cases/components/user_action_tree/user_action_alert_comment_event.test.tsx
index 228945bacf8a4..f4f610d07e2ff 100644
--- a/x-pack/plugins/security_solution/public/cases/components/user_action_tree/user_action_alert_comment_event.test.tsx
+++ b/x-pack/plugins/security_solution/public/cases/components/user_action_tree/user_action_alert_comment_event.test.tsx
@@ -46,11 +46,10 @@ describe('UserActionAvatar ', () => {
expect(wrapper.text()).toBe('added an alert from Awesome rule');
});
- it('does NOT render the link when the alert is undefined', async () => {
+ it('does NOT render the link when the rule is null', async () => {
const wrapper = mount(
- {/* @ts-expect-error */}
-
+
);
@@ -58,27 +57,7 @@ describe('UserActionAvatar ', () => {
wrapper.find(`[data-test-subj="alert-rule-link-alert-id-1"]`).first().exists()
).toBeFalsy();
- expect(wrapper.text()).toBe('added an alert from ');
- });
-
- it('does NOT render the link when the rule is undefined', async () => {
- const alert = {
- alertId: 'alert-id-1',
- commentType: CommentType.alert,
- };
-
- const wrapper = mount(
-
- {/* @ts-expect-error*/}
-
-
- );
-
- expect(
- wrapper.find(`[data-test-subj="alert-rule-link-alert-id-1"]`).first().exists()
- ).toBeFalsy();
-
- expect(wrapper.text()).toBe('added an alert from ');
+ expect(wrapper.text()).toBe('added an alert from Unknown rule');
});
it('navigate to app on link click', async () => {
diff --git a/x-pack/plugins/security_solution/public/cases/components/user_action_tree/user_action_alert_comment_event.tsx b/x-pack/plugins/security_solution/public/cases/components/user_action_tree/user_action_alert_comment_event.tsx
index 2a604b7c54d6b..57c366d412660 100644
--- a/x-pack/plugins/security_solution/public/cases/components/user_action_tree/user_action_alert_comment_event.tsx
+++ b/x-pack/plugins/security_solution/public/cases/components/user_action_tree/user_action_alert_comment_event.tsx
@@ -6,6 +6,7 @@
*/
import React, { memo, useCallback } from 'react';
+import { isEmpty } from 'lodash';
import { EuiText, EuiLoadingSpinner } from '@elastic/eui';
import { APP_ID } from '../../../../common/constants';
@@ -20,8 +21,8 @@ import { LinkAnchor } from '../../../common/components/links';
interface Props {
alertId: string;
commentType: CommentType;
- ruleId: string;
- ruleName: string;
+ ruleId?: string | null;
+ ruleName?: string | null;
alertsCount?: number;
loadingAlertData?: boolean;
}
@@ -51,16 +52,16 @@ const AlertCommentEventComponent: React.FC = ({
<>
{`${i18n.ALERT_COMMENT_LABEL_TITLE} `}
{loadingAlertData && }
- {!loadingAlertData && ruleId !== '' && (
+ {!loadingAlertData && !isEmpty(ruleId) && (
- {ruleName}
+ {ruleName ?? i18n.UNKNOWN_RULE}
)}
- {!loadingAlertData && ruleId === '' && {ruleName}}
+ {!loadingAlertData && isEmpty(ruleId) && i18n.UNKNOWN_RULE}
>
) : (
<>