Skip to content

Commit

Permalink
Fixed due to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
YulNaumenko committed Mar 20, 2020
1 parent d22aea5 commit 699dd87
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import { useAppDependencies } from '../app_context';
export const DeleteModalConfirmation = ({
idsToDelete,
apiDeleteCall,
callback,
onDeleted,
onCancel,
singleTitle,
multiplyTitle,
multipleTitle,
}: {
idsToDelete: string[];
apiDeleteCall: ({
Expand All @@ -24,9 +25,10 @@ export const DeleteModalConfirmation = ({
ids: string[];
http: HttpSetup;
}) => Promise<{ successes: string[]; errors: string[] }>;
callback: (deleted?: string[]) => void;
onDeleted: (deleted: string[]) => void;
onCancel: () => void;
singleTitle: string;
multiplyTitle: string;
multipleTitle: string;
}) => {
const { http, toastNotifications } = useAppDependencies();
const numIdsToDelete = idsToDelete.length;
Expand All @@ -37,16 +39,16 @@ export const DeleteModalConfirmation = ({
'xpack.triggersActionsUI.deleteSelectedIdsConfirmModal.descriptionText',
{
defaultMessage:
"You can't recover {numIdsToDelete, plural, one {a deleted {singleTitle}} other {deleted {multiplyTitle}}}.",
values: { numIdsToDelete, singleTitle, multiplyTitle },
"You can't recover {numIdsToDelete, plural, one {a deleted {singleTitle}} other {deleted {multipleTitle}}}.",
values: { numIdsToDelete, singleTitle, multipleTitle },
}
);
const confirmButtonText = i18n.translate(
'xpack.triggersActionsUI.deleteSelectedIdsConfirmModal.deleteButtonLabel',
{
defaultMessage:
'Delete {numIdsToDelete, plural, one {{singleTitle}} other {# {multiplyTitle}}} ',
values: { numIdsToDelete, singleTitle, multiplyTitle },
'Delete {numIdsToDelete, plural, one {{singleTitle}} other {# {multipleTitle}}} ',
values: { numIdsToDelete, singleTitle, multipleTitle },
}
);
const cancelButtonText = i18n.translate(
Expand All @@ -61,20 +63,20 @@ export const DeleteModalConfirmation = ({
buttonColor="danger"
data-test-subj="deleteIdsConfirmation"
title={confirmButtonText}
onCancel={() => callback()}
onCancel={() => onCancel()}
onConfirm={async () => {
const { successes, errors } = await apiDeleteCall({ ids: idsToDelete, http });
const numSuccesses = successes.length;
const numErrors = errors.length;
callback(successes);
onDeleted(successes);
if (numSuccesses > 0) {
toastNotifications.addSuccess(
i18n.translate(
'xpack.triggersActionsUI.components.deleteSelectedIdsSuccessNotification.descriptionText',
{
defaultMessage:
'Deleted {numSuccesses, number} {numSuccesses, plural, one {{singleTitle}} other {{multiplyTitle}}}',
values: { numSuccesses, singleTitle, multiplyTitle },
'Deleted {numSuccesses, number} {numSuccesses, plural, one {{singleTitle}} other {{multipleTitle}}}',
values: { numSuccesses, singleTitle, multipleTitle },
}
)
);
Expand All @@ -86,8 +88,8 @@ export const DeleteModalConfirmation = ({
'xpack.triggersActionsUI.components.deleteSelectedIdsErrorNotification.descriptionText',
{
defaultMessage:
'Failed to delete {numErrors, number} {numErrors, plural, one {{singleTitle}} other {{multiplyTitle}}}',
values: { numErrors, singleTitle, multiplyTitle },
'Failed to delete {numErrors, number} {numErrors, plural, one {{singleTitle}} other {{multipleTitle}}}',
values: { numErrors, singleTitle, multipleTitle },
}
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,31 +379,37 @@ export const ActionsConnectorsList: React.FunctionComponent = () => {
return (
<section data-test-subj="actionsList">
<DeleteModalConfirmation
callback={async (deleted?: string[]) => {
if (deleted) {
if (selectedItems.length === 0 || selectedItems.length === deleted.length) {
const updatedActions = actions.filter(
action => action.id && !connectorsToDelete.includes(action.id)
);
setActions(updatedActions);
setSelectedItems([]);
} else {
toastNotifications.addDanger({
title: i18n.translate(
'xpack.triggersActionsUI.sections.actionsConnectorsList.failedToDeleteActionsMessage',
{ defaultMessage: 'Failed to delete action(s)' }
),
});
// Refresh the actions from the server, some actions may have beend deleted
await loadActions();
}
onDeleted={(deleted: string[]) => {
if (selectedItems.length === 0 || selectedItems.length === deleted.length) {
const updatedActions = actions.filter(
action => action.id && !connectorsToDelete.includes(action.id)
);
setActions(updatedActions);
setSelectedItems([]);
}
setConnectorsToDelete([]);
}}
onCancel={async () => {
toastNotifications.addDanger({
title: i18n.translate(
'xpack.triggersActionsUI.sections.actionsConnectorsList.failedToDeleteActionsMessage',
{ defaultMessage: 'Failed to delete action(s)' }
),
});
// Refresh the actions from the server, some actions may have beend deleted
await loadActions();
setConnectorsToDelete([]);
}}
apiDeleteCall={deleteActions}
idsToDelete={connectorsToDelete}
singleTitle={'connector'}
multiplyTitle={'connectors'}
singleTitle={i18n.translate(
'xpack.triggersActionsUI.sections.actionsConnectorsList.singleTitle',
{ defaultMessage: 'connector' }
)}
multipleTitle={i18n.translate(
'xpack.triggersActionsUI.sections.actionsConnectorsList.multipleTitle',
{ defaultMessage: 'connectors' }
)}
/>
<EuiSpacer size="m" />
{/* Render the view based on if there's data or if they can save */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,35 +431,38 @@ export const AlertsList: React.FunctionComponent = () => {
return (
<section data-test-subj="alertsList">
<DeleteModalConfirmation
callback={(deleted?: string[]) => {
if (deleted) {
if (selectedIds.length === 0 || selectedIds.length === deleted.length) {
const updatedAlerts = alertsState.data.filter(
alert => alert.id && !alertsToDelete.includes(alert.id)
);
setAlertsState({
isLoading: false,
data: updatedAlerts,
totalItemCount: alertsState.totalItemCount - deleted.length,
});
setSelectedIds([]);
} else {
toastNotifications.addDanger({
title: i18n.translate(
'xpack.triggersActionsUI.sections.alertsList.failedToDeleteAlertsMessage',
{ defaultMessage: 'Failed to delete alert(s)' }
),
});
// Refresh the alerts from the server, some alerts may have beend deleted
loadAlertsData();
}
onDeleted={(deleted: string[]) => {
if (selectedIds.length === 0 || selectedIds.length === deleted.length) {
const updatedAlerts = alertsState.data.filter(
alert => alert.id && !alertsToDelete.includes(alert.id)
);
setAlertsState({
isLoading: false,
data: updatedAlerts,
totalItemCount: alertsState.totalItemCount - deleted.length,
});
setSelectedIds([]);
}
setAlertsToDelete([]);
}}
onCancel={async () => {
toastNotifications.addDanger({
title: i18n.translate(
'xpack.triggersActionsUI.sections.alertsList.failedToDeleteAlertsMessage',
{ defaultMessage: 'Failed to delete alert(s)' }
),
});
// Refresh the alerts from the server, some alerts may have beend deleted
await loadAlertsData();
}}
apiDeleteCall={deleteAlerts}
idsToDelete={alertsToDelete}
singleTitle={'alert'}
multiplyTitle={'alerts'}
singleTitle={i18n.translate('xpack.triggersActionsUI.sections.alertsList.singleTitle', {
defaultMessage: 'alert',
})}
multipleTitle={i18n.translate('xpack.triggersActionsUI.sections.alertsList.multipleTitle', {
defaultMessage: 'alerts',
})}
/>
<EuiSpacer size="m" />
{loadedItems.length || isFilterApplied ? (
Expand Down

0 comments on commit 699dd87

Please sign in to comment.