mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-27 19:34:38 +00:00
feat(collection): support source folder and selector in collections
This commit is contained in:
@@ -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)}
|
||||
|
||||
@@ -96,7 +96,7 @@ export default function FileSystemManager({
|
||||
}, [teamId, fetchMembers, fetchMetadata])
|
||||
|
||||
const initialFilterConditions = useMemo(() => {
|
||||
return collection?.filter?.conditions || []
|
||||
return collection?.filter?.searchFilter?.conditions || []
|
||||
}, [collection])
|
||||
|
||||
const [filterConditions, setFilterConditions] =
|
||||
|
||||
@@ -11,7 +11,6 @@ import {
|
||||
Loader2,
|
||||
Trash2,
|
||||
Plus,
|
||||
MoreHorizontal,
|
||||
Share2,
|
||||
LayoutGrid,
|
||||
Bookmark,
|
||||
@@ -32,6 +31,8 @@ interface FolderTreeProps {
|
||||
dragState?: DragState
|
||||
onSelect?: (folder: AssetInfo) => void
|
||||
selectedFolderId?: string
|
||||
hideCollections?: boolean
|
||||
hideShares?: boolean
|
||||
}
|
||||
|
||||
export function FolderTree({
|
||||
@@ -42,6 +43,8 @@ export function FolderTree({
|
||||
dragState,
|
||||
onSelect,
|
||||
selectedFolderId,
|
||||
hideCollections,
|
||||
hideShares,
|
||||
}: FolderTreeProps) {
|
||||
const navigate = useNavigate()
|
||||
const queryClient = useQueryClient()
|
||||
@@ -83,8 +86,11 @@ export function FolderTree({
|
||||
json: {
|
||||
name: 'Untitled Collection',
|
||||
filter: {
|
||||
conditions: [],
|
||||
recursively: true,
|
||||
sourceFolderId: rootFolderId,
|
||||
searchFilter: {
|
||||
conditions: [],
|
||||
recursively: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -186,78 +192,79 @@ export function FolderTree({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<header className="flex items-center justify-between px-2 mb-1">
|
||||
<h3 className="text-xs font-semibold text-muted-foreground uppercase tracking-wider">
|
||||
Collections
|
||||
</h3>
|
||||
<button
|
||||
onClick={() => createCollection()}
|
||||
className="text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
<Plus className="h-3.5 w-3.5" />
|
||||
</button>
|
||||
</header>
|
||||
|
||||
<div className="space-y-0.5">
|
||||
{collectionsData?.data.map((collection) => (
|
||||
<div
|
||||
key={collection.id}
|
||||
className="group flex cursor-pointer items-center gap-2 rounded-md px-2 py-1.5 text-sm transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"
|
||||
onClick={() =>
|
||||
navigate({
|
||||
to: '/projects/$projectId/collections/$collectionId',
|
||||
params: { projectId, collectionId: collection.id },
|
||||
})
|
||||
}
|
||||
>
|
||||
<div className="flex h-4 w-4 items-center justify-center">
|
||||
<Bookmark className="h-4 w-4 text-sidebar-primary" />
|
||||
</div>
|
||||
<span className="flex-1 truncate text-sidebar-foreground">{collection.name}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<header className="flex items-center justify-between px-2 mb-1">
|
||||
<h3 className="text-xs font-semibold text-muted-foreground uppercase tracking-wider">
|
||||
Share Links
|
||||
</h3>
|
||||
<div className="flex items-center gap-1">
|
||||
<button className="text-muted-foreground hover:text-foreground">
|
||||
<MoreHorizontal className="h-3.5 w-3.5" />
|
||||
</button>
|
||||
{!hideCollections && (
|
||||
<div>
|
||||
<header className="flex items-center justify-between px-2 mb-1">
|
||||
<h3 className="text-xs font-semibold text-muted-foreground uppercase tracking-wider">
|
||||
Collections
|
||||
</h3>
|
||||
<button
|
||||
onClick={() => createShareLink()}
|
||||
onClick={() => createCollection()}
|
||||
className="text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
<Plus className="h-3.5 w-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
</header>
|
||||
|
||||
<div className="space-y-0.5">
|
||||
<div className="group flex cursor-pointer items-center gap-2 rounded-md px-2 py-1.5 text-sm transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground">
|
||||
<div className="flex h-4 w-4 items-center justify-center">
|
||||
<LayoutGrid className="h-4 w-4 text-sidebar-primary" />
|
||||
</div>
|
||||
<span className="flex-1 truncate text-sidebar-foreground">
|
||||
All Share Links ({shareLinks.length})
|
||||
</span>
|
||||
<div className="space-y-0.5">
|
||||
{collectionsData?.data.map((collection) => (
|
||||
<div
|
||||
key={collection.id}
|
||||
className="group flex cursor-pointer items-center gap-2 rounded-md px-2 py-1.5 text-sm transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"
|
||||
onClick={() =>
|
||||
navigate({
|
||||
to: '/projects/$projectId/collections/$collectionId',
|
||||
params: { projectId, collectionId: collection.id },
|
||||
})
|
||||
}
|
||||
>
|
||||
<div className="flex h-4 w-4 items-center justify-center">
|
||||
<Bookmark className="h-4 w-4 text-sidebar-primary" />
|
||||
</div>
|
||||
<span className="flex-1 truncate text-sidebar-foreground">{collection.name}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{shareLinks.map((link) => (
|
||||
<ShareLinkItem
|
||||
key={link.id}
|
||||
link={link}
|
||||
projectId={projectId}
|
||||
dragState={dragState}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!hideShares && (
|
||||
<div>
|
||||
<header className="flex items-center justify-between px-2 mb-1">
|
||||
<h3 className="text-xs font-semibold text-muted-foreground uppercase tracking-wider">
|
||||
Share Links
|
||||
</h3>
|
||||
<div className="flex items-center gap-1">
|
||||
<button
|
||||
onClick={() => createShareLink()}
|
||||
className="text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
<Plus className="h-3.5 w-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div className="space-y-0.5">
|
||||
<div className="group flex cursor-pointer items-center gap-2 rounded-md px-2 py-1.5 text-sm transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground">
|
||||
<div className="flex h-4 w-4 items-center justify-center">
|
||||
<LayoutGrid className="h-4 w-4 text-sidebar-primary" />
|
||||
</div>
|
||||
<span className="flex-1 truncate text-sidebar-foreground">
|
||||
All Share Links ({shareLinks.length})
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{shareLinks.map((link) => (
|
||||
<ShareLinkItem
|
||||
key={link.id}
|
||||
link={link}
|
||||
projectId={projectId}
|
||||
dragState={dragState}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -113,8 +113,11 @@ export function SearchFilterDialog({
|
||||
json: {
|
||||
name,
|
||||
filter: {
|
||||
conditions: combinedConditions,
|
||||
recursively: true,
|
||||
sourceFolderId: assetId,
|
||||
searchFilter: {
|
||||
conditions: combinedConditions,
|
||||
recursively: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user