fix: refresh selection after deleting by batch
This commit is contained in:
@@ -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 (
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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
@@ -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 = (
|
||||||
|
|||||||
Reference in New Issue
Block a user