Skip to content

Commit

Permalink
addreses feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
yctercero committed Jan 5, 2021
1 parent fd7a475 commit 0140553
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React from 'react';
import { EuiButtonIcon, EuiBasicTableColumn, EuiToolTip } from '@elastic/eui';
import { History } from 'history';

import { Spacer } from '../../../../../../common/components/page';
import { NamespaceType } from '../../../../../../../../lists/common';
import { FormatUrl } from '../../../../../../common/components/link_to';
import { LinkAnchor } from '../../../../../../common/components/links';
Expand All @@ -17,15 +18,10 @@ import { ExceptionListInfo } from './use_all_exception_lists';
import { getRuleDetailsUrl } from '../../../../../../common/components/link_to/redirect_to_detection_engine';

export type AllExceptionListsColumns = EuiBasicTableColumn<ExceptionListInfo>;
export type Func = (arg: {
id: string;
listId: string;
namespaceType: NamespaceType;
}) => () => void;

export const getAllExceptionListsColumns = (
onExport: Func,
onDelete: Func,
onExport: (arg: { id: string; listId: string; namespaceType: NamespaceType }) => () => void,
onDelete: (arg: { id: string; namespaceType: NamespaceType }) => () => void,
history: History,
formatUrl: FormatUrl
): AllExceptionListsColumns[] => [
Expand Down Expand Up @@ -64,8 +60,9 @@ export const getAllExceptionListsColumns = (
return (
<>
{value.map(({ id, name }, index) => (
<>
<Spacer key={id}>
<LinkAnchor
key={id}
data-test-subj="ruleName"
onClick={(ev: { preventDefault: () => void }) => {
ev.preventDefault();
Expand All @@ -76,7 +73,7 @@ export const getAllExceptionListsColumns = (
{name}
</LinkAnchor>
{index !== value.length - 1 ? ', ' : ''}
</>
</Spacer>
))}
</>
);
Expand Down Expand Up @@ -117,14 +114,10 @@ export const getAllExceptionListsColumns = (
align: 'center',
width: '25px',
isExpander: false,
render: ({ id, list_id: listId, namespace_type: namespaceType }: ExceptionListInfo) => (
render: ({ id, namespace_type: namespaceType }: ExceptionListInfo) => (
<EuiButtonIcon
color="danger"
onClick={onDelete({
id,
listId,
namespaceType,
})}
onClick={onDelete({ id, namespaceType })}
aria-label="Delete exception list"
iconType="trash"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,26 +102,23 @@ export const ExceptionListsTable = React.memo<ExceptionListsTableProps>(
const [exportDownload, setExportDownload] = useState<{ name?: string; blob?: Blob }>({});

const handleDeleteSuccess = useCallback(() => {
notifications.toasts.addSuccess({ title: i18n.EXCEPTION_DELETE_SUCCESS });
}, [notifications.toasts]);
notifications.toasts.addSuccess({
title: i18n.exceptionDeleteSuccessMessage(referenceModalState.listId),
});
}, [notifications.toasts, referenceModalState]);

const handleDeleteError = useCallback(
(err: Error) => {
notifications.toasts.addError(err, { title: i18n.EXCEPTION_DELETE_ERROR });
(err: Error & { body?: { message: string } }): void => {
notifications.toasts.addError(err, {
title: i18n.EXCEPTION_DELETE_ERROR,
toastMessage: err.body != null ? err.body.message : err.message,
});
},
[notifications.toasts]
);

const handleDelete = useCallback(
({
id,
listId,
namespaceType,
}: {
id: string;
listId: string;
namespaceType: NamespaceType;
}) => async () => {
({ id, namespaceType }: { id: string; namespaceType: NamespaceType }) => async () => {
try {
setDeletingListIds((ids) => [...ids, id]);
if (refreshExceptions != null) {
Expand Down Expand Up @@ -291,7 +288,7 @@ export const ExceptionListsTable = React.memo<ExceptionListsTableProps>(
onSuccess: handleDeleteSuccess,
});
} catch (err) {
notifications.toasts.addError(err, { title: i18n.EXCEPTION_DELETE_ERROR });
handleDeleteError(err);
} finally {
setReferenceModalState(exceptionReferenceModalInitialState);
setDeletingListIds([]);
Expand All @@ -307,7 +304,6 @@ export const ExceptionListsTable = React.memo<ExceptionListsTableProps>(
deleteExceptionList,
handleDeleteError,
handleDeleteSuccess,
notifications.toasts,
refreshExceptions,
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,11 @@ export const EXCEPTION_DELETE_ERROR = i18n.translate(
}
);

export const EXCEPTION_DELETE_SUCCESS = i18n.translate(
'xpack.securitySolution.detectionEngine.rules.all.exceptions.deleteSuccess',
{
defaultMessage: 'Exception list deleted successfully',
}
);
export const exceptionDeleteSuccessMessage = (listId: string) =>
i18n.translate('xpack.securitySolution.exceptions.referenceModalDescription', {
defaultMessage: 'Exception list - {listId} - deleted successfully.',
values: { listId },
});

export const REFERENCE_MODAL_TITLE = i18n.translate(
'xpack.securitySolution.exceptions.referenceModalTitle',
Expand All @@ -121,13 +120,13 @@ export const REFERENCE_MODAL_CANCEL_BUTTON = i18n.translate(
export const REFERENCE_MODAL_CONFIRM_BUTTON = i18n.translate(
'xpack.securitySolution.exceptions.referenceModalDeleteButton',
{
defaultMessage: 'Remove exceptions list',
defaultMessage: 'Remove exception list',
}
);

export const referenceErrorMessage = (referenceCount: number) =>
i18n.translate('xpack.securitySolution.exceptions.referenceModalDescription', {
defaultMessage:
'This exceptions list is associated with ({referenceCount}) {referenceCount, plural, =1 {rule} other {rules}}. Removing this exception list will also remove its reference from the associated rules.',
'This exception list is associated with ({referenceCount}) {referenceCount, plural, =1 {rule} other {rules}}. Removing this exception list will also remove its reference from the associated rules.',
values: { referenceCount },
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"query": "host.name: *",
"interval": "30s",
"exceptions_list": [
{ "id": "cfb47060-4edd-11eb-865c-8bc292d0513c", "list_id": "detection_list_1", "namespace_type": "single", "type": "detection" },
{ "id": "7b4e8f40-4f0c-11eb-865c-8bc292d0513c", "list_id": "detection_list_1", "namespace_type": "single", "type": "detection" },
{ "id": "e8ac0a60-4edd-11eb-865c-8bc292d0513c", "list_id": "detection_list_3", "namespace_type": "single", "type": "detection" }
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"type": "query",
"query": "host.name: *",
"interval": "30s",
"exceptions_list": [{ "id": "cfb47060-4edd-11eb-865c-8bc292d0513c", "list_id": "detection_list_1", "namespace_type": "single", "type": "detection" }]
"exceptions_list": [{ "id": "7b4e8f40-4f0c-11eb-865c-8bc292d0513c", "list_id": "detection_list_1", "namespace_type": "single", "type": "detection" }]
}

0 comments on commit 0140553

Please sign in to comment.