feat: Do not display arrow icons on leaf node of folders #1826 (#1862)

### What problem does this PR solve?

feat: Do not display arrow icons on leaf node of folders #1826

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu 2024-08-08 10:50:41 +08:00 committed by GitHub
parent 1d5a9b74ff
commit ed6a693820
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 2 deletions

View File

@ -57,6 +57,12 @@ class FileService(CommonService):
if file["type"] == FileType.FOLDER.value: if file["type"] == FileType.FOLDER.value:
file["size"] = cls.get_folder_size(file["id"]) file["size"] = cls.get_folder_size(file["id"])
file['kbs_info'] = [] file['kbs_info'] = []
children = list(cls.model.select().where(
(cls.model.tenant_id == tenant_id),
(cls.model.parent_id == file["id"]),
~(cls.model.id == file["id"]),
).dicts())
file["has_child_folder"] = any(value["type"] == FileType.FOLDER.value for value in children)
continue continue
kbs_info = cls.get_kb_id_by_file_id(file['id']) kbs_info = cls.get_kb_id_by_file_id(file['id'])
file['kbs_info'] = kbs_info file['kbs_info'] = kbs_info

View File

@ -13,6 +13,7 @@ export interface IFile {
update_date: string; update_date: string;
update_time: number; update_time: number;
source_type: string; source_type: string;
has_child_folder?: boolean;
} }
export interface IFolder { export interface IFolder {

View File

@ -3,6 +3,7 @@ import { IFile } from '@/interfaces/database/file-manager';
import type { GetProp, TreeSelectProps } from 'antd'; import type { GetProp, TreeSelectProps } from 'antd';
import { TreeSelect } from 'antd'; import { TreeSelect } from 'antd';
import { useCallback, useEffect, useState } from 'react'; import { useCallback, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
type DefaultOptionType = GetProp<TreeSelectProps, 'treeData'>[number]; type DefaultOptionType = GetProp<TreeSelectProps, 'treeData'>[number];
@ -12,6 +13,7 @@ interface IProps {
} }
const AsyncTreeSelect = ({ value, onChange }: IProps) => { const AsyncTreeSelect = ({ value, onChange }: IProps) => {
const { t } = useTranslation();
const { fetchList } = useFetchPureFileList(); const { fetchList } = useFetchPureFileList();
const [treeData, setTreeData] = useState<Omit<DefaultOptionType, 'label'>[]>( const [treeData, setTreeData] = useState<Omit<DefaultOptionType, 'label'>[]>(
[], [],
@ -30,7 +32,10 @@ const AsyncTreeSelect = ({ value, onChange }: IProps) => {
pId: x.parent_id, pId: x.parent_id,
value: x.id, value: x.id,
title: x.name, title: x.name,
isLeaf: false, isLeaf:
typeof x.has_child_folder === 'boolean'
? !x.has_child_folder
: false,
})), })),
); );
}); });
@ -53,7 +58,7 @@ const AsyncTreeSelect = ({ value, onChange }: IProps) => {
style={{ width: '100%' }} style={{ width: '100%' }}
value={value} value={value}
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }} dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
placeholder="Please select" placeholder={t('fileManager.pleaseSelect')}
onChange={handleChange} onChange={handleChange}
loadData={onLoadData} loadData={onLoadData}
treeData={treeData} treeData={treeData}