mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-06 16:24:17 +00:00
fix(webui): clamp file card creation info to 2 lines and show tooltip on hover (#390)
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
// @vitest-environment happy-dom
|
// @vitest-environment happy-dom
|
||||||
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
|
import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||||
import { FileCard } from './file-card'
|
import { FileCard } from './file-card'
|
||||||
@@ -151,4 +151,67 @@ describe('FileCard', () => {
|
|||||||
expect(agentBadge.textContent).toBe('AI')
|
expect(agentBadge.textContent).toBe('AI')
|
||||||
expect(screen.getByText('v2')).toBeTruthy()
|
expect(screen.getByText('v2')).toBeTruthy()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('applies line-clamp-2 and h-[2lh] to creation info paragraph', () => {
|
||||||
|
const itemWithCreator: AssetInfo = {
|
||||||
|
...fileItem,
|
||||||
|
creator: { id: 'u1', name: 'Alice' },
|
||||||
|
} as AssetInfo
|
||||||
|
|
||||||
|
renderComponent({ item: itemWithCreator })
|
||||||
|
|
||||||
|
const creatorParagraph = screen.getByText(/Alice/i)
|
||||||
|
expect(creatorParagraph.className).toContain('line-clamp-2')
|
||||||
|
expect(creatorParagraph.className).toContain('h-[2lh]')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('does not show tooltip on hover when creator text is not truncated', () => {
|
||||||
|
vi.useFakeTimers()
|
||||||
|
const itemWithCreator: AssetInfo = {
|
||||||
|
...fileItem,
|
||||||
|
creator: { id: 'u1', name: 'Alice' },
|
||||||
|
} as AssetInfo
|
||||||
|
|
||||||
|
renderComponent({ item: itemWithCreator })
|
||||||
|
|
||||||
|
const creatorParagraph = screen.getByText(/Alice/i)
|
||||||
|
Object.defineProperty(creatorParagraph, 'scrollHeight', { value: 30, configurable: true })
|
||||||
|
Object.defineProperty(creatorParagraph, 'clientHeight', { value: 40, configurable: true })
|
||||||
|
Object.defineProperty(creatorParagraph, 'scrollWidth', { value: 100, configurable: true })
|
||||||
|
Object.defineProperty(creatorParagraph, 'clientWidth', { value: 150, configurable: true })
|
||||||
|
|
||||||
|
fireEvent.pointerMove(creatorParagraph, { pointerType: 'mouse' })
|
||||||
|
|
||||||
|
act(() => {
|
||||||
|
vi.advanceTimersByTime(200)
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(screen.queryByRole('tooltip')).toBeNull()
|
||||||
|
vi.useRealTimers()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('shows tooltip on hover when creator text is truncated', () => {
|
||||||
|
vi.useFakeTimers()
|
||||||
|
const itemWithCreator: AssetInfo = {
|
||||||
|
...fileItem,
|
||||||
|
creator: { id: 'u1', name: 'Very Long Creator Name That Wraps' },
|
||||||
|
} as AssetInfo
|
||||||
|
|
||||||
|
renderComponent({ item: itemWithCreator })
|
||||||
|
|
||||||
|
const creatorParagraph = screen.getByText(/Very Long Creator Name/i)
|
||||||
|
Object.defineProperty(creatorParagraph, 'scrollHeight', { value: 80, configurable: true })
|
||||||
|
Object.defineProperty(creatorParagraph, 'clientHeight', { value: 40, configurable: true })
|
||||||
|
|
||||||
|
fireEvent.pointerMove(creatorParagraph, { pointerType: 'mouse' })
|
||||||
|
|
||||||
|
act(() => {
|
||||||
|
vi.advanceTimersByTime(200)
|
||||||
|
})
|
||||||
|
|
||||||
|
const tooltip = screen.getByRole('tooltip')
|
||||||
|
expect(tooltip).toBeTruthy()
|
||||||
|
expect(tooltip.textContent).toContain('Very Long Creator Name')
|
||||||
|
vi.useRealTimers()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -14,6 +14,12 @@ import {
|
|||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
} from '@/ui/components/ui/dropdown-menu'
|
} from '@/ui/components/ui/dropdown-menu'
|
||||||
import { EditableText } from '@/ui/components/ui/editable-text'
|
import { EditableText } from '@/ui/components/ui/editable-text'
|
||||||
|
import {
|
||||||
|
Tooltip,
|
||||||
|
TooltipContent,
|
||||||
|
TooltipProvider,
|
||||||
|
TooltipTrigger,
|
||||||
|
} from '@/ui/components/ui/tooltip'
|
||||||
import { ProgressCircle } from '@/ui/components/ui/progress-circle'
|
import { ProgressCircle } from '@/ui/components/ui/progress-circle'
|
||||||
import { Skeleton } from '@/ui/components/ui/skeleton'
|
import { Skeleton } from '@/ui/components/ui/skeleton'
|
||||||
import { formatTimeAgo } from '@/ui/lib/time'
|
import { formatTimeAgo } from '@/ui/lib/time'
|
||||||
@@ -90,6 +96,8 @@ export function FileCard({
|
|||||||
}: FileCardProps) {
|
}: FileCardProps) {
|
||||||
const [name, setName] = useState(item.name)
|
const [name, setName] = useState(item.name)
|
||||||
const inputRef = useRef<HTMLInputElement>(null)
|
const inputRef = useRef<HTMLInputElement>(null)
|
||||||
|
const [isCreatorTooltipOpen, setIsCreatorTooltipOpen] = useState(false)
|
||||||
|
const creatorRef = useRef<HTMLParagraphElement>(null)
|
||||||
|
|
||||||
const fileUploadState = useUploadStore((state) => state.fileProgress[item.id || ''])
|
const fileUploadState = useUploadStore((state) => state.fileProgress[item.id || ''])
|
||||||
const uploadPercent = fileUploadState
|
const uploadPercent = fileUploadState
|
||||||
@@ -223,6 +231,19 @@ export function FileCard({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const creatorText = useMemo(() => {
|
||||||
|
if (!displayItem.createdAt) return ''
|
||||||
|
return m.created_by_at({
|
||||||
|
time: formatTimeAgo(displayItem.createdAt),
|
||||||
|
author: displayItem.agent
|
||||||
|
? m.user_via_agent({
|
||||||
|
user: displayItem.creator?.name || m.unknown_user(),
|
||||||
|
agent: displayItem.agent.name,
|
||||||
|
})
|
||||||
|
: displayItem.creator?.name || m.unknown_user(),
|
||||||
|
})
|
||||||
|
}, [displayItem.createdAt, displayItem.agent, displayItem.creator?.name])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
ref={setNodeRef}
|
ref={setNodeRef}
|
||||||
@@ -307,7 +328,7 @@ export function FileCard({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center justify-between gap-2 p-3">
|
<div className="flex items-center justify-between gap-2 p-3">
|
||||||
<div className="min-w-0 flex-1 line-clamp-3 h-[3lh]">
|
<div className="min-w-0 flex-1">
|
||||||
<EditableText
|
<EditableText
|
||||||
ref={inputRef}
|
ref={inputRef}
|
||||||
value={name}
|
value={name}
|
||||||
@@ -317,18 +338,40 @@ export function FileCard({
|
|||||||
disabled={!isEditing}
|
disabled={!isEditing}
|
||||||
className="h-auto p-0 text-sm font-medium text-foreground truncate !bg-transparent"
|
className="h-auto p-0 text-sm font-medium text-foreground truncate !bg-transparent"
|
||||||
/>
|
/>
|
||||||
<p className="text-sm text-muted-foreground">
|
<TooltipProvider delayDuration={100}>
|
||||||
{displayItem.createdAt &&
|
<Tooltip
|
||||||
m.created_by_at({
|
open={isCreatorTooltipOpen}
|
||||||
time: formatTimeAgo(displayItem.createdAt),
|
onOpenChange={(nextOpen) => {
|
||||||
author: displayItem.agent
|
if (nextOpen) {
|
||||||
? m.user_via_agent({
|
if (
|
||||||
user: displayItem.creator?.name || m.unknown_user(),
|
creatorRef.current &&
|
||||||
agent: displayItem.agent.name,
|
(creatorRef.current.scrollHeight > creatorRef.current.clientHeight ||
|
||||||
})
|
creatorRef.current.scrollWidth > creatorRef.current.clientWidth)
|
||||||
: displayItem.creator?.name || m.unknown_user(),
|
) {
|
||||||
})}
|
setIsCreatorTooltipOpen(true)
|
||||||
</p>
|
} else {
|
||||||
|
setIsCreatorTooltipOpen(false)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setIsCreatorTooltipOpen(false)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<p ref={creatorRef} className="text-sm text-muted-foreground line-clamp-2 h-[2lh]">
|
||||||
|
{creatorText}
|
||||||
|
</p>
|
||||||
|
</TooltipTrigger>
|
||||||
|
{isCreatorTooltipOpen && (
|
||||||
|
<TooltipContent
|
||||||
|
side="bottom"
|
||||||
|
className="max-w-md break-all text-wrap [text-wrap:normal] text-left"
|
||||||
|
>
|
||||||
|
{creatorText}
|
||||||
|
</TooltipContent>
|
||||||
|
)}
|
||||||
|
</Tooltip>
|
||||||
|
</TooltipProvider>
|
||||||
</div>
|
</div>
|
||||||
{!isRecents && (
|
{!isRecents && (
|
||||||
<DropdownMenu modal={false}>
|
<DropdownMenu modal={false}>
|
||||||
|
|||||||
Reference in New Issue
Block a user