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, action: actionName.toLowerCase() || title,
name, name,
}); });
const submitErrorMsgBatch = t('Unable to batch {action} {name}.', {
action: actionName.toLowerCase() || title,
name,
});
const performErrorMsg = t('You are not allowed to { action } {name}.', { const performErrorMsg = t('You are not allowed to { action } {name}.', {
action: actionName.toLowerCase() || title, action: actionName.toLowerCase() || title,
name, name,
@ -50,7 +46,6 @@ function getDefaultMsg(action, data) {
}); });
return { return {
submitErrorMsg, submitErrorMsg,
submitErrorMsgBatch,
submitSuccessMsg, submitSuccessMsg,
confirmContext, confirmContext,
performErrorMsg, 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 // eslint-disable-next-line no-unused-vars
onShowError = (data, error) => { onShowError = (data, error) => {
// this.handleModalVisible(); // this.handleModalVisible();
@ -340,23 +323,31 @@ class ActionButton extends Component {
const promises = data.map((it, index) => const promises = data.map((it, index) =>
onSubmit(it, containerProps, isBatch, index, data) onSubmit(it, containerProps, isBatch, index, data)
); );
const results = Promise.all(promises); const results = Promise.allSettled(promises);
// TODO: add catch to do with part error results.then((res) => {
results.then( 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); this.onShowSuccess(data);
resolve(); return resolve();
},
(error) => {
reject(error);
} }
); failedDatas.forEach((it) => {
}).catch((error) => { this.onShowError(it.data, it.reason);
if (data.length === 1) { });
this.onShowError(data[0], error); if (failedDatas.length === data.length) {
} else { return reject();
this.onShowErrorBatch(data, error);
} }
return resolve();
});
}); });
onConfirmOK = (data, onSubmit, isBatch, containerProps) => { 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 // eslint-disable-next-line no-unused-vars
onSubmit = (data) => Promise.resolve(); onSubmit = (data) => Promise.resolve();