From e504f7e3c6c8f301a351b113f7728fc69f1f3580 Mon Sep 17 00:00:00 2001 From: xusongfu Date: Wed, 7 Jul 2021 15:41:34 +0800 Subject: [PATCH] fix: Fix the prompts in batch deletion When batch deletion error, the error message will pop up according to the queue Change-Id: I3b3cf4b2a76aad13ebe79fc1a02d036ed163b9c4 --- .../Tables/Base/ActionButton/index.jsx | 55 ++++++++----------- src/containers/Action/ConfirmAction/index.jsx | 13 ----- 2 files changed, 23 insertions(+), 45 deletions(-) diff --git a/src/components/Tables/Base/ActionButton/index.jsx b/src/components/Tables/Base/ActionButton/index.jsx index 1c8b8c51..fe5a75d9 100644 --- a/src/components/Tables/Base/ActionButton/index.jsx +++ b/src/components/Tables/Base/ActionButton/index.jsx @@ -30,10 +30,6 @@ function getDefaultMsg(action, data) { action: actionName.toLowerCase() || title, name, }); - const submitErrorMsgBatch = t('Unable to batch {action} {name}.', { - action: actionName.toLowerCase() || title, - name, - }); const performErrorMsg = t('You are not allowed to { action } {name}.', { action: actionName.toLowerCase() || title, name, @@ -50,7 +46,6 @@ function getDefaultMsg(action, data) { }); return { submitErrorMsg, - submitErrorMsgBatch, submitSuccessMsg, confirmContext, performErrorMsg, @@ -236,18 +231,6 @@ class ActionButton extends Component { } }; - // eslint-disable-next-line no-unused-vars - onShowErrorBatch = (data, error) => { - // this.handleModalVisible(); - const { submitErrorMsgBatch } = this.props.action; - const message = submitErrorMsgBatch - ? submitErrorMsgBatch(data) - : getDefaultMsg(this.props.action, data).submitErrorMsgBatch; - const { data: responseData } = error.response || error || {}; - Notify.errorWithDetail(responseData || error, message); - this.onCallback(false, true); - }; - // eslint-disable-next-line no-unused-vars onShowError = (data, error) => { // this.handleModalVisible(); @@ -340,23 +323,31 @@ class ActionButton extends Component { const promises = data.map((it, index) => onSubmit(it, containerProps, isBatch, index, data) ); - const results = Promise.all(promises); - // TODO: add catch to do with part error - results.then( - () => { + const results = Promise.allSettled(promises); + results.then((res) => { + const failedDatas = res + .map((it, idx) => { + if (it.status === 'rejected') { + return { + data: data[idx], + reason: it.reason, + }; + } + return null; + }) + .filter((it) => !!it); + if (failedDatas.length === 0) { this.onShowSuccess(data); - resolve(); - }, - (error) => { - reject(error); + return resolve(); } - ); - }).catch((error) => { - if (data.length === 1) { - this.onShowError(data[0], error); - } else { - this.onShowErrorBatch(data, error); - } + failedDatas.forEach((it) => { + this.onShowError(it.data, it.reason); + }); + if (failedDatas.length === data.length) { + return reject(); + } + return resolve(); + }); }); onConfirmOK = (data, onSubmit, isBatch, containerProps) => { diff --git a/src/containers/Action/ConfirmAction/index.jsx b/src/containers/Action/ConfirmAction/index.jsx index 79c5d823..374ff6df 100644 --- a/src/containers/Action/ConfirmAction/index.jsx +++ b/src/containers/Action/ConfirmAction/index.jsx @@ -180,19 +180,6 @@ export default class ConfirmAction { }); }; - submitErrorMsgBatch = (data) => { - if (!this.messageHasItemName) { - return t('Unable to {action}.', { - action: this.actionNameDisplay || this.title, - }); - } - const name = this.getName(data); - return t('Unable to batch {action}, instance: {name}.', { - action: this.actionNameDisplay || this.title, - name, - }); - }; - // eslint-disable-next-line no-unused-vars onSubmit = (data) => Promise.resolve();