mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-19 14:16:29 +00:00
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:
@@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
||||
|
||||
### Changed
|
||||
|
||||
* **search**: Display search results in a responsive card grid with interactive hover video sprite scrubbing, semantic match chunk time range previews, and new-tab opening on click
|
||||
* **search**: Significantly improve semantic search response times by generating query text embeddings directly with in-memory caching instead of dispatching background tasks
|
||||
|
||||
## [0.5.2] - 2026-10-13
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,328 @@
|
||||
// @vitest-environment happy-dom
|
||||
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
|
||||
import React from 'react'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import type { AssetInfo } from '@shumai/dtos'
|
||||
import { SearchFilterDialog } from './search-filter-dialog'
|
||||
|
||||
vi.mock('@dnd-kit/react', () => ({
|
||||
useDraggable: () => ({
|
||||
ref: vi.fn(),
|
||||
isDragging: false,
|
||||
}),
|
||||
useDroppable: () => ({
|
||||
ref: vi.fn(),
|
||||
isDropTarget: false,
|
||||
}),
|
||||
}))
|
||||
|
||||
const mockSearchPost = vi.fn()
|
||||
const mockSettingsGet = vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({ semanticSearchEnabled: true }),
|
||||
})
|
||||
|
||||
vi.mock('@/ui/api/client', () => ({
|
||||
client: {
|
||||
api: {
|
||||
teams: {
|
||||
':teamId': {
|
||||
settings: {
|
||||
$get: (...args: unknown[]) => mockSettingsGet(...args),
|
||||
},
|
||||
},
|
||||
},
|
||||
folders: {
|
||||
':folderId': {
|
||||
search: {
|
||||
$post: (...args: unknown[]) => mockSearchPost(...args),
|
||||
},
|
||||
},
|
||||
},
|
||||
files: {
|
||||
':fileId': {
|
||||
$get: vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({}),
|
||||
}),
|
||||
},
|
||||
},
|
||||
projects: {
|
||||
':projectId': {
|
||||
collections: {
|
||||
$post: vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({ id: 'col-1' }),
|
||||
}),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}))
|
||||
|
||||
vi.mock('@tanstack/react-router', () => ({
|
||||
useNavigate: () => vi.fn(),
|
||||
useRouterState: () => '/projects/proj-1',
|
||||
}))
|
||||
|
||||
describe('SearchFilterDialog', () => {
|
||||
let queryClient: QueryClient
|
||||
let windowOpenSpy: ReturnType<typeof vi.spyOn>
|
||||
|
||||
beforeEach(() => {
|
||||
queryClient = new QueryClient({
|
||||
defaultOptions: { queries: { retry: false } },
|
||||
})
|
||||
windowOpenSpy = vi.spyOn(window, 'open').mockImplementation(() => null)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
vi.clearAllMocks()
|
||||
windowOpenSpy.mockRestore()
|
||||
})
|
||||
|
||||
const defaultProps = {
|
||||
open: true,
|
||||
onOpenChange: vi.fn(),
|
||||
teamId: 'team-1',
|
||||
projectId: 'proj-1',
|
||||
assetId: 'folder-root',
|
||||
fields: [],
|
||||
initialConditions: [],
|
||||
onApply: vi.fn(),
|
||||
}
|
||||
|
||||
it('renders initial ready to search state when open and no query', () => {
|
||||
render(
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<SearchFilterDialog {...defaultProps} />
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
|
||||
expect(screen.getByText(/Ready to search|准备搜索/i)).toBeTruthy()
|
||||
})
|
||||
|
||||
it('renders search results in a responsive grid using FileCard and FolderCard without checkboxes or action menus', async () => {
|
||||
const mockFile: AssetInfo = {
|
||||
id: 'file-101',
|
||||
name: 'video_clip.mp4',
|
||||
type: 'file',
|
||||
sizeByte: 1048576,
|
||||
status: 'processed',
|
||||
createdAt: '2026-01-01T00:00:00Z',
|
||||
updatedAt: '2026-01-01T00:00:00Z',
|
||||
preview: {
|
||||
proxyType: 'video',
|
||||
thumbnailUrl: 'https://example.com/clip.jpg',
|
||||
duration: 120,
|
||||
},
|
||||
} as AssetInfo
|
||||
|
||||
const mockFolder: AssetInfo = {
|
||||
id: 'folder-202',
|
||||
name: 'B-Roll Folder',
|
||||
type: 'folder',
|
||||
fileCount: 4,
|
||||
status: 'processed',
|
||||
createdAt: '2026-01-01T00:00:00Z',
|
||||
updatedAt: '2026-01-01T00:00:00Z',
|
||||
} as AssetInfo
|
||||
|
||||
mockSearchPost.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
data: [mockFile, mockFolder],
|
||||
pageInfo: { total: 2 },
|
||||
}),
|
||||
})
|
||||
|
||||
render(
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<SearchFilterDialog
|
||||
{...defaultProps}
|
||||
initialConditions={[{ field: 'name', operator: 'contains', value: 'video' }]}
|
||||
/>
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('video_clip.mp4')).toBeTruthy()
|
||||
expect(screen.getByText('B-Roll Folder')).toBeTruthy()
|
||||
})
|
||||
|
||||
// Neither card renders checkboxes or 3-dots action menus in search dialog
|
||||
expect(screen.queryByRole('checkbox')).toBeNull()
|
||||
expect(screen.queryByRole('button', { name: /more/i })).toBeNull()
|
||||
|
||||
// Grid container is present
|
||||
const fileCard = screen.getByText('video_clip.mp4').closest('[data-testid="file-card"]')
|
||||
expect(fileCard).toBeTruthy()
|
||||
const gridContainer = fileCard?.parentElement
|
||||
expect(gridContainer?.className).toContain('grid')
|
||||
})
|
||||
|
||||
it('single-clicking a file opens detail page in a new tab seeking to startTime without closing dialog', async () => {
|
||||
const onOpenChange = vi.fn()
|
||||
const mockSemanticFile: AssetInfo = {
|
||||
id: 'file-sem-1',
|
||||
name: 'interview.mp4',
|
||||
type: 'file',
|
||||
status: 'processed',
|
||||
startTime: 45,
|
||||
endTime: 90,
|
||||
createdAt: '2026-01-01T00:00:00Z',
|
||||
updatedAt: '2026-01-01T00:00:00Z',
|
||||
preview: {
|
||||
proxyType: 'video',
|
||||
thumbnailUrl: 'https://example.com/interview.jpg',
|
||||
duration: 300,
|
||||
},
|
||||
} as AssetInfo
|
||||
|
||||
mockSearchPost.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
data: [mockSemanticFile],
|
||||
pageInfo: { total: 1 },
|
||||
}),
|
||||
})
|
||||
|
||||
render(
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<SearchFilterDialog
|
||||
{...defaultProps}
|
||||
onOpenChange={onOpenChange}
|
||||
initialConditions={[{ field: 'name', operator: 'contains', value: 'interview' }]}
|
||||
/>
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('interview.mp4')).toBeTruthy()
|
||||
})
|
||||
|
||||
// Matched chunk duration replaces total duration in preview
|
||||
const matchedBadge = screen.getByTestId('file-preview-matched-duration')
|
||||
expect(matchedBadge.textContent).toBe('00:45 - 01:30')
|
||||
|
||||
// Single click on file card
|
||||
const card = screen.getByText('interview.mp4').closest('[data-testid="file-card"]')!
|
||||
fireEvent.click(card)
|
||||
|
||||
expect(windowOpenSpy).toHaveBeenCalledWith(
|
||||
'/projects/proj-1/files/file-sem-1?start=45',
|
||||
'_blank',
|
||||
'noopener,noreferrer',
|
||||
)
|
||||
// Dialog should NOT be closed
|
||||
expect(onOpenChange).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('single-clicking a folder opens folder page in a new tab without closing dialog', async () => {
|
||||
const onOpenChange = vi.fn()
|
||||
const mockFolder: AssetInfo = {
|
||||
id: 'folder-sub-1',
|
||||
name: 'Subfolder Alpha',
|
||||
type: 'folder',
|
||||
status: 'processed',
|
||||
createdAt: '2026-01-01T00:00:00Z',
|
||||
updatedAt: '2026-01-01T00:00:00Z',
|
||||
} as AssetInfo
|
||||
|
||||
mockSearchPost.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
data: [mockFolder],
|
||||
pageInfo: { total: 1 },
|
||||
}),
|
||||
})
|
||||
|
||||
render(
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<SearchFilterDialog
|
||||
{...defaultProps}
|
||||
onOpenChange={onOpenChange}
|
||||
initialConditions={[{ field: 'name', operator: 'contains', value: 'Subfolder' }]}
|
||||
/>
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('Subfolder Alpha')).toBeTruthy()
|
||||
})
|
||||
|
||||
const card = screen.getByText('Subfolder Alpha').closest('[data-testid="file-card"]')!
|
||||
fireEvent.click(card)
|
||||
|
||||
expect(windowOpenSpy).toHaveBeenCalledWith(
|
||||
'/projects/proj-1/folders/folder-sub-1',
|
||||
'_blank',
|
||||
'noopener,noreferrer',
|
||||
)
|
||||
expect(onOpenChange).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('renders multiple distinct chunk matches for the same video file with unique timestamps', async () => {
|
||||
const chunk1: AssetInfo = {
|
||||
id: 'video-same',
|
||||
name: 'drone_shots.mp4',
|
||||
type: 'file',
|
||||
status: 'processed',
|
||||
startTime: 10,
|
||||
endTime: 30,
|
||||
createdAt: '2026-01-01T00:00:00Z',
|
||||
updatedAt: '2026-01-01T00:00:00Z',
|
||||
preview: {
|
||||
proxyType: 'video',
|
||||
thumbnailUrl: 'https://example.com/drone.jpg',
|
||||
duration: 200,
|
||||
},
|
||||
} as AssetInfo
|
||||
|
||||
const chunk2: AssetInfo = {
|
||||
id: 'video-same',
|
||||
name: 'drone_shots.mp4',
|
||||
type: 'file',
|
||||
status: 'processed',
|
||||
startTime: 120,
|
||||
endTime: 150,
|
||||
createdAt: '2026-01-01T00:00:00Z',
|
||||
updatedAt: '2026-01-01T00:00:00Z',
|
||||
preview: {
|
||||
proxyType: 'video',
|
||||
thumbnailUrl: 'https://example.com/drone.jpg',
|
||||
duration: 200,
|
||||
},
|
||||
} as AssetInfo
|
||||
|
||||
mockSearchPost.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
data: [chunk1, chunk2],
|
||||
pageInfo: { total: 2 },
|
||||
}),
|
||||
})
|
||||
|
||||
render(
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<SearchFilterDialog
|
||||
{...defaultProps}
|
||||
initialConditions={[{ field: 'name', operator: 'contains', value: 'drone' }]}
|
||||
/>
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
|
||||
await waitFor(() => {
|
||||
const titles = screen.getAllByText('drone_shots.mp4')
|
||||
expect(titles).toHaveLength(2)
|
||||
})
|
||||
|
||||
const badges = screen.getAllByTestId('file-preview-matched-duration')
|
||||
expect(badges).toHaveLength(2)
|
||||
expect(badges[0].textContent).toBe('00:10 - 00:30')
|
||||
expect(badges[1].textContent).toBe('02:00 - 02:30')
|
||||
})
|
||||
})
|
||||
@@ -8,23 +8,15 @@ import { ScrollArea } from '@/ui/components/ui/scroll-area'
|
||||
import { Input } from '@/ui/components/ui/input'
|
||||
import { Label } from '@/ui/components/ui/label'
|
||||
import { Switch } from '@/ui/components/ui/switch'
|
||||
import { formatSize } from '@/ui/lib/format'
|
||||
import { cn } from '@/ui/lib/utils'
|
||||
import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { useNavigate } from '@tanstack/react-router'
|
||||
import {
|
||||
AlertCircle,
|
||||
ChevronDown,
|
||||
ChevronUp,
|
||||
FileIcon,
|
||||
FolderIcon,
|
||||
Loader2,
|
||||
Search,
|
||||
X,
|
||||
} from 'lucide-react'
|
||||
import { AlertCircle, ChevronDown, ChevronUp, Loader2, Search, X } from 'lucide-react'
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { useInView } from 'react-intersection-observer'
|
||||
import { toast } from 'sonner'
|
||||
import { FileCard } from '@/ui/components/file-browser/file-card'
|
||||
import { FolderCard } from '@/ui/components/file-browser/folder-card'
|
||||
import { FilterPanel } from './filter-panel'
|
||||
import { m } from '@/ui/paraglide/messages.js'
|
||||
|
||||
@@ -225,36 +217,25 @@ export function SearchFilterDialog({
|
||||
setConditions([])
|
||||
}
|
||||
|
||||
const formatTimestamp = (seconds: number) => {
|
||||
const m = Math.floor(seconds / 60)
|
||||
const s = Math.floor(seconds % 60)
|
||||
return `${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}`
|
||||
}
|
||||
|
||||
const handleResultClick = (item: AssetInfo) => {
|
||||
if (item.type === 'folder') {
|
||||
navigate({
|
||||
to: '/projects/$projectId/folders/$folderId',
|
||||
params: { projectId, folderId: item.id! },
|
||||
})
|
||||
window.open(`/projects/${projectId}/folders/${item.id}`, '_blank', 'noopener,noreferrer')
|
||||
} else {
|
||||
navigate({
|
||||
to: '/projects/$projectId/files/$fileId',
|
||||
params: { projectId, fileId: item.versionStack ? item.versionStack.id : item.id! },
|
||||
search: {
|
||||
version: undefined,
|
||||
start: item.startTime && item.startTime > 0 ? item.startTime : undefined,
|
||||
},
|
||||
})
|
||||
const fileId = item.versionStack ? item.versionStack.id : item.id!
|
||||
const searchParams = new URLSearchParams()
|
||||
if (item.startTime !== undefined && item.startTime !== null && item.startTime > 0) {
|
||||
searchParams.set('start', String(item.startTime))
|
||||
}
|
||||
const query = searchParams.toString() ? `?${searchParams.toString()}` : ''
|
||||
window.open(`/projects/${projectId}/files/${fileId}${query}`, '_blank', 'noopener,noreferrer')
|
||||
}
|
||||
onOpenChange(false)
|
||||
}
|
||||
|
||||
const activeFiltersCount = conditions.filter((c) => c.value !== '').length
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-[900px] p-0 gap-0 overflow-hidden bg-background border-border rounded-2xl shadow-2xl flex flex-col h-[85vh]">
|
||||
<DialogContent className="sm:max-w-4xl lg:max-w-5xl p-0 gap-0 overflow-hidden bg-background border-border rounded-2xl shadow-2xl flex flex-col h-[85vh]">
|
||||
<DialogHeader className="px-6 pt-3 pb-0 text-left">
|
||||
<DialogTitle className="text-lg font-bold">{m.search_dialog_title()}</DialogTitle>
|
||||
</DialogHeader>
|
||||
@@ -394,121 +375,94 @@ export function SearchFilterDialog({
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col border border-border rounded-xl divide-y divide-border overflow-hidden min-w-0">
|
||||
{!hasActiveCriteria ? (
|
||||
<div className="py-20 text-center flex flex-col items-center justify-center bg-muted/20 px-4">
|
||||
<Search className="w-10 h-10 text-muted-foreground/30 mb-2" />
|
||||
<h3 className="text-sm font-semibold text-foreground/80">
|
||||
{m.ready_to_search()}
|
||||
</h3>
|
||||
<p className="text-xs text-muted-foreground max-w-sm mt-1 mx-auto">
|
||||
{m.type_query_instruction()}
|
||||
{!hasActiveCriteria ? (
|
||||
<div className="border border-border rounded-xl py-20 text-center flex flex-col items-center justify-center bg-muted/20 px-4">
|
||||
<Search className="w-10 h-10 text-muted-foreground/30 mb-2" />
|
||||
<h3 className="text-sm font-semibold text-foreground/80">{m.ready_to_search()}</h3>
|
||||
<p className="text-xs text-muted-foreground max-w-sm mt-1 mx-auto">
|
||||
{m.type_query_instruction()}
|
||||
</p>
|
||||
{isSemantic && (
|
||||
<p className="text-xs text-muted-foreground/80 max-w-md mt-4 mx-auto border-t border-border/60 pt-3">
|
||||
{m.semantic_search_note()}
|
||||
</p>
|
||||
{isSemantic && (
|
||||
<p className="text-xs text-muted-foreground/80 max-w-md mt-4 mx-auto border-t border-border/60 pt-3">
|
||||
{m.semantic_search_note()}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
) : searchError ? (
|
||||
<div className="py-12 px-4 text-center flex flex-col items-center justify-center bg-muted/20">
|
||||
<AlertCircle className="w-10 h-10 text-destructive/50 mb-2" />
|
||||
<h3 className="text-sm font-semibold text-foreground/80">{m.search_failed()}</h3>
|
||||
<p className="text-xs text-muted-foreground max-w-sm mt-1 mx-auto">
|
||||
{searchError.message.includes('Embedding agent not configured')
|
||||
? m.enable_embedding_agent_hint()
|
||||
: searchError.message}
|
||||
</p>
|
||||
</div>
|
||||
) : isLoading ? (
|
||||
Array.from({ length: 3 }).map((_, idx) => (
|
||||
)}
|
||||
</div>
|
||||
) : searchError ? (
|
||||
<div className="border border-border rounded-xl py-12 px-4 text-center flex flex-col items-center justify-center bg-muted/20">
|
||||
<AlertCircle className="w-10 h-10 text-destructive/50 mb-2" />
|
||||
<h3 className="text-sm font-semibold text-foreground/80">{m.search_failed()}</h3>
|
||||
<p className="text-xs text-muted-foreground max-w-sm mt-1 mx-auto">
|
||||
{searchError.message.includes('Embedding agent not configured')
|
||||
? m.enable_embedding_agent_hint()
|
||||
: searchError.message}
|
||||
</p>
|
||||
</div>
|
||||
) : isLoading ? (
|
||||
<div className="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-4">
|
||||
{Array.from({ length: 8 }).map((_, idx) => (
|
||||
<div
|
||||
key={idx}
|
||||
className="p-3.5 flex items-center gap-3 animate-pulse bg-muted/10"
|
||||
className="flex flex-col rounded-xl border border-border bg-card p-2 space-y-2 animate-pulse"
|
||||
>
|
||||
<div className="w-11 h-11 rounded-xl bg-muted shrink-0" />
|
||||
<div className="flex-1 space-y-2">
|
||||
<div className="h-4 bg-muted rounded w-1/3" />
|
||||
<div className="h-3 bg-muted/50 rounded w-1/4" />
|
||||
<div className="aspect-square w-full rounded-lg bg-muted/60" />
|
||||
<div className="p-1 space-y-1.5">
|
||||
<div className="h-4 bg-muted/60 rounded w-3/4" />
|
||||
<div className="h-3 bg-muted/40 rounded w-1/2" />
|
||||
</div>
|
||||
</div>
|
||||
))
|
||||
) : flattenedResults.length === 0 ? (
|
||||
<div className="py-12 px-4 text-center flex flex-col items-center justify-center bg-muted/20">
|
||||
<AlertCircle className="w-10 h-10 text-muted-foreground/30 mb-2" />
|
||||
<h3 className="text-sm font-semibold text-foreground/80">
|
||||
{m.no_records_matched()}
|
||||
</h3>
|
||||
<p className="text-xs text-muted-foreground max-w-sm mt-1 mx-auto">
|
||||
{m.try_adjusting_spelling()}
|
||||
</p>
|
||||
))}
|
||||
</div>
|
||||
) : flattenedResults.length === 0 ? (
|
||||
<div className="border border-border rounded-xl py-12 px-4 text-center flex flex-col items-center justify-center bg-muted/20">
|
||||
<AlertCircle className="w-10 h-10 text-muted-foreground/30 mb-2" />
|
||||
<h3 className="text-sm font-semibold text-foreground/80">
|
||||
{m.no_records_matched()}
|
||||
</h3>
|
||||
<p className="text-xs text-muted-foreground max-w-sm mt-1 mx-auto">
|
||||
{m.try_adjusting_spelling()}
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-4">
|
||||
{flattenedResults.map((record) => {
|
||||
const itemKey =
|
||||
record.startTime != null && record.endTime != null
|
||||
? `${record.id}-${record.startTime}-${record.endTime}`
|
||||
: record.id
|
||||
if (record.type === 'folder') {
|
||||
return (
|
||||
<FolderCard
|
||||
key={itemKey}
|
||||
item={record}
|
||||
hideCheckbox
|
||||
hideActions
|
||||
disabled
|
||||
onSelect={() => handleResultClick(record)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<FileCard
|
||||
key={itemKey}
|
||||
teamId={teamId}
|
||||
item={record}
|
||||
hideCheckbox
|
||||
hideActions
|
||||
disabled
|
||||
onSelect={() => handleResultClick(record)}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
{flattenedResults.map((record) => (
|
||||
<div
|
||||
key={record.id}
|
||||
onClick={() => handleResultClick(record)}
|
||||
className="p-3.5 flex items-center gap-3 hover:bg-muted/40 transition-colors group/record cursor-pointer min-w-0"
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
'shrink-0 w-11 h-11 rounded-xl shadow-xs flex items-center justify-center text-white font-bold relative group-hover/record:scale-105 transition-transform bg-muted overflow-hidden',
|
||||
record.type === 'folder' ? 'bg-primary/5' : '',
|
||||
)}
|
||||
>
|
||||
{record.preview?.thumbnailUrl ? (
|
||||
<img
|
||||
src={record.preview.thumbnailUrl}
|
||||
alt=""
|
||||
className="w-full h-full object-cover rounded-xl"
|
||||
/>
|
||||
) : record.type === 'folder' ? (
|
||||
<FolderIcon className="h-6 w-6 text-primary/70" />
|
||||
) : (
|
||||
<FileIcon className="h-6 w-6 text-muted-foreground" />
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center justify-between gap-3 min-w-0">
|
||||
<div className="flex-1 min-w-0">
|
||||
<span className="font-medium text-sm text-foreground group-hover/record:text-primary transition-colors block truncate">
|
||||
{record.name}
|
||||
</span>
|
||||
<span className="text-xs text-muted-foreground block mt-0.5 truncate">
|
||||
{record.type === 'folder'
|
||||
? m.folder()
|
||||
: `${m.size_prefix()} ${formatSize(record.sizeByte || 0)}`}
|
||||
</span>
|
||||
{record.startTime !== undefined &&
|
||||
record.startTime !== null &&
|
||||
record.endTime !== undefined &&
|
||||
record.endTime !== null && (
|
||||
<span className="text-[10px] font-semibold text-primary bg-primary/10 border border-primary/20 px-1.5 py-0.5 rounded mt-1 inline-block max-w-full truncate">
|
||||
{m.match_found_at()} {formatTimestamp(record.startTime)} -{' '}
|
||||
{formatTimestamp(record.endTime)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<span className="text-xs text-muted-foreground font-mono shrink-0">
|
||||
{new Date(record.createdAt).toLocaleDateString(undefined, {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
})}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{(hasNextPage || isFetchingNextPage) && (
|
||||
<div ref={ref} className="p-4 flex justify-center items-center">
|
||||
<Loader2 className="h-6 w-6 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
{(hasNextPage || isFetchingNextPage) && (
|
||||
<div ref={ref} className="p-4 flex justify-center items-center">
|
||||
<Loader2 className="h-6 w-6 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
|
||||
|
||||
@@ -155,4 +155,19 @@ describe('SpriteScrubber', () => {
|
||||
fireEvent.mouseMove(scrubberVideo, { clientX: 25 })
|
||||
expect(scrubberVideo.getAttribute('data-frame')).toBe('25')
|
||||
})
|
||||
|
||||
it('renders with cursor-pointer instead of cursor-crosshair for cards', () => {
|
||||
const { getByTestId } = render(
|
||||
<SpriteScrubber
|
||||
spriteUrl="https://example.com/sprite.webp"
|
||||
thumbnailUrl="https://example.com/thumb.webp"
|
||||
videoWidth={1920}
|
||||
videoHeight={1080}
|
||||
/>,
|
||||
)
|
||||
|
||||
const scrubber = getByTestId('sprite-scrubber')
|
||||
expect(scrubber.className).toContain('cursor-pointer')
|
||||
expect(scrubber.className).not.toContain('cursor-crosshair')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -165,7 +165,7 @@ export const SpriteScrubber: React.FC<SpriteScrubberProps> = ({
|
||||
ref={containerRef}
|
||||
data-testid="sprite-scrubber"
|
||||
data-frame={currentFrame}
|
||||
className={`relative w-full h-full overflow-hidden cursor-crosshair group bg-black select-none ${className}`}
|
||||
className={`relative w-full h-full overflow-hidden cursor-pointer group bg-black select-none ${className}`}
|
||||
onMouseEnter={handleMouseEnter}
|
||||
onMouseLeave={handleMouseLeave}
|
||||
onMouseMove={handleMouseMove}
|
||||
|
||||
Reference in New Issue
Block a user