fix: Fix the prompts in batch deletion

When batch deletion error, the error message will pop up according to the queue

Change-Id: I3b3cf4b2a76aad13ebe79fc1a02d036ed163b9c4
This commit is contained in:
xusongfu 2021-07-07 15:41:34 +08:00
parent caf0429302
commit e504f7e3c6
2 changed files with 23 additions and 45 deletions

View File

@ -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) => {

View File

@ -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();