mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-04 15:14:10 +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
|
### 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
|
* **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
|
## [0.5.2] - 2026-10-13
|
||||||
|
|||||||
@@ -441,4 +441,39 @@ describe('FileCard', () => {
|
|||||||
expect(tooltip.textContent).toContain('FFmpeg transcode failed: exit code 1')
|
expect(tooltip.textContent).toContain('FFmpeg transcode failed: exit code 1')
|
||||||
vi.useRealTimers()
|
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 {
|
interface FileCardProps {
|
||||||
teamId?: string
|
teamId?: string
|
||||||
item: AssetInfo
|
item: AssetInfo
|
||||||
isSelected: boolean
|
isSelected?: boolean
|
||||||
isChecked: boolean
|
isChecked?: boolean
|
||||||
isEditing: boolean
|
isEditing?: boolean
|
||||||
onSelect: (item: AssetInfo, event: React.MouseEvent) => void
|
onSelect?: (item: AssetInfo, event: React.MouseEvent) => void
|
||||||
onDoubleClick: (item: AssetInfo) => void
|
onDoubleClick?: (item: AssetInfo) => void
|
||||||
onContextMenu: (e: React.MouseEvent, item: AssetInfo) => void
|
onContextMenu?: (e: React.MouseEvent, item: AssetInfo) => void
|
||||||
// Deprecated manual drag handlers replaced by dnd-kit
|
// Deprecated manual drag handlers replaced by dnd-kit
|
||||||
onDragStart: (item: AssetInfo) => void
|
onDragStart?: (item: AssetInfo) => void
|
||||||
onDrop: (target: AssetInfo) => void
|
onDrop?: (target: AssetInfo) => void
|
||||||
onRename: (newName: string) => void
|
onRename?: (newName: string) => void
|
||||||
onFinishEditing: () => void
|
onFinishEditing?: () => void
|
||||||
onSaveField: (fieldId: string, value: unknown) => void
|
onSaveField?: (fieldId: string, value: unknown) => void
|
||||||
dragState?: DragState
|
dragState?: DragState
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
onAction?: (
|
onAction?: (
|
||||||
@@ -69,39 +69,43 @@ interface FileCardProps {
|
|||||||
isRecentlyDeleted?: boolean
|
isRecentlyDeleted?: boolean
|
||||||
isRecents?: boolean
|
isRecents?: boolean
|
||||||
selectedCount?: number
|
selectedCount?: number
|
||||||
fields: MetadataFieldInfo[]
|
fields?: MetadataFieldInfo[]
|
||||||
isShareView?: boolean
|
isShareView?: boolean
|
||||||
canEdit?: boolean
|
canEdit?: boolean
|
||||||
/** When false, hides the download action. Defaults to true. */
|
/** When false, hides the download action. Defaults to true. */
|
||||||
allowDownload?: boolean
|
allowDownload?: boolean
|
||||||
|
hideCheckbox?: boolean
|
||||||
|
hideActions?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export function FileCard({
|
export function FileCard({
|
||||||
teamId,
|
teamId,
|
||||||
item,
|
item,
|
||||||
isSelected,
|
isSelected = false,
|
||||||
isChecked,
|
isChecked = false,
|
||||||
isEditing,
|
isEditing = false,
|
||||||
onSelect,
|
onSelect = () => {},
|
||||||
onDoubleClick,
|
onDoubleClick = () => {},
|
||||||
onContextMenu,
|
onContextMenu = () => {},
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
onDragStart: _onDragStart,
|
onDragStart: _onDragStart,
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
onDrop: _onDrop,
|
onDrop: _onDrop,
|
||||||
onRename,
|
onRename = () => {},
|
||||||
onFinishEditing,
|
onFinishEditing = () => {},
|
||||||
onSaveField,
|
onSaveField = () => {},
|
||||||
dragState,
|
dragState,
|
||||||
disabled,
|
disabled,
|
||||||
onAction,
|
onAction,
|
||||||
isRecentlyDeleted,
|
isRecentlyDeleted,
|
||||||
isRecents,
|
isRecents,
|
||||||
selectedCount,
|
selectedCount,
|
||||||
fields,
|
fields = [],
|
||||||
isShareView,
|
isShareView,
|
||||||
canEdit = true,
|
canEdit = true,
|
||||||
allowDownload = true,
|
allowDownload = true,
|
||||||
|
hideCheckbox = false,
|
||||||
|
hideActions = false,
|
||||||
}: FileCardProps) {
|
}: FileCardProps) {
|
||||||
const [name, setName] = useState(item.name)
|
const [name, setName] = useState(item.name)
|
||||||
const inputRef = useRef<HTMLInputElement>(null)
|
const inputRef = useRef<HTMLInputElement>(null)
|
||||||
@@ -170,10 +174,12 @@ export function FileCard({
|
|||||||
id: displayItem.id,
|
id: displayItem.id,
|
||||||
item: displayItem,
|
item: displayItem,
|
||||||
},
|
},
|
||||||
|
disabled: disabled,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Combine refs
|
// Combine refs
|
||||||
const setNodeRef = (node: HTMLElement | null) => {
|
const setNodeRef = (node: HTMLElement | null) => {
|
||||||
|
if (disabled) return
|
||||||
setDraggableRef(node)
|
setDraggableRef(node)
|
||||||
setDroppableRef(node)
|
setDroppableRef(node)
|
||||||
}
|
}
|
||||||
@@ -332,17 +338,19 @@ export function FileCard({
|
|||||||
showDropFeedback && 'border-primary outline-1 outline-primary',
|
showDropFeedback && 'border-primary outline-1 outline-primary',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className="absolute left-2 top-2 z-10 flex items-center gap-1.5">
|
{!hideCheckbox && (
|
||||||
<Checkbox
|
<div className="absolute left-2 top-2 z-10 flex items-center gap-1.5">
|
||||||
checked={isChecked}
|
<Checkbox
|
||||||
onCheckedChange={() => {}}
|
checked={isChecked}
|
||||||
onClick={(e) => {
|
onCheckedChange={() => {}}
|
||||||
e.stopPropagation()
|
onClick={(e) => {
|
||||||
onSelect(displayItem, 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"
|
}}
|
||||||
/>
|
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>
|
||||||
|
)}
|
||||||
|
|
||||||
<div className="absolute right-2 top-2 z-10 flex items-center gap-1.5">
|
<div className="absolute right-2 top-2 z-10 flex items-center gap-1.5">
|
||||||
{displayItem.agent && (
|
{displayItem.agent && (
|
||||||
@@ -395,7 +403,15 @@ export function FileCard({
|
|||||||
data-testid="file-card-preview-media"
|
data-testid="file-card-preview-media"
|
||||||
className={cn('h-full w-full', isProcessing && 'animate-pulse')}
|
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>
|
</div>
|
||||||
{previewBadges}
|
{previewBadges}
|
||||||
</>
|
</>
|
||||||
@@ -435,7 +451,15 @@ export function FileCard({
|
|||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<FilePreview item={displayItem} showDuration />
|
<FilePreview
|
||||||
|
item={displayItem}
|
||||||
|
showDuration
|
||||||
|
matchDuration={
|
||||||
|
displayItem.startTime != null && displayItem.endTime != null
|
||||||
|
? { startTime: displayItem.startTime, endTime: displayItem.endTime }
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
/>
|
||||||
{previewBadges}
|
{previewBadges}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
@@ -487,7 +511,7 @@ export function FileCard({
|
|||||||
</Tooltip>
|
</Tooltip>
|
||||||
</TooltipProvider>
|
</TooltipProvider>
|
||||||
</div>
|
</div>
|
||||||
{!isRecents && (
|
{!hideActions && !isRecents && (
|
||||||
<DropdownMenu modal={false}>
|
<DropdownMenu modal={false}>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -20,9 +20,13 @@ type FilePreviewItem = {
|
|||||||
interface FilePreviewProps {
|
interface FilePreviewProps {
|
||||||
item: FilePreviewItem
|
item: FilePreviewItem
|
||||||
showDuration?: boolean
|
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 proxyType = item.preview?.proxyType || item.proxyType
|
||||||
const isVideo = proxyType === 'video'
|
const isVideo = proxyType === 'video'
|
||||||
const isAudio = proxyType === 'audio'
|
const isAudio = proxyType === 'audio'
|
||||||
@@ -32,16 +36,25 @@ export const FilePreview = ({ item, showDuration = false }: FilePreviewProps) =>
|
|||||||
const duration = item.preview?.duration
|
const duration = item.preview?.duration
|
||||||
const pageCount = item.preview?.pageCount
|
const pageCount = item.preview?.pageCount
|
||||||
|
|
||||||
const overlay =
|
const hasMatchedChunk =
|
||||||
showDuration && hasDuration && typeof duration === 'number' && duration > 0 ? (
|
matchDuration != null && matchDuration.startTime != null && matchDuration.endTime != null
|
||||||
<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)}
|
const overlay = hasMatchedChunk ? (
|
||||||
</span>
|
<span
|
||||||
) : showDuration && isPdf && typeof pageCount === 'number' && pageCount > 0 ? (
|
data-testid="file-preview-matched-duration"
|
||||||
<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">
|
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>
|
{formatTime(matchDuration.startTime!)} - {formatTime(matchDuration.endTime!)}
|
||||||
) : null
|
</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 =
|
const isMediaWithSprite =
|
||||||
(isVideo || isPdf || is3D) &&
|
(isVideo || isPdf || is3D) &&
|
||||||
|
|||||||
@@ -96,4 +96,19 @@ describe('FolderCard', () => {
|
|||||||
renderComponent({ item: folderItem, isRecentlyDeleted: true })
|
renderComponent({ item: folderItem, isRecentlyDeleted: true })
|
||||||
expect(screen.queryByTestId('folder-card-days-left')).toBeNull()
|
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 {
|
interface FolderCardProps {
|
||||||
item: AssetInfo
|
item: AssetInfo
|
||||||
isSelected: boolean
|
isSelected?: boolean
|
||||||
isChecked: boolean
|
isChecked?: boolean
|
||||||
isEditing: boolean
|
isEditing?: boolean
|
||||||
onSelect: (item: AssetInfo, event: React.MouseEvent) => void
|
onSelect?: (item: AssetInfo, event: React.MouseEvent) => void
|
||||||
onDoubleClick: (item: AssetInfo) => void
|
onDoubleClick?: (item: AssetInfo) => void
|
||||||
onContextMenu: (e: React.MouseEvent, item: AssetInfo) => void
|
onContextMenu?: (e: React.MouseEvent, item: AssetInfo) => void
|
||||||
// Deprecated manual drag props replaced by dnd-kit
|
// Deprecated manual drag props replaced by dnd-kit
|
||||||
onDragStart: (item: AssetInfo) => void
|
onDragStart?: (item: AssetInfo) => void
|
||||||
onDrop: (target: AssetInfo) => void
|
onDrop?: (target: AssetInfo) => void
|
||||||
onRename: (newName: string) => void
|
onRename?: (newName: string) => void
|
||||||
onFinishEditing: () => void
|
onFinishEditing?: () => void
|
||||||
dragState?: DragState
|
dragState?: DragState
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
onAction?: (
|
onAction?: (
|
||||||
@@ -49,6 +49,8 @@ interface FolderCardProps {
|
|||||||
onExternalDrop?: (files: File[], folderId: string) => void
|
onExternalDrop?: (files: File[], folderId: string) => void
|
||||||
/** When false, hides the download action. Defaults to true. */
|
/** When false, hides the download action. Defaults to true. */
|
||||||
allowDownload?: boolean
|
allowDownload?: boolean
|
||||||
|
hideCheckbox?: boolean
|
||||||
|
hideActions?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const FolderPreviewGrid = ({ items }: { items: ChildPreview[] }) => {
|
const FolderPreviewGrid = ({ items }: { items: ChildPreview[] }) => {
|
||||||
@@ -106,18 +108,18 @@ const FolderPreviewGrid = ({ items }: { items: ChildPreview[] }) => {
|
|||||||
|
|
||||||
export function FolderCard({
|
export function FolderCard({
|
||||||
item,
|
item,
|
||||||
isSelected,
|
isSelected = false,
|
||||||
isChecked,
|
isChecked = false,
|
||||||
isEditing,
|
isEditing = false,
|
||||||
onSelect,
|
onSelect = () => {},
|
||||||
onDoubleClick,
|
onDoubleClick = () => {},
|
||||||
onContextMenu,
|
onContextMenu = () => {},
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
onDragStart: _onDragStart,
|
onDragStart: _onDragStart,
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
onDrop: _onDrop,
|
onDrop: _onDrop,
|
||||||
onRename,
|
onRename = () => {},
|
||||||
onFinishEditing,
|
onFinishEditing = () => {},
|
||||||
dragState,
|
dragState,
|
||||||
disabled,
|
disabled,
|
||||||
onAction,
|
onAction,
|
||||||
@@ -132,6 +134,8 @@ export function FolderCard({
|
|||||||
resetExternalDragState,
|
resetExternalDragState,
|
||||||
onExternalDrop,
|
onExternalDrop,
|
||||||
allowDownload = true,
|
allowDownload = true,
|
||||||
|
hideCheckbox = false,
|
||||||
|
hideActions = false,
|
||||||
}: FolderCardProps) {
|
}: FolderCardProps) {
|
||||||
const [name, setName] = useState(item.name || '')
|
const [name, setName] = useState(item.name || '')
|
||||||
const inputRef = useRef<HTMLInputElement>(null)
|
const inputRef = useRef<HTMLInputElement>(null)
|
||||||
@@ -154,9 +158,11 @@ export function FolderCard({
|
|||||||
id: item.id,
|
id: item.id,
|
||||||
item: item,
|
item: item,
|
||||||
},
|
},
|
||||||
|
disabled: disabled,
|
||||||
})
|
})
|
||||||
|
|
||||||
const setNodeRef = (node: HTMLElement | null) => {
|
const setNodeRef = (node: HTMLElement | null) => {
|
||||||
|
if (disabled) return
|
||||||
setDraggableRef(node)
|
setDraggableRef(node)
|
||||||
setDroppableRef(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="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="relative w-full aspect-video shrink-0 overflow-hidden">
|
||||||
<div className="absolute top-1 left-1 z-30 transition-all duration-200">
|
{!hideCheckbox && (
|
||||||
<Checkbox
|
<div className="absolute top-1 left-1 z-30 transition-all duration-200">
|
||||||
checked={isChecked}
|
<Checkbox
|
||||||
onClick={(e) => e.stopPropagation()} // Let parent handler deal with it
|
checked={isChecked}
|
||||||
className="w-5 h-5 border-1 border-foreground/20 bg-background/50 data-[state=checked]:bg-primary data-[state=checked]:border-primary"
|
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>
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{item.latestChildren && item.latestChildren.length > 0 && (
|
{item.latestChildren && item.latestChildren.length > 0 && (
|
||||||
<div data-testid="folder-preview-grid" className="h-full w-full">
|
<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_singular({ count: item.fileCount || 0 })
|
||||||
: m.n_items_plural({ count: item.fileCount || 0 })}
|
: m.n_items_plural({ count: item.fileCount || 0 })}
|
||||||
</span>
|
</span>
|
||||||
{!isRecents && (
|
{!hideActions && !isRecents && (
|
||||||
<DropdownMenu modal={false}>
|
<DropdownMenu modal={false}>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
<button
|
<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 { Input } from '@/ui/components/ui/input'
|
||||||
import { Label } from '@/ui/components/ui/label'
|
import { Label } from '@/ui/components/ui/label'
|
||||||
import { Switch } from '@/ui/components/ui/switch'
|
import { Switch } from '@/ui/components/ui/switch'
|
||||||
import { formatSize } from '@/ui/lib/format'
|
|
||||||
import { cn } from '@/ui/lib/utils'
|
import { cn } from '@/ui/lib/utils'
|
||||||
import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||||
import { useNavigate } from '@tanstack/react-router'
|
import { useNavigate } from '@tanstack/react-router'
|
||||||
import {
|
import { AlertCircle, ChevronDown, ChevronUp, Loader2, Search, X } from 'lucide-react'
|
||||||
AlertCircle,
|
|
||||||
ChevronDown,
|
|
||||||
ChevronUp,
|
|
||||||
FileIcon,
|
|
||||||
FolderIcon,
|
|
||||||
Loader2,
|
|
||||||
Search,
|
|
||||||
X,
|
|
||||||
} from 'lucide-react'
|
|
||||||
import { useEffect, useMemo, useState } from 'react'
|
import { useEffect, useMemo, useState } from 'react'
|
||||||
import { useInView } from 'react-intersection-observer'
|
import { useInView } from 'react-intersection-observer'
|
||||||
import { toast } from 'sonner'
|
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 { FilterPanel } from './filter-panel'
|
||||||
import { m } from '@/ui/paraglide/messages.js'
|
import { m } from '@/ui/paraglide/messages.js'
|
||||||
|
|
||||||
@@ -225,36 +217,25 @@ export function SearchFilterDialog({
|
|||||||
setConditions([])
|
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) => {
|
const handleResultClick = (item: AssetInfo) => {
|
||||||
if (item.type === 'folder') {
|
if (item.type === 'folder') {
|
||||||
navigate({
|
window.open(`/projects/${projectId}/folders/${item.id}`, '_blank', 'noopener,noreferrer')
|
||||||
to: '/projects/$projectId/folders/$folderId',
|
|
||||||
params: { projectId, folderId: item.id! },
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
navigate({
|
const fileId = item.versionStack ? item.versionStack.id : item.id!
|
||||||
to: '/projects/$projectId/files/$fileId',
|
const searchParams = new URLSearchParams()
|
||||||
params: { projectId, fileId: item.versionStack ? item.versionStack.id : item.id! },
|
if (item.startTime !== undefined && item.startTime !== null && item.startTime > 0) {
|
||||||
search: {
|
searchParams.set('start', String(item.startTime))
|
||||||
version: undefined,
|
}
|
||||||
start: item.startTime && item.startTime > 0 ? item.startTime : undefined,
|
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
|
const activeFiltersCount = conditions.filter((c) => c.value !== '').length
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
<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">
|
<DialogHeader className="px-6 pt-3 pb-0 text-left">
|
||||||
<DialogTitle className="text-lg font-bold">{m.search_dialog_title()}</DialogTitle>
|
<DialogTitle className="text-lg font-bold">{m.search_dialog_title()}</DialogTitle>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
@@ -394,121 +375,94 @@ export function SearchFilterDialog({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-col border border-border rounded-xl divide-y divide-border overflow-hidden min-w-0">
|
{!hasActiveCriteria ? (
|
||||||
{!hasActiveCriteria ? (
|
<div className="border border-border rounded-xl py-20 text-center flex flex-col items-center justify-center bg-muted/20 px-4">
|
||||||
<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" />
|
||||||
<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>
|
||||||
<h3 className="text-sm font-semibold text-foreground/80">
|
<p className="text-xs text-muted-foreground max-w-sm mt-1 mx-auto">
|
||||||
{m.ready_to_search()}
|
{m.type_query_instruction()}
|
||||||
</h3>
|
</p>
|
||||||
<p className="text-xs text-muted-foreground max-w-sm mt-1 mx-auto">
|
{isSemantic && (
|
||||||
{m.type_query_instruction()}
|
<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>
|
</p>
|
||||||
{isSemantic && (
|
)}
|
||||||
<p className="text-xs text-muted-foreground/80 max-w-md mt-4 mx-auto border-t border-border/60 pt-3">
|
</div>
|
||||||
{m.semantic_search_note()}
|
) : searchError ? (
|
||||||
</p>
|
<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" />
|
||||||
</div>
|
<h3 className="text-sm font-semibold text-foreground/80">{m.search_failed()}</h3>
|
||||||
) : searchError ? (
|
<p className="text-xs text-muted-foreground max-w-sm mt-1 mx-auto">
|
||||||
<div className="py-12 px-4 text-center flex flex-col items-center justify-center bg-muted/20">
|
{searchError.message.includes('Embedding agent not configured')
|
||||||
<AlertCircle className="w-10 h-10 text-destructive/50 mb-2" />
|
? m.enable_embedding_agent_hint()
|
||||||
<h3 className="text-sm font-semibold text-foreground/80">{m.search_failed()}</h3>
|
: searchError.message}
|
||||||
<p className="text-xs text-muted-foreground max-w-sm mt-1 mx-auto">
|
</p>
|
||||||
{searchError.message.includes('Embedding agent not configured')
|
</div>
|
||||||
? m.enable_embedding_agent_hint()
|
) : isLoading ? (
|
||||||
: searchError.message}
|
<div className="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-4">
|
||||||
</p>
|
{Array.from({ length: 8 }).map((_, idx) => (
|
||||||
</div>
|
|
||||||
) : isLoading ? (
|
|
||||||
Array.from({ length: 3 }).map((_, idx) => (
|
|
||||||
<div
|
<div
|
||||||
key={idx}
|
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="aspect-square w-full rounded-lg bg-muted/60" />
|
||||||
<div className="flex-1 space-y-2">
|
<div className="p-1 space-y-1.5">
|
||||||
<div className="h-4 bg-muted rounded w-1/3" />
|
<div className="h-4 bg-muted/60 rounded w-3/4" />
|
||||||
<div className="h-3 bg-muted/50 rounded w-1/4" />
|
<div className="h-3 bg-muted/40 rounded w-1/2" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
))
|
))}
|
||||||
) : flattenedResults.length === 0 ? (
|
</div>
|
||||||
<div className="py-12 px-4 text-center flex flex-col items-center justify-center bg-muted/20">
|
) : flattenedResults.length === 0 ? (
|
||||||
<AlertCircle className="w-10 h-10 text-muted-foreground/30 mb-2" />
|
<div className="border border-border rounded-xl py-12 px-4 text-center flex flex-col items-center justify-center bg-muted/20">
|
||||||
<h3 className="text-sm font-semibold text-foreground/80">
|
<AlertCircle className="w-10 h-10 text-muted-foreground/30 mb-2" />
|
||||||
{m.no_records_matched()}
|
<h3 className="text-sm font-semibold text-foreground/80">
|
||||||
</h3>
|
{m.no_records_matched()}
|
||||||
<p className="text-xs text-muted-foreground max-w-sm mt-1 mx-auto">
|
</h3>
|
||||||
{m.try_adjusting_spelling()}
|
<p className="text-xs text-muted-foreground max-w-sm mt-1 mx-auto">
|
||||||
</p>
|
{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>
|
</div>
|
||||||
) : (
|
{(hasNextPage || isFetchingNextPage) && (
|
||||||
<>
|
<div ref={ref} className="p-4 flex justify-center items-center">
|
||||||
{flattenedResults.map((record) => (
|
<Loader2 className="h-6 w-6 animate-spin text-muted-foreground" />
|
||||||
<div
|
</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>
|
|
||||||
</div>
|
</div>
|
||||||
</ScrollArea>
|
</ScrollArea>
|
||||||
|
|
||||||
|
|||||||
@@ -155,4 +155,19 @@ describe('SpriteScrubber', () => {
|
|||||||
fireEvent.mouseMove(scrubberVideo, { clientX: 25 })
|
fireEvent.mouseMove(scrubberVideo, { clientX: 25 })
|
||||||
expect(scrubberVideo.getAttribute('data-frame')).toBe('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}
|
ref={containerRef}
|
||||||
data-testid="sprite-scrubber"
|
data-testid="sprite-scrubber"
|
||||||
data-frame={currentFrame}
|
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}
|
onMouseEnter={handleMouseEnter}
|
||||||
onMouseLeave={handleMouseLeave}
|
onMouseLeave={handleMouseLeave}
|
||||||
onMouseMove={handleMouseMove}
|
onMouseMove={handleMouseMove}
|
||||||
|
|||||||
Reference in New Issue
Block a user