chore: models list re-render

This commit is contained in:
jialin
2024-07-05 18:51:13 +08:00
parent 8c66c482b2
commit b753528e44
38 changed files with 810 additions and 657 deletions
+5
View File
@@ -7,8 +7,13 @@ export default function useTableRowSelection() {
setSelectedRowKeys(selectedRowKeys);
};
const clearSelections = () => {
setSelectedRowKeys([]);
};
const rowSelection = {
selectedRowKeys,
clearSelections,
onChange: onSelectChange
};
+23 -16
View File
@@ -42,31 +42,38 @@ export function useUpdateChunkedList(
);
if (updateIndex === -1) {
const updateItem = _.cloneDeep(item);
const list = _.concat(updateItem, dataList);
options.setDataList(list);
options.setDataList((preDataList: any) => {
return _.concat(updateItem, preDataList);
});
}
});
}
// DELETE
if (data?.type === WatchEventType.DELETE) {
const list = _.filter(dataList, (item: any) => {
return !_.find(ids, (id: any) => id === item.id);
options.setDataList((prevDataList: any) => {
const updatedList = _.filter(prevDataList, (item: any) => {
return !_.find(ids, (id: any) => id === item.id);
});
return updatedList;
});
options.setDataList(list);
}
// UPDATE
if (data?.type === WatchEventType.UPDATE) {
_.each(collections, (item: any) => {
const updateIndex = _.findIndex(
dataList,
(sItem: any) => sItem.id === item.id
);
console.log('updateIndex===========', dataList, updateIndex, data);
if (updateIndex > -1) {
const updateItem = _.cloneDeep(item);
dataList[updateIndex] = updateItem;
}
options.setDataList(dataList);
options.setDataList((prevDataList: any[]) => {
const updatedDataList = _.cloneDeep(prevDataList);
_.each(collections, (item: any) => {
const updateIndex = _.findIndex(
updatedDataList,
(sItem: any) => sItem.id === item.id
);
if (updateIndex > -1) {
const updateItem = _.cloneDeep(item);
updatedDataList[updateIndex] = updateItem;
}
});
return updatedDataList;
});
}
if (options?.callback) {