[Detection Engine] Update toast message for adding exception (#191032)

## Summary

Addresses https://github.com/elastic/kibana/issues/156246

Updates exception toast message to accurately reflect when it's an
endpoint exception.
This commit is contained in:
Yara Tercero 2024-08-26 14:21:15 -07:00 committed by GitHub
parent d1cc0cb93c
commit cbc8f17388
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 49 additions and 14 deletions

View file

@ -10,7 +10,12 @@ import { getExceptionListSchemaMock } from '@kbn/lists-plugin/common/schemas/res
import { ExceptionListTypeEnum } from '@kbn/securitysolution-io-ts-list-types';
import { getRulesSchemaMock } from '../../../../../common/api/detection_engine/model/rule_schema/rule_response_schema.mock';
import { isSubmitDisabled, prepareNewItemsForSubmission, prepareToCloseAlerts } from './helpers';
import {
isSubmitDisabled,
prepareNewItemsForSubmission,
prepareToCloseAlerts,
getSuccessToastTitle,
} from './helpers';
import type { Rule } from '../../../rule_management/logic/types';
import type { AlertData } from '../../utils/types';
@ -469,4 +474,18 @@ describe('add_exception_flyout#helpers', () => {
expect(ruleStaticIds).toEqual(['query-rule-id']);
});
});
describe('getSuccessToastTitle', () => {
it('returns endpoint title when list type is "endpoint"', () => {
expect(getSuccessToastTitle(ExceptionListTypeEnum.ENDPOINT)).toEqual(
'Endpoint exception added to shared exception list'
);
});
it('returns non endpoint title when list type is not "endpoint"', () => {
expect(getSuccessToastTitle(ExceptionListTypeEnum.DETECTION)).toEqual(
'Rule exception added to shared exception list'
);
});
});
});

View file

@ -14,6 +14,7 @@ import type { ExceptionsBuilderReturnExceptionItem } from '@kbn/securitysolution
import type { Rule } from '../../../rule_management/logic/types';
import { enrichNewExceptionItems } from '../flyout_components/utils';
import type { AlertData } from '../../utils/types';
import * as i18n from './translations';
const RULE_DEFAULT_OPTIONS = ['add_to_rule', 'add_to_rules', 'select_rules_to_add_to'];
@ -183,3 +184,14 @@ export const prepareToCloseAlerts = ({
ruleStaticIds,
};
};
export const getSuccessToastTitle = (listType: ExceptionListTypeEnum) =>
listType === ExceptionListTypeEnum.ENDPOINT
? i18n.ADD_ENDPOINT_EXCEPTION_SUCCESS
: i18n.ADD_EXCEPTION_SUCCESS;
export const getSuccessToastText = (listType: ExceptionListTypeEnum, sharedListNames: string[]) =>
i18n.ADD_EXCEPTION_SUCCESS_DETAILS(
listType === ExceptionListTypeEnum.ENDPOINT ? 'Endpoint' : 'Rule',
sharedListNames.join(',')
);

View file

