Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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'
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down Expand Up @@ -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(',')
);
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down Expand Up @@ -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,
});
}

Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "このルールに例外を追加",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "将例外添加到此规则",
Expand Down