Files
shumai/packages/webui/components/kanban/task-related-assets.tsx
T
Yiling-J 1f2bdc8c9e feat(agentic kanban): phase 1 not-agentic kanban board (#330)
* feat(kanban): implement AI-native kanban database models, services, and REST APIs

* feat(webui): implement team kanban board and task management

* style(webui): increase kanban dialog widths and form container

* fix(webui): ensure kanban dialogs override sm:max-w-lg base class

* style(webui): set edit task dialog max width to 5xl

* chore: untrack kanban plan markdown files

* feat(webui): update kanban page layout to 2 columns and refine task activity UI

* fix(webui): constrain kanban column and board heights for vertical scrolling

* feat(kanban): unify task status transition into updateTask API and allow unconstrained human task transitions

* fix(webui): add optimistic updates to kanban drag-and-drop to eliminate flash

* refactor(webui): remove client-side search box from kanban header

* feat(kanban): redesign task dialog comments area and add attachment support

* refactor(webui): remove top status action bar from task info dialog

* fix(webui): narrow query cache predicate and add defensive guards for kanban drag optimistic update

* feat(kanban): add drag-and-drop task reordering with fractional indexing (#331)

* feat(kanban): add drag-and-drop task reordering with fractional indexing

* fix(kanban): improve card drop zones, snap indicators, and column highlight

* fix(kanban): enable card droppables only during active drag

* fix(kanban): refine hover styles and drop indicators for column boundaries

* fix(kanban): unify bottom drop indicator and fix top indicator clipping

* fix(kanban): ensure full column highlight and full coverage drop target

* minor change

* feat(kanban): allow agent tasks free drag-and-drop and enforce status change permissions (#332)

* refactor(kanban): rename task_type_agentic translation keys to task_type_agent

* feat(kanban): refactor task type enum to isAgentTask boolean (#333)

* refactor(kanban): remove phase 2 agent execution logic and streamline phase 1 kanban

* feat(kanban): add notifications and audit logging for kanban (#334)

* feat(kanban): redesign config area layout and add parent tasks multi-selector (#335)

* feat(webui): redesign kanban task dialog config area

* feat(kanban): simplify task dependencies with parent tasks multi-selector

* refactor(kanban): remove unused links routes and legacy dependency methods

* feat(kanban): connect assets and kanban tasks with many-to-many relationship (#336)

* feat(kanban): connect assets and kanban tasks with many-to-many relationship

* feat(kanban): improve asset picker layout, infinite scrolling, and breadcrumb icon styling

* fix(kanban): ensure asset picker scrollarea is scrollable with min-h-0 and shrink-0 flex styling

* fix(kanban): hide recently deleted in folder tree picker and adjust header padding

* fix(kanban): use lucide files icon instead of paperclip for linked assets

* feat(kanban): improve task deletion, goal sidebar interaction, and card styling (#337)

* feat(kanban): improve task deletion, goal sidebar interaction, and card styling

* feat(kanban): move agent task badge after priority and update to orange style

* feat(kanban): add status Compare-And-Swap (CAS) to prevent drag-and-drop race conditions (#338)

* feat(kanban): add status Compare-And-Swap (CAS) to prevent drag-and-drop race conditions

* style(kanban): rotate kanban icon 180 degrees in sidebar and top nav

* style(kanban): remove rotate-180 from SquareKanban icons

* feat(kanban): add unassigned goal record and fix all tasks count (#339)

* feat(kanban): add unassigned goal record and fix all tasks count

* feat(kanban): toggle task count with three-dot action button on goal card hover

* fix(ci): pin bun version to 1.3.14 across CI and Docker (#340)

* fix(webui): truncate goal name to max 2 lines in kanban sidebar (#341)
2026-08-23 10:28:56 +08:00

158 lines
5.6 KiB
TypeScript

import { useState } from 'react'
import { Button } from '@/ui/components/ui/button'
import { Separator } from '@/ui/components/ui/separator'
import { Avatar, AvatarFallback, AvatarImage } from '@/ui/components/ui/avatar'
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'
interface TaskRelatedAssetsProps {
teamId: string
projectId?: string | null
assets: KanbanTaskAssetInfo[]
onAddAssets: (newAssets: KanbanTaskAssetInfo[]) => void
onRemoveAsset: (assetId: string) => void
disabled?: boolean
}
export function TaskRelatedAssets({
teamId,
projectId,
assets,
onAddAssets,
onRemoveAsset,
disabled = false,
}: TaskRelatedAssetsProps) {
const [isPickerOpen, setIsPickerOpen] = useState(false)
const handleConfirmPicker = (selectedAssets: KanbanTaskAssetInfo[]) => {
// Filter out already linked assets
const existingIds = new Set(assets.map((a) => a.id))
const toAdd = selectedAssets.filter((a) => !existingIds.has(a.id))
if (toAdd.length > 0) {
onAddAssets(toAdd)
}
}
return (
<div className="space-y-2">
{/* Title + Plus Button */}
<div className="flex items-center justify-between">
<div className="flex items-center gap-1.5 text-xs font-semibold text-foreground">
<Files className="w-3.5 h-3.5 text-muted-foreground" />
<span>{m.related_assets()}</span>
{assets.length > 0 && (
<span className="text-[11px] text-muted-foreground font-normal">({assets.length})</span>
)}
</div>
{!disabled && (
<Button
type="button"
variant="ghost"
size="sm"
className="h-6 w-6 p-0 hover:bg-muted"
onClick={() => setIsPickerOpen(true)}
title={m.add_assets()}
>
<Plus className="w-3.5 h-3.5" />
</Button>
)}
</div>
<Separator />
{/* Assets List Rows */}
{assets.length === 0 ? (
<p className="text-xs text-muted-foreground/70 py-1 italic">{m.no_related_assets()}</p>
) : (
<div className="space-y-1.5 max-h-48 overflow-y-auto pr-1">
{assets.map((asset) => {
const isFolder = asset.type === 'folder'
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>
{/* Right: Creator & Remove Button */}
<div className="flex items-center gap-2 shrink-0">
{asset.creator && (
<div
className="flex items-center gap-1 text-[11px] text-muted-foreground"
title={asset.creator.name}
>
<Avatar className="w-4 h-4 text-[9px]">
<AvatarImage src={asset.creator.image || undefined} />
<AvatarFallback>
{asset.creator.name.slice(0, 1).toUpperCase()}
</AvatarFallback>
</Avatar>
<span className="hidden sm:inline text-[11px] max-w-[80px] truncate">
{asset.creator.name}
</span>
</div>
)}
{!disabled && (
<Button
type="button"
variant="ghost"
size="sm"
className="h-5 w-5 p-0 text-muted-foreground hover:text-destructive hover:bg-destructive/10"
onClick={() => onRemoveAsset(asset.id)}
title={m.unlink_asset()}
>
<X className="w-3 h-3" />
</Button>
)}
</div>
</div>
)
})}
</div>
)}
{/* Asset Picker Dialog */}
{isPickerOpen && (
<AssetPickerDialog
teamId={teamId}
initialProjectId={projectId}
excludeAssetIds={assets.map((a) => a.id)}
isOpen={isPickerOpen}
onClose={() => setIsPickerOpen(false)}
onConfirm={handleConfirmPicker}
/>
)}
</div>
)
}