fix: Fix callback after action submit

Fix callback after action submit

Change-Id: I6b63e3219402e9ac0008145fddff7f417fc7b6df
This commit is contained in:
zhangjingwei 2021-07-16 21:04:50 +08:00 committed by Jingwei.Zhang
parent 1ab6cf9b34
commit af6446ceb2
3 changed files with 37 additions and 18 deletions

View File

@ -211,22 +211,22 @@ class ActionButton extends Component {
}); });
}; };
onShowSuccess = (data) => { onShowSuccess = (data, afterSubmit) => {
const { submitSuccessMsg } = this.props.action; const { submitSuccessMsg } = this.props.action;
const message = submitSuccessMsg const message = submitSuccessMsg
? submitSuccessMsg(data) ? submitSuccessMsg(data)
: getDefaultMsg(this.props.action, data).submitSuccessMsg; : getDefaultMsg(this.props.action, data).submitSuccessMsg;
Notify.success(message); Notify.success(message);
this.onCallback(true, false); this.onCallback(true, false, afterSubmit);
}; };
// eslint-disable-next-line no-shadow // eslint-disable-next-line no-shadow
onCallback = (success, fail) => { onCallback = (success, fail, afterSubmit) => {
const { onFinishAction, id } = this.props; const { onFinishAction, id } = this.props;
if (onFinishAction) { if (onFinishAction) {
const isDelete = id === 'delete'; const isDelete = id === 'delete';
setTimeout(() => { setTimeout(() => {
onFinishAction(success, fail, isDelete); onFinishAction(success, fail, isDelete, afterSubmit);
}, 500); }, 500);
} }
}; };
@ -254,8 +254,15 @@ class ActionButton extends Component {
}; };
onShowConfirm = async () => { onShowConfirm = async () => {
const { perform, title, confirmContext, okText, cancelText, onSubmit } = const {
this.props.action; perform,
title,
confirmContext,
okText,
cancelText,
onSubmit,
afterSubmit,
} = this.props.action;
const { item, items, isBatch, containerProps, onCancelAction } = this.props; const { item, items, isBatch, containerProps, onCancelAction } = this.props;
const data = isBatch ? items : item; const data = isBatch ? items : item;
const content = confirmContext const content = confirmContext
@ -270,7 +277,13 @@ class ActionButton extends Component {
okText, okText,
cancelText, cancelText,
onOk: () => onOk: () =>
this.onConfirmOK(data, onSubmit, isBatch, containerProps), this.onConfirmOK(
data,
onSubmit,
isBatch,
containerProps,
afterSubmit
),
onCancel: () => { onCancel: () => {
onCancelAction && onCancelAction(); onCancelAction && onCancelAction();
}, },
@ -295,13 +308,13 @@ class ActionButton extends Component {
} }
}; };
onSubmitOne = (data, onSubmit, containerProps) => onSubmitOne = (data, onSubmit, containerProps, afterSubmit) =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
const result = onSubmit(data, containerProps); const result = onSubmit(data, containerProps);
if (result instanceof Promise) { if (result instanceof Promise) {
result.then( result.then(
() => { () => {
this.onShowSuccess(data); this.onShowSuccess(data, afterSubmit);
resolve(); resolve();
}, },
(error) => { (error) => {
@ -309,7 +322,7 @@ class ActionButton extends Component {
} }
); );
} else if (result) { } else if (result) {
this.onShowSuccess(data); this.onShowSuccess(data, afterSubmit);
resolve(); resolve();
} else { } else {
reject(result); reject(result);
@ -318,7 +331,7 @@ class ActionButton extends Component {
this.onShowError(data, error); this.onShowError(data, error);
}); });
onSubmitBatch = (data, onSubmit, containerProps, isBatch) => onSubmitBatch = (data, onSubmit, containerProps, isBatch, afterSubmit) =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
const promises = data.map((it, index) => const promises = data.map((it, index) =>
onSubmit(it, containerProps, isBatch, index, data) onSubmit(it, containerProps, isBatch, index, data)
@ -337,7 +350,7 @@ class ActionButton extends Component {
}) })
.filter((it) => !!it); .filter((it) => !!it);
if (failedDatas.length === 0) { if (failedDatas.length === 0) {
this.onShowSuccess(data); this.onShowSuccess(data, afterSubmit);
return resolve(); return resolve();
} }
failedDatas.forEach((it) => { failedDatas.forEach((it) => {
@ -350,11 +363,17 @@ class ActionButton extends Component {
}); });
}); });
onConfirmOK = (data, onSubmit, isBatch, containerProps) => { onConfirmOK = (data, onSubmit, isBatch, containerProps, afterSubmit) => {
if (isBatch) { if (isBatch) {
return this.onSubmitBatch(data, onSubmit, containerProps, isBatch); return this.onSubmitBatch(
data,
onSubmit,
containerProps,
isBatch,
afterSubmit
);
} }
return this.onSubmitOne(data, onSubmit, containerProps); return this.onSubmitOne(data, onSubmit, containerProps, afterSubmit);
}; };
onClickModalActionOk = () => { onClickModalActionOk = () => {

View File

@ -131,7 +131,7 @@ export default class BaseList extends React.Component {
return !!detail; return !!detail;
} }
get alsoRefreshDetail() { get shouldRefreshDetail() {
return true; return true;
} }
@ -782,7 +782,7 @@ export default class BaseList extends React.Component {
silent: !force, silent: !force,
}; };
this.handleFetch(params, true); this.handleFetch(params, true);
if (this.isInDetailPage && force && this.alsoRefreshDetail) { if (this.isInDetailPage && force && this.shouldRefreshDetail) {
this.refreshDetailData(); this.refreshDetailData();
} }
}; };

View File

@ -77,7 +77,7 @@ export default class Snapshots extends Base {
return rest; return rest;
}; };
alsoRefreshDetail() { shouldRefreshDetail() {
return false; return false;
} }