fix: refresh selection after deleting by batch

This commit is contained in:
jialin
2025-05-16 16:07:55 +08:00
parent febdc5b8e2
commit 6340f1fb54
4 changed files with 41 additions and 13 deletions
+19 -4
View File
@@ -73,10 +73,25 @@ const DeleteModal: FC<DeleteModalProps> = forwardRef((props, ref) => {
}; };
const handleOk = async () => { const handleOk = async () => {
await config.onOk?.(); try {
message.success(intl.formatMessage({ id: 'common.message.success' })); const res = await config.onOk?.();
setVisible(false); const isArray = Array.isArray(res);
restoreScrollHeight(); 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 ( return (
+11 -5
View File
@@ -199,13 +199,19 @@ export default function useTableFetch<ListItem>(options: {
...options, ...options,
async onOk() { async onOk() {
if (!deleteAPI) return; if (!deleteAPI) return;
await handleBatchRequest(rowSelection.selectedRowKeys, (id) => const successIds: any[] = [];
deleteAPI(id, { const res = await handleBatchRequest(
...modalRef.current?.configuration rowSelection.selectedRowKeys,
}) async (id: any) => {
await deleteAPI(id, {
...modalRef.current?.configuration
});
successIds.push(id);
}
); );
rowSelection.clearSelections(); rowSelection.removeSelectedKeys(successIds);
fetchData(); fetchData();
return res;
} }
}); });
}; };
+10 -3
View File
@@ -343,11 +343,18 @@ const Models: React.FC<ModelsProps> = ({
operation: 'common.delete.confirm', operation: 'common.delete.confirm',
selection: true, selection: true,
async onOk() { async onOk() {
await handleBatchRequest(rowSelection.selectedRowKeys, deleteModel); const successIds: any[] = [];
rowSelection.clearSelections(); const res = await handleBatchRequest(
removeExpandedRowKey(rowSelection.selectedRowKeys); rowSelection.selectedRowKeys,
async (id: any) => {
await deleteModel(id);
successIds.push(id);
}
);
rowSelection.removeSelectedKeys(successIds);
handleDeleteSuccess(); handleDeleteSuccess();
handleSearch(); handleSearch();
return res;
} }
}); });
}; };
+1 -1
View File
@@ -18,7 +18,7 @@ export const handleBatchRequest = async (
list: any[], list: any[],
fn: (args: any) => void fn: (args: any) => void
) => { ) => {
return Promise.all(list.map((item) => fn(item))); return Promise.allSettled(list.map((item) => fn(item)));
}; };
export const convertFileSize = ( export const convertFileSize = (