feat(kanban): link related assets to their file or folder (#453)

Related assets in the task edit dialog were plain rows with no way to
open them. Add an opt-in `linkable` prop to TaskRelatedAssets that turns
each row's thumbnail and name into a router Link to the asset in its
project (files -> /projects/$projectId/files/$fileId, folders ->
/projects/$projectId/folders/$folderId), falling back to the task's
project when the asset has none. The edit dialog opts in; the create
dialog does not, so a click cannot discard an unsaved draft.

Co-authored-by: Frederic De Decker <hello@trinity.video>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
FredericTrinity
2026-10-07 20:14:36 +08:00
committed by GitHub
co-authored by Frederic De Decker Claude Opus 5.5
parent f8beb195dd
commit 4b1b64fe2b
4 changed files with 119 additions and 27 deletions
+2
View File
@@ -8,6 +8,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
### Added
* **kanban**: Related assets on a task are now clickable, taking you directly to that file or folder in its project
### Fixed
### Changed
@@ -445,6 +445,7 @@ export function TaskInfoForm({ teamId, task, canEdit = true }: TaskInfoFormProps
onAddAssets={(newAssets) => linkAssets(newAssets)}
onRemoveAsset={(assetId) => unlinkAsset(assetId)}
disabled={!canEdit}
linkable
/>
</div>
</div>
@@ -59,6 +59,15 @@ vi.mock('@dnd-kit/react', () => ({
KeyboardSensor: {},
}))
// Mock TanStack Router Link as a plain anchor
vi.mock('@tanstack/react-router', () => ({
Link: ({ children, to, ...props }: { children: React.ReactNode; to: string }) => (
<a href={to} {...props}>
{children}
</a>
),
}))
// Mock @dnd-kit/dom
vi.mock('@dnd-kit/dom', () => ({
PointerActivationConstraints: {
@@ -690,6 +699,58 @@ describe('Kanban UI Unit & Component Tests', () => {
fireEvent.click(removeButtons[0])
expect(onRemove).toHaveBeenCalledWith('asset-1')
})
it('does not link asset rows by default', () => {
render(
<TaskRelatedAssets
teamId="team-1"
assets={mockAssets}
onAddAssets={vi.fn()}
onRemoveAsset={vi.fn()}
/>,
)
expect(screen.queryAllByRole('link')).toHaveLength(0)
})
it('links files and folders to their project when linkable', () => {
const onRemove = vi.fn()
render(
<TaskRelatedAssets
teamId="team-1"
projectId="task-proj"
assets={[...mockAssets, { ...mockAssets[0], id: 'asset-3', projectId: null }]}
onAddAssets={vi.fn()}
onRemoveAsset={onRemove}
linkable
/>,
)
const links = screen.getAllByRole('link')
expect(links.map((link) => link.getAttribute('href'))).toEqual([
'/projects/proj-1/files/asset-1',
'/projects/proj-1/folders/asset-2',
// Falls back to the task's project when the asset has none
'/projects/task-proj/files/asset-3',
])
// The remove button stays outside the link
fireEvent.click(screen.getAllByTitle(/Unlink Asset|取消关联资产/i)[1])
expect(onRemove).toHaveBeenCalledWith('asset-2')
})
it('does not link assets when no project is known', () => {
render(
<TaskRelatedAssets
teamId="team-1"
assets={[{ ...mockAssets[0], projectId: null }]}
onAddAssets={vi.fn()}
onRemoveAsset={vi.fn()}
linkable
/>,
)
expect(screen.queryAllByRole('link')).toHaveLength(0)
})
})
describe('KanbanGoalSidebar component', () => {
@@ -1,4 +1,5 @@
import { useState } from 'react'
import { Link } from '@tanstack/react-router'
import { Button } from '@/ui/components/ui/button'
import { Separator } from '@/ui/components/ui/separator'
import { Avatar, AvatarFallback, AvatarImage } from '@/ui/components/ui/avatar'
@@ -6,6 +7,7 @@ import { m } from '@/ui/paraglide/messages.js'
import type { KanbanTaskAssetInfo } from '@shumai/dtos'
import { AssetPickerDialog } from './asset-picker-dialog'
import { Plus, X, Folder, File, Files } from 'lucide-react'
import { cn } from '@/ui/lib/utils'
interface TaskRelatedAssetsProps {
teamId: string
@@ -14,6 +16,8 @@ interface TaskRelatedAssetsProps {
onAddAssets: (newAssets: KanbanTaskAssetInfo[]) => void
onRemoveAsset: (assetId: string) => void
disabled?: boolean
/** Make each row a link to the asset in its project. Off by default so unsaved drafts are not discarded. */
linkable?: boolean
}
export function TaskRelatedAssets({
@@ -23,6 +27,7 @@ export function TaskRelatedAssets({
onAddAssets,
onRemoveAsset,
disabled = false,
linkable = false,
}: TaskRelatedAssetsProps) {
const [isPickerOpen, setIsPickerOpen] = useState(false)
@@ -69,39 +74,62 @@ export function TaskRelatedAssets({
<div className="space-y-1.5 max-h-48 overflow-y-auto pr-1">
{assets.map((asset) => {
const isFolder = asset.type === 'folder'
const assetProjectId = asset.projectId || projectId
const assetHref =
linkable && assetProjectId
? `/projects/${assetProjectId}/${isFolder ? 'folders' : 'files'}/${asset.id}`
: null
const body = (
<>
{/* Thumbnail / Icon */}
<div className="w-7 h-7 rounded bg-muted border shrink-0 flex items-center justify-center overflow-hidden">
{asset.thumbnailUrl ? (
<img
src={asset.thumbnailUrl}
alt={asset.name}
className="w-full h-full object-cover"
/>
) : isFolder ? (
<Folder className="w-4 h-4 text-primary fill-primary/20" />
) : (
<File className="w-4 h-4 text-muted-foreground" />
)}
</div>
{/* Name & Path */}
<div className="flex-1 min-w-0">
<p
className={cn(
'font-medium truncate text-foreground leading-snug',
assetHref && 'group-hover:underline group-hover:text-primary',
)}
>
{asset.name}
</p>
<p className="text-[10px] text-muted-foreground truncate leading-none mt-0.5">
{asset.path || '/'}
</p>
</div>
</>
)
return (
<div
key={asset.id}
className="flex items-center justify-between gap-2 p-1.5 px-2 rounded-md bg-muted/40 hover:bg-muted/70 transition-colors text-xs border border-border/40"
>
{/* Left: Thumbnail & Names */}
<div className="flex items-center gap-2.5 min-w-0 flex-1">
{/* Thumbnail / Icon */}
<div className="w-7 h-7 rounded bg-muted border shrink-0 flex items-center justify-center overflow-hidden">
{asset.thumbnailUrl ? (
<img
src={asset.thumbnailUrl}
alt={asset.name}
className="w-full h-full object-cover"
/>
) : isFolder ? (
<Folder className="w-4 h-4 text-primary fill-primary/20" />
) : (
<File className="w-4 h-4 text-muted-foreground" />
)}
</div>
{/* Name & Path */}
<div className="flex-1 min-w-0">
<p className="font-medium truncate text-foreground leading-snug">
{asset.name}
</p>
<p className="text-[10px] text-muted-foreground truncate leading-none mt-0.5">
{asset.path || '/'}
</p>
</div>
</div>
{/* Left: Thumbnail & Names (links to the asset when linkable) */}
{assetHref ? (
<Link
to={assetHref}
title={asset.name}
className="group flex items-center gap-2.5 min-w-0 flex-1 rounded-sm cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
>
{body}
</Link>
) : (
<div className="flex items-center gap-2.5 min-w-0 flex-1">{body}</div>
)}
{/* Right: Creator & Remove Button */}
<div className="flex items-center gap-2 shrink-0">