From 4b1b64fe2b4304e870912dfa5e6d8ccfc6fbd9b4 Mon Sep 17 00:00:00 2001 From: FredericTrinity Date: Wed, 7 Oct 2026 14:14:36 +0200 Subject: [PATCH] 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 Co-authored-by: Claude Opus 5.5 --- CHANGELOG.md | 2 + .../edit-task-dialog/task-info-form.tsx | 1 + .../webui/components/kanban/kanban.test.tsx | 61 ++++++++++++++ .../components/kanban/task-related-assets.tsx | 82 +++++++++++++------ 4 files changed, 119 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b75c302a..40add3bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/webui/components/kanban/edit-task-dialog/task-info-form.tsx b/packages/webui/components/kanban/edit-task-dialog/task-info-form.tsx index 940e8116..84e23f99 100644 --- a/packages/webui/components/kanban/edit-task-dialog/task-info-form.tsx +++ b/packages/webui/components/kanban/edit-task-dialog/task-info-form.tsx @@ -445,6 +445,7 @@ export function TaskInfoForm({ teamId, task, canEdit = true }: TaskInfoFormProps onAddAssets={(newAssets) => linkAssets(newAssets)} onRemoveAsset={(assetId) => unlinkAsset(assetId)} disabled={!canEdit} + linkable /> diff --git a/packages/webui/components/kanban/kanban.test.tsx b/packages/webui/components/kanban/kanban.test.tsx index 5a0bba12..9cd7090b 100644 --- a/packages/webui/components/kanban/kanban.test.tsx +++ b/packages/webui/components/kanban/kanban.test.tsx @@ -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 }) => ( + + {children} + + ), +})) + // 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( + , + ) + + expect(screen.queryAllByRole('link')).toHaveLength(0) + }) + + it('links files and folders to their project when linkable', () => { + const onRemove = vi.fn() + render( + , + ) + + 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( + , + ) + + expect(screen.queryAllByRole('link')).toHaveLength(0) + }) }) describe('KanbanGoalSidebar component', () => { diff --git a/packages/webui/components/kanban/task-related-assets.tsx b/packages/webui/components/kanban/task-related-assets.tsx index 4cdbc028..fda8c3c6 100644 --- a/packages/webui/components/kanban/task-related-assets.tsx +++ b/packages/webui/components/kanban/task-related-assets.tsx @@ -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({
{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 */} +
+ {asset.thumbnailUrl ? ( + {asset.name} + ) : isFolder ? ( + + ) : ( + + )} +
+ + {/* Name & Path */} +
+

+ {asset.name} +

+

+ {asset.path || '/'} +

+
+ + ) return (
- {/* Left: Thumbnail & Names */} -
- {/* Thumbnail / Icon */} -
- {asset.thumbnailUrl ? ( - {asset.name} - ) : isFolder ? ( - - ) : ( - - )} -
- - {/* Name & Path */} -
-

- {asset.name} -

-

- {asset.path || '/'} -

-
-
+ {/* Left: Thumbnail & Names (links to the asset when linkable) */} + {assetHref ? ( + + {body} + + ) : ( +
{body}
+ )} {/* Right: Creator & Remove Button */}