From 699dd87967e17c4e54b7c3a2e0d986697f067ece Mon Sep 17 00:00:00 2001 From: Yuliia Naumenko Date: Fri, 20 Mar 2020 14:18:57 -0700 Subject: [PATCH] Fixed due to comments --- .../components/delete_modal_confirmation.tsx | 30 ++++++----- .../components/actions_connectors_list.tsx | 46 +++++++++-------- .../alerts_list/components/alerts_list.tsx | 51 ++++++++++--------- 3 files changed, 69 insertions(+), 58 deletions(-) diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/delete_modal_confirmation.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/delete_modal_confirmation.tsx index f77e8d4cc020a..80b59e15644ec 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/delete_modal_confirmation.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/delete_modal_confirmation.tsx @@ -12,9 +12,10 @@ import { useAppDependencies } from '../app_context'; export const DeleteModalConfirmation = ({ idsToDelete, apiDeleteCall, - callback, + onDeleted, + onCancel, singleTitle, - multiplyTitle, + multipleTitle, }: { idsToDelete: string[]; apiDeleteCall: ({ @@ -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; @@ -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( @@ -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 }, } ) ); @@ -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 }, } ) ); diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/actions_connectors_list/components/actions_connectors_list.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/actions_connectors_list/components/actions_connectors_list.tsx index 7bd31e84300dc..8c2565538f718 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/actions_connectors_list/components/actions_connectors_list.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/actions_connectors_list/components/actions_connectors_list.tsx @@ -379,31 +379,37 @@ export const ActionsConnectorsList: React.FunctionComponent = () => { return (
{ - 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' } + )} /> {/* Render the view based on if there's data or if they can save */} diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_list/components/alerts_list.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_list/components/alerts_list.tsx index f95166514cf37..84e4d5794859c 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_list/components/alerts_list.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_list/components/alerts_list.tsx @@ -431,35 +431,38 @@ export const AlertsList: React.FunctionComponent = () => { return (
{ - 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', + })} /> {loadedItems.length || isFilterApplied ? (