From 73cd87a261e95aebe73f5f6069b04208dfa64ad3 Mon Sep 17 00:00:00 2001 From: yiling Date: Mon, 25 May 2026 15:26:19 +0800 Subject: [PATCH] fix(search): address code review feedback on colors, race conditions, and utilities --- .../components/file-browser/file-browser.tsx | 7 +- src/ui/components/file-browser/toolbar.tsx | 13 +- .../search/search-filter-dialog.tsx | 146 +++++++----------- src/ui/components/search/sort-control.tsx | 13 +- src/ui/lib/format.ts | 7 + 5 files changed, 77 insertions(+), 109 deletions(-) create mode 100644 src/ui/lib/format.ts diff --git a/src/ui/components/file-browser/file-browser.tsx b/src/ui/components/file-browser/file-browser.tsx index b654b548..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 diff --git a/src/ui/components/file-browser/toolbar.tsx b/src/ui/components/file-browser/toolbar.tsx index 52873545..9d877cf2 100644 --- a/src/ui/components/file-browser/toolbar.tsx +++ b/src/ui/components/file-browser/toolbar.tsx @@ -1,8 +1,9 @@ -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' @@ -11,8 +12,6 @@ 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 { SlidersHorizontal } from 'lucide-react' -import { useState } from 'react' import { Separator } from '../ui/separator' type FileBrowserToolbarProps = { @@ -125,7 +124,6 @@ export function FileBrowserToolbar({
@@ -145,12 +143,11 @@ export function FileBrowserToolbar({ disabled={isRecentlyDeleted} variant={activeFiltersCount > 0 ? 'secondary' : 'ghost'} size="sm" - className="inline-flex items-center gap-2 px-4 py-2 bg-indigo-600 hover:bg-indigo-700 text-white text-xs font-semibold rounded-xl shadow-xs hover:shadow-indigo-500/10 transition-all cursor-pointer h-8" + className="inline-flex items-center gap-2 px-4 py-2 hover:bg-primary/10 font-semibold rounded-xl cursor-pointer h-8" > - - Query Console + Search {activeFiltersCount > 0 && ( - + {activeFiltersCount} )} diff --git a/src/ui/components/search/search-filter-dialog.tsx b/src/ui/components/search/search-filter-dialog.tsx index 76d4af06..3faa0e89 100644 --- a/src/ui/components/search/search-filter-dialog.tsx +++ b/src/ui/components/search/search-filter-dialog.tsx @@ -5,19 +5,19 @@ 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, - SlidersHorizontal, - X, + AlertCircle, + ChevronDown, + ChevronUp, + FileIcon, + FolderIcon, + Loader2, + Search, + X, } from 'lucide-react' import { useEffect, useMemo, useState } from 'react' import { FilterPanel } from './filter-panel' @@ -115,7 +115,15 @@ export function SearchFilterDialog({ }) const handleApply = () => { - onApply(combinedConditions) + const finalConditions = [...conditions] + if (searchInput.trim()) { + finalConditions.push({ + field: 'name', + operator: 'contains', + value: searchInput.trim(), + }) + } + onApply(finalConditions) onOpenChange(false) } @@ -144,31 +152,8 @@ export function SearchFilterDialog({ return ( - - {/* Header Block ported from Demo */} -
-
-
-
- -
-
-

- Advanced Query Console -

-
-

- Refining live workspace directory -

- - - LIVE-DB - -
-
-
-
- + +
{ e.preventDefault() @@ -180,20 +165,20 @@ export function SearchFilterDialog({ value={searchInput} onChange={(e) => setSearchInput(e.target.value)} placeholder="Search records by name..." - className="w-full pl-4 pr-24 py-3 bg-white dark:bg-neutral-900 border border-neutral-300 dark:border-neutral-800 rounded-xl text-sm h-12 focus-visible:ring-2 focus-visible:ring-indigo-500/20 shadow-sm" + 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 && ( )} @@ -201,20 +186,18 @@ export function SearchFilterDialog({
setIsFiltersExpanded(!isFiltersExpanded)} - className="flex items-center justify-between py-1.5 px-1 mt-1 rounded-lg hover:bg-neutral-100/50 dark:hover:bg-neutral-900/50 cursor-pointer select-none transition-colors group" + 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 - + Filters {activeFiltersCount > 0 && ( - + {activeFiltersCount} active )} @@ -227,7 +210,7 @@ export function SearchFilterDialog({ e.stopPropagation() handleClearFilters() }} - className="text-[11px] font-medium text-rose-500 hover:text-rose-600 underline underline-offset-2 transition-colors" + className="text-[11px] font-medium text-destructive hover:text-destructive/80 underline underline-offset-2 transition-colors" > Reset All Criteria @@ -235,7 +218,7 @@ export function SearchFilterDialog({
{isFiltersExpanded && ( -
+
{/* Results Body ported from Demo */} -
+
- + Search Results {isLoading && ( - + Querying database... )}
-
+
{!hasActiveCriteria ? ( -
- -

- Ready to Search -

-

+

+ +

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.

@@ -301,12 +279,12 @@ export function SearchFilterDialog({
handleResultClick(record)} - className="p-3.5 flex items-center gap-3 hover:bg-neutral-50 dark:hover:bg-neutral-900/40 transition-colors group/record cursor-pointer" + className="p-3.5 flex items-center gap-3 hover:bg-muted/40 transition-colors group/record cursor-pointer" >
{record.preview?.thumbnailUrl ? ( @@ -316,25 +294,25 @@ export function SearchFilterDialog({ className="w-full h-full object-cover rounded-xl" /> ) : record.type === 'folder' ? ( - + ) : ( - + )}
- + {record.name} - + {record.type === 'folder' ? 'Folder' - : `Size: ${formatBytes(record.sizeByte || 0)}`} + : `Size: ${formatSize(record.sizeByte || 0)}`}
- + {new Date(record.createdAt).toLocaleDateString(undefined, { year: 'numeric', month: 'short', @@ -349,11 +327,11 @@ export function SearchFilterDialog({
{/* Footer ported from Demo */} -
-
+
+
Matched{' '} - + {searchResults?.data?.length || 0} {' '} items @@ -377,11 +355,3 @@ export function SearchFilterDialog({

) } - -function formatBytes(bytes: number) { - if (bytes === 0) return '0 B' - const k = 1024 - const sizes = ['B', 'KB', 'MB', 'GB'] - const i = Math.floor(Math.log(bytes) / Math.log(k)) - return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i] -} diff --git a/src/ui/components/search/sort-control.tsx b/src/ui/components/search/sort-control.tsx index 079d914f..91eb2b15 100644 --- a/src/ui/components/search/sort-control.tsx +++ b/src/ui/components/search/sort-control.tsx @@ -1,13 +1,13 @@ -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 { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue, + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, } from '@/ui/components/ui/select' import { ArrowDownWideNarrow } from 'lucide-react' @@ -79,7 +79,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] +}