feat(collection): support source folder and selector in collections

This commit is contained in:
yiling
2026-05-25 20:26:03 +08:00
parent 00dc7f7bda
commit 5037b27d81
10 changed files with 238 additions and 131 deletions
+96 -35
View File
@@ -1,6 +1,7 @@
import { type FieldInfo as MetadataFieldInfo } from '@/dtos/metadata'
import type { SearchCondition, SearchSort } from '@/dtos/search'
import type { CollectionInfo } from '@/dtos/collection'
import type { AssetInfo } from '@/dtos/asset'
import { client } from '@/ui/api/client'
import { useMutation, useQuery } from '@tanstack/react-query'
import type { InferRequestType, InferResponseType } from 'hono/client'
@@ -11,6 +12,7 @@ import { MembersDialog } from '../members-dialog'
import { SearchFilterDialog } from '../search/search-filter-dialog'
import { FilterPanel } from '../search/filter-panel'
import { SortControl } from '../search/sort-control'
import { FolderTree } from '../folder-tree'
import { Avatar, AvatarFallback } from '../ui/avatar'
import { Button } from '../ui/button'
import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover'
@@ -48,10 +50,23 @@ export function FileBrowserToolbar({
const [searchDialogOpen, setSearchDialogOpen] = useState(false)
const [manageDialogOpen, setManageDialogOpen] = useState(false)
const [isMembersDialogOpen, setIsMembersDialogOpen] = useState(false)
const [isFolderSelectorOpen, setIsFolderSelectorOpen] = useState(false)
const activeFiltersCount = filterConditions.length
const isCollection = !!collection
const { data: folderInfo } = useQuery({
queryKey: ['folders', teamId, assetId],
queryFn: async () => {
const res = await client.api.teams[':teamId'].folders[':folderId'].$get({
param: { teamId: teamId, folderId: assetId },
})
if (!res.ok) throw new Error('failed to fetch folder')
return (await res.json()) as unknown as AssetInfo
},
enabled: isCollection && !!teamId && !!assetId,
})
const { data: members } = useQuery({
queryKey: ['projects', projectId, 'members'],
queryFn: async () => {
@@ -156,41 +171,87 @@ export function FileBrowserToolbar({
<Separator orientation="vertical" />
{isCollection ? (
<Popover>
<PopoverTrigger asChild>
<Button
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>Filter</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>
</PopoverTrigger>
<PopoverContent className="w-[500px] p-0 overflow-hidden" align="start">
<div className="max-h-[80vh] overflow-y-auto">
<FilterPanel
fields={fields}
conditions={filterConditions}
onChange={(newConditions) => {
onFilterChange(newConditions)
onUpdateCollection?.({
filter: {
...collection.filter,
conditions: newConditions,
},
})
}}
excludeFields={[]}
hidePrefix
/>
</div>
</PopoverContent>
</Popover>
<>
<Popover open={isFolderSelectorOpen} onOpenChange={setIsFolderSelectorOpen}>
<PopoverTrigger asChild>
<Button
variant="ghost"
size="sm"
className="inline-flex items-center gap-2 px-3 py-2 hover:bg-primary/10 font-semibold rounded-xl cursor-pointer h-8 text-muted-foreground"
>
<span className="truncate max-w-[150px]">{folderInfo?.name || 'Loading...'}</span>
</Button>
</PopoverTrigger>
<PopoverContent className="w-[300px] p-0" align="start">
<div className="h-[400px] flex flex-col">
<div className="p-2 border-b text-xs font-semibold text-muted-foreground uppercase tracking-wider">
Select Source Folder
</div>
<div className="flex-1 overflow-y-auto">
<FolderTree
teamId={teamId}
projectId={projectId}
projectName=""
rootFolderId={collection.filter.sourceFolderId} // This is not ideal but FolderTree handles subtrees
onSelect={(folder: AssetInfo) => {
onUpdateCollection?.({
filter: {
...collection.filter,
sourceFolderId: folder.id,
},
})
setIsFolderSelectorOpen(false)
}}
selectedFolderId={assetId}
hideCollections
hideShares
/>
</div>
</div>
</PopoverContent>
</Popover>
<Separator orientation="vertical" />
<Popover>
<PopoverTrigger asChild>
<Button
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>Filter</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>
</PopoverTrigger>
<PopoverContent className="w-[500px] p-0 overflow-hidden" align="start">
<div className="max-h-[80vh] overflow-y-auto">
<FilterPanel
fields={fields}
conditions={filterConditions}
onChange={(newConditions) => {
onFilterChange(newConditions)
onUpdateCollection?.({
filter: {
...collection.filter,
searchFilter: {
...collection.filter.searchFilter,
conditions: newConditions,
},
},
})
}}
excludeFields={[]}
hidePrefix
/>
</div>
</PopoverContent>
</Popover>
</>
) : (
<Button
onClick={() => setSearchDialogOpen(true)}