feat(search): render results in responsive card grid with sprite preview and new-tab navigation (#479)

* feat(search): render results in responsive card grid with sprite preview and new-tab navigation

* fix(search): align semantic matched duration badge style with standard duration badge

* fix(webui): use pointer cursor instead of crosshair cursor for sprite scrubber on hover
This commit is contained in:
Yiling-J
2026-10-16 10:42:32 +08:00
committed by GitHub
parent 1a46f63160
commit 0f318b4050
10 changed files with 606 additions and 213 deletions
@@ -441,4 +441,39 @@ describe('FileCard', () => {
expect(tooltip.textContent).toContain('FFmpeg transcode failed: exit code 1')
vi.useRealTimers()
})
it('does not render selection checkbox when hideCheckbox is true', () => {
renderComponent({ item: fileItem, hideCheckbox: true })
expect(screen.queryByRole('checkbox')).toBeNull()
})
it('renders selection checkbox by default when hideCheckbox is false or omitted', () => {
renderComponent({ item: fileItem })
expect(screen.getByRole('checkbox')).toBeTruthy()
})
it('does not render 3-dot dropdown menu when hideActions is true', () => {
renderComponent({ item: fileItem, hideActions: true })
// No dropdown trigger button rendered
expect(screen.queryByRole('button')).toBeNull()
})
it('renders matched duration chunk in preview when startTime and endTime are present', () => {
const videoWithMatch: AssetInfo = {
...fileItem,
startTime: 65,
endTime: 125,
preview: {
proxyType: 'video',
thumbnailUrl: 'https://example.com/poster.webp',
duration: 300,
},
} as AssetInfo
renderComponent({ item: videoWithMatch })
const matchedDuration = screen.getByTestId('file-preview-matched-duration')
expect(matchedDuration).toBeTruthy()
expect(matchedDuration.textContent).toBe('01:05 - 02:05')
})
})
@@ -48,18 +48,18 @@ import { FIELD_TYPE_ICONS } from '../fields-manager'
interface FileCardProps {
teamId?: string
item: AssetInfo
isSelected: boolean
isChecked: boolean
isEditing: boolean
onSelect: (item: AssetInfo, event: React.MouseEvent) => void
onDoubleClick: (item: AssetInfo) => void
onContextMenu: (e: React.MouseEvent, item: AssetInfo) => void
isSelected?: boolean
isChecked?: boolean
isEditing?: boolean
onSelect?: (item: AssetInfo, event: React.MouseEvent) => void
onDoubleClick?: (item: AssetInfo) => void
onContextMenu?: (e: React.MouseEvent, item: AssetInfo) => void
// Deprecated manual drag handlers replaced by dnd-kit
onDragStart: (item: AssetInfo) => void
onDrop: (target: AssetInfo) => void
onRename: (newName: string) => void
onFinishEditing: () => void
onSaveField: (fieldId: string, value: unknown) => void
onDragStart?: (item: AssetInfo) => void
onDrop?: (target: AssetInfo) => void
onRename?: (newName: string) => void
onFinishEditing?: () => void
onSaveField?: (fieldId: string, value: unknown) => void
dragState?: DragState
disabled?: boolean
onAction?: (
@@ -69,39 +69,43 @@ interface FileCardProps {
isRecentlyDeleted?: boolean
isRecents?: boolean
selectedCount?: number
fields: MetadataFieldInfo[]
fields?: MetadataFieldInfo[]
isShareView?: boolean
canEdit?: boolean
/** When false, hides the download action. Defaults to true. */
allowDownload?: boolean
hideCheckbox?: boolean
hideActions?: boolean
}
export function FileCard({
teamId,
item,
isSelected,
isChecked,
isEditing,
onSelect,
onDoubleClick,
onContextMenu,
isSelected = false,
isChecked = false,
isEditing = false,
onSelect = () => {},
onDoubleClick = () => {},
onContextMenu = () => {},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onDragStart: _onDragStart,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onDrop: _onDrop,
onRename,
onFinishEditing,
onSaveField,
onRename = () => {},
onFinishEditing = () => {},
onSaveField = () => {},
dragState,
disabled,
onAction,
isRecentlyDeleted,
isRecents,
selectedCount,
fields,
fields = [],
isShareView,
canEdit = true,
allowDownload = true,
hideCheckbox = false,
hideActions = false,
}: FileCardProps) {
const [name, setName] = useState(item.name)
const inputRef = useRef<HTMLInputElement>(null)
@@ -170,10 +174,12 @@ export function FileCard({
id: displayItem.id,
item: displayItem,
},
disabled: disabled,
})
// Combine refs
const setNodeRef = (node: HTMLElement | null) => {
if (disabled) return
setDraggableRef(node)
setDroppableRef(node)
}
@@ -332,17 +338,19 @@ export function FileCard({
showDropFeedback && 'border-primary outline-1 outline-primary',
)}
>
<div className="absolute left-2 top-2 z-10 flex items-center gap-1.5">
<Checkbox
checked={isChecked}
onCheckedChange={() => {}}
onClick={(e) => {
e.stopPropagation()
onSelect(displayItem, e)
}}
className="h-4 w-4 bg-white/20 dark:bg-white/20 border-2 data-[state=checked]:bg-primary data-[state=checked]:border-primary border-foreground/15"
/>
</div>
{!hideCheckbox && (
<div className="absolute left-2 top-2 z-10 flex items-center gap-1.5">
<Checkbox
checked={isChecked}
onCheckedChange={() => {}}
onClick={(e) => {
e.stopPropagation()
onSelect(displayItem, e)
}}
className="h-4 w-4 bg-white/20 dark:bg-white/20 border-2 data-[state=checked]:bg-primary data-[state=checked]:border-primary border-foreground/15"
/>
</div>
)}
<div className="absolute right-2 top-2 z-10 flex items-center gap-1.5">
{displayItem.agent && (
@@ -395,7 +403,15 @@ export function FileCard({
data-testid="file-card-preview-media"
className={cn('h-full w-full', isProcessing && 'animate-pulse')}
>
<FilePreview item={displayItem} showDuration={!isProcessing && !isFailed} />
<FilePreview
item={displayItem}
showDuration={!isProcessing && !isFailed}
matchDuration={
displayItem.startTime != null && displayItem.endTime != null
? { startTime: displayItem.startTime, endTime: displayItem.endTime }
: null
}
/>
</div>
{previewBadges}
</>
@@ -435,7 +451,15 @@ export function FileCard({
</div>
) : (
<>
<FilePreview item={displayItem} showDuration />
<FilePreview
item={displayItem}
showDuration
matchDuration={
displayItem.startTime != null && displayItem.endTime != null
? { startTime: displayItem.startTime, endTime: displayItem.endTime }
: null
}
/>
{previewBadges}
</>
)}
@@ -487,7 +511,7 @@ export function FileCard({
</Tooltip>
</TooltipProvider>
</div>
{!isRecents && (
{!hideActions && !isRecents && (
<DropdownMenu modal={false}>
<DropdownMenuTrigger asChild>
<Button
@@ -20,9 +20,13 @@ type FilePreviewItem = {
interface FilePreviewProps {
item: FilePreviewItem
showDuration?: boolean
matchDuration?: {
startTime?: number | null
endTime?: number | null
} | null
}
export const FilePreview = ({ item, showDuration = false }: FilePreviewProps) => {
export const FilePreview = ({ item, showDuration = false, matchDuration }: FilePreviewProps) => {
const proxyType = item.preview?.proxyType || item.proxyType
const isVideo = proxyType === 'video'
const isAudio = proxyType === 'audio'
@@ -32,16 +36,25 @@ export const FilePreview = ({ item, showDuration = false }: FilePreviewProps) =>
const duration = item.preview?.duration
const pageCount = item.preview?.pageCount
const overlay =
showDuration && hasDuration && typeof duration === 'number' && duration > 0 ? (
<span className="pointer-events-none absolute bottom-1 right-1 rounded bg-black/60 px-1 py-0.5 text-xs font-medium tabular-nums text-white">
{formatTime(duration)}
</span>
) : showDuration && isPdf && typeof pageCount === 'number' && pageCount > 0 ? (
<span className="pointer-events-none absolute bottom-1 right-1 rounded bg-black/60 px-1 py-0.5 text-xs font-medium tabular-nums text-white">
{pageCount} P
</span>
) : null
const hasMatchedChunk =
matchDuration != null && matchDuration.startTime != null && matchDuration.endTime != null
const overlay = hasMatchedChunk ? (
<span
data-testid="file-preview-matched-duration"
className="pointer-events-none absolute bottom-1 right-1 rounded bg-black/60 px-1 py-0.5 text-xs font-medium tabular-nums text-white"
>
{formatTime(matchDuration.startTime!)} - {formatTime(matchDuration.endTime!)}
</span>
) : showDuration && hasDuration && typeof duration === 'number' && duration > 0 ? (
<span className="pointer-events-none absolute bottom-1 right-1 rounded bg-black/60 px-1 py-0.5 text-xs font-medium tabular-nums text-white">
{formatTime(duration)}
</span>
) : showDuration && isPdf && typeof pageCount === 'number' && pageCount > 0 ? (
<span className="pointer-events-none absolute bottom-1 right-1 rounded bg-black/60 px-1 py-0.5 text-xs font-medium tabular-nums text-white">
{pageCount} P
</span>
) : null
const isMediaWithSprite =
(isVideo || isPdf || is3D) &&
@@ -96,4 +96,19 @@ describe('FolderCard', () => {
renderComponent({ item: folderItem, isRecentlyDeleted: true })
expect(screen.queryByTestId('folder-card-days-left')).toBeNull()
})
it('does not render selection checkbox when hideCheckbox is true', () => {
renderComponent({ item: folderItem, hideCheckbox: true })
expect(screen.queryByRole('checkbox')).toBeNull()
})
it('renders selection checkbox by default when hideCheckbox is false or omitted', () => {
renderComponent({ item: folderItem })
expect(screen.getByRole('checkbox')).toBeTruthy()
})
it('does not render 3-dot dropdown menu when hideActions is true', () => {
renderComponent({ item: folderItem, hideActions: true })
expect(screen.queryByRole('button')).toBeNull()
})
})
@@ -20,17 +20,17 @@ import { getAllFilesFromEntries } from '@/ui/lib/dnd-utils'
interface FolderCardProps {
item: AssetInfo
isSelected: boolean
isChecked: boolean
isEditing: boolean
onSelect: (item: AssetInfo, event: React.MouseEvent) => void
onDoubleClick: (item: AssetInfo) => void
onContextMenu: (e: React.MouseEvent, item: AssetInfo) => void
isSelected?: boolean
isChecked?: boolean
isEditing?: boolean
onSelect?: (item: AssetInfo, event: React.MouseEvent) => void
onDoubleClick?: (item: AssetInfo) => void
onContextMenu?: (e: React.MouseEvent, item: AssetInfo) => void
// Deprecated manual drag props replaced by dnd-kit
onDragStart: (item: AssetInfo) => void
onDrop: (target: AssetInfo) => void
onRename: (newName: string) => void
onFinishEditing: () => void
onDragStart?: (item: AssetInfo) => void
onDrop?: (target: AssetInfo) => void
onRename?: (newName: string) => void
onFinishEditing?: () => void
dragState?: DragState
disabled?: boolean
onAction?: (
@@ -49,6 +49,8 @@ interface FolderCardProps {
onExternalDrop?: (files: File[], folderId: string) => void
/** When false, hides the download action. Defaults to true. */
allowDownload?: boolean
hideCheckbox?: boolean
hideActions?: boolean
}
const FolderPreviewGrid = ({ items }: { items: ChildPreview[] }) => {
@@ -106,18 +108,18 @@ const FolderPreviewGrid = ({ items }: { items: ChildPreview[] }) => {
export function FolderCard({
item,
isSelected,
isChecked,
isEditing,
onSelect,
onDoubleClick,
onContextMenu,
isSelected = false,
isChecked = false,
isEditing = false,
onSelect = () => {},
onDoubleClick = () => {},
onContextMenu = () => {},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onDragStart: _onDragStart,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onDrop: _onDrop,
onRename,
onFinishEditing,
onRename = () => {},
onFinishEditing = () => {},
dragState,
disabled,
onAction,
@@ -132,6 +134,8 @@ export function FolderCard({
resetExternalDragState,
onExternalDrop,
allowDownload = true,
hideCheckbox = false,
hideActions = false,
}: FolderCardProps) {
const [name, setName] = useState(item.name || '')
const inputRef = useRef<HTMLInputElement>(null)
@@ -154,9 +158,11 @@ export function FolderCard({
id: item.id,
item: item,
},
disabled: disabled,
})
const setNodeRef = (node: HTMLElement | null) => {
if (disabled) return
setDraggableRef(node)
setDroppableRef(node)
}
@@ -333,13 +339,15 @@ export function FolderCard({
<div className="shadow-[0_-4px_6px_rgba(0,0,0,0.08)] relative w-full flex flex-1 flex-col p-2 mt-5 bg-muted dark:bg-muted/50 rounded-sm">
<div className="relative w-full aspect-video shrink-0 overflow-hidden">
<div className="absolute top-1 left-1 z-30 transition-all duration-200">
<Checkbox
checked={isChecked}
onClick={(e) => e.stopPropagation()} // Let parent handler deal with it
className="w-5 h-5 border-1 border-foreground/20 bg-background/50 data-[state=checked]:bg-primary data-[state=checked]:border-primary"
/>
</div>
{!hideCheckbox && (
<div className="absolute top-1 left-1 z-30 transition-all duration-200">
<Checkbox
checked={isChecked}
onClick={(e) => e.stopPropagation()} // Let parent handler deal with it
className="w-5 h-5 border-1 border-foreground/20 bg-background/50 data-[state=checked]:bg-primary data-[state=checked]:border-primary"
/>
</div>
)}
{item.latestChildren && item.latestChildren.length > 0 && (
<div data-testid="folder-preview-grid" className="h-full w-full">
@@ -376,7 +384,7 @@ export function FolderCard({
? m.n_items_singular({ count: item.fileCount || 0 })
: m.n_items_plural({ count: item.fileCount || 0 })}
</span>
{!isRecents && (
{!hideActions && !isRecents && (
<DropdownMenu modal={false}>
<DropdownMenuTrigger asChild>
<button