⚡ 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
perf(web): avoid per-task kanban metadata requests
MarkXian990d70ef6340
diff --git a/apps/web/src/components/kanban-board/task-card.tsx b/apps/web/src/components/kanban-board/task-card.tsxindex 2ecfc3f27..fb3ffeebd 100644--- a/apps/web/src/components/kanban-board/task-card.tsx+++ b/apps/web/src/components/kanban-board/task-card.tsx@@ -27,7 +27,6 @@ import {HoverCardTrigger,} from "@/components/ui/preview-card";import { useDeleteTask } from "@/hooks/mutations/task/use-delete-task";-import useExternalLinks from "@/hooks/queries/external-link/use-external-links";import useActiveWorkspace from "@/hooks/queries/workspace/use-active-workspace";import { useGetActiveWorkspaceUsers } from "@/hooks/queries/workspace-users/use-get-active-workspace-users";import { dueDateStatusColors, getDueDateStatus } from "@/lib/due-date-status";@@ -42,7 +41,7 @@ import type Task from "@/types/task";import { Button } from "../ui/button";import { ContextMenu, ContextMenuTrigger } from "../ui/context-menu";import TaskCardContextMenuContent from "./task-card-context-menu/task-card-context-menu-content";-import TaskCardLabels from "./task-labels";+import { TaskLabels } from "./task-labels";type TaskCardProps = {task: Task;@@ -71,15 +70,15 @@ function TaskCard({ task, disableDragDrop = false }: TaskCardProps) {showTaskNumbers,} = useUserPreferencesStore();const [isDeleteTaskModalOpen, setIsDeleteTaskModalOpen] = useState(false);- const { data: externalLinks } = useExternalLinks(task.id);const { toggleSelection, isSelected, isFocused } = useBulkSelectionStore();const isTaskSelected = isSelected(task.id);const isTaskFocused = isFocused(task.id);const pullRequests = useMemo(() => {- if (!externalLinks) return [];- return externalLinks.filter((link) => link.resourceType === "pull_request");- }, [externalLinks]);+ return (task.externalLinks ?? []).filter(+ (link) => link.resourceType === "pull_request",+ );+ }, [task.externalLinks]);const getPRInfo = (pr: (typeof pullRequests)[number]) => {const isMerged = pr.metadata?.merged === true;@@ -248,7 +247,7 @@ function TaskCard({ task, disableDragDrop = false }: TaskCardProps) {{showLabels && (<div className="mb-2.5">- <TaskCardLabels taskId={task.id} />+ <TaskLabels labels={task.labels ?? []} /></div>)}diff --git a/apps/web/src/components/kanban-board/task-labels.test.tsx b/apps/web/src/components/kanban-board/task-labels.test.tsxnew file mode 100644index 000000000..338f67250--- /dev/null+++ b/apps/web/src/components/kanban-board/task-labels.test.tsx@@ -0,0 +1,25 @@+import { cleanup, render, screen } from "@testing-library/react";+import { afterEach, describe, expect, it, vi } from "vitest";+import { TaskLabels } from "./task-labels";++const useGetLabelsByTask = vi.fn();++vi.mock("@/hooks/queries/label/use-get-labels-by-task", () => ({+ default: (...args: unknown[]) => useGetLabelsByTask(...args),+}));++afterEach(() => {+ cleanup();+ useGetLabelsByTask.mockReset();+});++describe("TaskLabels", () => {+ it("renders labels supplied by the task without fetching them", () => {+ render(+ <TaskLabels labels={[{ id: "label-1", name: "Bug", color: "red" }]} />,+ );++ expect(screen.getByText("Bug")).toBeVisible();+ expect(useGetLabelsByTask).not.toHaveBeenCalled();+ });+});diff --git a/apps/web/src/components/kanban-board/task-labels.tsx b/apps/web/src/components/kanban-board/task-labels.tsxindex a06651f49..22eabced5 100644--- a/apps/web/src/components/kanban-board/task-labels.tsx+++ b/apps/web/src/components/kanban-board/task-labels.tsx@@ -1,5 +1,6 @@import { Badge } from "@/components/ui/badge";import useGetLabelsByTask from "@/hooks/queries/label/use-get-labels-by-task";+import type Task from "@/types/task";const labelColors = [{ value: "gray", label: "Stone", color: "var(--color-stone-500)" },@@ -32,9 +33,11 @@ function validColor(value: string): string {return "var(--color-neutral-400)";}-function TaskCardLabels({ taskId }: { taskId: string }) {- const { data: labels = [] } = useGetLabelsByTask(taskId);-+export function TaskLabels({+ labels,+}: {+ labels: NonNullable<Task["labels"]>;+}) {if (!labels.length) return null;return (@@ -58,4 +61,10 @@ function TaskCardLabels({ taskId }: { taskId: string }) {);}+function TaskCardLabels({ taskId }: { taskId: string }) {+ const { data: labels = [] } = useGetLabelsByTask(taskId);++ return <TaskLabels labels={labels} />;+}+export default TaskCardLabels;