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.

fix: preserve inbox content and display configured activity statuses

Tin023950ca3597
diff --git a/apps/api/src/activity/controllers/get-workspace-activities.ts b/apps/api/src/activity/controllers/get-workspace-activities.ts
index 134986d6e..7f5f8f0c4 100644
--- a/apps/api/src/activity/controllers/get-workspace-activities.ts
+++ b/apps/api/src/activity/controllers/get-workspace-activities.ts
@@ -1,7 +1,8 @@
-import { and, desc, eq, gte, isNull, sql } from "drizzle-orm";
+import { and, asc, desc, eq, gte, inArray, isNull, sql } from "drizzle-orm";
import db from "../../database";
import {
activityTable,
+ columnTable,
projectTable,
taskTable,
userTable,
@@ -64,10 +65,67 @@ async function getWorkspaceActivities(workspaceId: string) {
.orderBy(desc(activityTable.createdAt), desc(activityTable.id))
.limit(WORKSPACE_ACTIVITY_LIMIT);
- return rows.map(({ content, ...row }) => ({
- ...row,
- excerpt: commentExcerpt(content),
- }));
+ const statusChanges = rows.filter((row) => row.type === "status_changed");
+ const statusSlugs = [
+ ...new Set(
+ statusChanges.flatMap((row) => {
+ const data = statusData(row.eventData);
+ return [data?.oldStatus, data?.newStatus].filter(
+ (value): value is string => typeof value === "string",
+ );
+ }),
+ ),
+ ];
+ const columns = statusSlugs.length
+ ? await db
+ .select({
+ projectId: columnTable.projectId,
+ slug: columnTable.slug,
+ name: columnTable.name,
+ })
+ .from(columnTable)
+ .innerJoin(projectTable, eq(columnTable.projectId, projectTable.id))
+ .where(
+ and(
+ eq(projectTable.workspaceId, workspaceId),
+ inArray(columnTable.projectId, [
+ ...new Set(statusChanges.map((row) => row.projectId)),
+ ]),
+ inArray(columnTable.slug, statusSlugs),
+ ),
+ )
+ .orderBy(
+ asc(columnTable.position),
+ asc(columnTable.createdAt),
+ asc(columnTable.id),
+ )
+ : [];
+
+ return rows.map(({ content, ...row }) => {
+ const data =
+ row.type === "status_changed" ? statusData(row.eventData) : null;
+ const nameOf = (slug: unknown) =>
+ columns.find(
+ (column) => column.projectId === row.projectId && column.slug === slug,
+ )?.name;
+ return {
+ ...row,
+ eventData: data
+ ? {
+ ...data,
+ oldStatusName: nameOf(data.oldStatus),
+ newStatusName: nameOf(data.newStatus),
+ }
+ : row.eventData,
+ excerpt: commentExcerpt(content),
+ };
+ });
+}
+
+function statusData(value: unknown): Record<string, unknown> | null {
+ return value && typeof value === "object" && !Array.isArray(value)
+ ? (value as Record<string, unknown>)
+ : null;
}
export default getWorkspaceActivities;
diff --git a/apps/api/src/activity/response.ts b/apps/api/src/activity/response.ts
index a6a60fb87..c6cf88d16 100644
--- a/apps/api/src/activity/response.ts
+++ b/apps/api/src/activity/response.ts
@@ -37,7 +37,7 @@ export const workspaceActivityListSchema = z.array(
createdAt: responseTimestamp,
eventData: z.unknown().openapi({
description:
- "Type-specific payload, e.g. { oldStatus, newStatus } for status_changed.",
+ "Type-specific payload. For status_changed, oldStatus/newStatus are slugs and oldStatusName/newStatusName carry current configured column names when available.",
}),
excerpt: z.string().nullable().openapi({
description:
diff --git a/apps/docs/openapi.json b/apps/docs/openapi.json
index 72b41dc5f..19df741b3 100644
--- a/apps/docs/openapi.json
+++ b/apps/docs/openapi.json
@@ -1472,7 +1472,7 @@
"format": "date-time"
},
"eventData": {
- "description": "Type-specific payload, e.g. { oldStatus, newStatus } for status_changed."
+ "description": "Type-specific payload. For status_changed, oldStatus/newStatus are slugs and oldStatusName/newStatusName carry current configured column names when available."
},
"excerpt": {
"type": [
diff --git a/apps/web/src/components/home/activity-feed.tsx b/apps/web/src/components/home/activity-feed.tsx
index e33b2f744..b6ae8cc30 100644
--- a/apps/web/src/components/home/activity-feed.tsx
+++ b/apps/web/src/components/home/activity-feed.tsx
@@ -35,7 +35,7 @@ export function ActivityFeed({ workspaceId }: ActivityFeedProps) {
))}
</div>
) : isError && !activities ? (
- <p className="py-6 text-muted-foreground text-sm">
+ <p role="alert" className="py-6 text-muted-foreground text-sm">
{t("workspace:home.activity.loadError")}
</p>
) : !activities?.length ? (
diff --git a/apps/web/src/components/home/describe-activity.test.ts b/apps/web/src/components/home/describe-activity.test.ts
index 3ace74dba..ce04f52b3 100644
--- a/apps/web/src/components/home/describe-activity.test.ts
+++ b/apps/web/src/components/home/describe-activity.test.ts
@@ -51,6 +51,40 @@ describe("describeActivity", () => {
).toBe("activity:clearedDueDate");
});
+ it("uses configured status names and falls back for deleted columns", () => {
+ expect(
+ describeActivity(
+ activity({
+ type: "status_changed",
+ eventData: {
+ oldStatus: "review",
+ newStatus: "approved",
+ oldStatusName: "Awaiting approval",
+ newStatusName: "Ready to ship",
+ },
+ }),
+ t,
+ ),
+ ).toBe(
+ 'activity:changedStatus {"from":"Awaiting approval","to":"Ready to ship"}',
+ );
+ expect(
+ describeActivity(
+ activity({
+ type: "status_changed",
+ eventData: {
+ oldStatus: "removed-lane",
+ newStatus: "review",
+ newStatusName: "Awaiting approval",
+ },
+ }),
+ t,
+ ),
+ ).toBe(
+ 'activity:changedStatus {"from":"Removed Lane","to":"Awaiting approval"}',
+ );
+ });
+
it("falls back to the stored text for events without event data", () => {
expect(
describeActivity(
diff --git a/apps/web/src/components/home/describe-activity.ts b/apps/web/src/components/home/describe-activity.ts
index 774894cce..44e69f3e2 100644
--- a/apps/web/src/components/home/describe-activity.ts
+++ b/apps/web/src/components/home/describe-activity.ts
@@ -1,6 +1,6 @@
import type { WorkspaceActivity } from "@/fetchers/activity/get-workspace-activities";
import { formatDateMedium } from "@/lib/format";
-import { getPriorityLabel, getStatusLabel } from "@/lib/i18n/domain";
+import { getPriorityLabel, getStatusDisplayLabel } from "@/lib/i18n/domain";
type Translate = (key: string, options?: Record<string, unknown>) => string;
@@ -33,8 +33,18 @@ export function describeActivity(activity: WorkspaceActivity, t: Translate) {
case "status_changed":
if (eventData) {
return t("activity:changedStatus", {
- from: getStatusLabel(String(eventData.oldStatus ?? "")),
- to: getStatusLabel(String(eventData.newStatus ?? "")),
+ from: getStatusDisplayLabel(
+ String(eventData.oldStatus ?? ""),
+ typeof eventData.oldStatusName === "string"
+ ? eventData.oldStatusName
+ : undefined,
+ ),
+ to: getStatusDisplayLabel(
+ String(eventData.newStatus ?? ""),
+ typeof eventData.newStatusName === "string"
+ ? eventData.newStatusName
+ : undefined,
+ ),
});
}
break;
diff --git a/apps/web/src/components/home/up-next.tsx b/apps/web/src/components/home/up-next.tsx
index 4873cac82..e78c22f33 100644
--- a/apps/web/src/components/home/up-next.tsx
+++ b/apps/web/src/components/home/up-next.tsx
@@ -61,7 +61,7 @@ export function UpNext({
))}
</div>
) : isError && !tasks ? (
- <p className="py-6 text-muted-foreground text-sm">
+ <p role="alert" className="py-6 text-muted-foreground text-sm">
{t("workspace:myWork.loadError")}
</p>
) : !tasks?.length ? (
diff --git a/apps/web/src/components/inbox/inbox-task.test.tsx b/apps/web/src/components/inbox/inbox-task.test.tsx
index aaa8b8afd..d54fb5298 100644
--- a/apps/web/src/components/inbox/inbox-task.test.tsx
+++ b/apps/web/src/components/inbox/inbox-task.test.tsx
@@ -1,19 +1,30 @@
import { cleanup, render, screen } from "@testing-library/react";
-import { afterEach, describe, expect, it, vi } from "vite-plus/test";
+import {
+ afterEach,
+ beforeEach,
+ describe,
+ expect,
+ it,
+ vi,
+} from "vite-plus/test";
import { InboxTask } from "./inbox-task";
-const activityQuery = vi.hoisted(() => vi.fn(() => ({ data: [] })));
-vi.mock("@/hooks/queries/task/use-get-task", () => ({
- default: () => ({
+const queries = vi.hoisted(() => ({
+ activity: vi.fn(),
+ task: vi.fn(),
+}));
+beforeEach(() => {
+ queries.task.mockReturnValue({
data: {
id: "task",
title: "Custom workflow",
status: "review",
- columnId: "review-column",
projectId: "project",
},
- }),
-}));
+ });
+ queries.activity.mockReturnValue({ data: [] });
+});
+vi.mock("@/hooks/queries/task/use-get-task", () => ({ default: queries.task }));
vi.mock("@/hooks/queries/column/use-get-columns", () => ({
useGetColumns: () => ({
data: [
@@ -28,7 +39,7 @@ vi.mock("@/hooks/queries/column/use-get-columns", () => ({
}),
}));
vi.mock("@/hooks/queries/activity/use-get-activities-by-task-id", () => ({
- default: activityQuery,
+ default: queries.activity,
}));
vi.mock("@/hooks/use-workspace-permission", () => ({
useWorkspacePermission: () => ({ canUpdateTasks: () => false }),
@@ -46,6 +57,29 @@ describe("Inbox task preview", () => {
render(<InboxTask taskId="task" />);
expect(screen.getByText("Awaiting approval")).toBeInTheDocument();
expect(document.querySelector(".lucide-flag")).not.toBeNull();
- expect(activityQuery).toHaveBeenCalledWith("task", true, 6);
+ expect(queries.activity).toHaveBeenCalledWith("task", true, 6);
+ });
+ it("keeps cached task and activity content after a failed background refresh", () => {
+ queries.task.mockReturnValue({
+ data: { title: "Cached task", status: "review", projectId: "project" },
+ isError: true,
+ });
+ queries.activity.mockReturnValue({ data: [], isError: true });
+ render(<InboxTask taskId="task" />);
+ expect(screen.getByText("Cached task")).toBeVisible();
+ expect(
+ screen.queryByText("notifications:inbox.taskUnavailable"),
+ ).not.toBeInTheDocument();
+ expect(
+ screen.queryByText("workspace:home.activity.loadError"),
+ ).not.toBeInTheDocument();
+ });
+
+ it("announces initial task failures", () => {
+ queries.task.mockReturnValue({ isError: true });
+ render(<InboxTask taskId="task" />);
+ expect(screen.getByRole("alert")).toHaveTextContent(
+ "notifications:inbox.taskUnavailable",
+ );
});
});
diff --git a/apps/web/src/components/inbox/inbox-task.tsx b/apps/web/src/components/inbox/inbox-task.tsx
index 9590c917e..2f57c6674 100644
--- a/apps/web/src/components/inbox/inbox-task.tsx
+++ b/apps/web/src/components/inbox/inbox-task.tsx
@@ -23,9 +23,9 @@ const VISIBLE_ACTIVITIES = 6;
// without leaving the inbox.
export function InboxTask({ taskId }: InboxTaskProps) {
const { t } = useTranslation();
- const { data: task, isLoading, isError } = useGetTask(taskId, true);
+ const { data: task, isLoading } = useGetTask(taskId, true);
const {
- data: activities = [],
+ data: activities,
isPending: activityPending,
isError: activityError,
} = useGetActivitiesByTaskId(taskId, true, VISIBLE_ACTIVITIES);
@@ -45,15 +45,15 @@ export function InboxTask({ taskId }: InboxTaskProps) {
);
}
- if (isError || !task) {
+ if (!task) {
return (
- <p className="text-muted-foreground text-sm">
+ <p role="alert" className="text-muted-foreground text-sm">
{t("notifications:inbox.taskUnavailable")}
</p>
);
}
- const recent = activities.slice(0, VISIBLE_ACTIVITIES);
+ const recent = (activities ?? []).slice(0, VISIBLE_ACTIVITIES);
return (
<div className="flex flex-col gap-7">
@@ -106,7 +106,7 @@ export function InboxTask({ taskId }: InboxTaskProps) {
aria-label={t("common:empty.loading")}
className="h-24 w-full"
/>
- ) : activityError ? (
+ ) : activityError && !activities ? (
<p role="alert" className="text-muted-foreground text-sm">
{t("workspace:home.activity.loadError")}
</p>
diff --git a/apps/web/src/components/shared/modals/create-task-modal.test.tsx b/apps/web/src/components/shared/modals/create-task-modal.test.tsx
index 5093be6b8..eca339325 100644
--- a/apps/web/src/components/shared/modals/create-task-modal.test.tsx
+++ b/apps/web/src/components/shared/modals/create-task-modal.test.tsx
@@ -343,12 +343,29 @@ describe("CreateTaskModal", () => {
expect(screen.getByRole("alert")).toHaveTextContent(
"common:modals.createTask.statusLoadError",
);
- fireEvent.click(screen.getByText("common:actions.tryAgain"));
+ fireEvent.click(screen.getByText("common:error.tryAgain"));
expect(refetchColumns).toHaveBeenCalledOnce();
submit();
expect(createTask).not.toHaveBeenCalled();
});
+ it("uses planned when every column is final", async () => {
+ projectColumns = [
+ { id: "done", slug: "done", name: "Finished", isFinal: true },
+ ];
+ render(<CreateTaskModal open onClose={vi.fn()} />, {
+ wrapper: createWrapper(),
+ });
+ await chooseBeta();
+ enterTitle();
+ submit();
+ await vi.waitFor(() =>
+ expect(createTask).toHaveBeenCalledWith(
+ expect.objectContaining({ status: "planned" }),
+ ),
+ );
+ });
+
it("keeps an explicit planned status even when the project has custom columns", async () => {
projectColumns = [
{ id: "ready", slug: "ready", name: "Ready", isFinal: false },
diff --git a/apps/web/src/components/shared/modals/create-task-modal.tsx b/apps/web/src/components/shared/modals/create-task-modal.tsx
index 447555e92..8711cd8f5 100644
--- a/apps/web/src/components/shared/modals/create-task-modal.tsx
+++ b/apps/web/src/components/shared/modals/create-task-modal.tsx
@@ -281,8 +281,7 @@ function CreateTaskModalContent({
} = useGetColumns(open ? resolvedProjectId : "");
const initialColumn = status
? projectColumns?.find((column) => column.slug === status)
- : (projectColumns?.find((column) => !column.isFinal) ??
- projectColumns?.[0]);
+ : projectColumns?.find((column) => !column.isFinal);
const taskStatus = status ?? initialColumn?.slug ?? "planned";
const awaitingColumns =
!status && Boolean(resolvedProjectId) && !projectColumns;
@@ -1494,7 +1493,7 @@ function CreateTaskModalContent({
size="sm"
onClick={() => void refetchColumns()}
>
- {t("common:actions.tryAgain")}
+ {t("common:error.tryAgain")}
</Button>
</div>
)}
diff --git a/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/inbox.tsx b/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/inbox.tsx
index 569aab1e0..17fda3d53 100644
--- a/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/inbox.tsx
+++ b/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/inbox.tsx
@@ -21,15 +21,12 @@ export const Route = createFileRoute(
function RouteComponent() {
const { t } = useTranslation();
const { workspaceId } = Route.useParams();
- const {
- data: notifications = [],
- isPending,
- isError,
- refetch,
- } = useGetNotifications(workspaceId);
+ const { data, isPending, isError, refetch } =
+ useGetNotifications(workspaceId);
const { mutate: markAsRead } = useMarkNotificationAsRead();
const [selectedId, setSelectedId] = useState<string>();
+ const notifications = data ?? [];
const selected = notifications.find(
(notification) => notification.id === selectedId,
);
@@ -55,7 +52,7 @@ function RouteComponent() {
<p role="status" className="p-5 text-muted-foreground text-sm">
{t("common:empty.loading")}
</p>
- ) : isError ? (
+ ) : isError && !data ? (
<div className="flex flex-col items-start gap-3 p-5">
<p role="alert" className="text-muted-foreground text-sm">
{t("notifications:inbox.loadError")}
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.tsx
index 4f70d5da9..591436348 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
@@ -62,7 +62,7 @@ function RouteComponent() {
))}
</div>
) : isError && !assigned ? (
- <p className="p-6 text-muted-foreground text-sm">
+ <p role="alert" className="p-6 text-muted-foreground text-sm">
{t("workspace:myWork.loadError")}
</p>
) : !assigned?.tasks.length ? (
diff --git a/tests/api-integration/workspace-activity.test.ts b/tests/api-integration/workspace-activity.test.ts
index 35d6cefa8..901881063 100644
--- a/tests/api-integration/workspace-activity.test.ts
+++ b/tests/api-integration/workspace-activity.test.ts
@@ -1,3 +1,4 @@
+import { eq } from "drizzle-orm";
import { beforeEach, describe, expect, it } from "vite-plus/test";
import db, { schema } from "../../apps/api/src/database";
import { createApp } from "../../apps/api/src/index";
@@ -15,6 +16,7 @@ type WorkspaceActivityResponse = Array<{
userName: string | null;
taskTitle: string;
projectSlug: string;
+ eventData: Record<string, unknown> | null;
}>;
const DAY = 24 * 60 * 60 * 1000;
@@ -31,6 +33,10 @@ describe("API integration: workspace activity", () => {
workspaceId: member.workspace.id,
slug: "web",
});
+ await db
+ .update(schema.columnTable)
+ .set({ name: "Queued for QA" })
+ .where(eq(schema.columnTable.id, web.columns.todo.id));
const foreign = await createProjectFixture({
workspaceId: elsewhere.workspace.id,
slug: "foreign",
@@ -110,7 +116,16 @@ describe("API integration: workspace activity", () => {
projectSlug: "web",
});
expect(body[0]).not.toHaveProperty("content");
- expect(body[1]).toMatchObject({ type: "status_changed", excerpt: null });
+ expect(body[1]).toMatchObject({
+ type: "status_changed",
+ excerpt: null,
+ eventData: {
+ oldStatus: "to-do",
+ newStatus: "in-progress",
+ oldStatusName: "Queued for QA",
+ newStatusName: "In Progress",
+ },
+ });
});
it("refuses a workspace the caller does not belong to", async () => {