diff --git a/web/src/components/home-card.tsx b/web/src/components/home-card.tsx index fa72fb9342..3bbab828ec 100644 --- a/web/src/components/home-card.tsx +++ b/web/src/components/home-card.tsx @@ -1,12 +1,8 @@ import { RAGFlowAvatar } from '@/components/ragflow-avatar'; +import { TruncatedText } from '@/components/truncated-text'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; -import { - Tooltip, - TooltipContent, - TooltipTrigger, -} from '@/components/ui/tooltip'; import { formatDate } from '@/utils/date'; -import { ElementType, ReactNode, useRef, useState } from 'react'; +import { ReactNode } from 'react'; import { useTranslation } from 'react-i18next'; interface IProps { @@ -30,48 +26,6 @@ function Time({ time }: { time: string | number | undefined }) { return

{formatDate(time)}

; } -function TruncatedText({ - as: Tag = 'div', - className, - children, - tooltip, - testId, -}: { - as?: ElementType; - className?: string; - children?: ReactNode; - tooltip?: ReactNode; - testId?: string; -}) { - const ref = useRef(null); - const [open, setOpen] = useState(false); - - if (tooltip == null) { - return ( - - {children} - - ); - } - - return ( - { - const el = ref.current; - setOpen(next && el !== null && el.scrollWidth > el.clientWidth); - }} - > - - - {children} - - - {tooltip} - - ); -} - export function HomeCard({ data, onClick, diff --git a/web/src/components/structure-graph/adapters.ts b/web/src/components/structure-graph/adapters.ts index 9de4848f6b..efefc94b8b 100644 --- a/web/src/components/structure-graph/adapters.ts +++ b/web/src/components/structure-graph/adapters.ts @@ -1,3 +1,4 @@ +import trim from 'lodash/trim'; import { type TreeDataItem } from '@/components/ui/tree-view'; import { type IArtifactGraph, @@ -17,7 +18,7 @@ declare module '@/components/ui/tree-view' { } export function getEntityDisplayName(entity: IStructureGraphEntity) { - return entity.name ?? entity.id ?? ''; + return trim(entity.name ?? entity.id ?? ''); } function normalizeEntity(entity: IStructureGraphEntity) { diff --git a/web/src/components/truncated-text.tsx b/web/src/components/truncated-text.tsx new file mode 100644 index 0000000000..2809623215 --- /dev/null +++ b/web/src/components/truncated-text.tsx @@ -0,0 +1,48 @@ +import { + Tooltip, + TooltipContent, + TooltipTrigger, +} from '@/components/ui/tooltip'; +import { ElementType, ReactNode, useRef, useState } from 'react'; + +export function TruncatedText({ + as: Tag = 'div', + className, + children, + tooltip, + testId, +}: { + as?: ElementType; + className?: string; + children?: ReactNode; + tooltip?: ReactNode; + testId?: string; +}) { + const ref = useRef(null); + const [open, setOpen] = useState(false); + + if (tooltip == null) { + return ( + + {children} + + ); + } + + return ( + { + const el = ref.current; + setOpen(next && el !== null && el.scrollWidth > el.clientWidth); + }} + > + + + {children} + + + {tooltip} + + ); +} diff --git a/web/src/components/ui/tree-view.tsx b/web/src/components/ui/tree-view.tsx index 39500d2f4c..cb39506add 100644 --- a/web/src/components/ui/tree-view.tsx +++ b/web/src/components/ui/tree-view.tsx @@ -40,7 +40,9 @@ type TreeProps = React.HTMLAttributes & { const TreeItemLabel = ({ item }: { item: TreeDataItem }) => { if (!item.entityType) { - return {item.name}; + return ( + {item.name} + ); } const isTitle = item.entityType === 'title'; diff --git a/web/src/pages/agents/compilation-template-card.tsx b/web/src/pages/agents/compilation-template-card.tsx index 7231dc9f64..d650b8f26f 100644 --- a/web/src/pages/agents/compilation-template-card.tsx +++ b/web/src/pages/agents/compilation-template-card.tsx @@ -1,5 +1,6 @@ import { MoreButton } from '@/components/more-button'; import { RAGFlowAvatar } from '@/components/ragflow-avatar'; +import { TruncatedText } from '@/components/truncated-text'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Card, CardContent } from '@/components/ui/card'; @@ -42,9 +43,13 @@ export function CompilationTemplateCard({
-

+ {data.name} -

+
-

+ {data.description} -

+
{kinds.map((kind) => ( diff --git a/web/src/pages/dataset/compilation/utils/nav-tree.ts b/web/src/pages/dataset/compilation/utils/nav-tree.ts index 6f6e93d792..7b4e3ded6b 100644 --- a/web/src/pages/dataset/compilation/utils/nav-tree.ts +++ b/web/src/pages/dataset/compilation/utils/nav-tree.ts @@ -1,5 +1,6 @@ import { TreeDataItem } from '@/components/ui/tree-view'; import { DatasetNavNode } from '@/interfaces/database/dataset-nav'; +import trim from 'lodash/trim'; import { ReactNode } from 'react'; export type NavTreeActionsFactory = ( @@ -28,7 +29,7 @@ export function buildNavTreeData( return items.map((node) => { const item: TreeDataItem = { id: node.name, - name: node.name, + name: trim(node.name), hasChildren: node.has_children, actions: getActions?.(node, null), onClick: () => onParentClick(node), @@ -39,7 +40,7 @@ export function buildNavTreeData( if (children?.length) { item.children = children.map((child) => ({ id: `${node.name}/${child.name}`, - name: child.name, + name: trim(child.name), hasChildren: child.has_children, actions: getActions?.(child, node.name), onClick: () => onChildClick(child, node.name),