From 7a6a396f2a008df15890d015f757a3a11ab40cbb Mon Sep 17 00:00:00 2001 From: heheer Date: Thu, 10 Jul 2025 18:16:03 +0800 Subject: [PATCH] optimize ParentPaths component (#5179) * optimize ParentPaths component * fix dataset list diaplay * component --- .../web/components/common/Icon/constants.ts | 1 + .../common/Icon/icons/common/ellipsis.svg | 4 + .../web/components/common/MyMenu/index.tsx | 1 + .../components/common/ParentPaths/index.tsx | 67 -------- .../app/src/components/common/folder/Path.tsx | 150 +++++++++++++----- .../components/common/folder/SlideCard.tsx | 9 +- .../components/core/dataset/SelectModal.tsx | 4 +- .../dataset/detail/CollectionCard/Header.tsx | 4 +- .../pageComponents/dataset/detail/NavBar.tsx | 4 +- .../src/pageComponents/dataset/list/List.tsx | 16 +- projects/app/src/pages/dataset/list/index.tsx | 4 +- .../dataset/components/SelectCollections.tsx | 4 +- 12 files changed, 141 insertions(+), 127 deletions(-) create mode 100644 packages/web/components/common/Icon/icons/common/ellipsis.svg delete mode 100644 projects/app/src/components/common/ParentPaths/index.tsx diff --git a/packages/web/components/common/Icon/constants.ts b/packages/web/components/common/Icon/constants.ts index d348740fd..1169958b9 100644 --- a/packages/web/components/common/Icon/constants.ts +++ b/packages/web/components/common/Icon/constants.ts @@ -45,6 +45,7 @@ export const iconPaths = { 'common/download': () => import('./icons/common/download.svg'), 'common/edit': () => import('./icons/common/edit.svg'), 'common/editor/resizer': () => import('./icons/common/editor/resizer.svg'), + 'common/ellipsis': () => import('./icons/common/ellipsis.svg'), 'common/enable': () => import('./icons/common/enable.svg'), 'common/errorFill': () => import('./icons/common/errorFill.svg'), 'common/file/move': () => import('./icons/common/file/move.svg'), diff --git a/packages/web/components/common/Icon/icons/common/ellipsis.svg b/packages/web/components/common/Icon/icons/common/ellipsis.svg new file mode 100644 index 000000000..b12b2bf37 --- /dev/null +++ b/packages/web/components/common/Icon/icons/common/ellipsis.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/packages/web/components/common/MyMenu/index.tsx b/packages/web/components/common/MyMenu/index.tsx index 4f67dcca0..220589d19 100644 --- a/packages/web/components/common/MyMenu/index.tsx +++ b/packages/web/components/common/MyMenu/index.tsx @@ -326,6 +326,7 @@ const MyMenu = ({ {child.label} diff --git a/projects/app/src/components/common/ParentPaths/index.tsx b/projects/app/src/components/common/ParentPaths/index.tsx deleted file mode 100644 index 606f9af68..000000000 --- a/projects/app/src/components/common/ParentPaths/index.tsx +++ /dev/null @@ -1,67 +0,0 @@ -import { Box, Flex } from '@chakra-ui/react'; -import { type ParentTreePathItemType } from '@fastgpt/global/common/parentFolder/type'; -import React, { useMemo } from 'react'; -import { useTranslation } from 'next-i18next'; - -const ParentPaths = (props: { - paths?: ParentTreePathItemType[]; - rootName?: string; - FirstPathDom?: React.ReactNode; - onClick: (parentId: string) => void; - fontSize?: string; -}) => { - const { t } = useTranslation(); - const { paths = [], rootName = t('common:root_folder'), FirstPathDom, onClick, fontSize } = props; - const concatPaths = useMemo( - () => [ - { - parentId: '', - parentName: rootName - }, - ...paths - ], - [rootName, paths] - ); - - return paths.length === 0 && !!FirstPathDom ? ( - <>{FirstPathDom} - ) : ( - - {concatPaths.map((item, i) => ( - - { - onClick(item.parentId); - } - })} - > - {item.parentName} - - {i !== concatPaths.length - 1 && ( - - / - - )} - - ))} - - ); -}; - -export default React.memo(ParentPaths); diff --git a/projects/app/src/components/common/folder/Path.tsx b/projects/app/src/components/common/folder/Path.tsx index 4efebdc1b..03417e26d 100644 --- a/projects/app/src/components/common/folder/Path.tsx +++ b/projects/app/src/components/common/folder/Path.tsx @@ -3,6 +3,8 @@ import { type ParentTreePathItemType } from '@fastgpt/global/common/parentFolder import React, { useMemo } from 'react'; import { useTranslation } from 'next-i18next'; import MyIcon from '@fastgpt/web/components/common/Icon'; +import MyMenu from '@fastgpt/web/components/common/MyMenu'; +import MyTooltip from '@fastgpt/web/components/common/MyTooltip'; const FolderPath = (props: { paths: ParentTreePathItemType[]; @@ -35,50 +37,116 @@ const FolderPath = (props: { [rootName, paths] ); + const displayPaths = useMemo(() => { + if (concatPaths.length <= 3) { + return concatPaths; + } else { + return [ + concatPaths[0], + null, + concatPaths[concatPaths.length - 2], + concatPaths[concatPaths.length - 1] + ]; + } + }, [concatPaths]); + + const renderPathItem = (item: (typeof concatPaths)[0] | null, index: number) => { + if (item === null) { + const middlePaths = concatPaths.slice(1, -2); + + return ( + + + + + } + trigger={'hover'} + size={'xs'} + menuList={[ + { + children: middlePaths.map((pathItem) => ({ + label: ( + + {pathItem.parentName} + + ), + icon: 'file/fill/folder', + onClick: () => onClick(pathItem.parentId) + })) + } + ]} + /> + + + ); + } + + const isLast = index === displayPaths.length - 1; + const clickStyles = { + cursor: 'pointer', + _hover: { + bg: 'myGray.100', + ...hoverStyle + }, + onClick: () => { + onClick(item.parentId); + } + }; + + const shouldTruncate = !isLast && item.parentName.length > 10; + const displayName = shouldTruncate ? `${item.parentName.slice(0, 10)}...` : item.parentName; + + const pathBox = ( + 1 + ? { + color: 'myGray.700', + fontWeight: 'bold' + } + : { + fontWeight: 'medium', + color: 'myGray.500', + ...clickStyles + })} + {...(isLast && !forbidLastClick && clickStyles)} + > + {displayName} + + ); + + return ( + + {shouldTruncate ? {pathBox} : pathBox} + {!isLast && } + + ); + }; + return paths.length === 0 && !!FirstPathDom ? ( <>{FirstPathDom} ) : ( - - {concatPaths.map((item, i) => { - const clickStyles = { - cursor: 'pointer', - _hover: { - bg: 'myGray.100', - ...hoverStyle - }, - onClick: () => { - onClick(item.parentId); - } - }; - return ( - - 1 - ? { - color: 'myGray.700', - fontWeight: 'bold' - } - : { - fontWeight: 'medium', - color: 'myGray.500', - ...clickStyles - })} - {...(i === concatPaths.length - 1 && !forbidLastClick && clickStyles)} - > - {item.parentName} - - {i !== concatPaths.length - 1 && ( - - )} - - ); - })} + + {displayPaths.map((item, index) => renderPathItem(item, index))} ); }; diff --git a/projects/app/src/components/common/folder/SlideCard.tsx b/projects/app/src/components/common/folder/SlideCard.tsx index 6d9eea41b..e4908f1dc 100644 --- a/projects/app/src/components/common/folder/SlideCard.tsx +++ b/projects/app/src/components/common/folder/SlideCard.tsx @@ -51,7 +51,14 @@ const FolderSlideCard = ({ - {name} + + {name} + - ({ parentId: path.parentId, parentName: path.parentName diff --git a/projects/app/src/pageComponents/dataset/detail/CollectionCard/Header.tsx b/projects/app/src/pageComponents/dataset/detail/CollectionCard/Header.tsx index 4633ff85a..ddbddce77 100644 --- a/projects/app/src/pageComponents/dataset/detail/CollectionCard/Header.tsx +++ b/projects/app/src/pageComponents/dataset/detail/CollectionCard/Header.tsx @@ -22,7 +22,7 @@ import { } from '@fastgpt/global/core/dataset/constants'; import EditFolderModal, { useEditFolder } from '../../EditFolderModal'; import { TabEnum } from '../../../../pages/dataset/detail/index'; -import ParentPath from '@/components/common/ParentPaths'; +import FolderPath from '@/components/common/folder/Path'; import dynamic from 'next/dynamic'; import { ImportDataSourceEnum } from '@fastgpt/global/core/dataset/constants'; @@ -117,7 +117,7 @@ const Header = ({ hasTrainingData }: { hasTrainingData: boolean }) => { - ({ parentId: path.parentId, parentName: i === paths.length - 1 ? `${path.parentName}` : path.parentName diff --git a/projects/app/src/pageComponents/dataset/detail/NavBar.tsx b/projects/app/src/pageComponents/dataset/detail/NavBar.tsx index c16b3adab..8fc108053 100644 --- a/projects/app/src/pageComponents/dataset/detail/NavBar.tsx +++ b/projects/app/src/pageComponents/dataset/detail/NavBar.tsx @@ -8,7 +8,7 @@ import { DatasetPageContext } from '@/web/core/dataset/context/datasetPageContex import LightRowTabs from '@fastgpt/web/components/common/Tabs/LightRowTabs'; import { useSystem } from '@fastgpt/web/hooks/useSystem'; import MyPopover from '@fastgpt/web/components/common/MyPopover'; -import ParentPaths from '@/components/common/ParentPaths'; +import FolderPath from '@/components/common/folder/Path'; import { getTrainingQueueLen } from '@/web/core/dataset/api'; import { useRequest2 } from '@fastgpt/web/hooks/useRequest'; @@ -166,7 +166,7 @@ const NavBar = ({ currentTab }: { currentTab: TabEnum }) => { ) : ( - { router.push(`/dataset/list?parentId=${e}`); diff --git a/projects/app/src/pageComponents/dataset/list/List.tsx b/projects/app/src/pageComponents/dataset/list/List.tsx index f6cec5119..36615b18e 100644 --- a/projects/app/src/pageComponents/dataset/list/List.tsx +++ b/projects/app/src/pageComponents/dataset/list/List.tsx @@ -219,14 +219,14 @@ function List() { } }} > - - - + + + {dataset.name} - - {dataset.type !== DatasetTypeEnum.folder && ( + {dataset.type !== DatasetTypeEnum.folder && ( + - )} - - + + )} + { - diff --git a/projects/app/src/web/core/dataset/components/SelectCollections.tsx b/projects/app/src/web/core/dataset/components/SelectCollections.tsx index 79b2fd08b..79efd244a 100644 --- a/projects/app/src/web/core/dataset/components/SelectCollections.tsx +++ b/projects/app/src/web/core/dataset/components/SelectCollections.tsx @@ -1,6 +1,6 @@ import MyIcon from '@fastgpt/web/components/common/Icon'; import MyModal from '@fastgpt/web/components/common/MyModal'; -import ParentPaths from '@/components/common/ParentPaths'; +import FolderPath from '@/components/common/folder/Path'; import { useRequest, useRequest2 } from '@fastgpt/web/hooks/useRequest'; import { getDatasetCollectionPathById, getDatasetCollections } from '@/web/core/dataset/api'; import { Box, Flex, ModalFooter, Button, useTheme, Grid, Card, ModalBody } from '@chakra-ui/react'; @@ -114,7 +114,7 @@ const SelectCollections = ({ iconSrc="/imgs/modal/move.svg" title={ - ({ parentId: path.parentId, parentName: path.parentName