⚡ 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: add bulk assign labels, priority & deadlines
Andrej37d1356631fa
diff --git a/apps/api/src/task/controllers/bulk-update-tasks.ts b/apps/api/src/task/controllers/bulk-update-tasks.tsindex 1dd60f05f..b0b9c1e4d 100644--- a/apps/api/src/task/controllers/bulk-update-tasks.ts+++ b/apps/api/src/task/controllers/bulk-update-tasks.ts@@ -15,7 +15,8 @@ type BulkOperation =| "updateAssignee"| "delete"| "addLabel"- | "removeLabel";+ | "removeLabel"+ | "updateDueDate";async function bulkUpdateTasks({taskIds,@@ -190,6 +191,16 @@ async function bulkUpdateTasks({updatedCount = result.rowCount ?? foundIds.length;break;}++ case "updateDueDate": {+ const result = await db+ .update(taskTable)+ .set({ dueDate: value ? new Date(value) : null })+ .where(inArray(taskTable.id, foundIds));++ updatedCount = result.rowCount ?? foundIds.length;+ break;+ }}return { success: true, updatedCount };diff --git a/apps/api/src/task/index.ts b/apps/api/src/task/index.tsindex 4e7b0fc6a..e548c286b 100644--- a/apps/api/src/task/index.ts+++ b/apps/api/src/task/index.ts@@ -125,6 +125,7 @@ const task = new Hono<{"delete","addLabel","removeLabel",+ "updateDueDate",] as const),value: v.optional(v.nullable(v.string())),}),@@ -137,7 +138,11 @@ const task = new Hono<{throw new HTTPException(401, { message: "Unauthorized" });}- if (operation !== "delete" && value === undefined) {+ if (+ operation !== "delete" &&+ operation !== "updateDueDate" &&+ value === undefined+ ) {throw new HTTPException(400, {message: "Value is required for this operation",});diff --git a/apps/web/src/components/bulk-selection/backlog-bulk-toolbar.tsx b/apps/web/src/components/bulk-selection/backlog-bulk-toolbar.tsxindex e38662c22..c85355340 100644--- a/apps/web/src/components/bulk-selection/backlog-bulk-toolbar.tsx+++ b/apps/web/src/components/bulk-selection/backlog-bulk-toolbar.tsx@@ -1,6 +1,7 @@import {Archive,ArrowUpToLine,+ CalendarIcon,ChevronDown,Menu,Trash2,@@ -15,6 +16,7 @@ import {useState,} from "react";import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";+import { Calendar } from "@/components/ui/calendar";import {Command,CommandCollection,@@ -35,10 +37,18 @@ import {DropdownMenuItem,DropdownMenuTrigger,} from "@/components/ui/menu";+import {+ Popover,+ PopoverContent,+ PopoverTrigger,+} from "@/components/ui/popover";+import labelColors from "@/constants/label-colors";import { useBulkOperations } from "@/hooks/mutations/task/use-bulk-operations";+import useGetLabelsByWorkspace from "@/hooks/queries/label/use-get-labels-by-workspace";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 { getPriorityIcon } from "@/lib/priority";import { toast } from "@/lib/toast";import useBacklogBulkSelectionStore from "@/store/backlog-bulk-selection";import useProjectStore from "@/store/project";@@ -58,20 +68,50 @@ type BacklogActionGroup = {items: BacklogActionItem[];};+const priorityOptions = [+ { value: "urgent", label: "Urgent" },+ { value: "high", label: "High" },+ { value: "medium", label: "Medium" },+ { value: "low", label: "Low" },+ { value: "no-priority", label: "No Priority" },+];+function BacklogBulkToolbar() {const { selectedTaskIds, clearSelection, selectAll } =useBacklogBulkSelectionStore();const { project } = useProjectStore();- const { bulkMoveToBoard, bulkDelete, bulkArchive, bulkAssign } =- useBulkOperations();+ const {+ bulkMoveToBoard,+ bulkDelete,+ bulkArchive,+ bulkAssign,+ bulkPriority,+ bulkAddLabel,+ bulkDueDate,+ } = useBulkOperations();const { data: workspace } = useActiveWorkspace();const { data: workspaceUsers } = useGetActiveWorkspaceUsers(workspace?.id ?? "",);+ const { data: workspaceLabels = [] } = useGetLabelsByWorkspace(+ workspace?.id ?? "",+ );const [isActionsOpen, setIsActionsOpen] = useState(false);+ const [isDatePickerOpen, setIsDatePickerOpen] = useState(false);const selectedCount = selectedTaskIds.size;+ const uniqueLabels = useMemo(() => {+ const labelMap = new Map<string, (typeof workspaceLabels)[0]>();+ for (const label of workspaceLabels) {+ const existing = labelMap.get(label.name);+ if (!existing || (label.taskId === null && existing.taskId !== null)) {+ labelMap.set(label.name, label);+ }+ }+ return Array.from(labelMap.values());+ }, [workspaceLabels]);+useEffect(() => {const handleKeyDown = (e: KeyboardEvent) => {const target = e.target as HTMLElement | null;@@ -155,6 +195,57 @@ function BacklogBulkToolbar() {[bulkAssign, selectedTaskIds, selectedCount, clearSelection],);+ const handleBulkPriority = useCallback(+ async (priority: string) => {+ try {+ await bulkPriority({+ taskIds: Array.from(selectedTaskIds),+ priority,+ });+ toast.success(`${selectedCount} tasks updated`);+ clearSelection();+ setIsActionsOpen(false);+ } catch (_error) {+ toast.error("Failed to update priority");+ }+ },+ [bulkPriority, selectedTaskIds, selectedCount, clearSelection],+ );++ const handleBulkAddLabel = useCallback(+ async (labelId: string) => {+ try {+ await bulkAddLabel({+ taskIds: Array.from(selectedTaskIds),+ labelId,+ });+ toast.success(`Label added to ${selectedCount} tasks`);+ clearSelection();+ setIsActionsOpen(false);+ } catch (_error) {+ toast.error("Failed to add label");+ }+ },+ [bulkAddLabel, selectedTaskIds, selectedCount, clearSelection],+ );++ const handleBulkDueDate = useCallback(+ async (date: Date | undefined) => {+ try {+ await bulkDueDate({+ taskIds: Array.from(selectedTaskIds),+ dueDate: date?.toISOString() ?? null,+ });+ toast.success(`${selectedCount} tasks updated`);+ clearSelection();+ setIsDatePickerOpen(false);+ } catch (_error) {+ toast.error("Failed to update due date");+ }+ },+ [bulkDueDate, selectedTaskIds, selectedCount, clearSelection],+ );+const groupedItems = useMemo<BacklogActionGroup[]>(() => [{@@ -201,12 +292,48 @@ function BacklogBulkToolbar() {},})),},+ {+ value: "priority",+ label: "Set Priority",+ items: priorityOptions.map((opt) => ({+ value: `priority-${opt.value}`,+ label: opt.label,+ icon: getPriorityIcon(opt.value),+ onRun: () => {+ void handleBulkPriority(opt.value);+ },+ })),+ },+ {+ value: "label",+ label: "Add Label",+ items: uniqueLabels.map((label) => ({+ value: `label-${label.id}`,+ label: label.name,+ icon: (+ <span+ className="inline-block w-3 h-3 rounded-full shrink-0"+ style={{+ backgroundColor:+ labelColors.find((c) => c.value === label.color)?.color ||+ "var(--color-neutral-400)",+ }}+ />+ ),+ onRun: () => {+ void handleBulkAddLabel(label.id);+ },+ })),+ },],[workspaceUsers?.members,+ uniqueLabels,handleBulkDelete,handleBulkArchive,handleBulkAssign,+ handleBulkPriority,+ handleBulkAddLabel,],);@@ -248,6 +375,37 @@ function BacklogBulkToolbar() {<ToolbarSeparator orientation="vertical" className="my-1 h-5" />+ <ToolbarGroup>+ <Popover open={isDatePickerOpen} onOpenChange={setIsDatePickerOpen}>+ <PopoverTrigger asChild>+ <Button size="sm" variant="ghost">+ <CalendarIcon className="size-4" />+ Set Due Date+ </Button>+ </PopoverTrigger>+ <PopoverContent className="p-0" align="center">+ <Calendar+ mode="single"+ onSelect={handleBulkDueDate}+ className="w-full bg-popover"+ />+ <div className="p-0 border-t border-border">+ <Button+ variant="ghost"+ size="sm"+ className="w-full justify-start gap-2 text-muted-foreground hover:text-foreground rounded-none"+ onClick={() => handleBulkDueDate(undefined)}+ >+ <X className="h-4 w-4" />+ Clear date+ </Button>+ </div>+ </PopoverContent>+ </Popover>+ </ToolbarGroup>++ <ToolbarSeparator orientation="vertical" className="my-1 h-5" />+<ToolbarGroup><Buttonsize="sm"diff --git a/apps/web/src/components/bulk-selection/bulk-toolbar.tsx b/apps/web/src/components/bulk-selection/bulk-toolbar.tsxindex 7af6725ac..82c772567 100644--- a/apps/web/src/components/bulk-selection/bulk-toolbar.tsx+++ b/apps/web/src/components/bulk-selection/bulk-toolbar.tsx@@ -1,4 +1,12 @@-import { Archive, ArrowDownToLine, Menu, Trash2, X } from "lucide-react";+import {+ Archive,+ ArrowDownToLine,+ CalendarIcon,+ Menu,+ Tag,+ Trash2,+ X,+} from "lucide-react";import {Fragment,type ReactNode,@@ -8,6 +16,7 @@ import {useState,} from "react";import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";+import { Calendar } from "@/components/ui/calendar";import {Command,CommandCollection,@@ -22,10 +31,18 @@ import {CommandPanel,CommandSeparator,} from "@/components/ui/command";+import {+ Popover,+ PopoverContent,+ PopoverTrigger,+} from "@/components/ui/popover";+import labelColors from "@/constants/label-colors";import { useBulkOperations } from "@/hooks/mutations/task/use-bulk-operations";+import useGetLabelsByWorkspace from "@/hooks/queries/label/use-get-labels-by-workspace";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 { getPriorityIcon } from "@/lib/priority";import { toast } from "@/lib/toast";import useBulkSelectionStore from "@/store/bulk-selection";import useProjectStore from "@/store/project";@@ -45,6 +62,14 @@ type BulkActionGroup = {items: BulkActionItem[];};+const priorityOptions = [+ { value: "urgent", label: "Urgent" },+ { value: "high", label: "High" },+ { value: "medium", label: "Medium" },+ { value: "low", label: "Low" },+ { value: "no-priority", label: "No Priority" },+];+function BulkToolbar() {const { selectedTaskIds, clearSelection, selectAll } =useBulkSelectionStore();@@ -55,15 +80,33 @@ function BulkToolbar() {bulkArchive,bulkChangeStatus,bulkAssign,+ bulkPriority,+ bulkAddLabel,+ bulkDueDate,} = useBulkOperations();const { data: workspace } = useActiveWorkspace();const { data: workspaceUsers } = useGetActiveWorkspaceUsers(workspace?.id ?? "",);+ const { data: workspaceLabels = [] } = useGetLabelsByWorkspace(+ workspace?.id ?? "",+ );const [isActionsOpen, setIsActionsOpen] = useState(false);+ const [isDatePickerOpen, setIsDatePickerOpen] = useState(false);const selectedCount = selectedTaskIds.size;+ const uniqueLabels = useMemo(() => {+ const labelMap = new Map<string, (typeof workspaceLabels)[0]>();+ for (const label of workspaceLabels) {+ const existing = labelMap.get(label.name);+ if (!existing || (label.taskId === null && existing.taskId !== null)) {+ labelMap.set(label.name, label);+ }+ }+ return Array.from(labelMap.values());+ }, [workspaceLabels]);+useEffect(() => {const handleKeyDown = (e: KeyboardEvent) => {const target = e.target as HTMLElement | null;@@ -158,6 +201,57 @@ function BulkToolbar() {[bulkAssign, selectedTaskIds, selectedCount, clearSelection],);+ const handleBulkPriority = useCallback(+ async (priority: string) => {+ try {+ await bulkPriority({+ taskIds: Array.from(selectedTaskIds),+ priority,+ });+ toast.success(`${selectedCount} tasks updated`);+ clearSelection();+ setIsActionsOpen(false);+ } catch (_error) {+ toast.error("Failed to update priority");+ }+ },+ [bulkPriority, selectedTaskIds, selectedCount, clearSelection],+ );++ const handleBulkAddLabel = useCallback(+ async (labelId: string) => {+ try {+ await bulkAddLabel({+ taskIds: Array.from(selectedTaskIds),+ labelId,+ });+ toast.success(`Label added to ${selectedCount} tasks`);+ clearSelection();+ setIsActionsOpen(false);+ } catch (_error) {+ toast.error("Failed to add label");+ }+ },+ [bulkAddLabel, selectedTaskIds, selectedCount, clearSelection],+ );++ const handleBulkDueDate = useCallback(+ async (date: Date | undefined) => {+ try {+ await bulkDueDate({+ taskIds: Array.from(selectedTaskIds),+ dueDate: date?.toISOString() ?? null,+ });+ toast.success(`${selectedCount} tasks updated`);+ clearSelection();+ setIsDatePickerOpen(false);+ } catch (_error) {+ toast.error("Failed to update due date");+ }+ },+ [bulkDueDate, selectedTaskIds, selectedCount, clearSelection],+ );+const groupedItems = useMemo<BulkActionGroup[]>(() => [{@@ -216,14 +310,50 @@ function BulkToolbar() {},})),},+ {+ value: "priority",+ label: "Set Priority",+ items: priorityOptions.map((opt) => ({+ value: `priority-${opt.value}`,+ label: opt.label,+ icon: getPriorityIcon(opt.value),+ onRun: () => {+ void handleBulkPriority(opt.value);+ },+ })),+ },+ {+ value: "label",+ label: "Add Label",+ items: uniqueLabels.map((label) => ({+ value: `label-${label.id}`,+ label: label.name,+ icon: (+ <span+ className="inline-block w-3 h-3 rounded-full shrink-0"+ style={{+ backgroundColor:+ labelColors.find((c) => c.value === label.color)?.color ||+ "var(--color-neutral-400)",+ }}+ />+ ),+ onRun: () => {+ void handleBulkAddLabel(label.id);+ },+ })),+ },],[project?.columns,workspaceUsers?.members,+ uniqueLabels,handleBulkDelete,handleBulkArchive,handleBulkChangeStatus,handleBulkAssign,+ handleBulkPriority,+ handleBulkAddLabel,],);@@ -249,6 +379,37 @@ function BulkToolbar() {<ToolbarSeparator orientation="vertical" className="my-1 h-5" />+ <ToolbarGroup>+ <Popover open={isDatePickerOpen} onOpenChange={setIsDatePickerOpen}>+ <PopoverTrigger asChild>+ <Button size="sm" variant="ghost">+ <CalendarIcon className="size-4" />+ Set Due Date+ </Button>+ </PopoverTrigger>+ <PopoverContent className="p-0" align="center">+ <Calendar+ mode="single"+ onSelect={handleBulkDueDate}+ className="w-full bg-popover"+ />+ <div className="p-0 border-t border-border">+ <Button+ variant="ghost"+ size="sm"+ className="w-full justify-start gap-2 text-muted-foreground hover:text-foreground rounded-none"+ onClick={() => handleBulkDueDate(undefined)}+ >+ <X className="h-4 w-4" />+ Clear date+ </Button>+ </div>+ </PopoverContent>+ </Popover>+ </ToolbarGroup>++ <ToolbarSeparator orientation="vertical" className="my-1 h-5" />+<ToolbarGroup><Buttonsize="sm"diff --git a/apps/web/src/components/kanban-board/task-labels.tsx b/apps/web/src/components/kanban-board/task-labels.tsxindex 2d6d992ee..41dc3eec0 100644--- a/apps/web/src/components/kanban-board/task-labels.tsx+++ b/apps/web/src/components/kanban-board/task-labels.tsx@@ -20,14 +20,16 @@ function isValidHtmlColor(color: string): boolean {}function validColor(value: string): string {+ const mapped = labelColors.find((c) => c.value === value)?.color;+ if (mapped) {+ return mapped;+ }+if (isValidHtmlColor(value)) {return value;}- return (- labelColors.find((c) => c.value === value)?.color ||- "var(--color-neutral-400)"- );+ return "var(--color-neutral-400)";}function TaskCardLabels({ taskId }: { taskId: string }) {@@ -40,7 +42,6 @@ function TaskCardLabels({ taskId }: { taskId: string }) {{labels.map((label: { id: string; name: string; color: string }) => (<Badgekey={label.id}- color={label.color}variant="outline"className="px-2 py-0.5 text-[10px] flex items-center">diff --git a/apps/web/src/fetchers/task/bulk-operation.ts b/apps/web/src/fetchers/task/bulk-operation.tsnew file mode 100644index 000000000..8fad79753--- /dev/null+++ b/apps/web/src/fetchers/task/bulk-operation.ts@@ -0,0 +1,33 @@+import { client } from "@kaneo/libs";++type BulkOperationType =+ | "updateStatus"+ | "updatePriority"+ | "updateAssignee"+ | "delete"+ | "addLabel"+ | "removeLabel"+ | "updateDueDate";++async function bulkOperation({+ taskIds,+ operation,+ value,+}: {+ taskIds: string[];+ operation: BulkOperationType;+ value?: string | null;+}) {+ const response = await client.task.bulk.$patch({+ json: { taskIds, operation, value },+ });++ if (!response.ok) {+ const error = await response.text();+ throw new Error(error);+ }++ return response.json();+}++export default bulkOperation;diff --git a/apps/web/src/hooks/mutations/task/use-bulk-operations.ts b/apps/web/src/hooks/mutations/task/use-bulk-operations.tsindex 04f82a6c8..b96cea296 100644--- a/apps/web/src/hooks/mutations/task/use-bulk-operations.ts+++ b/apps/web/src/hooks/mutations/task/use-bulk-operations.ts@@ -1,39 +1,31 @@import { useMutation, useQueryClient } from "@tanstack/react-query";+import bulkOperation from "@/fetchers/task/bulk-operation";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 invalidateCommon = () => {+ queryClientRef.invalidateQueries({ queryKey: ["tasks"] });+ queryClientRef.invalidateQueries({ queryKey: ["projects"] });+ };+const bulkDelete = useMutation({mutationFn: async (taskIds: string[]) => {await Promise.all(taskIds.map((id) => deleteTask(id)));},- onSuccess: () => {- queryClientRef.invalidateQueries({- queryKey: ["tasks"],- });- queryClientRef.invalidateQueries({- queryKey: ["projects"],- });- },+ onSuccess: invalidateCommon,});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"],+ await bulkOperation({+ taskIds,+ operation: "updateStatus",+ value: "archived",});},+ onSuccess: invalidateCommon,});const bulkChangeStatus = useMutation({@@ -44,16 +36,13 @@ export function useBulkOperations() {taskIds: string[];status: string;}) => {- await Promise.all(taskIds.map((id) => updateTaskStatus(id, { status })));- },- onSuccess: () => {- queryClientRef.invalidateQueries({- queryKey: ["tasks"],- });- queryClientRef.invalidateQueries({- queryKey: ["projects"],+ await bulkOperation({+ taskIds,+ operation: "updateStatus",+ value: status,});},+ onSuccess: invalidateCommon,});const bulkAssign = useMutation({@@ -64,34 +53,24 @@ export function useBulkOperations() {taskIds: string[];userId: string;}) => {- await Promise.all(- taskIds.map((id) => updateTaskAssignee(id, { userId })),- );- },- onSuccess: () => {- queryClientRef.invalidateQueries({- queryKey: ["tasks"],- });- queryClientRef.invalidateQueries({- queryKey: ["projects"],+ await bulkOperation({+ taskIds,+ operation: "updateAssignee",+ value: userId,});},+ onSuccess: invalidateCommon,});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"],+ await bulkOperation({+ taskIds,+ operation: "updateStatus",+ value: "planned",});},+ onSuccess: invalidateCommon,});const bulkMoveToBoard = useMutation({@@ -102,16 +81,67 @@ export function useBulkOperations() {taskIds: string[];status: string;}) => {- await Promise.all(taskIds.map((id) => updateTaskStatus(id, { status })));+ await bulkOperation({+ taskIds,+ operation: "updateStatus",+ value: status,+ });},- onSuccess: () => {- queryClientRef.invalidateQueries({- queryKey: ["tasks"],+ onSuccess: invalidateCommon,+ });++ const bulkPriority = useMutation({+ mutationFn: async ({+ taskIds,+ priority,+ }: {+ taskIds: string[];+ priority: string;+ }) => {+ await bulkOperation({+ taskIds,+ operation: "updatePriority",+ value: priority,});- queryClientRef.invalidateQueries({- queryKey: ["projects"],+ },+ onSuccess: invalidateCommon,+ });++ const bulkAddLabel = useMutation({+ mutationFn: async ({+ taskIds,+ labelId,+ }: {+ taskIds: string[];+ labelId: string;+ }) => {+ await bulkOperation({+ taskIds,+ operation: "addLabel",+ value: labelId,+ });+ },+ onSuccess: () => {+ invalidateCommon();+ queryClientRef.invalidateQueries({ queryKey: ["labels"] });+ },+ });++ const bulkDueDate = useMutation({+ mutationFn: async ({+ taskIds,+ dueDate,+ }: {+ taskIds: string[];+ dueDate: string | null;+ }) => {+ await bulkOperation({+ taskIds,+ operation: "updateDueDate",+ value: dueDate,});},+ onSuccess: invalidateCommon,});return {@@ -121,5 +151,8 @@ export function useBulkOperations() {bulkAssign: bulkAssign.mutateAsync,bulkMoveToBacklog: bulkMoveToBacklog.mutateAsync,bulkMoveToBoard: bulkMoveToBoard.mutateAsync,+ bulkPriority: bulkPriority.mutateAsync,+ bulkAddLabel: bulkAddLabel.mutateAsync,+ bulkDueDate: bulkDueDate.mutateAsync,};}