fix: refresh selection after deleting by batch

main
jialin 11 months ago
parent febdc5b8e2
commit 6340f1fb54

@ -73,10 +73,25 @@ const DeleteModal: FC<DeleteModalProps> = forwardRef((props, ref) => {
};
const handleOk = async () => {
await config.onOk?.();
message.success(intl.formatMessage({ id: 'common.message.success' }));
setVisible(false);
restoreScrollHeight();
try {
const res = await config.onOk?.();
const isArray = Array.isArray(res);
if (isArray) {
const allSuccess = res.every(
(item: any) => item?.status === 'fulfilled'
);
if (allSuccess) {
message.success(intl.formatMessage({ id: 'common.message.success' }));
}
} else {
message.success(intl.formatMessage({ id: 'common.message.success' }));
}
} catch (error) {
// Handle error if needed
} finally {
setVisible(false);
restoreScrollHeight();
}
};
return (

@ -199,13 +199,19 @@ export default function useTableFetch<ListItem>(options: {
...options,
async onOk() {
if (!deleteAPI) return;
await handleBatchRequest(rowSelection.selectedRowKeys, (id) =>
deleteAPI(id, {
...modalRef.current?.configuration
})
const successIds: any[] = [];
const res = await handleBatchRequest(
rowSelection.selectedRowKeys,
async (id: any) => {
await deleteAPI(id, {
...modalRef.current?.configuration
});
successIds.push(id);
}
);
rowSelection.clearSelections();
rowSelection.removeSelectedKeys(successIds);
fetchData();
return res;
}
});
};

@ -343,11 +343,18 @@ const Models: React.FC<ModelsProps> = ({
operation: 'common.delete.confirm',
selection: true,
async onOk() {
await handleBatchRequest(rowSelection.selectedRowKeys, deleteModel);
rowSelection.clearSelections();
removeExpandedRowKey(rowSelection.selectedRowKeys);
const successIds: any[] = [];
const res = await handleBatchRequest(
rowSelection.selectedRowKeys,
async (id: any) => {
await deleteModel(id);
successIds.push(id);
}
);
rowSelection.removeSelectedKeys(successIds);
handleDeleteSuccess();
handleSearch();
return res;
}
});
};

@ -18,7 +18,7 @@ export const handleBatchRequest = async (
list: any[],
fn: (args: any) => void
) => {
return Promise.all(list.map((item) => fn(item)));
return Promise.allSettled(list.map((item) => fn(item)));
};
export const convertFileSize = (

Loading…
Cancel
Save