⚡ 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
fix: retain cached work and deduplicate assigned task results
Tinf3e41b8a5f96
diff --git a/apps/api/src/task/controllers/get-assigned-tasks.ts b/apps/api/src/task/controllers/get-assigned-tasks.tsindex 07c91aa5c..105db4a94 100644--- a/apps/api/src/task/controllers/get-assigned-tasks.ts+++ b/apps/api/src/task/controllers/get-assigned-tasks.ts@@ -38,6 +38,26 @@ async function getAssignedTasks(workspaceId: string, userId: string) {sql`not ${taskIsCompleted}`,);+ // Existing databases may contain duplicate slugs from concurrent column+ // creation. A lateral lookup must return at most one decoration per task.+ const statusColumn = db+ .select({ name: columnTable.name, icon: columnTable.icon })+ .from(columnTable)+ .where(+ and(+ eq(columnTable.projectId, taskTable.projectId),+ eq(columnTable.slug, taskTable.status),+ ),+ )+ .orderBy(+ sql`case when ${columnTable.id} = ${taskTable.columnId} then 0 else 1 end`,+ asc(columnTable.position),+ asc(columnTable.createdAt),+ asc(columnTable.id),+ )+ .limit(1)+ .as("assigned_status_column");+const [tasks, [totals]] = await Promise.all([db.select({@@ -46,8 +66,8 @@ async function getAssignedTasks(workspaceId: string, userId: string) {number: taskTable.number,title: taskTable.title,status: taskTable.status,- statusName: columnTable.name,- statusIcon: columnTable.icon,+ statusName: statusColumn.name,+ statusIcon: statusColumn.icon,priority: taskTable.priority,dueDate: taskTable.dueDate,projectName: projectTable.name,@@ -56,13 +76,7 @@ async function getAssignedTasks(workspaceId: string, userId: string) {}).from(taskTable).innerJoin(projectTable, eq(taskTable.projectId, projectTable.id))- .leftJoin(- columnTable,- and(- eq(columnTable.projectId, taskTable.projectId),- eq(columnTable.slug, taskTable.status),- ),- )+ .leftJoinLateral(statusColumn, sql`true`).where(openAndMine).orderBy(sql`${taskTable.dueDate} asc nulls last`,diff --git a/apps/web/src/components/home/activity-feed.tsx b/apps/web/src/components/home/activity-feed.tsxindex 536e2863e..e33b2f744 100644--- a/apps/web/src/components/home/activity-feed.tsx+++ b/apps/web/src/components/home/activity-feed.tsx@@ -34,7 +34,7 @@ export function ActivityFeed({ workspaceId }: ActivityFeedProps) {</div>))}</div>- ) : isError ? (+ ) : isError && !activities ? (<p className="py-6 text-muted-foreground text-sm">{t("workspace:home.activity.loadError")}</p>diff --git a/apps/web/src/components/home/home-projects.tsx b/apps/web/src/components/home/home-projects.tsxindex ba1a9b614..5b0e4778d 100644--- a/apps/web/src/components/home/home-projects.tsx+++ b/apps/web/src/components/home/home-projects.tsx@@ -38,7 +38,7 @@ export function HomeProjects({ workspaceId }: HomeProjectsProps) {aria-label={t("common:empty.loading")}className="h-28 w-full"/>- ) : isError ? (+ ) : isError && !projects ? (<p role="alert" className="text-muted-foreground text-sm">{t("workspace:home.projects.loadError")}</p>diff --git a/apps/web/src/components/home/up-next.test.tsx b/apps/web/src/components/home/up-next.test.tsxnew file mode 100644index 000000000..14bd278b3--- /dev/null+++ b/apps/web/src/components/home/up-next.test.tsx@@ -0,0 +1,76 @@+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";+import { act, cleanup, render, screen } from "@testing-library/react";+import type { PropsWithChildren } from "react";+import { afterEach, beforeEach, expect, it, vi } from "vite-plus/test";+import useGetAssignedTasks from "@/hooks/queries/task/use-get-assigned-tasks";+import { UpNext } from "./up-next";++const { getAssignedTasks } = vi.hoisted(() => ({ getAssignedTasks: vi.fn() }));+vi.mock("@/fetchers/task/get-assigned-tasks", () => ({+ default: getAssignedTasks,+}));+vi.mock("react-i18next", () => ({+ useTranslation: () => ({ t: (key: string) => key }),+}));+vi.mock("@tanstack/react-router", () => ({+ Link: ({ children }: PropsWithChildren) => <a href="/my-tasks">{children}</a>,+}));+vi.mock("@/components/my-work/assigned-task-row", () => ({+ AssignedTaskRow: ({ task }: { task: { title: string } }) => (+ <span>{task.title}</span>+ ),+}));++let client: QueryClient;+beforeEach(() => {+ client = new QueryClient({ defaultOptions: { queries: { retry: false } } });+});+afterEach(() => {+ cleanup();+ client.clear();+ vi.clearAllMocks();+});++function Harness() {+ const query = useGetAssignedTasks("workspace");+ return (+ <UpNext+ tasks={query.data?.tasks}+ total={query.data?.total ?? 0}+ isLoading={query.isLoading}+ isError={query.isError}+ workspaceId="workspace"+ />+ );+}++function mount() {+ render(+ <QueryClientProvider client={client}>+ <Harness />+ </QueryClientProvider>,+ );+}++it("keeps loaded tasks visible after a transient background refresh failure", async () => {+ getAssignedTasks.mockResolvedValue({+ tasks: [{ id: "task", title: "Still here" }],+ total: 1,+ });+ mount();+ expect(await screen.findByText("Still here")).toBeVisible();+ getAssignedTasks.mockRejectedValue(new Error("Network unavailable"));+ await act(async () => {+ await client.refetchQueries({ queryKey: ["assigned-tasks", "workspace"] });+ });+ expect(screen.getByText("Still here")).toBeVisible();+ expect(+ screen.queryByText("workspace:myWork.loadError"),+ ).not.toBeInTheDocument();+});++it("shows the load error when no tasks have been loaded", async () => {+ getAssignedTasks.mockRejectedValue(new Error("Network unavailable"));+ mount();+ expect(await screen.findByText("workspace:myWork.loadError")).toBeVisible();+});diff --git a/apps/web/src/components/home/up-next.tsx b/apps/web/src/components/home/up-next.tsxindex 0aab696bb..4873cac82 100644--- a/apps/web/src/components/home/up-next.tsx+++ b/apps/web/src/components/home/up-next.tsx@@ -60,7 +60,7 @@ export function UpNext({</div>))}</div>- ) : isError ? (+ ) : isError && !tasks ? (<p className="py-6 text-muted-foreground text-sm">{t("workspace:myWork.loadError")}</p>diff --git a/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/my-tasks.tsx b/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/my-tasks.tsxindex 27a102a57..4f70d5da9 100644--- a/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/my-tasks.tsx+++ b/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/my-tasks.tsx@@ -61,7 +61,7 @@ function RouteComponent() {</div>))}</div>- ) : isError ? (+ ) : isError && !assigned ? (<p className="p-6 text-muted-foreground text-sm">{t("workspace:myWork.loadError")}</p>diff --git a/tests/api-integration/assigned-tasks.test.ts b/tests/api-integration/assigned-tasks.test.tsindex 8151db522..fdf1c9edb 100644--- a/tests/api-integration/assigned-tasks.test.ts+++ b/tests/api-integration/assigned-tasks.test.ts@@ -151,6 +151,40 @@ describe("API integration: assigned tasks", () => {});});+ it("returns each task once when existing columns share a slug", async () => {+ const member = await createWorkspaceMember();+ const { project, columns } = await createProjectFixture({+ workspaceId: member.workspace.id,+ });+ await db.insert(schema.columnTable).values({+ projectId: project.id,+ name: "Duplicate to-do",+ slug: columns.todo.slug,+ position: -1,+ });+ const [task] = await db+ .insert(schema.taskTable)+ .values({+ projectId: project.id,+ title: "Once only",+ status: columns.todo.slug,+ columnId: columns.todo.id,+ userId: member.user.id,+ })+ .returning();+ mockAuthenticatedSession(member.user);+ const { app } = createApp();+ const response = await app.request(+ `/api/task/assigned?workspaceId=${member.workspace.id}`,+ );+ expect(response.status).toBe(200);+ const body = (await response.json()) as AssignedTasksResponse;+ expect(body.total).toBe(1);+ expect(body.tasks).toEqual([+ expect.objectContaining({ id: task.id, statusName: columns.todo.name }),+ ]);+ });+it("refuses a workspace the caller does not belong to", async () => {const member = await createWorkspaceMember();const outsider = await createWorkspaceMember();