Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

feat(web): add relations to task detail, animated subtasks, and keyboard nav

Andrej752bab0277ba
diff --git a/apps/web/src/components/task/subtask-row.tsx b/apps/web/src/components/task/subtask-row.tsx
index 9fa685186..d9ed8bb7c 100644
--- a/apps/web/src/components/task/subtask-row.tsx
+++ b/apps/web/src/components/task/subtask-row.tsx
@@ -1,3 +1,4 @@
+import { motion } from "framer-motion";
import TaskCardContextMenuContent from "@/components/kanban-board/task-card-context-menu/task-card-context-menu-content";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import { Checkbox } from "@/components/ui/checkbox";
@@ -13,6 +14,7 @@ type SubtaskRowProps = {
projectId: string;
workspaceId: string;
isSelected: boolean;
+ isFocused: boolean;
selectionRadius: string;
assignee: {
user?: { image?: string | null; name?: string | null } | null;
@@ -28,6 +30,7 @@ export default function SubtaskRow({
projectId,
workspaceId,
isSelected,
+ isFocused,
selectionRadius,
assignee,
onToggleSelection,
@@ -35,72 +38,83 @@ export default function SubtaskRow({
onDeleteClick,
}: SubtaskRowProps) {
return (
- <ContextMenu>
- <ContextMenuTrigger asChild>
- <div
- className={`group flex items-center gap-2 py-1 px-2 ${selectionRadius} transition-colors cursor-default ${isSelected ? "bg-primary/10 hover:bg-primary/15" : "hover:bg-accent/50"}`}
- >
- <Checkbox checked={isSelected} onCheckedChange={onToggleSelection} />
-
- <SubtaskStatusPopover tasks={tasks} projectId={projectId}>
- <button
- type="button"
- className="shrink-0 flex items-center justify-center rounded p-0.5 transition-colors outline-none [&_svg]:text-muted-foreground hover:[&_svg]:text-foreground"
- >
- {getColumnIcon(task.status, false)}
- </button>
- </SubtaskStatusPopover>
-
- <button
- type="button"
- className="flex-1 min-w-0 text-left outline-none"
- onClick={onNavigate}
+ <motion.div
+ layout
+ initial={{ opacity: 0, height: 0 }}
+ animate={{ opacity: 1, height: "auto" }}
+ exit={{ opacity: 0, height: 0 }}
+ transition={{ duration: 0.2, ease: "easeOut" }}
+ >
+ <ContextMenu>
+ <ContextMenuTrigger asChild>
+ <div
+ className={`group flex items-center gap-2 py-1 px-2 ${selectionRadius} transition-colors cursor-default ${isSelected ? "bg-primary/10 hover:bg-primary/15" : "hover:bg-accent/50"} ${isFocused ? "ring-1 ring-inset ring-ring/50" : ""}`}
>
- <span
- className={`text-sm truncate block ${task.status === "done" ? "line-through text-muted-foreground" : "text-foreground/90"}`}
- >
- {task.title}
- </span>
- </button>
+ <Checkbox
+ checked={isSelected}
+ onCheckedChange={onToggleSelection}
+ />
+
+ <SubtaskStatusPopover tasks={tasks} projectId={projectId}>
+ <button
+ type="button"
+ className="shrink-0 flex items-center justify-center rounded p-0.5 transition-colors outline-none [&_svg]:text-muted-foreground hover:[&_svg]:text-foreground"
+ >
+ {getColumnIcon(task.status, false)}
+ </button>
+ </SubtaskStatusPopover>
- <SubtaskAssigneePopover tasks={tasks} workspaceId={workspaceId}>
<button
type="button"
- className="shrink-0 flex items-center justify-center rounded p-0.5 transition-colors outline-none"
+ className="flex-1 min-w-0 text-left outline-none"
+ onClick={onNavigate}
>
- {task.userId && assignee ? (
- <Avatar className="h-5 w-5">
- <AvatarImage
- src={assignee?.user?.image ?? ""}
- alt={assignee?.user?.name || ""}
- />
- <AvatarFallback className="text-[9px] font-medium border border-border/30">
- {assignee?.user?.name?.charAt(0).toUpperCase()}
- </AvatarFallback>
- </Avatar>
- ) : (
- <div
- className="flex h-5 w-5 items-center justify-center rounded-full border border-dashed border-border/70"
- title="Unassigned"
- >
- <span className="text-[9px] font-medium text-muted-foreground">
- ?
- </span>
- </div>
- )}
+ <span
+ className={`text-sm truncate block ${task.status === "done" ? "line-through text-muted-foreground" : "text-foreground/90"}`}
+ >
+ {task.title}
+ </span>
</button>
- </SubtaskAssigneePopover>
- </div>
- </ContextMenuTrigger>
- <TaskCardContextMenuContent
- task={task}
- taskCardContext={{
- projectId,
- worskpaceId: workspaceId,
- }}
- onDeleteClick={onDeleteClick}
- />
- </ContextMenu>
+ <SubtaskAssigneePopover tasks={tasks} workspaceId={workspaceId}>
+ <button
+ type="button"
+ className="shrink-0 flex items-center justify-center rounded p-0.5 transition-colors outline-none"
+ >
+ {task.userId && assignee ? (
+ <Avatar className="h-5 w-5">
+ <AvatarImage
+ src={assignee?.user?.image ?? ""}
+ alt={assignee?.user?.name || ""}
+ />
+ <AvatarFallback className="text-[9px] font-medium border border-border/30">
+ {assignee?.user?.name?.charAt(0).toUpperCase()}
+ </AvatarFallback>
+ </Avatar>
+ ) : (
+ <div
+ className="flex h-5 w-5 items-center justify-center rounded-full border border-dashed border-border/70"
+ title="Unassigned"
+ >
+ <span className="text-[9px] font-medium text-muted-foreground">
+ ?
+ </span>
+ </div>
+ )}
+ </button>
+ </SubtaskAssigneePopover>
+ </div>
+ </ContextMenuTrigger>
+
+ <TaskCardContextMenuContent
+ task={task}
+ taskCardContext={{
+ projectId,
+ worskpaceId: workspaceId,
+ }}
+ onDeleteClick={onDeleteClick}
+ />
+ </ContextMenu>
+ </motion.div>
);
}
diff --git a/apps/web/src/components/task/task-details-content.tsx b/apps/web/src/components/task/task-details-content.tsx
index 245e711bc..28c7182db 100644
--- a/apps/web/src/components/task/task-details-content.tsx
+++ b/apps/web/src/components/task/task-details-content.tsx
@@ -13,6 +13,7 @@ import useGetTask from "@/hooks/queries/task/use-get-task";
import useGetTaskRelations from "@/hooks/queries/task-relation/use-get-task-relations";
import type { ExternalLink } from "@/types/external-link";
import TaskDescription from "./task-description";
+import TaskRelations from "./task-relations";
import TaskSubtasks from "./task-subtasks";
import TaskTitle from "./task-title";
@@ -90,6 +91,13 @@ export default function TaskDetailsContent({
workspaceId={workspaceId}
/>
</div>
+ <div className="mt-2">
+ <TaskRelations
+ taskId={taskId}
+ projectId={projectId}
+ workspaceId={workspaceId}
+ />
+ </div>
<span className="text-sm font-medium text-muted-foreground h-[1px] bg-border w-full block shrink-0" />
<div className="flex flex-col gap-4">
<h1 className="text-md font-semibold">Activity</h1>
diff --git a/apps/web/src/components/task/task-properties-sidebar.tsx b/apps/web/src/components/task/task-properties-sidebar.tsx
index 71dcb5792..8dae7b654 100644
--- a/apps/web/src/components/task/task-properties-sidebar.tsx
+++ b/apps/web/src/components/task/task-properties-sidebar.tsx
@@ -424,7 +424,7 @@ export default function TaskPropertiesSidebar({
{/* Desktop: Title + stacked properties */}
<div className="hidden lg:block">
<div className="flex items-center justify-between px-3 py-2 border-b border-border lg:border-none">
- <p className="text-sm font-medium text-muted-foreground flex-1">
+ <p className="text-sm font-medium text-foreground/70 flex-1">
Properties
</p>
<div className="flex gap-2">
@@ -583,7 +583,7 @@ export default function TaskPropertiesSidebar({
<div className="hidden lg:flex px-3 flex-col gap-3 p-2">
<div className="flex flex-col gap-1">
- <span className="text-xs font-medium text-muted-foreground px-2">
+ <span className="text-xs font-medium text-foreground/70 px-2">
Labels
</span>
<div className="flex flex-wrap items-center gap-1.5 px-2">
diff --git a/apps/web/src/components/task/task-relations.tsx b/apps/web/src/components/task/task-relations.tsx
index 5c6e1773b..479d9b745 100644
--- a/apps/web/src/components/task/task-relations.tsx
+++ b/apps/web/src/components/task/task-relations.tsx
@@ -7,7 +7,8 @@ import {
Search,
X,
} from "lucide-react";
-import { useMemo, useState } from "react";
+import { Fragment, useEffect, useMemo, useState } from "react";
+import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import { Button } from "@/components/ui/button";
import {
Collapsible,
@@ -15,22 +16,39 @@ import {
CollapsibleTrigger,
} from "@/components/ui/collapsible";
import {
- Dialog,
- DialogClose,
- DialogDescription,
- DialogFooter,
- DialogHeader,
- DialogPopup,
- DialogTitle,
- DialogTrigger,
-} from "@/components/ui/dialog";
-import { Input } from "@/components/ui/input";
+ Command,
+ CommandCollection,
+ CommandDialog,
+ CommandDialogPopup,
+ CommandEmpty,
+ CommandFooter,
+ CommandGroup,
+ CommandGroupLabel,
+ CommandInput,
+ CommandItem,
+ CommandList,
+ CommandPanel,
+ CommandSeparator,
+} from "@/components/ui/command";
+import {
+ ContextMenu,
+ ContextMenuContent,
+ ContextMenuItem,
+ ContextMenuSeparator,
+ ContextMenuTrigger,
+} from "@/components/ui/context-menu";
import useCreateTaskRelation from "@/hooks/mutations/task-relation/use-create-task-relation";
import useDeleteTaskRelation from "@/hooks/mutations/task-relation/use-delete-task-relation";
+import useGetProject from "@/hooks/queries/project/use-get-project";
import { useGetTasks } from "@/hooks/queries/task/use-get-tasks";
import useGetTaskRelations from "@/hooks/queries/task-relation/use-get-task-relations";
+import useActiveWorkspace from "@/hooks/queries/workspace/use-active-workspace";
+import { useGetActiveWorkspaceUsers } from "@/hooks/queries/workspace-users/use-get-active-workspace-users";
import { getColumnIcon } from "@/lib/column";
import { toast } from "@/lib/toast";
+import type Task from "@/types/task";
+import SubtaskAssigneePopover from "./subtask-assignee-popover";
+import SubtaskStatusPopover from "./subtask-status-popover";
type TaskRelationsProps = {
taskId: string;
@@ -39,8 +57,21 @@ type TaskRelationsProps = {
};
const relationTypeLabels: Record<string, string> = {
- blocks: "Blocks",
- related: "Related to",
+ blocks: "blocks",
+ related: "relates to",
+};
+
+type TaskItem = {
+ id: string;
+ title: string;
+ number: number | null;
+ status: string;
+};
+
+type TaskGroup = {
+ value: string;
+ label: string;
+ items: TaskItem[];
};
export default function TaskRelations({
@@ -50,7 +81,7 @@ export default function TaskRelations({
}: TaskRelationsProps) {
const navigate = useNavigate();
const [isOpen, setIsOpen] = useState(true);
- const [dialogOpen, setDialogOpen] = useState(false);
+ const [commandOpen, setCommandOpen] = useState(false);
const [searchQuery, setSearchQuery] = useState("");
const [selectedRelationType, setSelectedRelationType] = useState<
"blocks" | "related"
@@ -58,9 +89,20 @@ export default function TaskRelations({
const { data: relations = [] } = useGetTaskRelations(taskId);
const { data: projectData } = useGetTasks(projectId);
+ const { data: project } = useGetProject({ id: projectId, workspaceId });
+ const { data: workspace } = useActiveWorkspace();
+ const { data: workspaceUsers } = useGetActiveWorkspaceUsers(
+ workspace?.id ?? "",
+ );
const createRelation = useCreateTaskRelation();
const deleteRelation = useDeleteTaskRelation(taskId);
+ useEffect(() => {
+ if (!commandOpen) {
+ setSearchQuery("");
+ }
+ }, [commandOpen]);
+
const nonSubtaskRelations = relations.filter(
(rel) => rel.relationType !== "subtask",
);
@@ -72,7 +114,6 @@ export default function TaskRelations({
id: string;
relationType: string;
task: NonNullable<(typeof nonSubtaskRelations)[number]["sourceTask"]>;
- direction: "source" | "target";
}>
> = {};
@@ -89,7 +130,6 @@ export default function TaskRelations({
id: rel.id,
relationType: type,
task: linkedTask,
- direction: isSource ? "source" : "target",
});
}
@@ -103,21 +143,11 @@ export default function TaskRelations({
const allTasks = useMemo(() => {
if (!projectData) return [];
- const tasks: Array<{
- id: string;
- title: string;
- number: number | null;
- status: string;
- }> = [];
+ const tasks: TaskItem[] = [];
if ("columns" in projectData && Array.isArray(projectData.columns)) {
for (const col of projectData.columns as Array<{
- tasks: Array<{
- id: string;
- title: string;
- number: number | null;
- status: string;
- }>;
+ tasks: TaskItem[];
}>) {
if (col.tasks) {
for (const t of col.tasks) {
@@ -131,11 +161,19 @@ export default function TaskRelations({
}, [projectData]);
const filteredTasks = allTasks.filter(
- (t) =>
- !existingRelatedTaskIds.has(t.id) &&
- t.title.toLowerCase().includes(searchQuery.toLowerCase()),
+ (t) => !existingRelatedTaskIds.has(t.id),
);
+ const commandGroups = useMemo<TaskGroup[]>(() => {
+ return [
+ {
+ value: "tasks",
+ label: "Tasks in project",
+ items: filteredTasks,
+ },
+ ];
+ }, [filteredTasks]);
+
const handleLinkTask = async (targetTaskId: string) => {
try {
await createRelation.mutateAsync({
@@ -143,7 +181,7 @@ export default function TaskRelations({
targetTaskId,
relationType: selectedRelationType,
});
- setDialogOpen(false);
+ setCommandOpen(false);
setSearchQuery("");
} catch {
toast.error("Failed to link task");
@@ -161,162 +199,242 @@ export default function TaskRelations({
});
};
- const hasRelations = nonSubtaskRelations.length > 0;
+ const getAssignee = (userId: string | null) => {
+ if (!userId || !workspaceUsers?.members) return null;
+ return workspaceUsers.members.find((member) => member.userId === userId);
+ };
+
+ const buildTaskObject = (item: {
+ task: NonNullable<(typeof nonSubtaskRelations)[number]["sourceTask"]>;
+ }): Task => ({
+ id: item.task.id,
+ title: item.task.title,
+ number: item.task.number,
+ description: null,
+ status: item.task.status,
+ priority: item.task.priority,
+ dueDate: null,
+ position: null,
+ createdAt: "",
+ userId: item.task.userId,
+ assigneeId: item.task.userId,
+ assigneeName: item.task.assigneeName,
+ projectId: item.task.projectId,
+ });
+
+ const totalCount = nonSubtaskRelations.length;
return (
- <Collapsible open={isOpen} onOpenChange={setIsOpen} className="w-full">
- <div className="flex items-center justify-between">
- <CollapsibleTrigger asChild>
+ <>
+ <Collapsible open={isOpen} onOpenChange={setIsOpen} className="w-full">
+ <div className="flex items-center justify-between">
+ <div className="flex items-center gap-1.5">
+ <CollapsibleTrigger asChild>
+ <button
+ type="button"
+ className="flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors"
+ >
+ {isOpen ? (
+ <ChevronDown className="size-4" />
+ ) : (
+ <ChevronRight className="size-4" />
+ )}
+ <span>Relations</span>
+ </button>
+ </CollapsibleTrigger>
+ {totalCount > 0 && (
+ <span className="text-xs text-muted-foreground">
+ {totalCount}
+ </span>
+ )}
+ </div>
<Button
variant="ghost"
- size="sm"
- className="w-full justify-start gap-1 px-0 h-8 hover:bg-transparent"
+ size="xs"
+ className="text-muted-foreground"
+ onClick={() => setCommandOpen(true)}
>
- {isOpen ? (
- <ChevronDown className="size-4 text-muted-foreground" />
- ) : (
- <ChevronRight className="size-4 text-muted-foreground" />
- )}
- <Link2 className="size-4 text-muted-foreground" />
- <span className="text-sm text-muted-foreground">Relations</span>
- {hasRelations && (
- <span className="text-xs text-muted-foreground ml-1">
- {nonSubtaskRelations.length}
- </span>
- )}
+ <Plus className="size-3.5" />
</Button>
- </CollapsibleTrigger>
- <Dialog open={dialogOpen} onOpenChange={setDialogOpen}>
- <DialogTrigger asChild>
- <Button variant="ghost" size="xs" className="text-muted-foreground">
- <Plus className="size-3.5" />
- </Button>
- </DialogTrigger>
- <DialogPopup className="max-w-md">
- <DialogHeader>
- <DialogTitle>Link task</DialogTitle>
- <DialogDescription>
- Search for a task in this project to create a relation.
- </DialogDescription>
- </DialogHeader>
- <div className="px-6 pb-4 flex flex-col gap-3">
- <div className="flex gap-2">
- <Button
- variant={
- selectedRelationType === "related" ? "default" : "outline"
- }
- size="xs"
+ </div>
+
+ <CollapsibleContent>
+ {Object.entries(groupedRelations).map(([type, items]) => (
+ <div key={type} className="mt-1.5">
+ <span className="text-[11px] text-muted-foreground/70 px-2">
+ {relationTypeLabels[type] || type}
+ </span>
+ <div className="flex flex-col mt-0.5">
+ {items.map((item) => {
+ const assignee = getAssignee(item.task.userId);
+ const taskObj = buildTaskObject(item);
+
+ return (
+ <ContextMenu key={item.id}>
+ <ContextMenuTrigger asChild>
+ <div className="group flex items-center gap-2 py-1 px-2 rounded-md hover:bg-accent/50 transition-colors cursor-default">
+ <SubtaskStatusPopover
+ tasks={[taskObj]}
+ projectId={projectId}
+ >
+ <button
+ type="button"
+ className="shrink-0 flex items-center justify-center rounded p-0.5 transition-colors outline-none [&_svg]:text-muted-foreground hover:[&_svg]:text-foreground"
+ >
+ {getColumnIcon(item.task.status, false)}
+ </button>
+ </SubtaskStatusPopover>
+
+ <button
+ type="button"
+ className="flex-1 min-w-0 text-left outline-none"
+ onClick={() => handleNavigateToTask(item.task.id)}
+ >
+ <span
+ className={`text-sm truncate block ${item.task.status === "done" ? "line-through text-muted-foreground" : "text-foreground/90"}`}
+ >
+ {item.task.title}
+ </span>
+ </button>
+
+ <SubtaskAssigneePopover
+ tasks={[taskObj]}
+ workspaceId={workspaceId}
+ >
+ <button
+ type="button"
+ className="shrink-0 flex items-center justify-center rounded p-0.5 transition-colors outline-none"
+ >
+ {item.task.userId && assignee ? (
+ <Avatar className="h-5 w-5">
+ <AvatarImage
+ src={assignee?.user?.image ?? ""}
+ alt={assignee?.user?.name || ""}
+ />
+ <AvatarFallback className="text-[9px] font-medium border border-border/30">
+ {assignee?.user?.name
+ ?.charAt(0)
+ .toUpperCase()}
+ </AvatarFallback>
+ </Avatar>
+ ) : (
+ <div
+ className="flex h-5 w-5 items-center justify-center rounded-full border border-dashed border-border/70"
+ title="Unassigned"
+ >
+ <span className="text-[9px] font-medium text-muted-foreground">
+ ?
+ </span>
+ </div>
+ )}
+ </button>
+ </SubtaskAssigneePopover>
+ </div>
+ </ContextMenuTrigger>
+
+ <ContextMenuContent className="w-40">
+ <ContextMenuItem
+ onClick={() => handleNavigateToTask(item.task.id)}
+ >
+ <span>Open task</span>
+ </ContextMenuItem>
+ <ContextMenuSeparator />
+ <ContextMenuItem
+ className="text-destructive"
+ onClick={() => handleRemoveRelation(item.id)}
+ >
+ <span>Remove relation</span>
+ </ContextMenuItem>
+ </ContextMenuContent>
+ </ContextMenu>
+ );
+ })}
+ </div>
+ </div>
+ ))}
+
+ {totalCount === 0 && (
+ <p className="text-xs text-muted-foreground px-2 py-1">
+ No related tasks
+ </p>
+ )}
+ </CollapsibleContent>
+ </Collapsible>
+
+ <CommandDialog open={commandOpen} onOpenChange={setCommandOpen}>
+ <CommandDialogPopup>
+ <Command items={commandGroups}>
+ <CommandInput
+ placeholder="Search tasks to link..."
+ value={searchQuery}
+ onChange={(e) => setSearchQuery(e.target.value)}
+ />
+ <CommandPanel>
+ <CommandEmpty>
+ <div className="text-center py-6">
+ <Search className="h-8 w-8 mx-auto mb-2 text-muted-foreground" />
+ <p className="text-sm text-muted-foreground">
+ No tasks found
+ </p>
+ </div>
+ </CommandEmpty>
+ <CommandList>
+ {(group: TaskGroup, groupIndex: number) => (
+ <Fragment key={group.value}>
+ <CommandGroup items={group.items}>
+ <CommandGroupLabel>{group.label}</CommandGroupLabel>
+ <CommandCollection>
+ {(item: TaskItem) => (
+ <CommandItem
+ key={item.id}
+ value={`${project?.slug}-${item.number} ${item.title}`}
+ onClick={() => handleLinkTask(item.id)}
+ className="flex items-center gap-3 py-2"
+ >
+ {getColumnIcon(item.status, false)}
+ <span className="text-xs text-muted-foreground shrink-0 font-mono">
+ {project?.slug}-{item.number}
+ </span>
+ <span className="text-sm truncate flex-1">
+ {item.title}
+ </span>
+ </CommandItem>
+ )}
+ </CommandCollection>
+ </CommandGroup>
+ {groupIndex < commandGroups.length - 1 && (
+ <CommandSeparator />
+ )}
+ </Fragment>
+ )}
+ </CommandList>
+ </CommandPanel>
+ <CommandFooter>
+ <div className="flex items-center gap-3">
+ <button
+ type="button"
+ className={`flex items-center gap-1.5 text-xs px-2 py-1 rounded-md transition-colors ${selectedRelationType === "related" ? "bg-accent text-foreground" : "text-muted-foreground hover:text-foreground"}`}
onClick={() => setSelectedRelationType("related")}
>
+ <Link2 className="size-3" />
Related
- </Button>
- <Button
- variant={
- selectedRelationType === "blocks" ? "default" : "outline"
- }
- size="xs"
+ </button>
+ <button
+ type="button"
+ className={`flex items-center gap-1.5 text-xs px-2 py-1 rounded-md transition-colors ${selectedRelationType === "blocks" ? "bg-accent text-foreground" : "text-muted-foreground hover:text-foreground"}`}
onClick={() => setSelectedRelationType("blocks")}
>
+ <X className="size-3" />
Blocks
- </Button>
- </div>
- <div className="relative">
- <Search className="absolute left-2.5 top-1/2 -translate-y-1/2 size-3.5 text-muted-foreground pointer-events-none" />
- <Input
- size="sm"
- placeholder="Search tasks..."
- value={searchQuery}
- onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
- setSearchQuery(e.target.value)
- }
- className="pl-8"
- autoFocus
- />
+ </button>
</div>
- <div className="max-h-60 overflow-y-auto flex flex-col gap-0.5">
- {filteredTasks.length === 0 && (
- <p className="text-sm text-muted-foreground py-4 text-center">
- No tasks found
- </p>
- )}
- {filteredTasks.map((t) => (
- <button
- key={t.id}
- type="button"
- className="flex items-center gap-2 py-2 px-2 rounded-md hover:bg-accent/50 transition-colors text-left w-full"
- onClick={() => handleLinkTask(t.id)}
- >
- {getColumnIcon(t.status, false)}
- <span className="text-sm truncate flex-1 text-foreground/90">
- {t.title}
- </span>
- {t.number != null && (
- <span className="text-xs text-muted-foreground shrink-0">
- #{t.number}
- </span>
- )}
- </button>
- ))}
- </div>
- </div>
- <DialogFooter variant="bare">
- <DialogClose asChild>
- <Button variant="outline" size="sm">
- Cancel
- </Button>
- </DialogClose>
- </DialogFooter>
- </DialogPopup>
- </Dialog>
- </div>
-
- <CollapsibleContent>
- {Object.entries(groupedRelations).map(([type, items]) => (
- <div key={type} className="mt-2">
- <p className="text-xs font-medium text-muted-foreground px-2 mb-1">
- {relationTypeLabels[type] || type}
- </p>
- <div className="flex flex-col gap-0.5">
- {items.map((item) => (
- <div
- key={item.id}
- className="group flex items-center gap-2 py-1.5 px-2 rounded-md hover:bg-accent/50 transition-colors"
- >
- <button
- type="button"
- className="flex items-center gap-2 flex-1 min-w-0 text-left"
- onClick={() => handleNavigateToTask(item.task.id)}
- >
- {getColumnIcon(item.task.status, false)}
- <span className="text-sm truncate flex-1 text-foreground/90">
- {item.task.title}
- </span>
- {item.task.number != null && (
- <span className="text-xs text-muted-foreground shrink-0">
- #{item.task.number}
- </span>
- )}
- </button>
- <Button
- variant="ghost"
- size="xs"
- className="opacity-0 group-hover:opacity-100 text-muted-foreground h-5 w-5 p-0"
- onClick={() => handleRemoveRelation(item.id)}
- >
- <X className="size-3" />
- </Button>
- </div>
- ))}
- </div>
- </div>
- ))}
-
- {!hasRelations && (
- <p className="text-xs text-muted-foreground px-2 py-1">
- No related tasks
- </p>
- )}
- </CollapsibleContent>
- </Collapsible>
+ <span className="text-muted-foreground/60">
+ Select a task to link
+ </span>
+ </CommandFooter>
+ </Command>
+ </CommandDialogPopup>
+ </CommandDialog>
+ </>
);
}
diff --git a/apps/web/src/components/task/task-subtasks.tsx b/apps/web/src/components/task/task-subtasks.tsx
index c2744a797..ae56c46c3 100644
--- a/apps/web/src/components/task/task-subtasks.tsx
+++ b/apps/web/src/components/task/task-subtasks.tsx
@@ -1,6 +1,7 @@
import { useNavigate } from "@tanstack/react-router";
+import { AnimatePresence } from "framer-motion";
import { ChevronDown, ChevronRight, Plus } from "lucide-react";
-import { useState } from "react";
+import { useCallback, useEffect, useRef, useState } from "react";
import {
AlertDialog,
AlertDialogClose,
@@ -46,6 +47,8 @@ export default function TaskSubtasks({
const [newTitle, setNewTitle] = useState("");
const [deleteTaskId, setDeleteTaskId] = useState<string | null>(null);
const [selectedIds, setSelectedIds] = useState<Set<string>>(new Set());
+ const [focusedIndex, setFocusedIndex] = useState(-1);
+ const containerRef = useRef<HTMLDivElement>(null);
const { data: relations = [] } = useGetTaskRelations(taskId);
const { data: workspace } = useActiveWorkspace();
@@ -72,7 +75,7 @@ export default function TaskSubtasks({
const totalCount = subtasks.length;
const hasSelection = selectedIds.size > 0;
- const toggleSelection = (id: string) => {
+ const toggleSelection = useCallback((id: string) => {
setSelectedIds((prev) => {
const next = new Set(prev);
if (next.has(id)) {
@@ -82,7 +85,12 @@ export default function TaskSubtasks({
}
return next;
});
- };
+ }, []);
+
+ const clearSelection = useCallback(() => {
+ setSelectedIds(new Set());
+ setFocusedIndex(-1);
+ }, []);
const buildTaskObject = (subtask: (typeof subtasks)[number]): Task => ({
id: subtask.task.id,
@@ -129,6 +137,84 @@ export default function TaskSubtasks({
return "rounded-md";
};
+ // Keyboard navigation
+ useEffect(() => {
+ const container = containerRef.current;
+ if (!container || totalCount === 0) return;
+
+ const handleKeyDown = (e: KeyboardEvent) => {
+ const target = e.target as HTMLElement | null;
+ if (
+ target?.closest(
+ "input, textarea, [contenteditable='true'], .ProseMirror",
+ )
+ )
+ return;
+
+ if (!container.contains(document.activeElement) && focusedIndex === -1)
+ return;
+
+ switch (e.key) {
+ case "ArrowDown":
+ case "j": {
+ e.preventDefault();
+ setFocusedIndex((prev) => (prev < totalCount - 1 ? prev + 1 : prev));
+ break;
+ }
+ case "ArrowUp":
+ case "k": {
+ e.preventDefault();
+ setFocusedIndex((prev) => (prev > 0 ? prev - 1 : prev));
+ break;
+ }
+ case " ": {
+ if (focusedIndex >= 0 && focusedIndex < totalCount) {
+ e.preventDefault();
+ toggleSelection(subtasks[focusedIndex].task.id);
+ }
+ break;
+ }
+ case "Enter": {
+ if (focusedIndex >= 0 && focusedIndex < totalCount) {
+ e.preventDefault();
+ navigate({
+ to: "/dashboard/workspace/$workspaceId/project/$projectId/task/$taskId",
+ params: {
+ workspaceId,
+ projectId,
+ taskId: subtasks[focusedIndex].task.id,
+ },
+ });
+ }
+ break;
+ }
+ case "Escape": {
+ if (hasSelection) {
+ e.preventDefault();
+ clearSelection();
+ } else if (focusedIndex >= 0) {
+ e.preventDefault();
+ setFocusedIndex(-1);
+ }
+ break;
+ }
+ }
+ };
+
+ document.addEventListener("keydown", handleKeyDown);
+ return () => document.removeEventListener("keydown", handleKeyDown);
+ }, [
+ focusedIndex,
+ totalCount,
+ subtasks,
+ hasSelection,
+ clearSelection,
+ navigate,
+ workspaceId,
+ projectId,
+ toggleSelection,
+ ]);
+
const handleAddSubtask = async () => {
if (!newTitle.trim()) return;
@@ -216,36 +302,48 @@ export default function TaskSubtasks({
</div>
<CollapsibleContent>
- <div className="flex flex-col mt-1">
- {subtasks.map((subtask, index) => {
- const taskObj = buildTaskObject(subtask);
- const isSelected = selectedIds.has(subtask.task.id);
+ {/* biome-ignore lint/a11y/noStaticElementInteractions: keyboard nav managed via document listener */}
+ <div
+ ref={containerRef}
+ className="flex flex-col mt-1"
+ onMouseDown={() => {
+ if (focusedIndex === -1 && !hasSelection) {
+ setFocusedIndex(0);
+ }
+ }}
+ >
+ <AnimatePresence initial={false}>
+ {subtasks.map((subtask, index) => {
+ const taskObj = buildTaskObject(subtask);
+ const isSelected = selectedIds.has(subtask.task.id);
- return (
- <SubtaskRow
- key={subtask.relation.id}
- task={taskObj}
- tasks={getTargetTasks(taskObj)}
- projectId={projectId}
- workspaceId={workspace?.id ?? workspaceId}
- isSelected={isSelected}
- selectionRadius={getSelectionRadius(index, isSelected)}
- assignee={getAssignee(subtask.task.userId)}
- onToggleSelection={() => toggleSelection(subtask.task.id)}
- onNavigate={() =>
- navigate({
- to: "/dashboard/workspace/$workspaceId/project/$projectId/task/$taskId",
- params: {
- workspaceId,
- projectId,
- taskId: subtask.task.id,
- },
- })
- }
- onDeleteClick={() => setDeleteTaskId(subtask.task.id)}
- />
- );
- })}
+ return (
+ <SubtaskRow
+ key={subtask.task.id}
+ task={taskObj}
+ tasks={getTargetTasks(taskObj)}
+ projectId={projectId}
+ workspaceId={workspace?.id ?? workspaceId}
+ isSelected={isSelected}
+ isFocused={focusedIndex === index}
+ selectionRadius={getSelectionRadius(index, isSelected)}
+ assignee={getAssignee(subtask.task.userId)}
+ onToggleSelection={() => toggleSelection(subtask.task.id)}
+ onNavigate={() =>
+ navigate({
+ to: "/dashboard/workspace/$workspaceId/project/$projectId/task/$taskId",
+ params: {
+ workspaceId,
+ projectId,
+ taskId: subtask.task.id,
+ },
+ })
+ }
+ onDeleteClick={() => setDeleteTaskId(subtask.task.id)}
+ />
+ );
+ })}
+ </AnimatePresence>
</div>
{isAdding && (