Fix: optimize folder data handling in MoveDialog component (#16580)

This commit is contained in:
chanx
2026-07-03 16:13:57 +08:00
committed by GitHub
parent 4effd057f0
commit 79518973e5

View File

@@ -13,9 +13,10 @@ import {
import { useFetchPureFileList } from '@/hooks/use-file-request';
import { IModalProps } from '@/interfaces/common';
import { IFile } from '@/interfaces/database/file-manager';
import { isEmpty } from 'lodash';
import { isEmpty, uniqBy } from 'lodash';
import { useCallback, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { isFolderType } from './util';
export function MoveDialog({ hideModal, onOk, loading }: IModalProps<any>) {
const { t } = useTranslation();
@@ -31,22 +32,28 @@ export function MoveDialog({ hideModal, onOk, loading }: IModalProps<any>) {
const ret = await fetchList(id as string);
if (ret.code === 0) {
setTreeData((tree) => {
const existingIds = new Set(tree.map((n) => n.id));
const newNodes = ret.data.files
.filter(
(x: IFile) =>
x.type === 'folder' && !existingIds.has(x.id),
)
.map((x: IFile) => ({
id: x.id,
parentId: x.parent_id,
title: x.name,
isLeaf:
typeof x.has_child_folder === 'boolean'
? !x.has_child_folder
: false,
}));
return tree.concat(newNodes);
return uniqBy(
tree.concat(
ret.data.files
.filter(
(x: IFile) =>
x.type === 'folder' &&
!(
isFolderType(x.type) && x.name.toLowerCase() === 'skills'
),
)
.map((x: IFile) => ({
id: x.id,
parentId: x.parent_id,
title: x.name,
isLeaf:
typeof x.has_child_folder === 'boolean'
? !x.has_child_folder
: false,
})),
),
'id',
);
});
}
},