⚡ 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: added task item counters
Tymek72c36f9e8614
diff --git a/apps/web/src/components/kanban-board/task-card.tsx b/apps/web/src/components/kanban-board/task-card.tsxindex c31fc44dc..736c9b652 100644--- a/apps/web/src/components/kanban-board/task-card.tsx+++ b/apps/web/src/components/kanban-board/task-card.tsx@@ -8,6 +8,7 @@ import {CalendarX,GitMerge,GitPullRequest,+ SquareCheck,} from "lucide-react";import { type CSSProperties, useMemo, useState } from "react";import { useTranslation } from "react-i18next";@@ -35,6 +36,7 @@ import {isTaskCompleted,} from "@/lib/due-date-status";import { getInitials } from "@/lib/get-initials";+import { getTaskItemStats } from "@/lib/get-task-item-stats";import { getPriorityIcon } from "@/lib/priority";import { toast } from "@/lib/toast";import queryClient from "@/query-client";@@ -73,11 +75,16 @@ function TaskCard({ task, disableDragDrop = false }: TaskCardProps) {showDueDates,showLabels,showTaskNumbers,+ showTaskItemCounts,} = useUserPreferencesStore();const [isDeleteTaskModalOpen, setIsDeleteTaskModalOpen] = useState(false);const { toggleSelection, isSelected, isFocused } = useBulkSelectionStore();const isTaskSelected = isSelected(task.id);const isTaskFocused = isFocused(task.id);+ const taskItemStats = useMemo(+ () => getTaskItemStats(task.description),+ [task.description],+ );const pullRequests = useMemo(() => {return (task.externalLinks ?? []).filter(@@ -258,14 +265,21 @@ function TaskCard({ task, disableDragDrop = false }: TaskCardProps) {<div className="flex items-center gap-1.5">{showPriority && (- <span className="inline-flex items-center gap-1 rounded border border-border/70 bg-muted/55 px-2 py-1 text-[10px] font-medium text-muted-foreground">+ <span className="inline-flex items-center gap-1 rounded border border-border/70 bg-muted/55 px-2 py-1 text-[10px] font-medium text-muted-foreground h-5.5">{getPriorityIcon(task.priority ?? "")}</span>)}+ {showTaskItemCounts && taskItemStats.total > 0 && (+ <span className="flex items-center gap-1 text-[10px] px-2 py-1 rounded bg-muted/50 text-muted-foreground h-5.5">+ <SquareCheck className="h-[12px] w-[12px] text-muted-foreground" />+ {taskItemStats.completed}/{taskItemStats.total}+ </span>+ )}+{showDueDates && task.dueDate && (<div- className={`flex items-center gap-1 text-[10px] px-2 py-1 rounded ${dueDateStatusColors[getDueDateStatus(task.dueDate, taskIsCompleted)]}`}+ className={`flex items-center gap-1 text-[10px] px-2 py-1 rounded h-5.5 ${dueDateStatusColors[getDueDateStatus(task.dueDate, taskIsCompleted)]}`}>{getDueDateStatus(task.dueDate, taskIsCompleted) ==="overdue" && <CalendarX className="w-3 h-3" />}diff --git a/apps/web/src/lib/get-task-item-stats.test.ts b/apps/web/src/lib/get-task-item-stats.test.tsnew file mode 100644index 000000000..ec1a2530b--- /dev/null+++ b/apps/web/src/lib/get-task-item-stats.test.ts@@ -0,0 +1,38 @@+import { describe, expect, it } from "vitest";+import { getTaskItemStats } from "./get-task-item-stats";++describe("getTaskItems", () => {+ it("returns zeroes for an empty description", () => {+ expect(getTaskItemStats(null)).toEqual({ total: 0, completed: 0 });+ expect(getTaskItemStats("")).toEqual({ total: 0, completed: 0 });+ });++ it("counts checked and unchecked Markdown task-list items", () => {+ expect(+ getTaskItemStats("- [ ] Plan\n- [x] Build\n - [X] Review\n- [ ] Ship"),+ ).toEqual({ total: 4, completed: 2 });+ });++ it("does not count ordinary lists or checkbox syntax outside a list item", () => {+ expect(+ getTaskItemStats(+ "- Plain bullet\n[ ] Not a task item\n1. [x] Ordered item",+ ),+ ).toEqual({ total: 1, completed: 1 });+ });++ it("does not count Markdown examples in fenced code blocks", () => {+ expect(+ getTaskItemStats(+ "- [x] Real item\n```md\n- [ ] Example\n```\n- [ ] Another item",+ ),+ ).toEqual({ total: 2, completed: 1 });+ });++ it("supports blockquoted task-list items", () => {+ expect(getTaskItemStats("> - [x] Quoted item")).toEqual({+ total: 1,+ completed: 1,+ });+ });+});diff --git a/apps/web/src/lib/get-task-item-stats.ts b/apps/web/src/lib/get-task-item-stats.tsnew file mode 100644index 000000000..dc36406e9--- /dev/null+++ b/apps/web/src/lib/get-task-item-stats.ts@@ -0,0 +1,50 @@+type TaskItemsStats = {+ total: number;+ completed: number;+};++const TASK_ITEM_PATTERN =+ /^\s*(?:>\s*)*(?:[-+*]|\d{1,9}[.)])\s+\[([ xX])\](?:\s|$)/;+const FENCE_PATTERN = /^\s*(`{3,}|~{3,})/;++/**+ * Get task items count from a task description.+ *+ * @param description - Task description+ * @returns Object with completed and total items+ */+export function getTaskItemStats(description: string | null): TaskItemsStats {+ if (!description) return { total: 0, completed: 0 };++ let total = 0;+ let completed = 0;+ let fenceChar: string | null = null;+ let fenceLen = 0;++ for (const line of description.split(/\r\n|\n/)) {+ const fenceMatch = FENCE_PATTERN.exec(line);++ if (fenceMatch) {+ const marker = fenceMatch[1];+ if (!fenceChar) {+ // Opening a new fence+ fenceChar = marker[0];+ fenceLen = marker.length;+ } else if (marker[0] === fenceChar && marker.length >= fenceLen) {+ // Closing the current fence+ fenceChar = null;+ }+ continue;+ }++ if (fenceChar) continue; // inside a fenced block, skip++ const taskMatch = TASK_ITEM_PATTERN.exec(line);+ if (!taskMatch) continue;++ total++;+ if (taskMatch[1].toLowerCase() === "x") completed++;+ }++ return { total, completed };+}diff --git a/apps/web/src/store/user-preferences.ts b/apps/web/src/store/user-preferences.tsindex 481d88925..891fcf555 100644--- a/apps/web/src/store/user-preferences.ts+++ b/apps/web/src/store/user-preferences.ts@@ -36,6 +36,9 @@ type UserPreferencesStore = {showPriority: boolean;setShowPriority: (show: boolean) => void;togglePriority: () => void;+ showTaskItemCounts: boolean;+ setShowTaskItemCounts: (show: boolean) => void;+ toggleTaskItemCounts: () => void;resetDisplayPreferences: () => void;sidebarDefaultOpen: boolean;@@ -101,6 +104,10 @@ export const useUserPreferencesStore = create<UserPreferencesStore>()(setShowPriority: (show) => set({ showPriority: show }),togglePriority: () =>set((state) => ({ showPriority: !state.showPriority })),+ showTaskItemCounts: true,+ setShowTaskItemCounts: (show) => set({ showTaskItemCounts: show }),+ toggleTaskItemCounts: () =>+ set((state) => ({ showTaskItemCounts: !state.showTaskItemCounts })),resetDisplayPreferences: () =>set({showAssignees: true,