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.

perf(web): render list and backlog rows from the task payload

Andrej6fc3f44fb856
diff --git a/apps/web/src/components/backlog-list-view/backlog-task-row.tsx b/apps/web/src/components/backlog-list-view/backlog-task-row.tsx
index e888b743e..66bc9ed84 100644
--- a/apps/web/src/components/backlog-list-view/backlog-task-row.tsx
+++ b/apps/web/src/components/backlog-list-view/backlog-task-row.tsx
@@ -30,7 +30,7 @@ import useProjectStore from "@/store/project";
import { useUserPreferencesStore } from "@/store/user-preferences";
import type Task from "@/types/task";
import TaskCardContextMenuContent from "../kanban-board/task-card-context-menu/task-card-context-menu-content";
-import TaskCardLabels from "../kanban-board/task-labels";
+import { TaskLabels } from "../kanban-board/task-labels";
import { ContextMenu, ContextMenuTrigger } from "../ui/context-menu";
type BacklogTaskRowProps = {
@@ -171,7 +171,7 @@ export default function BacklogTaskRow({ task }: BacklogTaskRowProps) {
</span>
{showLabels && (
<div className="flex items-center gap-1">
- <TaskCardLabels taskId={task.id} />
+ <TaskLabels labels={task.labels ?? []} />
</div>
)}
</div>
diff --git a/apps/web/src/components/kanban-board/task-labels.test.tsx b/apps/web/src/components/kanban-board/task-labels.test.tsx
index 338f67250..bb7c865f0 100644
--- a/apps/web/src/components/kanban-board/task-labels.test.tsx
+++ b/apps/web/src/components/kanban-board/task-labels.test.tsx
@@ -1,25 +1,17 @@
import { cleanup, render, screen } from "@testing-library/react";
-import { afterEach, describe, expect, it, vi } from "vitest";
+import { afterEach, describe, expect, it } 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", () => {
+ it("renders labels supplied by the task", () => {
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.tsx
index 22eabced5..9b6af8273 100644
--- a/apps/web/src/components/kanban-board/task-labels.tsx
+++ b/apps/web/src/components/kanban-board/task-labels.tsx
@@ -1,5 +1,4 @@
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 = [
@@ -60,11 +59,3 @@ export function TaskLabels({
</div>
);
}
-
-function TaskCardLabels({ taskId }: { taskId: string }) {
- const { data: labels = [] } = useGetLabelsByTask(taskId);
-
- return <TaskLabels labels={labels} />;
-}
-
-export default TaskCardLabels;
diff --git a/apps/web/src/components/list-view/task-row.test.tsx b/apps/web/src/components/list-view/task-row.test.tsx
new file mode 100644
index 000000000..2e266c6cd
--- /dev/null
+++ b/apps/web/src/components/list-view/task-row.test.tsx
@@ -0,0 +1,111 @@
+import { cleanup, render, screen } from "@testing-library/react";
+import { afterEach, describe, expect, it, vi } from "vitest";
+import type Task from "@/types/task";
+import TaskRow from "./task-row";
+
+const useExternalLinks = vi.fn((_taskId: string) => ({ data: [] }));
+const useGetLabelsByTask = vi.fn((_taskId: string) => ({ data: [] }));
+
+afterEach(() => {
+ cleanup();
+ vi.clearAllMocks();
+});
+
+vi.mock("@tanstack/react-router", () => ({
+ useNavigate: () => vi.fn(),
+}));
+
+vi.mock("@/hooks/queries/external-link/use-external-links", () => ({
+ default: (taskId: string) => useExternalLinks(taskId),
+}));
+
+vi.mock("@/hooks/queries/label/use-get-labels-by-task", () => ({
+ default: (taskId: string) => useGetLabelsByTask(taskId),
+}));
+
+vi.mock("@/hooks/mutations/task/use-delete-task", () => ({
+ useDeleteTask: () => ({ mutateAsync: vi.fn() }),
+}));
+
+vi.mock("@/hooks/queries/workspace/use-active-workspace", () => ({
+ default: () => ({ data: { id: "workspace-1" } }),
+}));
+
+vi.mock(
+ "@/hooks/queries/workspace-users/use-get-active-workspace-users",
+ () => ({
+ useGetActiveWorkspaceUsers: () => ({ data: { members: [] } }),
+ }),
+);
+
+vi.mock(
+ "../kanban-board/task-card-context-menu/task-card-context-menu-content",
+ () => ({ default: () => null }),
+);
+
+vi.mock("@/store/bulk-selection", () => ({
+ default: () => ({
+ toggleSelection: vi.fn(),
+ isSelected: () => false,
+ isFocused: () => false,
+ }),
+}));
+
+vi.mock("@/store/project", () => ({
+ default: () => ({ project: { id: "project-1", slug: "kan" } }),
+}));
+
+vi.mock("@/store/user-preferences", () => ({
+ useUserPreferencesStore: () => ({
+ showAssignees: true,
+ showDueDates: true,
+ showLabels: true,
+ showTaskNumbers: true,
+ }),
+}));
+
+vi.mock("react-i18next", () => ({
+ useTranslation: () => ({ t: (key: string) => key }),
+ initReactI18next: { type: "3rdParty", init: vi.fn() },
+}));
+
+const task: Task = {
+ id: "task-1",
+ title: "Row from payload",
+ number: 7,
+ description: null,
+ status: "to-do",
+ priority: null,
+ startDate: null,
+ dueDate: null,
+ position: 1,
+ createdAt: "2026-08-05T00:00:00.000Z",
+ userId: null,
+ assigneeId: null,
+ assigneeName: null,
+ projectId: "project-1",
+ labels: [{ id: "label-1", name: "Bug", color: "red" }],
+ externalLinks: [
+ {
+ id: "link-1",
+ taskId: "task-1",
+ integrationId: "integration-1",
+ resourceType: "pull_request",
+ externalId: "42",
+ url: "https://github.com/o/r/pull/42",
+ title: "Fix it",
+ metadata: { merged: false, draft: false },
+ },
+ ],
+};
+
+describe("TaskRow", () => {
+ it("renders labels and pull requests from the task payload without per-row requests", () => {
+ render(<TaskRow task={task} projectSlug="kan" />);
+
+ expect(screen.getByText("Bug")).toBeVisible();
+ expect(screen.getByText("#42")).toBeVisible();
+ expect(useExternalLinks).not.toHaveBeenCalled();
+ expect(useGetLabelsByTask).not.toHaveBeenCalled();
+ });
+});
diff --git a/apps/web/src/components/list-view/task-row.tsx b/apps/web/src/components/list-view/task-row.tsx
index 39b312049..96c83e28b 100644
--- a/apps/web/src/components/list-view/task-row.tsx
+++ b/apps/web/src/components/list-view/task-row.tsx
@@ -28,7 +28,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 { cn } from "@/lib/cn";
@@ -42,7 +41,7 @@ import useProjectStore from "@/store/project";
import { useUserPreferencesStore } from "@/store/user-preferences";
import type Task from "@/types/task";
import TaskCardContextMenuContent from "../kanban-board/task-card-context-menu/task-card-context-menu-content";
-import TaskCardLabels from "../kanban-board/task-labels";
+import { TaskLabels } from "../kanban-board/task-labels";
import { ContextMenu, ContextMenuTrigger } from "../ui/context-menu";
type TaskRowProps = {
@@ -73,7 +72,6 @@ function TaskRow({ task, projectSlug }: TaskRowProps) {
} = useUserPreferencesStore();
const [isDeleteTaskModalOpen, setIsDeleteTaskModalOpen] = useState(false);
const { mutateAsync: deleteTask } = useDeleteTask();
- const { data: externalLinks } = useExternalLinks(task.id);
const { toggleSelection, isSelected, isFocused } = useBulkSelectionStore();
const isTaskSelected = isSelected(task.id);
const isTaskFocused = isFocused(task.id);
@@ -89,9 +87,10 @@ function TaskRow({ task, projectSlug }: TaskRowProps) {
}, [workspaceUsers, task.userId]);
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;
@@ -215,7 +214,7 @@ function TaskRow({ task, projectSlug }: TaskRowProps) {
{task.title}
</span>
<div className="flex items-center gap-1">
- {showLabels && <TaskCardLabels taskId={task.id} />}
+ {showLabels && <TaskLabels labels={task.labels ?? []} />}
{pullRequests.length === 1 && (
<HoverCard openDelay={200} closeDelay={100}>