mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-25 20:29:28 +00:00
* 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)
231 lines
8.8 KiB
TypeScript
231 lines
8.8 KiB
TypeScript
import React, { useState } from 'react'
|
|
import { format } from 'date-fns'
|
|
import Markdown from 'react-markdown'
|
|
import { Download, FileText, MoreHorizontal, Trash2 } from 'lucide-react'
|
|
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
import { client } from '@/ui/api/client'
|
|
import { m } from '@/ui/paraglide/messages.js'
|
|
import { toast } from 'sonner'
|
|
import { Avatar, AvatarFallback, AvatarImage } from '@/ui/components/ui/avatar'
|
|
import { Button } from '@/ui/components/ui/button'
|
|
import {
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuTrigger,
|
|
} from '@/ui/components/ui/dropdown-menu'
|
|
import {
|
|
AlertDialog,
|
|
AlertDialogAction,
|
|
AlertDialogCancel,
|
|
AlertDialogContent,
|
|
AlertDialogDescription,
|
|
AlertDialogFooter,
|
|
AlertDialogHeader,
|
|
AlertDialogTitle,
|
|
} from '@/ui/components/ui/alert-dialog'
|
|
import { formatSize } from '@/ui/lib/format'
|
|
import type { KanbanAttachmentInfo, KanbanCommentInfo } from '@shumai/dtos'
|
|
|
|
interface TaskCommentCardProps {
|
|
teamId: string
|
|
taskId: string
|
|
comment: KanbanCommentInfo
|
|
currentUserId?: string
|
|
isOwnerOrAdmin?: boolean
|
|
onViewAttachment?: (attachment: KanbanAttachmentInfo) => void
|
|
}
|
|
|
|
export function TaskCommentCard({
|
|
teamId,
|
|
taskId,
|
|
comment,
|
|
currentUserId,
|
|
isOwnerOrAdmin,
|
|
onViewAttachment,
|
|
}: TaskCommentCardProps) {
|
|
const queryClient = useQueryClient()
|
|
const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false)
|
|
|
|
const canDelete = isOwnerOrAdmin || comment.author.id === currentUserId
|
|
|
|
const { mutate: deleteComment, isPending: isDeleting } = useMutation({
|
|
mutationFn: async () => {
|
|
const res = await client.api.teams[':teamId'].kanban.tasks[':taskId'].comments[
|
|
':commentId'
|
|
].$delete({
|
|
param: { teamId, taskId, commentId: comment.id },
|
|
})
|
|
if (!res.ok) {
|
|
const err = await res.json().catch(() => ({ message: m.error() }))
|
|
throw new Error((err as { message?: string }).message || m.error())
|
|
}
|
|
return await res.json()
|
|
},
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({
|
|
queryKey: ['teams', teamId, 'kanban', 'tasks', taskId, 'comments'],
|
|
})
|
|
queryClient.invalidateQueries({
|
|
queryKey: ['teams', teamId, 'kanban', 'task', taskId],
|
|
})
|
|
queryClient.invalidateQueries({
|
|
queryKey: ['teams', teamId, 'kanban', 'tasks'],
|
|
})
|
|
toast.success('Comment deleted')
|
|
setIsDeleteDialogOpen(false)
|
|
},
|
|
onError: (err) => {
|
|
toast.error(err.message)
|
|
},
|
|
})
|
|
|
|
const authorInitials = (comment.author.name || 'U')
|
|
.split(' ')
|
|
.map((n) => n[0])
|
|
.slice(0, 2)
|
|
.join('')
|
|
.toUpperCase()
|
|
|
|
return (
|
|
<div className="relative flex gap-3 p-3 rounded-xl border border-transparent bg-foreground/[0.03] dark:bg-foreground/[0.08] hover:bg-foreground/[0.06] dark:hover:bg-foreground/[0.12] transition-colors group">
|
|
{/* Left Avatar */}
|
|
<Avatar className="w-7 h-7 shrink-0 mt-0.5 border border-border">
|
|
{comment.author.image && (
|
|
<AvatarImage src={comment.author.image} alt={comment.author.name} />
|
|
)}
|
|
<AvatarFallback className="text-[10px] font-medium bg-muted text-muted-foreground">
|
|
{authorInitials}
|
|
</AvatarFallback>
|
|
</Avatar>
|
|
|
|
{/* Main Content Area */}
|
|
<div className="flex-1 min-w-0 space-y-1.5">
|
|
{/* Header: Author + Timestamp + Actions */}
|
|
<div className="flex items-center justify-between gap-2">
|
|
<div className="flex items-center gap-2 min-w-0">
|
|
<span className="font-semibold text-xs text-foreground truncate">
|
|
{comment.author.name}
|
|
</span>
|
|
<span className="text-[10px] text-muted-foreground shrink-0 font-mono">
|
|
{format(new Date(comment.createdAt), 'MMM d, h:mm a')}
|
|
</span>
|
|
</div>
|
|
|
|
{canDelete && (
|
|
<div className="opacity-0 group-hover:opacity-100 transition-opacity">
|
|
<DropdownMenu modal={false}>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button size="icon-xs" variant="ghost" className="h-5 w-5 text-muted-foreground">
|
|
<MoreHorizontal className="h-3.5 w-3.5" />
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end">
|
|
<DropdownMenuItem
|
|
className="text-destructive focus:text-destructive cursor-pointer text-xs"
|
|
onClick={() => setIsDeleteDialogOpen(true)}
|
|
>
|
|
<Trash2 className="mr-1.5 h-3.5 w-3.5" />
|
|
<span>{m.delete()}</span>
|
|
</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
{/* Markdown Comment Body */}
|
|
{comment.body && (
|
|
<div className="text-xs leading-relaxed prose prose-xs dark:prose-invert max-w-none break-words text-foreground/90 font-sans">
|
|
<Markdown>{comment.body}</Markdown>
|
|
</div>
|
|
)}
|
|
|
|
{/* Attachments Section */}
|
|
{comment.attachments && comment.attachments.length > 0 && (
|
|
<div className="flex flex-wrap gap-2 pt-1.5">
|
|
{comment.attachments.map((att) => {
|
|
const isImage = att.proxyType === 'image' || att.contentType?.startsWith('image/')
|
|
return (
|
|
<div
|
|
key={att.id}
|
|
className="relative group/att rounded-lg border border-border bg-card overflow-hidden transition-all duration-200"
|
|
>
|
|
{isImage ? (
|
|
<div
|
|
className="w-40 h-28 relative cursor-pointer overflow-hidden bg-muted/40"
|
|
onClick={() => onViewAttachment?.(att)}
|
|
>
|
|
<img
|
|
src={att.url}
|
|
alt={att.name}
|
|
className="w-full h-full object-cover group-hover/att:scale-105 transition-transform duration-200"
|
|
/>
|
|
<a
|
|
href={att.url}
|
|
download={att.name}
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
className="absolute right-1.5 bottom-1.5 bg-black/60 hover:bg-black/80 text-white p-1 rounded-md opacity-0 group-hover/att:opacity-100 transition-opacity shadow-xs"
|
|
onClick={(e) => e.stopPropagation()}
|
|
title="Download"
|
|
>
|
|
<Download className="w-3.5 h-3.5" />
|
|
</a>
|
|
</div>
|
|
) : (
|
|
<div className="flex items-center gap-2.5 p-2.5 max-w-[240px] bg-card hover:bg-muted/40 transition-colors">
|
|
<FileText className="w-7 h-7 text-primary/80 shrink-0" />
|
|
<div className="min-w-0 flex-1">
|
|
<p
|
|
className="text-xs font-medium text-foreground truncate"
|
|
title={att.name}
|
|
>
|
|
{att.name}
|
|
</p>
|
|
<p className="text-[10px] text-muted-foreground font-mono">
|
|
{formatSize(att.sizeByte)}
|
|
</p>
|
|
</div>
|
|
<a
|
|
href={att.url}
|
|
download={att.name}
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
className="p-1 text-muted-foreground hover:text-foreground shrink-0 rounded-md hover:bg-muted transition-colors"
|
|
title="Download"
|
|
>
|
|
<Download className="w-3.5 h-3.5" />
|
|
</a>
|
|
</div>
|
|
)}
|
|
</div>
|
|
)
|
|
})}
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
{/* Delete Confirmation Alert Dialog */}
|
|
<AlertDialog open={isDeleteDialogOpen} onOpenChange={setIsDeleteDialogOpen}>
|
|
<AlertDialogContent>
|
|
<AlertDialogHeader>
|
|
<AlertDialogTitle>{m.delete_comment_confirm()}</AlertDialogTitle>
|
|
<AlertDialogDescription>{m.delete_comment_description()}</AlertDialogDescription>
|
|
</AlertDialogHeader>
|
|
<AlertDialogFooter>
|
|
<AlertDialogCancel disabled={isDeleting}>{m.cancel()}</AlertDialogCancel>
|
|
<AlertDialogAction
|
|
className="bg-destructive hover:bg-destructive/90 text-white"
|
|
disabled={isDeleting}
|
|
onClick={() => deleteComment()}
|
|
>
|
|
{m.delete()}
|
|
</AlertDialogAction>
|
|
</AlertDialogFooter>
|
|
</AlertDialogContent>
|
|
</AlertDialog>
|
|
</div>
|
|
)
|
|
}
|