diff --git a/src/ui/components/file-browser/file-browser.tsx b/src/ui/components/file-browser/file-browser.tsx index 44d1da22..be1ff462 100644 --- a/src/ui/components/file-browser/file-browser.tsx +++ b/src/ui/components/file-browser/file-browser.tsx @@ -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 && ( 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({
@@ -132,29 +136,7 @@ export function FileBrowserToolbar({ /> - - - - - - - - - + + + +
@@ -198,6 +197,17 @@ export function FileBrowserToolbar({ isOwner={me?.role === 'owner'} onInvite={handleInvite} /> + +
) } diff --git a/src/ui/components/search/filter-panel.tsx b/src/ui/components/search/filter-panel.tsx index 2bfb5e37..e4808588 100644 --- a/src/ui/components/search/filter-panel.tsx +++ b/src/ui/components/search/filter-panel.tsx @@ -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
{conditions.map((condition, index) => (
-
- {index === 0 ? 'Where' : 'and'} -
+ {!hidePrefix && ( +
+ {index === 0 ? 'Where' : 'and'} +
+ )}
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 && ( + + )} + + + +
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" + > +
+ {isFiltersExpanded ? ( + + ) : ( + + )} + Filters + + {activeFiltersCount > 0 && ( + + {activeFiltersCount} active + + )} +
+ + {(activeFiltersCount > 0 || searchInput) && ( + + )} +
+ + {isFiltersExpanded && ( +
+ +
+ )} +
+ + {/* Results Body ported from Demo */} +
+
+ + Search Results + + {isLoading && ( + + + Querying database... + + )} +
+ +
+ {!hasActiveCriteria ? ( +
+ +

Ready to Search

+

+ Enter a name or add a filter rule to start discovering assets. +

+
+ ) : isLoading ? ( + Array.from({ length: 3 }).map((_, idx) => ( +
+
+
+
+
+
+
+ )) + ) : searchResults?.data?.length === 0 ? ( +
+ +

+ No records matched your criteria +

+

+ Try adjusting spelling or removing filter rows. +

+
+ ) : ( + searchResults?.data?.map((record) => ( +
handleResultClick(record)} + className="p-3.5 flex items-center gap-3 hover:bg-muted/40 transition-colors group/record cursor-pointer" + > +
+ {record.preview?.thumbnailUrl ? ( + + ) : record.type === 'folder' ? ( + + ) : ( + + )} +
+ +
+
+
+ + {record.name} + + + {record.type === 'folder' + ? 'Folder' + : `Size: ${formatSize(record.sizeByte || 0)}`} + +
+ + {new Date(record.createdAt).toLocaleDateString(undefined, { + year: 'numeric', + month: 'short', + })} + +
+
+
+ )) + )} +
+
+ + {/* Footer ported from Demo */} +
+
+ + Matched{' '} + + {searchResults?.data?.length || 0} + {' '} + items + +
+ +
+ +
+
+ + + ) +} diff --git a/src/ui/components/search/sort-control.tsx b/src/ui/components/search/sort-control.tsx index 079d914f..0518cd83 100644 --- a/src/ui/components/search/sort-control.tsx +++ b/src/ui/components/search/sort-control.tsx @@ -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} > - {sort ? `Sorted by ${currentField.label}` : 'Sort by'} diff --git a/src/ui/lib/format.ts b/src/ui/lib/format.ts new file mode 100644 index 00000000..726d90a7 --- /dev/null +++ b/src/ui/lib/format.ts @@ -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] +}