⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
feat: implement bulk selection and actions for tasks with a new toolbar and menu
Andrej Acevskibe1f90a60eb0
diff --git a/apps/web/src/components/bulk-selection/bulk-actions-menu.tsx b/apps/web/src/components/bulk-selection/bulk-actions-menu.tsxnew file mode 100644index 000000000..3c4d1246f--- /dev/null+++ b/apps/web/src/components/bulk-selection/bulk-actions-menu.tsx@@ -0,0 +1,161 @@+import {+ Archive,+ EllipsisVertical,+ Flag,+ Menu,+ Trash2,+ User,+} from "lucide-react";+import { useState } from "react";+import { toast } from "sonner";+import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";+import {+ CommandDialog,+ CommandGroup,+ CommandInput,+ CommandItem,+ CommandList,+} from "@/components/ui/command";+import { useBulkOperations } from "@/hooks/mutations/task/use-bulk-operations";+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 useBulkSelectionStore from "@/store/bulk-selection";+import { Button } from "../ui/button";++function BulkActionsMenu() {+ const [isOpen, setIsOpen] = useState(false);+ const { selectedTaskIds, clearSelection } = useBulkSelectionStore();+ const { data: workspace } = useActiveWorkspace();+ const { data: workspaceUsers } = useGetActiveWorkspaceUsers(+ workspace?.id ?? "",+ );+ const { bulkDelete, bulkArchive, bulkChangeStatus, bulkAssign } =+ useBulkOperations();++ const selectedCount = selectedTaskIds.size;++ const handleBulkDelete = async () => {+ if (+ !confirm(`Delete ${selectedCount} tasks? This action cannot be undone.`)+ ) {+ return;+ }++ try {+ await bulkDelete(Array.from(selectedTaskIds));+ toast.success(`${selectedCount} tasks deleted`);+ clearSelection();+ setIsOpen(false);+ } catch (_error) {+ toast.error("Failed to delete tasks");+ }+ };++ const handleBulkArchive = async () => {+ try {+ await bulkArchive(Array.from(selectedTaskIds));+ toast.success(`${selectedCount} tasks archived`);+ clearSelection();+ setIsOpen(false);+ } catch (_error) {+ toast.error("Failed to archive tasks");+ }+ };++ const handleBulkChangeStatus = async (status: string) => {+ try {+ await bulkChangeStatus({ taskIds: Array.from(selectedTaskIds), status });+ toast.success(`${selectedCount} tasks updated`);+ clearSelection();+ setIsOpen(false);+ } catch (_error) {+ toast.error("Failed to update tasks");+ }+ };++ const handleBulkAssign = async (userId: string) => {+ try {+ await bulkAssign({ taskIds: Array.from(selectedTaskIds), userId });+ toast.success(`${selectedCount} tasks assigned`);+ clearSelection();+ setIsOpen(false);+ } catch (_error) {+ toast.error("Failed to assign tasks");+ }+ };++ if (selectedCount === 0) return null;++ return (+ <>+ <Button size="sm" variant="outline" onClick={() => setIsOpen(true)}>+ <Menu className="size-3" />+ Actions+ </Button>++ <CommandDialog+ title="Bulk Actions"+ open={isOpen}+ onOpenChange={setIsOpen}+ >+ <CommandInput placeholder="Search actions..." />+ <CommandList>+ <CommandGroup heading="Actions">+ <CommandItem onSelect={handleBulkDelete}>+ <Trash2 className="w-4 h-4 mr-2" />+ Delete tasks+ </CommandItem>+ <CommandItem onSelect={handleBulkArchive}>+ <Archive className="w-4 h-4 mr-2" />+ Archive tasks+ </CommandItem>+ </CommandGroup>++ <CommandGroup heading="Change Status">+ <CommandItem onSelect={() => handleBulkChangeStatus("to-do")}>+ {getColumnIcon("to-do")}+ To Do+ </CommandItem>+ <CommandItem onSelect={() => handleBulkChangeStatus("in-progress")}>+ {getColumnIcon("in-progress")}+ In Progress+ </CommandItem>+ <CommandItem onSelect={() => handleBulkChangeStatus("in-review")}>+ {getColumnIcon("in-review")}+ In Review+ </CommandItem>+ <CommandItem onSelect={() => handleBulkChangeStatus("done")}>+ {getColumnIcon("done")}+ Done+ </CommandItem>+ </CommandGroup>++ <CommandGroup heading="Assign to">+ {workspaceUsers?.members?.map((member) => (+ <CommandItem+ key={member.userId}+ onSelect={() => handleBulkAssign(member.userId)}+ >+ <Avatar className="h-6 w-6">+ <AvatarImage+ src={member.user?.image ?? ""}+ alt={member.user?.name || ""}+ />+ <AvatarFallback className="text-xs font-medium border border-border/30">+ {member.user?.name?.charAt(0).toUpperCase()}+ </AvatarFallback>+ </Avatar>+ <span className="text-sm">+ {member.user?.name || "Unknown User"}+ </span>+ </CommandItem>+ ))}+ </CommandGroup>+ </CommandList>+ </CommandDialog>+ </>+ );+}++export default BulkActionsMenu;diff --git a/apps/web/src/components/bulk-selection/bulk-toolbar.tsx b/apps/web/src/components/bulk-selection/bulk-toolbar.tsxnew file mode 100644index 000000000..68748544b--- /dev/null+++ b/apps/web/src/components/bulk-selection/bulk-toolbar.tsx@@ -0,0 +1,89 @@+import { ArrowDownToLine, X } from "lucide-react";+import { useEffect } from "react";+import { toast } from "sonner";+import { useBulkOperations } from "@/hooks/mutations/task/use-bulk-operations";+import useBulkSelectionStore from "@/store/bulk-selection";+import { Button } from "../ui/button";+import BulkActionsMenu from "./bulk-actions-menu";++function BulkToolbar() {+ const { selectedTaskIds, clearSelection, selectAll } =+ useBulkSelectionStore();+ const { bulkMoveToBacklog } = useBulkOperations();++ const selectedCount = selectedTaskIds.size;++ useEffect(() => {+ const handleKeyDown = (e: KeyboardEvent) => {+ if ((e.metaKey || e.ctrlKey) && e.key === "a") {+ e.preventDefault();+ selectAll();+ }++ if (e.key === "Escape") {+ e.preventDefault();+ clearSelection();+ }+ };++ document.addEventListener("keydown", handleKeyDown);+ return () => document.removeEventListener("keydown", handleKeyDown);+ }, [selectAll, clearSelection]);++ const handleMoveToBacklog = async () => {+ if (+ !confirm(+ `Move ${selectedCount} tasks to backlog? This will change their status to "planned".`,+ )+ ) {+ return;+ }++ try {+ await bulkMoveToBacklog(Array.from(selectedTaskIds));+ toast.success(`${selectedCount} tasks moved to backlog`);+ clearSelection();+ } catch (_error) {+ toast.error("Failed to move tasks to backlog");+ }+ };++ if (selectedCount === 0) return null;++ return (+ <div className="fixed bottom-4 left-1/2 transform -translate-x-1/2 z-50">+ <div className="bg-background/95 backdrop-blur-sm border border-border rounded-lg shadow-lg p-3 flex items-center gap-3">+ <span className="text-sm font-medium text-foreground">+ {selectedCount} selected+ </span>+ <hr className="w-px h-6 bg-border" />++ <Button onClick={handleMoveToBacklog} size="sm" variant="outline">+ <ArrowDownToLine className="size-3" />+ Move to Backlog+ </Button>++ <div className="flex-1 gap-2">+ <BulkActionsMenu />++ <Button+ variant="ghost"+ className="ml-2"+ onClick={clearSelection}+ size="sm"+ >+ <X className="size-3" />+ </Button>+ </div>+ </div>++ {selectedCount === 0 && (+ <div className="fixed bottom-20 left-1/2 transform -translate-x-1/2 text-xs text-muted-foreground/70 bg-background/90 backdrop-blur-sm border border-border/40 rounded-md px-3 py-2 shadow-md max-w-sm">+ Hold Cmd/Ctrl + Click to select tasks • Cmd/Ctrl + A to select all+ </div>+ )}+ </div>+ );+}++export default BulkToolbar;diff --git a/apps/web/src/components/kanban-board/index.tsx b/apps/web/src/components/kanban-board/index.tsxindex 00bd1ddf5..a462d3cee 100644--- a/apps/web/src/components/kanban-board/index.tsx+++ b/apps/web/src/components/kanban-board/index.tsx@@ -15,10 +15,12 @@ import {} from "@dnd-kit/core";import { useQueryClient } from "@tanstack/react-query";import { produce } from "immer";-import { useState } from "react";+import { useEffect, useState } from "react";import { useUpdateTask } from "@/hooks/mutations/task/use-update-task";+import useBulkSelectionStore from "@/store/bulk-selection";import useProjectStore from "@/store/project";import type { ProjectWithTasks } from "@/types/project";+import BulkToolbar from "../bulk-selection/bulk-toolbar";import Column from "./column";import TaskCard from "./task-card";@@ -29,9 +31,19 @@ type KanbanBoardProps = {function KanbanBoard({ project }: KanbanBoardProps) {const queryClient = useQueryClient();const { setProject } = useProjectStore();+ const { setAvailableTasks } = useBulkSelectionStore();const [activeId, setActiveId] = useState<UniqueIdentifier | null>(null);const { mutate: updateTask } = useUpdateTask();+ useEffect(() => {+ if (project?.columns) {+ const allTaskIds = project.columns.flatMap((column) =>+ column.tasks.map((task) => task.id),+ );+ setAvailableTasks(allTaskIds);+ }+ }, [project, setAvailableTasks]);+const sensors = useSensors(useSensor(MouseSensor, {activationConstraint: { distance: 8 },@@ -207,6 +219,8 @@ function KanbanBoard({ project }: KanbanBoardProps) {</div>) : null}</DragOverlay>++ <BulkToolbar /></DndContext>);}diff --git a/apps/web/src/components/kanban-board/task-card.tsx b/apps/web/src/components/kanban-board/task-card.tsxindex 40dbb79b3..96175cd3b 100644--- a/apps/web/src/components/kanban-board/task-card.tsx+++ b/apps/web/src/components/kanban-board/task-card.tsx@@ -34,6 +34,7 @@ import { useGetActiveWorkspaceUsers } from "@/hooks/queries/workspace-users/use-import { dueDateStatusColors, getDueDateStatus } from "@/lib/due-date-status";import { getPriorityIcon } from "@/lib/priority";import queryClient from "@/query-client";+import useBulkSelectionStore from "@/store/bulk-selection";import useProjectStore from "@/store/project";import { useUserPreferencesStore } from "@/store/user-preferences";import type Task from "@/types/task";@@ -67,6 +68,8 @@ function TaskCard({ task }: TaskCardProps) {const [isDeleteTaskModalOpen, setIsDeleteTaskModalOpen] = useState(false);const { mutateAsync: deleteTask } = useDeleteTask();const { data: externalLinks } = useExternalLinks(task.id);+ const { toggleSelection, isSelected } = useBulkSelectionStore();+ const isTaskSelected = isSelected(task.id);const pullRequests = useMemo(() => {if (!externalLinks) return [];@@ -119,9 +122,16 @@ function TaskCard({ task }: TaskCardProps) {);}, [workspaceUsers, task.userId]);- function handleTaskCardClick() {+ function handleTaskCardClick(+ e: React.MouseEvent<HTMLDivElement> | React.KeyboardEvent<HTMLDivElement>,+ ) {if (!project || !task || !workspace) return;+ if ((e as React.MouseEvent).metaKey || (e as React.KeyboardEvent).ctrlKey) {+ toggleSelection(task.id);+ return;+ }+navigate({to: "/dashboard/workspace/$workspaceId/project/$projectId/task/$taskId",params: {@@ -132,6 +142,12 @@ function TaskCard({ task }: TaskCardProps) {});}+ const handleKeyDown = (e: React.KeyboardEvent) => {+ if (e.key === "Escape") {+ toggleSelection(task.id);+ }+ };+const handleDeleteTask = async () => {try {await deleteTask(task.id);@@ -158,9 +174,13 @@ function TaskCard({ task }: TaskCardProps) {isDragging? "border-primary/30 shadow-lg shadow-primary/10 bg-card/90": "hover:border-border/70 hover:shadow-sm"- }`}+ } ${isTaskSelected ? "bg-primary/10 shadow-sm" : ""}`}onKeyDown={(e) => {- if (e.key === "Enter") handleTaskCardClick();+ if (e.key === "Enter") {+ handleTaskCardClick(e);+ } else if (e.key === "Escape") {+ handleKeyDown(e);+ }}}>{showTaskNumbers && (diff --git a/apps/web/src/components/ui/button.tsx b/apps/web/src/components/ui/button.tsxindex f175d4968..326bbb3da 100644--- a/apps/web/src/components/ui/button.tsx+++ b/apps/web/src/components/ui/button.tsx@@ -23,7 +23,7 @@ const buttonVariants = cva(},size: {default: "h-9 px-4 py-2 has-[>svg]:px-3",- sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",+ sm: "h-7 rounded-md gap-1.5 px-2.5 has-[>svg]:px-2",xs: "h-6 rounded-md gap-1 px-2 text-xs has-[>svg]:px-1.5",lg: "h-10 rounded-md px-6 has-[>svg]:px-4",icon: "size-9",diff --git a/apps/web/src/hooks/mutations/task/use-bulk-operations.ts b/apps/web/src/hooks/mutations/task/use-bulk-operations.tsnew file mode 100644index 000000000..92d4e8571--- /dev/null+++ b/apps/web/src/hooks/mutations/task/use-bulk-operations.ts@@ -0,0 +1,104 @@+import { useMutation, useQueryClient } from "@tanstack/react-query";+import deleteTask from "@/fetchers/task/delete-task";+import updateTaskAssignee from "@/fetchers/task/update-task-assignee";+import updateTaskStatus from "@/fetchers/task/update-task-status";++export function useBulkOperations() {+ const queryClientRef = useQueryClient();++ const bulkDelete = useMutation({+ mutationFn: async (taskIds: string[]) => {+ await Promise.all(taskIds.map((id) => deleteTask(id)));+ },+ onSuccess: () => {+ queryClientRef.invalidateQueries({+ queryKey: ["tasks"],+ });+ queryClientRef.invalidateQueries({+ queryKey: ["projects"],+ });+ },+ });++ const bulkArchive = useMutation({+ mutationFn: async (taskIds: string[]) => {+ await Promise.all(+ taskIds.map((id) => updateTaskStatus(id, { status: "archived" })),+ );+ },+ onSuccess: () => {+ queryClientRef.invalidateQueries({+ queryKey: ["tasks"],+ });+ queryClientRef.invalidateQueries({+ queryKey: ["projects"],+ });+ },+ });++ const bulkChangeStatus = useMutation({+ mutationFn: async ({+ taskIds,+ status,+ }: {+ taskIds: string[];+ status: string;+ }) => {+ await Promise.all(taskIds.map((id) => updateTaskStatus(id, { status })));+ },+ onSuccess: () => {+ queryClientRef.invalidateQueries({+ queryKey: ["tasks"],+ });+ queryClientRef.invalidateQueries({+ queryKey: ["projects"],+ });+ },+ });++ const bulkAssign = useMutation({+ mutationFn: async ({+ taskIds,+ userId,+ }: {+ taskIds: string[];+ userId: string;+ }) => {+ await Promise.all(+ taskIds.map((id) => updateTaskAssignee(id, { userId })),+ );+ },+ onSuccess: () => {+ queryClientRef.invalidateQueries({+ queryKey: ["tasks"],+ });+ queryClientRef.invalidateQueries({+ queryKey: ["projects"],+ });+ },+ });++ const bulkMoveToBacklog = useMutation({+ mutationFn: async (taskIds: string[]) => {+ await Promise.all(+ taskIds.map((id) => updateTaskStatus(id, { status: "planned" })),+ );+ },+ onSuccess: () => {+ queryClientRef.invalidateQueries({+ queryKey: ["tasks"],+ });+ queryClientRef.invalidateQueries({+ queryKey: ["projects"],+ });+ },+ });++ return {+ bulkDelete: bulkDelete.mutateAsync,+ bulkArchive: bulkArchive.mutateAsync,+ bulkChangeStatus: bulkChangeStatus.mutateAsync,+ bulkAssign: bulkAssign.mutateAsync,+ bulkMoveToBacklog: bulkMoveToBacklog.mutateAsync,+ };+}diff --git a/apps/web/src/store/bulk-selection.ts b/apps/web/src/store/bulk-selection.tsnew file mode 100644index 000000000..06907df61--- /dev/null+++ b/apps/web/src/store/bulk-selection.ts@@ -0,0 +1,76 @@+import { create } from "zustand";++interface BulkSelectionState {+ selectedTaskIds: Set<string>;+ isSelectMode: boolean;+ availableTaskIds: string[];++ selectTask: (taskId: string) => void;+ deselectTask: (taskId: string) => void;+ toggleSelection: (taskId: string) => void;+ clearSelection: () => void;+ selectAll: () => void;+ setAvailableTasks: (taskIds: string[]) => void;+ getSelectedCount: () => number;+ isSelected: (taskId: string) => boolean;+}++const useBulkSelectionStore = create<BulkSelectionState>((set, get) => ({+ selectedTaskIds: new Set(),+ isSelectMode: false,+ availableTaskIds: [],++ selectTask: (taskId: string) =>+ set((state) => ({+ selectedTaskIds: new Set([...state.selectedTaskIds, taskId]),+ isSelectMode: true,+ })),++ deselectTask: (taskId: string) =>+ set((state) => {+ const newSet = new Set(state.selectedTaskIds);+ newSet.delete(taskId);+ return {+ selectedTaskIds: newSet,+ isSelectMode: newSet.size > 0,+ };+ }),++ toggleSelection: (taskId: string) => {+ const { selectedTaskIds } = get();+ if (selectedTaskIds.has(taskId)) {+ get().deselectTask(taskId);+ } else {+ get().selectTask(taskId);+ }+ },++ clearSelection: () =>+ set({+ selectedTaskIds: new Set(),+ isSelectMode: false,+ }),++ selectAll: () =>+ set((state) => ({+ selectedTaskIds: new Set(state.availableTaskIds),+ isSelectMode: true,+ })),++ setAvailableTasks: (taskIds: string[]) =>+ set(() => ({+ availableTaskIds: taskIds,+ })),++ getSelectedCount: () => {+ const { selectedTaskIds } = get();+ return selectedTaskIds.size;+ },++ isSelected: (taskId: string) => {+ const { selectedTaskIds } = get();+ return selectedTaskIds.has(taskId);+ },+}));++export default useBulkSelectionStore;