@ -53,14 +53,18 @@ export const ADD_EXCEPTION_SUCCESS = i18n.translate(
}
);
export const ADD_EXCEPTION_SUCCESS_DETAILS = (listNames: string) =>
i18n.translate(
'xpack.securitySolution.ruleExceptions.addExceptionFlyout.closeAlerts.successDetails',
{
values: { listNames },
defaultMessage: 'Rule exception has been added to shared lists: {listNames}.',
}
);
export const ADD_ENDPOINT_EXCEPTION_SUCCESS = i18n.translate(
'xpack.securitySolution.ruleExceptions.addEndpointException.success',
{
defaultMessage: 'Endpoint exception added to shared exception list',
}
);
export const ADD_EXCEPTION_SUCCESS_DETAILS = (listType: string, listNames: string) =>
i18n.translate('xpack.securitySolution.ruleExceptions.addExceptionFlyout.successDetails', {
values: { listNames, listType },
defaultMessage: '{listType} exception has been added to shared lists: {listNames}.',
});
export const ADD_RULE_EXCEPTION_SUCCESS_TITLE = i18n.translate(
'xpack.securitySolution.ruleExceptions.addExceptionFlyout.addRuleExceptionToastSuccessTitle',

View file

@ -25,6 +25,7 @@ import { useAppToasts } from '../../../../common/hooks/use_app_toasts';
import type { Rule } from '../../../rule_management/logic/types';
import { useCreateOrUpdateException } from '../../logic/use_create_update_exception';
import { useAddRuleDefaultException } from '../../logic/use_add_rule_exception';
import { getSuccessToastText, getSuccessToastTitle } from './helpers';
export interface AddNewExceptionItemHookProps {
itemsToAdd: ExceptionsBuilderReturnExceptionItem[];
@ -110,10 +111,12 @@ export const useAddNewExceptionItems = (): ReturnUseAddNewExceptionItems => {
result = await addSharedExceptions(itemsToAdd);
const sharedListNames = sharedLists.map(({ name }) => name);
const title = getSuccessToastTitle(listType);
const text = getSuccessToastText(listType, sharedListNames);
addSuccess({
title: i18n.ADD_EXCEPTION_SUCCESS,
text: i18n.ADD_EXCEPTION_SUCCESS_DETAILS(sharedListNames.join(',')),
title,
text,
});
}

View file

@ -40635,7 +40635,6 @@
"xpack.securitySolution.ruleExceptions.addExceptionFlyout.addRuleExceptionFromAlertComment": "Les conditions d'exceptions sont préremplies avec les données pertinentes d'une alerte possédant l'identifiant d'alerte (_id) : {alertId}.",
"xpack.securitySolution.ruleExceptions.addExceptionFlyout.addRuleExceptionToastSuccessText": "L'exception a été ajoutée aux règles - {ruleName}.",
"xpack.securitySolution.ruleExceptions.addExceptionFlyout.addRuleExceptionToastSuccessTitle": "Exception à la règle ajoutée",
"xpack.securitySolution.ruleExceptions.addExceptionFlyout.closeAlerts.successDetails": "L'exception de la règle a été ajoutée aux listes partagées : {listNames}.",
"xpack.securitySolution.ruleExceptions.addExceptionFlyout.commentsTitle": "Ajouter des commentaires ({comments})",
"xpack.securitySolution.ruleExceptions.allExceptionItems.activeDetectionsLabel": "Exceptions actives",
"xpack.securitySolution.ruleExceptions.allExceptionItems.addExceptionsEmptyPromptTitle": "Ajouter des exceptions à cette règle",

View file

@ -40618,7 +40618,6 @@
"xpack.securitySolution.ruleExceptions.addExceptionFlyout.addRuleExceptionFromAlertComment": "例外条件は、アラートID(_id)のアラートからの関連データがあらかじめ入力されます:{alertId}。",
"xpack.securitySolution.ruleExceptions.addExceptionFlyout.addRuleExceptionToastSuccessText": "例外がルール - {ruleName}に追加されました。",
"xpack.securitySolution.ruleExceptions.addExceptionFlyout.addRuleExceptionToastSuccessTitle": "ルール例外が追加されました",
"xpack.securitySolution.ruleExceptions.addExceptionFlyout.closeAlerts.successDetails": "ルール例外が共有リストに追加されました:{listNames}。",
"xpack.securitySolution.ruleExceptions.addExceptionFlyout.commentsTitle": "コメントの追加({comments}",
"xpack.securitySolution.ruleExceptions.allExceptionItems.activeDetectionsLabel": "アクティブな例外",
"xpack.securitySolution.ruleExceptions.allExceptionItems.addExceptionsEmptyPromptTitle": "このルールに例外を追加",

View file

@ -40661,7 +40661,6 @@
"xpack.securitySolution.ruleExceptions.addExceptionFlyout.addRuleExceptionFromAlertComment": "将使用具有告警 ID (_id) 的告警中的相关数据预填充例外条件:{alertId}。",
"xpack.securitySolution.ruleExceptions.addExceptionFlyout.addRuleExceptionToastSuccessText": "例外已添加到规则 - {ruleName}。",
"xpack.securitySolution.ruleExceptions.addExceptionFlyout.addRuleExceptionToastSuccessTitle": "已添加规则例外",
"xpack.securitySolution.ruleExceptions.addExceptionFlyout.closeAlerts.successDetails": "规则例外已添加到共享列表:{listNames}。",
"xpack.securitySolution.ruleExceptions.addExceptionFlyout.commentsTitle": "添加注释 ({comments})",
"xpack.securitySolution.ruleExceptions.allExceptionItems.activeDetectionsLabel": "活动例外",
"xpack.securitySolution.ruleExceptions.allExceptionItems.addExceptionsEmptyPromptTitle": "将例外添加到此规则",