fix: model list duplicate
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { useCallback, useState } from 'react';
|
||||
|
||||
export default function useExpandedRowKeys() {
|
||||
const [expandedRowKeys, setExpandedRowKeys] = useState<React.Key[]>([]);
|
||||
|
||||
const handleExpandChange = useCallback(
|
||||
(expanded: boolean, record: any, rowKey: any) => {
|
||||
if (expanded) {
|
||||
setExpandedRowKeys((keys) => [...keys, rowKey]);
|
||||
} else {
|
||||
setExpandedRowKeys((keys) => keys.filter((key) => key !== rowKey));
|
||||
}
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
const updateExpandedRowKeys = (keys: React.Key[]) => {
|
||||
// remove expanded row keys that are in the deleted keys
|
||||
const newExpandedRowKeys = expandedRowKeys.filter(
|
||||
(key) => !keys.includes(key)
|
||||
);
|
||||
setExpandedRowKeys(newExpandedRowKeys);
|
||||
};
|
||||
|
||||
const clearExpandedRowKeys = () => {
|
||||
setExpandedRowKeys([]);
|
||||
};
|
||||
|
||||
return {
|
||||
expandedRowKeys,
|
||||
clearExpandedRowKeys,
|
||||
updateExpandedRowKeys,
|
||||
handleExpandChange
|
||||
};
|
||||
}
|
||||
@@ -8,17 +8,17 @@ interface ChunkedCollection {
|
||||
type: string | number;
|
||||
}
|
||||
// Only used to update lists without nested state
|
||||
export function useUpdateChunkedList(
|
||||
dataList: { id: string | number }[],
|
||||
options: {
|
||||
setDataList: (args: any) => void;
|
||||
callback?: (args: any) => void;
|
||||
filterFun?: (args: any) => boolean;
|
||||
mapFun?: (args: any) => any;
|
||||
computedID?: (d: object) => string;
|
||||
}
|
||||
) {
|
||||
const updateChunkedList = (data: ChunkedCollection) => {
|
||||
export function useUpdateChunkedList(options: {
|
||||
setDataList: (args: any) => void;
|
||||
callback?: (args: any) => void;
|
||||
filterFun?: (args: any) => boolean;
|
||||
mapFun?: (args: any) => any;
|
||||
computedID?: (d: object) => string;
|
||||
}) {
|
||||
const updateChunkedList = (
|
||||
data: ChunkedCollection,
|
||||
dataList: { id: string | number }[]
|
||||
) => {
|
||||
let collections = data?.collection || [];
|
||||
if (options?.computedID) {
|
||||
collections = _.map(collections, (item: any) => {
|
||||
@@ -42,16 +42,17 @@ export function useUpdateChunkedList(
|
||||
);
|
||||
if (updateIndex === -1) {
|
||||
const updateItem = _.cloneDeep(item);
|
||||
options.setDataList((preDataList: any) => {
|
||||
options.setDataList?.((preDataList: any) => {
|
||||
return _.concat(updateItem, preDataList);
|
||||
});
|
||||
}
|
||||
console.log('create=========', updateIndex, dataList, collections);
|
||||
});
|
||||
}
|
||||
// DELETE
|
||||
if (data?.type === WatchEventType.DELETE) {
|
||||
options.setDataList((prevDataList: any) => {
|
||||
const updatedList = _.filter(prevDataList, (item: any) => {
|
||||
options.setDataList?.(() => {
|
||||
const updatedList = _.filter(dataList, (item: any) => {
|
||||
return !_.find(ids, (id: any) => id === item.id);
|
||||
});
|
||||
return updatedList;
|
||||
@@ -59,8 +60,8 @@ export function useUpdateChunkedList(
|
||||
}
|
||||
// UPDATE
|
||||
if (data?.type === WatchEventType.UPDATE) {
|
||||
options.setDataList((prevDataList: any[]) => {
|
||||
const updatedDataList = _.cloneDeep(prevDataList);
|
||||
options.setDataList?.(() => {
|
||||
const updatedDataList = _.cloneDeep(dataList);
|
||||
|
||||
_.each(collections, (item: any) => {
|
||||
const updateIndex = _.findIndex(
|
||||
|
||||
Reference in New Issue
Block a user