[SECURITY SOLUTION] BUG Manual Alert in case (#93726)
* get the data where it belongs * Fix layout when alert is deleted Co-authored-by: Christos Nasikas <christos.nasikas@elastic.co>
This commit is contained in:
parent
5e634e9931
commit
5d96e5f334
|
@ -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: (
|
||||
|
|
|
@ -379,11 +379,10 @@ export const UserActionTree = React.memo(
|
|||
return comments;
|
||||
}
|
||||
|
||||
const ruleId = comment?.rule?.id ?? manualAlertsData[alertId]?.rule?.id?.[0] ?? '';
|
||||
const ruleId =
|
||||
comment?.rule?.id ?? manualAlertsData[alertId]?.signal?.rule?.id?.[0] ?? null;
|
||||
const ruleName =
|
||||
comment?.rule?.name ??
|
||||
manualAlertsData[alertId]?.rule?.name?.[0] ??
|
||||
i18n.UNKNOWN_RULE;
|
||||
comment?.rule?.name ?? manualAlertsData[alertId]?.signal?.rule?.name?.[0] ?? null;
|
||||
|
||||
return [
|
||||
...comments,
|
||||
|
|
|
@ -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(
|
||||
<TestProviders>
|
||||
{/* @ts-expect-error */}
|
||||
<AlertCommentEvent alert={undefined} commentType={CommentType.alert} />
|
||||
<AlertCommentEvent {...props} ruleId={null} />
|
||||
</TestProviders>
|
||||
);
|
||||
|
||||
|
@ -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(
|
||||
<TestProviders>
|
||||
{/* @ts-expect-error*/}
|
||||
<AlertCommentEvent alert={alert} />
|
||||
</TestProviders>
|
||||
);
|
||||
|
||||
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 () => {
|
||||
|
|
|
@ -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<Props> = ({
|
|||
<>
|
||||
{`${i18n.ALERT_COMMENT_LABEL_TITLE} `}
|
||||
{loadingAlertData && <EuiLoadingSpinner size="m" />}
|
||||
{!loadingAlertData && ruleId !== '' && (
|
||||
{!loadingAlertData && !isEmpty(ruleId) && (
|
||||
<LinkAnchor
|
||||
onClick={onLinkClick}
|
||||
href={formatUrl(getRuleDetailsUrl(ruleId ?? '', urlSearch))}
|
||||
data-test-subj={`alert-rule-link-${alertId ?? 'deleted'}`}
|
||||
>
|
||||
{ruleName}
|
||||
{ruleName ?? i18n.UNKNOWN_RULE}
|
||||
</LinkAnchor>
|
||||
)}
|
||||
{!loadingAlertData && ruleId === '' && <EuiText>{ruleName}</EuiText>}
|
||||
{!loadingAlertData && isEmpty(ruleId) && i18n.UNKNOWN_RULE}
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
|
|
Loading…
Reference in a new issue