mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-23 11:46:53 +00:00
Merge pull request #17 from shumaiOne/feat/search-filter-redesign
feat(search): redesign search filter UI
This commit is contained in:
@@ -13,6 +13,7 @@ import { Download } from 'lucide-react'
|
||||
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { useInView } from 'react-intersection-observer'
|
||||
import { toast } from 'sonner'
|
||||
import { formatSize } from '@/ui/lib/format'
|
||||
import type { DragState } from '../dnd-types'
|
||||
import { FileBrowserContextMenu } from './context-menu'
|
||||
import { useNavigate } from '@tanstack/react-router'
|
||||
@@ -395,12 +396,6 @@ export function FileBrowser({
|
||||
return `${count} ${isFile ? 'Asset' : 'Folder'}${count !== 1 ? 's' : ''}`
|
||||
}
|
||||
|
||||
const formatSize = (bytes: number) => {
|
||||
if (bytes < 1024) return `${bytes} B`
|
||||
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(0)} KB`
|
||||
return `${(bytes / (1024 * 1024)).toFixed(0)} MB`
|
||||
}
|
||||
|
||||
const handleEmptyAreaClick = (e: React.MouseEvent) => {
|
||||
const target = e.target as HTMLElement
|
||||
// Clear selection if we didn't click on a card/row, button, or other interactive element
|
||||
@@ -741,7 +736,9 @@ export function FileBrowser({
|
||||
>
|
||||
{!isShareView && !isPublic && onFilterChange && onSortChange && (
|
||||
<FileBrowserToolbar
|
||||
teamId={teamId}
|
||||
projectId={projectId}
|
||||
assetId={assetId}
|
||||
fields={fields || []}
|
||||
filterConditions={filterConditions || []}
|
||||
onFilterChange={onFilterChange}
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
import type { SearchCondition, SearchSort } from '@/dtos/search'
|
||||
import { type FieldInfo as MetadataFieldInfo } from '@/dtos/metadata'
|
||||
import type { SearchCondition, SearchSort } from '@/dtos/search'
|
||||
import { client } from '@/ui/api/client'
|
||||
import { useMutation, useQuery } from '@tanstack/react-query'
|
||||
import type { InferRequestType, InferResponseType } from 'hono/client'
|
||||
import { useState } from 'react'
|
||||
import { FieldsManager } from '../fields-manager'
|
||||
import { ManageFieldsDialog } from '../manage-fields-dialog'
|
||||
import { MembersDialog } from '../members-dialog'
|
||||
import { FilterPanel } from '../search/filter-panel'
|
||||
import { SearchFilterDialog } from '../search/search-filter-dialog'
|
||||
import { SortControl } from '../search/sort-control'
|
||||
import { Avatar, AvatarFallback } from '../ui/avatar'
|
||||
import { Button } from '../ui/button'
|
||||
import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover'
|
||||
import { ListFilter, SlidersHorizontal } from 'lucide-react'
|
||||
import { useState } from 'react'
|
||||
import { Separator } from '../ui/separator'
|
||||
|
||||
type FileBrowserToolbarProps = {
|
||||
teamId: string
|
||||
projectId: string
|
||||
assetId: string
|
||||
fields: MetadataFieldInfo[]
|
||||
filterConditions: SearchCondition[]
|
||||
onFilterChange: (conditions: SearchCondition[]) => void
|
||||
@@ -26,7 +27,9 @@ type FileBrowserToolbarProps = {
|
||||
}
|
||||
|
||||
export function FileBrowserToolbar({
|
||||
teamId,
|
||||
projectId,
|
||||
assetId,
|
||||
fields,
|
||||
filterConditions,
|
||||
onFilterChange,
|
||||
@@ -35,10 +38,12 @@ export function FileBrowserToolbar({
|
||||
isRecentlyDeleted,
|
||||
}: FileBrowserToolbarProps) {
|
||||
const [popoverOpen, setPopoverOpen] = useState(false)
|
||||
const [filterPopoverOpen, setFilterPopoverOpen] = useState(false)
|
||||
const [searchDialogOpen, setSearchDialogOpen] = useState(false)
|
||||
const [manageDialogOpen, setManageDialogOpen] = useState(false)
|
||||
const [isMembersDialogOpen, setIsMembersDialogOpen] = useState(false)
|
||||
|
||||
const activeFiltersCount = filterConditions.length
|
||||
|
||||
const { data: members } = useQuery({
|
||||
queryKey: ['projects', projectId, 'members'],
|
||||
queryFn: async () => {
|
||||
@@ -119,7 +124,6 @@ export function FileBrowserToolbar({
|
||||
<PopoverTrigger asChild>
|
||||
<div>
|
||||
<Button variant="ghost" size="sm">
|
||||
<SlidersHorizontal className="h-4 w-4 mr-2" />
|
||||
Fields
|
||||
</Button>
|
||||
</div>
|
||||
@@ -132,29 +136,7 @@ export function FileBrowserToolbar({
|
||||
/>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
<Separator orientation="vertical" />
|
||||
|
||||
<Popover open={filterPopoverOpen} onOpenChange={setFilterPopoverOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<Button
|
||||
variant={filterConditions.length > 0 ? 'secondary' : 'ghost'}
|
||||
size="sm"
|
||||
className="h-8"
|
||||
disabled={isRecentlyDeleted}
|
||||
>
|
||||
<ListFilter className="h-4 w-4 mr-1" />
|
||||
Filter
|
||||
{filterConditions.length > 0 && (
|
||||
<span className="ml-1 rounded-full bg-primary/20 px-1.5 py-0.5 text-[10px]">
|
||||
{filterConditions.length}
|
||||
</span>
|
||||
)}
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-auto p-0" align="center">
|
||||
<FilterPanel fields={fields} conditions={filterConditions} onChange={onFilterChange} />
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
<Separator orientation="vertical" />
|
||||
<SortControl
|
||||
fields={fields}
|
||||
@@ -162,6 +144,23 @@ export function FileBrowserToolbar({
|
||||
onSortChange={onSortChange}
|
||||
disabled={isRecentlyDeleted}
|
||||
/>
|
||||
|
||||
<Separator orientation="vertical" />
|
||||
|
||||
<Button
|
||||
onClick={() => setSearchDialogOpen(true)}
|
||||
disabled={isRecentlyDeleted}
|
||||
variant={activeFiltersCount > 0 ? 'secondary' : 'ghost'}
|
||||
size="sm"
|
||||
className="inline-flex items-center gap-2 px-4 py-2 hover:bg-primary/10 font-semibold rounded-xl cursor-pointer h-8"
|
||||
>
|
||||
<span>Search</span>
|
||||
{activeFiltersCount > 0 && (
|
||||
<span className="ml-1 px-1.5 py-0.5 rounded-full text-[10px] font-mono font-bold bg-primary/50 border border-primary-foreground/20">
|
||||
{activeFiltersCount}
|
||||
</span>
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
@@ -198,6 +197,17 @@ export function FileBrowserToolbar({
|
||||
isOwner={me?.role === 'owner'}
|
||||
onInvite={handleInvite}
|
||||
/>
|
||||
|
||||
<SearchFilterDialog
|
||||
open={searchDialogOpen}
|
||||
onOpenChange={setSearchDialogOpen}
|
||||
teamId={teamId}
|
||||
projectId={projectId}
|
||||
assetId={assetId}
|
||||
fields={fields}
|
||||
initialConditions={filterConditions}
|
||||
onApply={onFilterChange}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ interface FilterPanelProps {
|
||||
conditions: SearchCondition[]
|
||||
onChange: (conditions: SearchCondition[]) => void
|
||||
className?: string
|
||||
excludeFields?: string[]
|
||||
hidePrefix?: boolean
|
||||
}
|
||||
|
||||
const SYSTEM_FIELDS = [
|
||||
@@ -27,7 +29,14 @@ const SYSTEM_FIELDS = [
|
||||
{ id: 'sizeByte', label: 'Size', type: 'number' },
|
||||
]
|
||||
|
||||
export function FilterPanel({ fields, conditions, onChange, className }: FilterPanelProps) {
|
||||
export function FilterPanel({
|
||||
fields,
|
||||
conditions,
|
||||
onChange,
|
||||
className,
|
||||
excludeFields,
|
||||
hidePrefix,
|
||||
}: FilterPanelProps) {
|
||||
const allFields = [
|
||||
...SYSTEM_FIELDS,
|
||||
...fields.map((f) => ({
|
||||
@@ -36,14 +45,14 @@ export function FilterPanel({ fields, conditions, onChange, className }: FilterP
|
||||
type: getFieldType(f),
|
||||
options: f.config?.select?.options,
|
||||
})),
|
||||
]
|
||||
].filter((f) => !excludeFields?.includes(f.id))
|
||||
|
||||
const handleAddCondition = () => {
|
||||
onChange([
|
||||
...conditions,
|
||||
{
|
||||
field: 'name',
|
||||
operator: 'contains',
|
||||
field: allFields[0]?.id || 'name',
|
||||
operator: 'eq',
|
||||
value: '',
|
||||
},
|
||||
])
|
||||
@@ -75,9 +84,11 @@ export function FilterPanel({ fields, conditions, onChange, className }: FilterP
|
||||
<div className={cn('p-2 space-y-4 min-w-[100px]', className)}>
|
||||
{conditions.map((condition, index) => (
|
||||
<div key={index} className="flex items-center gap-2">
|
||||
<div className="w-16 text-sm text-muted-foreground font-medium text-right">
|
||||
{index === 0 ? 'Where' : 'and'}
|
||||
</div>
|
||||
{!hidePrefix && (
|
||||
<div className="w-16 text-sm text-muted-foreground font-medium text-right">
|
||||
{index === 0 ? 'Where' : 'and'}
|
||||
</div>
|
||||
)}
|
||||
<div className="flex-1 flex items-center gap-2">
|
||||
<Select
|
||||
value={condition.field}
|
||||
|
||||
@@ -0,0 +1,357 @@
|
||||
import { type AssetInfo } from '@/dtos/asset'
|
||||
import { type FieldInfo as MetadataFieldInfo } from '@/dtos/metadata'
|
||||
import type { SearchCondition } from '@/dtos/search'
|
||||
import { client } from '@/ui/api/client'
|
||||
import { Button } from '@/ui/components/ui/button'
|
||||
import { Dialog, DialogContent } from '@/ui/components/ui/dialog'
|
||||
import { Input } from '@/ui/components/ui/input'
|
||||
import { formatSize } from '@/ui/lib/format'
|
||||
import { cn } from '@/ui/lib/utils'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { useNavigate } from '@tanstack/react-router'
|
||||
import {
|
||||
AlertCircle,
|
||||
ChevronDown,
|
||||
ChevronUp,
|
||||
FileIcon,
|
||||
FolderIcon,
|
||||
Loader2,
|
||||
Search,
|
||||
X,
|
||||
} from 'lucide-react'
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { FilterPanel } from './filter-panel'
|
||||
|
||||
interface SearchFilterDialogProps {
|
||||
open: boolean
|
||||
onOpenChange: (open: boolean) => void
|
||||
teamId: string
|
||||
projectId: string
|
||||
assetId: string
|
||||
fields: MetadataFieldInfo[]
|
||||
initialConditions: SearchCondition[]
|
||||
onApply: (conditions: SearchCondition[]) => void
|
||||
}
|
||||
|
||||
export function SearchFilterDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
teamId,
|
||||
projectId,
|
||||
assetId,
|
||||
fields,
|
||||
initialConditions,
|
||||
onApply,
|
||||
}: SearchFilterDialogProps) {
|
||||
const navigate = useNavigate()
|
||||
|
||||
const initialKeyword = useMemo(() => {
|
||||
const cond = initialConditions.find((c) => c.field === 'name' && c.operator === 'contains')
|
||||
return cond ? String(cond.value) : ''
|
||||
}, [initialConditions])
|
||||
|
||||
const initialOtherConditions = useMemo(() => {
|
||||
return initialConditions.filter((c) => !(c.field === 'name' && c.operator === 'contains'))
|
||||
}, [initialConditions])
|
||||
|
||||
const [conditions, setConditions] = useState<SearchCondition[]>(initialOtherConditions)
|
||||
const [isFiltersExpanded, setIsFiltersExpanded] = useState(true)
|
||||
const [searchInput, setSearchInput] = useState(initialKeyword)
|
||||
const [debouncedSearchInput, setDebouncedSearchInput] = useState(initialKeyword)
|
||||
|
||||
// Sync back if changed from outside
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
setSearchInput(initialKeyword)
|
||||
setDebouncedSearchInput(initialKeyword)
|
||||
setConditions(initialOtherConditions)
|
||||
}
|
||||
}, [open, initialKeyword, initialOtherConditions])
|
||||
|
||||
// Debounce search input
|
||||
useEffect(() => {
|
||||
const timer = setTimeout(() => {
|
||||
setDebouncedSearchInput(searchInput)
|
||||
}, 300)
|
||||
return () => clearTimeout(timer)
|
||||
}, [searchInput])
|
||||
|
||||
const combinedConditions = useMemo(() => {
|
||||
const result: SearchCondition[] = [...conditions]
|
||||
if (debouncedSearchInput.trim()) {
|
||||
result.push({
|
||||
field: 'name',
|
||||
operator: 'contains',
|
||||
value: debouncedSearchInput.trim(),
|
||||
})
|
||||
}
|
||||
return result
|
||||
}, [debouncedSearchInput, conditions])
|
||||
|
||||
const hasActiveCriteria = useMemo(() => {
|
||||
return (
|
||||
debouncedSearchInput.trim() !== '' ||
|
||||
conditions.some((c) => String(c.value || '').trim() !== '')
|
||||
)
|
||||
}, [debouncedSearchInput, conditions])
|
||||
|
||||
const { data: searchResults, isLoading } = useQuery({
|
||||
queryKey: ['search-preview', teamId, assetId, combinedConditions],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.teams[':teamId'].folders[':folderId'].search.$post({
|
||||
param: { teamId, folderId: assetId },
|
||||
json: {
|
||||
assetType: undefined,
|
||||
conditions: combinedConditions,
|
||||
recursively: true,
|
||||
first: 20,
|
||||
},
|
||||
})
|
||||
if (!res.ok) throw new Error('Search failed')
|
||||
return (await res.json()) as { data: AssetInfo[] }
|
||||
},
|
||||
enabled: open && hasActiveCriteria,
|
||||
staleTime: 500,
|
||||
})
|
||||
|
||||
const handleApply = () => {
|
||||
const finalConditions = [...conditions]
|
||||
if (searchInput.trim()) {
|
||||
finalConditions.push({
|
||||
field: 'name',
|
||||
operator: 'contains',
|
||||
value: searchInput.trim(),
|
||||
})
|
||||
}
|
||||
onApply(finalConditions)
|
||||
onOpenChange(false)
|
||||
}
|
||||
|
||||
const handleClearFilters = () => {
|
||||
setConditions([])
|
||||
setSearchInput('')
|
||||
}
|
||||
|
||||
const handleResultClick = (item: AssetInfo) => {
|
||||
if (item.type === 'folder') {
|
||||
navigate({
|
||||
to: '/projects/$projectId/folders/$folderId',
|
||||
params: { projectId, folderId: item.id! },
|
||||
})
|
||||
} else {
|
||||
navigate({
|
||||
to: '/projects/$projectId/files/$fileId',
|
||||
params: { projectId, fileId: item.versionStack ? item.versionStack.id : item.id! },
|
||||
search: { version: undefined },
|
||||
})
|
||||
}
|
||||
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 max-h-[90vh]">
|
||||
<div className="p-5 pt-8 border-b border-border bg-muted/30 flex flex-col gap-3">
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault()
|
||||
handleApply()
|
||||
}}
|
||||
className="relative mt-2"
|
||||
>
|
||||
<Input
|
||||
value={searchInput}
|
||||
onChange={(e) => setSearchInput(e.target.value)}
|
||||
placeholder="Search records by name..."
|
||||
className="w-full pl-4 pr-24 py-3 bg-background border-border rounded-xl text-sm h-12 focus-visible:ring-2 focus-visible:ring-primary/20 shadow-sm"
|
||||
/>
|
||||
{searchInput && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setSearchInput('')}
|
||||
className="absolute right-20 top-1/2 -translate-y-1/2 p-1 rounded-md text-muted-foreground hover:text-foreground transition-colors"
|
||||
>
|
||||
<X className="w-4 h-4" />
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
type="submit"
|
||||
className="absolute right-1.5 top-1.5 bottom-1.5 px-4 bg-primary hover:bg-primary/90 text-primary-foreground text-xs font-semibold rounded-lg flex items-center justify-center transition-colors shadow-sm"
|
||||
>
|
||||
Search
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div
|
||||
onClick={() => setIsFiltersExpanded(!isFiltersExpanded)}
|
||||
className="flex items-center justify-between py-1.5 px-1 mt-1 rounded-lg hover:bg-accent/50 cursor-pointer select-none transition-colors group"
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
{isFiltersExpanded ? (
|
||||
<ChevronUp className="w-4 h-4 text-muted-foreground group-hover:text-foreground" />
|
||||
) : (
|
||||
<ChevronDown className="w-4 h-4 text-muted-foreground group-hover:text-foreground" />
|
||||
)}
|
||||
<span className="text-xs font-semibold text-foreground/80">Filters</span>
|
||||
|
||||
{activeFiltersCount > 0 && (
|
||||
<span className="px-1.5 py-0.5 rounded-full text-[10px] font-mono font-bold bg-primary/10 text-primary border border-primary/20">
|
||||
{activeFiltersCount} active
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{(activeFiltersCount > 0 || searchInput) && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
handleClearFilters()
|
||||
}}
|
||||
className="text-[11px] font-medium text-destructive hover:text-destructive/80 underline underline-offset-2 transition-colors"
|
||||
>
|
||||
Reset
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{isFiltersExpanded && (
|
||||
<div className="mt-1 p-4 bg-muted/40 border border-border rounded-xl flex flex-col gap-3 animate-in slide-in-from-top-1 duration-200">
|
||||
<FilterPanel
|
||||
fields={fields}
|
||||
conditions={conditions}
|
||||
onChange={setConditions}
|
||||
excludeFields={['name']}
|
||||
hidePrefix={true}
|
||||
className="p-0 bg-transparent space-y-2"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Results Body ported from Demo */}
|
||||
<div className="flex-1 overflow-y-auto p-4 md:p-5 bg-background">
|
||||
<div className="flex items-center justify-between mb-3 px-1">
|
||||
<span className="text-[11px] font-bold uppercase tracking-wider text-muted-foreground/60 font-mono">
|
||||
Search Results
|
||||
</span>
|
||||
{isLoading && (
|
||||
<span className="inline-flex items-center gap-1.5 text-xs text-primary">
|
||||
<Loader2 className="h-3 w-3 animate-spin" />
|
||||
Querying database...
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col border border-border rounded-xl divide-y divide-border overflow-hidden">
|
||||
{!hasActiveCriteria ? (
|
||||
<div className="py-20 text-center flex flex-col items-center justify-center bg-muted/20">
|
||||
<Search className="w-10 h-10 text-muted-foreground/30 mb-2" />
|
||||
<h3 className="text-sm font-semibold text-foreground/80">Ready to Search</h3>
|
||||
<p className="text-xs text-muted-foreground max-w-sm mt-1 mx-auto">
|
||||
Enter a name or add a filter rule to start discovering assets.
|
||||
</p>
|
||||
</div>
|
||||
) : isLoading ? (
|
||||
Array.from({ length: 3 }).map((_, idx) => (
|
||||
<div key={idx} className="p-3.5 flex items-center gap-3 animate-pulse bg-muted/10">
|
||||
<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>
|
||||
</div>
|
||||
))
|
||||
) : searchResults?.data?.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">
|
||||
No records matched your criteria
|
||||
</h3>
|
||||
<p className="text-xs text-muted-foreground max-w-sm mt-1 mx-auto">
|
||||
Try adjusting spelling or removing filter rows.
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
searchResults?.data?.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"
|
||||
>
|
||||
<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">
|
||||
<div className="truncate">
|
||||
<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'
|
||||
? 'Folder'
|
||||
: `Size: ${formatSize(record.sizeByte || 0)}`}
|
||||
</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>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Footer ported from Demo */}
|
||||
<div className="p-4 border-t border-border bg-muted/30 flex items-center justify-between shrink-0">
|
||||
<div className="text-xs text-muted-foreground flex items-center gap-2">
|
||||
<span>
|
||||
Matched{' '}
|
||||
<strong className="font-mono font-bold text-foreground">
|
||||
{searchResults?.data?.length || 0}
|
||||
</strong>{' '}
|
||||
items
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="xs"
|
||||
className="h-8 text-[10px] font-semibold uppercase tracking-wider"
|
||||
onClick={() => {
|
||||
// Future implementation for saving collections
|
||||
}}
|
||||
>
|
||||
Save as collection
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { SearchSort } from '@/dtos/search'
|
||||
import { type FieldInfo as MetadataFieldInfo } from '@/dtos/metadata'
|
||||
import type { SearchSort } from '@/dtos/search'
|
||||
import { Button } from '@/ui/components/ui/button'
|
||||
import { Popover, PopoverContent, PopoverTrigger } from '@/ui/components/ui/popover'
|
||||
import {
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/ui/components/ui/select'
|
||||
import { ArrowDownWideNarrow } from 'lucide-react'
|
||||
|
||||
interface SortControlProps {
|
||||
fields: MetadataFieldInfo[]
|
||||
@@ -79,7 +78,6 @@ export function SortControl({ fields, sort, onSortChange, disabled }: SortContro
|
||||
className="h-8"
|
||||
disabled={disabled}
|
||||
>
|
||||
<ArrowDownWideNarrow className="h-4 w-4 mr-1" />
|
||||
{sort ? `Sorted by ${currentField.label}` : 'Sort by'}
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
export function formatSize(bytes: number): string {
|
||||
if (bytes === 0) return '0 B'
|
||||
const k = 1024
|
||||
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i]
|
||||
}
|
||||
Reference in New Issue
Block a user