⚡ 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: refresh personal work after workflow and task changes
Tin2fc93b203dbf
diff --git a/apps/api/src/task/controllers/get-task.ts b/apps/api/src/task/controllers/get-task.tsindex 940332512..00ef30e50 100644--- a/apps/api/src/task/controllers/get-task.ts+++ b/apps/api/src/task/controllers/get-task.ts@@ -22,7 +22,6 @@ async function getTask(taskId: string, board = false) {...(board? {descriptionDeferred,- workspaceId: sql<string>`(select ${projectTable.workspaceId} from ${projectTable} where ${projectTable.id} = ${taskTable.projectId})`,}: {}),status: taskTable.status,@@ -36,6 +35,7 @@ async function getTask(taskId: string, board = false) {assigneeName: userTable.name,assigneeId: userTable.id,projectId: taskTable.projectId,+ workspaceId: sql<string>`(select ${projectTable.workspaceId} from ${projectTable} where ${projectTable.id} = ${taskTable.projectId})`,}).from(taskTable).leftJoin(userTable, eq(taskTable.userId, userTable.id))@@ -48,7 +48,8 @@ async function getTask(taskId: string, board = false) {});}- const { workspaceId, ...result } = task[0];+ const result = task[0];+ const { workspaceId } = result;if (!board || !workspaceId) return result;const parent = alias(taskTable, "parent");const parents = await dbdiff --git a/apps/api/src/task/response.ts b/apps/api/src/task/response.tsindex 803616dd1..3e4932900 100644--- a/apps/api/src/task/response.ts+++ b/apps/api/src/task/response.ts@@ -37,6 +37,9 @@ export const taskSchema = zexport const taskWithAssigneeSchema = taskSchema.extend({+ workspaceId: z.string().openapi({+ description: "The workspace currently owning the task's project.",+ }),columnId: z.string().nullable().openapi({description:"The referenced workflow column; null for virtual statuses and legacy tasks without a column reference.",diff --git a/apps/docs/openapi.json b/apps/docs/openapi.jsonindex 3debf07b0..1efe9f4da 100644--- a/apps/docs/openapi.json+++ b/apps/docs/openapi.json@@ -1173,6 +1173,10 @@{"type": "object","properties": {+ "workspaceId": {+ "type": "string",+ "description": "The workspace currently owning the task's project."+ },"columnId": {"type": ["string",@@ -1231,6 +1235,7 @@}},"required": [+ "workspaceId","columnId","assigneeName","assigneeId"diff --git a/apps/web/src/components/inbox/inbox-detail.tsx b/apps/web/src/components/inbox/inbox-detail.tsxindex 813133c96..fff799272 100644--- a/apps/web/src/components/inbox/inbox-detail.tsx+++ b/apps/web/src/components/inbox/inbox-detail.tsx@@ -1,8 +1,6 @@-import { Link } from "@tanstack/react-router";-import { ArrowLeft, ArrowUpRight } from "lucide-react";+import { ArrowLeft } from "lucide-react";import { useTranslation } from "react-i18next";import {- getEventDataRecord,getNotificationContent,getNotificationTitle,} from "@/components/notification/notification-text";@@ -15,15 +13,15 @@ import { NotificationIcon } from "./notification-icon";type InboxDetailProps = {notification: Notification;onBack: () => void;+ workspaceId: string;};-export function InboxDetail({ notification, onBack }: InboxDetailProps) {+export function InboxDetail({+ notification,+ onBack,+ workspaceId,+}: InboxDetailProps) {const { t } = useTranslation();- const eventData = getEventDataRecord(notification.eventData);- const workspaceId =- typeof eventData?.workspaceId === "string" ? eventData.workspaceId : null;- const projectId =- typeof eventData?.projectId === "string" ? eventData.projectId : null;const taskId =notification.resourceType === "task" ? notification.resourceId : null;const content = getNotificationContent(notification, t);@@ -48,21 +46,6 @@ export function InboxDetail({ notification, onBack }: InboxDetailProps) {{formatRelativeTime(notification.createdAt)}</time></span>- {taskId && workspaceId && projectId && (- <Button- variant="outline"- size="xs"- render={- <Link- to="/dashboard/workspace/$workspaceId/project/$projectId/task/$taskId"- params={{ workspaceId, projectId, taskId }}- />- }- >- {t("notifications:inbox.openTask")}- <ArrowUpRight />- </Button>- )}</div><div className="min-h-0 flex-1 overflow-y-auto">@@ -79,7 +62,9 @@ export function InboxDetail({ notification, onBack }: InboxDetailProps) {</div></div>- {taskId && <InboxTask key={taskId} taskId={taskId} />}+ {taskId && (+ <InboxTask key={taskId} taskId={taskId} workspaceId={workspaceId} />+ )}</div></div></div>diff --git a/apps/web/src/components/inbox/inbox-task.test.tsx b/apps/web/src/components/inbox/inbox-task.test.tsxindex 89d423f3d..1d44bbc89 100644--- a/apps/web/src/components/inbox/inbox-task.test.tsx+++ b/apps/web/src/components/inbox/inbox-task.test.tsx@@ -1,3 +1,4 @@+import type { ReactNode } from "react";import { cleanup, fireEvent, render, screen } from "@testing-library/react";import {afterEach,@@ -22,10 +23,28 @@ beforeEach(() => {status: "review",columnId: "review-column",projectId: "project",+ workspaceId: "workspace",},});queries.activity.mockReturnValue({ data: [] });});+vi.mock("@tanstack/react-router", () => ({+ Link: ({+ params,+ children,+ ...props+ }: {+ params: { workspaceId: string; projectId: string; taskId: string };+ children?: ReactNode;+ }) => (+ <a+ {...props}+ href={`/dashboard/workspace/${params.workspaceId}/project/${params.projectId}/task/${params.taskId}`}+ >+ {children}+ </a>+ ),+}));vi.mock("@/hooks/queries/task/use-get-task", () => ({ default: queries.task }));vi.mock("@/hooks/queries/column/use-get-columns", () => ({useGetColumns: () => ({@@ -68,6 +87,33 @@ describe("Inbox task preview", () => {expect(document.querySelector(".lucide-flag")).not.toBeNull();expect(queries.activity).toHaveBeenCalledWith("task", true, 6);});+ it("updates the task link when a remote move changes its project and workspace", () => {+ const view = render(+ <InboxTask taskId="task" workspaceId="old-workspace" />,+ );+ expect(+ screen.getByRole("link", { name: "notifications:inbox.openTask" }),+ ).toHaveAttribute(+ "href",+ "/dashboard/workspace/workspace/project/project/task/task",+ );+ queries.task.mockReturnValue({+ data: {+ id: "task",+ title: "Moved task",+ status: "review",+ projectId: "new-project",+ workspaceId: "new-workspace",+ },+ });+ view.rerender(<InboxTask taskId="task" workspaceId="old-workspace" />);+ expect(+ screen.getByRole("link", { name: "notifications:inbox.openTask" }),+ ).toHaveAttribute(+ "href",+ "/dashboard/workspace/new-workspace/project/new-project/task/task",+ );+ });it("keeps cached task and activity content after a failed background refresh", () => {queries.task.mockReturnValue({data: { title: "Cached task", status: "review", projectId: "project" },diff --git a/apps/web/src/components/inbox/inbox-task.tsx b/apps/web/src/components/inbox/inbox-task.tsxindex e8131285b..2e392310e 100644--- a/apps/web/src/components/inbox/inbox-task.tsx+++ b/apps/web/src/components/inbox/inbox-task.tsx@@ -1,3 +1,5 @@+import { Link } from "@tanstack/react-router";+import { ArrowUpRight } from "lucide-react";import { useTranslation } from "react-i18next";import Activity from "@/components/activity";import CommentInput from "@/components/activity/comment-input";@@ -17,13 +19,14 @@ import { getPriorityIcon } from "@/lib/priority";type InboxTaskProps = {taskId: string;+ workspaceId?: string;};const VISIBLE_ACTIVITIES = 6;// The task a notification points at, with enough of its thread to answer// without leaving the inbox.-export function InboxTask({ taskId }: InboxTaskProps) {+export function InboxTask({ taskId, workspaceId }: InboxTaskProps) {const { t } = useTranslation();const {data: task,@@ -81,14 +84,36 @@ export function InboxTask({ taskId }: InboxTaskProps) {);}+ const linkWorkspaceId = task.workspaceId || workspaceId;const recent = (activities ?? []).slice(0, VISIBLE_ACTIVITIES);return (<div className="flex flex-col gap-7"><div className="flex flex-col gap-3.5">- <h2 className="font-semibold text-2xl text-foreground tracking-tight">- {task.title}- </h2>+ <div className="flex flex-wrap items-start justify-between gap-3">+ <h2 className="min-w-0 flex-1 font-semibold text-2xl text-foreground tracking-tight">+ {task.title}+ </h2>+ {linkWorkspaceId && (+ <Button+ variant="outline"+ size="xs"+ render={+ <Link+ to="/dashboard/workspace/$workspaceId/project/$projectId/task/$taskId"+ params={{+ workspaceId: linkWorkspaceId,+ projectId: task.projectId,+ taskId: task.id,+ }}+ />+ }+ >+ {t("notifications:inbox.openTask")}+ <ArrowUpRight />+ </Button>+ )}+ </div><dl className="flex flex-wrap items-center gap-x-5 gap-y-2 text-[13px] text-foreground/85"><div className="flex items-center gap-1.5"><dt className="sr-only">{t("tasks:status.label")}</dt>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.tsxindex 34cf16ac6..fea9ebf16 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@@ -45,6 +45,7 @@ const setProject = vi.fn();let workspaceId = "workspace-1";let projects: { id: string; name: string; slug: string }[] | undefined;let columnsError = false;+let columnsFetching = false;const refetchColumns = vi.fn();let projectColumns:| { id: string; slug: string; name: string; isFinal: boolean }[]@@ -64,6 +65,11 @@ beforeEach(() => {];storedProject = null;columnsError = false;+ columnsFetching = false;+ refetchColumns.mockImplementation(async () => ({+ data: projectColumns,+ isError: columnsError,+ }));projectColumns = [{ id: "todo", slug: "to-do", name: "To Do", isFinal: false },];@@ -154,6 +160,7 @@ vi.mock("@/hooks/queries/column/use-get-columns", () => ({useGetColumns: () => ({data: projectColumns,isError: columnsError,+ isFetching: columnsFetching,refetch: refetchColumns,}),}));@@ -333,6 +340,74 @@ describe("CreateTaskModal", () => {expect(createTask).not.toHaveBeenCalled();});+ it("uses fresh workflow columns when a cached open column became final", async () => {+ refetchColumns.mockResolvedValue({+ data: [+ { id: "todo", slug: "to-do", name: "Completed", isFinal: true },+ { id: "ready", slug: "ready", name: "Ready", isFinal: false },+ ],+ isError: false,+ });+ render(<CreateTaskModal open onClose={vi.fn()} />, {+ wrapper: createWrapper(),+ });+ await chooseBeta();+ enterTitle();+ submit();+ await vi.waitFor(() =>+ expect(createTask).toHaveBeenCalledWith(+ expect.objectContaining({ status: "ready" }),+ ),+ );+ });++ it("does not create from cached columns when the submission refresh fails", async () => {+ refetchColumns.mockResolvedValue({ data: projectColumns, isError: true });+ render(<CreateTaskModal open onClose={vi.fn()} />, {+ wrapper: createWrapper(),+ });+ await chooseBeta();+ enterTitle();+ submit();+ await vi.waitFor(() => expect(refetchColumns).toHaveBeenCalledOnce());+ expect(createTask).not.toHaveBeenCalled();+ });++ it("waits for refreshing cached workflow columns", async () => {+ columnsFetching = true;+ render(<CreateTaskModal open onClose={vi.fn()} />, {+ wrapper: createWrapper(),+ });+ await chooseBeta();+ enterTitle();+ expect(+ screen.getByText("common:modals.createTask.createButton"),+ ).toBeDisabled();+ submit();+ expect(createTask).not.toHaveBeenCalled();+ });++ it("does not publish after closing during workflow verification", async () => {+ let finish!: (value: unknown) => void;+ refetchColumns.mockImplementation(+ () =>+ new Promise((resolve) => {+ finish = resolve;+ }),+ );+ const view = render(<CreateTaskModal open onClose={vi.fn()} />, {+ wrapper: createWrapper(),+ });+ await chooseBeta();+ enterTitle();+ submit();+ view.rerender(<CreateTaskModal open={false} onClose={vi.fn()} />);+ await act(async () => {+ finish({ data: projectColumns, isError: false });+ });+ expect(createTask).not.toHaveBeenCalled();+ });+it("offers a retry when project statuses could not be loaded", async () => {projectColumns = undefined;columnsError = true;diff --git a/apps/web/src/components/shared/modals/create-task-modal.tsx b/apps/web/src/components/shared/modals/create-task-modal.tsxindex d86a131f1..3ace63e23 100644--- a/apps/web/src/components/shared/modals/create-task-modal.tsx+++ b/apps/web/src/components/shared/modals/create-task-modal.tsx@@ -95,6 +95,7 @@ import { getPriorityIcon } from "@/lib/priority";import { toast } from "@/lib/toast";import useProjectStore from "@/store/project";import type Task from "@/types/task";+import { getInitialTaskColumn } from "./initial-task-column";type CreateTaskModalProps = {open: boolean;@@ -278,18 +279,14 @@ function CreateTaskModalContent({data: projectColumns,isError: columnsError,refetch: refetchColumns,- } = useGetColumns(open ? resolvedProjectId : "");- const initialColumn = status- ? projectColumns?.find((column) => column.slug === status)- : projectColumns?.find(- (column) =>- !column.isFinal &&- projectColumns.filter((other) => other.slug === column.slug)- .length === 1,- );+ isFetching: columnsFetching,+ } = useGetColumns(open ? resolvedProjectId : "", true);+ const initialColumn = getInitialTaskColumn(projectColumns, status);const taskStatus = status ?? initialColumn?.slug ?? "planned";const awaitingColumns =- !status && Boolean(resolvedProjectId) && !projectColumns;+ !status &&+ Boolean(resolvedProjectId) &&+ (!projectColumns || columnsFetching || columnsError);const searchInputRef = useRef<HTMLInputElement>(null);const stagedAssetsRef = useRef<string[]>([]);@@ -504,6 +501,14 @@ function CreateTaskModalContent({submittingRef.current = true;setIsSubmitting(true);try {+ let submitStatus = taskStatus;+ if (!status) {+ const workflow = await refetchColumns();+ if (!activeRef.current) return;+ if (workflow.isError || !workflow.data)+ throw new Error(t("common:modals.createTask.statusLoadError"));+ submitStatus = getInitialTaskColumn(workflow.data)?.slug ?? "planned";+ }didSubmitRef.current = true;const savedTask = normalizeTask(await createTask({@@ -514,7 +519,7 @@ function CreateTaskModalContent({projectId: resolvedProjectId,startDate: startDate ? startDate.toISOString() : undefined,dueDate: dueDate ? dueDate.toISOString() : undefined,- status: taskStatus,+ status: submitStatus,draftAssetIds: stagedAssetsRef.current.filter((id) =>description.includes(`/asset/${id}`),),diff --git a/apps/web/src/components/shared/modals/initial-task-column.ts b/apps/web/src/components/shared/modals/initial-task-column.tsnew file mode 100644index 000000000..a800073ea--- /dev/null+++ b/apps/web/src/components/shared/modals/initial-task-column.ts@@ -0,0 +1,16 @@+type WorkflowColumn = { slug: string; isFinal: boolean };++export function getInitialTaskColumn<T extends WorkflowColumn>(+ columns: T[] | undefined,+ status?: string,+): T | undefined {+ if (status) return columns?.find((column) => column.slug === status);+ const counts = new Map<string, number>();+ for (const column of columns ?? []) {+ counts.set(column.slug, (counts.get(column.slug) ?? 0) + 1);+ }+ // Creation accepts slugs, so an ambiguous legacy slug cannot pick a column.+ return columns?.find(+ (column) => !column.isFinal && counts.get(column.slug) === 1,+ );+}diff --git a/apps/web/src/hooks/mutations/comment/use-create-comment.ts b/apps/web/src/hooks/mutations/comment/use-create-comment.tsindex 545e258bb..943ef05f0 100644--- a/apps/web/src/hooks/mutations/comment/use-create-comment.ts+++ b/apps/web/src/hooks/mutations/comment/use-create-comment.ts@@ -1,9 +1,13 @@-import { useMutation } from "@tanstack/react-query";+import { useMutation, useQueryClient } from "@tanstack/react-query";import createComment from "@/fetchers/comment/create-comment";function useCreateComment() {+ const queryClient = useQueryClient();return useMutation({mutationFn: createComment,+ onSuccess: () => {+ void queryClient.invalidateQueries({ queryKey: ["workspace-activity"] });+ },});}diff --git a/apps/web/src/hooks/mutations/comment/use-delete-comment.ts b/apps/web/src/hooks/mutations/comment/use-delete-comment.tsindex 3e9ce9786..142d3af96 100644--- a/apps/web/src/hooks/mutations/comment/use-delete-comment.ts+++ b/apps/web/src/hooks/mutations/comment/use-delete-comment.ts@@ -8,6 +8,7 @@ function useDeleteComment(taskId: string) {mutationFn: deleteComment,onSuccess: () => {queryClient.invalidateQueries({ queryKey: ["activities", taskId] });+ void queryClient.invalidateQueries({ queryKey: ["workspace-activity"] });},});}diff --git a/apps/web/src/hooks/mutations/comment/use-update-comment.ts b/apps/web/src/hooks/mutations/comment/use-update-comment.tsindex 5abe19432..27b42f001 100644--- a/apps/web/src/hooks/mutations/comment/use-update-comment.ts+++ b/apps/web/src/hooks/mutations/comment/use-update-comment.ts@@ -1,9 +1,13 @@-import { useMutation } from "@tanstack/react-query";+import { useMutation, useQueryClient } from "@tanstack/react-query";import updateComment from "@/fetchers/comment/update-comment";function useUpdateComment() {+ const queryClient = useQueryClient();return useMutation({mutationFn: updateComment,+ onSuccess: () => {+ void queryClient.invalidateQueries({ queryKey: ["workspace-activity"] });+ },});}diff --git a/apps/web/src/hooks/queries/column/use-get-columns.ts b/apps/web/src/hooks/queries/column/use-get-columns.tsindex 22924482f..d67ec153f 100644--- a/apps/web/src/hooks/queries/column/use-get-columns.ts+++ b/apps/web/src/hooks/queries/column/use-get-columns.ts@@ -1,10 +1,16 @@import { useQuery } from "@tanstack/react-query";import getColumns from "@/fetchers/column/get-columns";-export function useGetColumns(projectId: string) {+export function useGetColumns(projectId: string, refreshOnMount = false) {return useQuery({queryKey: ["columns", projectId],queryFn: () => getColumns(projectId),enabled: !!projectId,+ ...(refreshOnMount+ ? {+ refetchOnMount: "always" as const,+ refetchOnWindowFocus: "always" as const,+ }+ : {}),});}diff --git a/apps/web/src/hooks/queries/personal-work-refresh.test.tsx b/apps/web/src/hooks/queries/personal-work-refresh.test.tsxindex ce93773e8..79f9f8e38 100644--- a/apps/web/src/hooks/queries/personal-work-refresh.test.tsx+++ b/apps/web/src/hooks/queries/personal-work-refresh.test.tsx@@ -10,6 +10,9 @@ import useGetWorkspaceActivities from "./activity/use-get-workspace-activities";import useGetAssignedTasks from "./task/use-get-assigned-tasks";import useGetTask from "./task/use-get-task";import useGetActivitiesByTaskId from "./activity/use-get-activities-by-task-id";+import useCreateComment from "@/hooks/mutations/comment/use-create-comment";+import useUpdateComment from "@/hooks/mutations/comment/use-update-comment";+import useDeleteComment from "@/hooks/mutations/comment/use-delete-comment";import useGetProjects from "./project/use-get-projects";const mocks = vi.hoisted(() => ({@@ -18,6 +21,9 @@ const mocks = vi.hoisted(() => ({task: vi.fn(),comments: vi.fn(),projects: vi.fn(),+ createComment: vi.fn(),+ updateComment: vi.fn(),+ deleteComment: vi.fn(),}));vi.mock("@/fetchers/task/get-assigned-tasks", () => ({default: mocks.assigned,@@ -32,6 +38,16 @@ vi.mock("@/fetchers/activity/get-activites-by-task-id", () => ({}));vi.mock("@/fetchers/project/get-projects", () => ({ default: mocks.projects }));+vi.mock("@/fetchers/comment/create-comment", () => ({+ default: mocks.createComment,+}));+vi.mock("@/fetchers/comment/update-comment", () => ({+ default: mocks.updateComment,+}));+vi.mock("@/fetchers/comment/delete-comment", () => ({+ default: mocks.deleteComment,+}));+afterEach(() => {cleanup();focusManager.setFocused(undefined);@@ -130,6 +146,57 @@ describe("personal work refresh", () => {client.clear();});+ it.each(["create", "edit", "delete"])(+ "refreshes Home activity immediately after comment %s without refreshing assigned counts",+ async (action) => {+ mocks.activities.mockResolvedValue([]);+ mocks.assigned.mockResolvedValue({ tasks: [], total: 0 });+ mocks.createComment.mockResolvedValue({ id: "comment" });+ mocks.updateComment.mockResolvedValue({ id: "comment" });+ mocks.deleteComment.mockResolvedValue({ id: "comment" });+ const client = new QueryClient({+ defaultOptions: { queries: { retry: false } },+ });+ const wrapper = ({ children }: PropsWithChildren) => (+ <QueryClientProvider client={client}>{children}</QueryClientProvider>+ );+ const { result } = renderHook(+ () => ({+ activity: useGetWorkspaceActivities("workspace"),+ assigned: useGetAssignedTasks("workspace", true),+ create: useCreateComment(),+ edit: useUpdateComment(),+ remove: useDeleteComment("task"),+ }),+ { wrapper },+ );+ await waitFor(() => {+ expect(result.current.activity.isSuccess).toBe(true);+ expect(result.current.assigned.isSuccess).toBe(true);+ });+ mocks.activities.mockResolvedValue([{ id: "fresh" }]);+ await act(async () => {+ if (action === "create")+ await result.current.create.mutateAsync({+ taskId: "task",+ comment: "Added",+ });+ else if (action === "edit")+ await result.current.edit.mutateAsync({+ activityId: "comment",+ comment: "Edited",+ });+ else await result.current.remove.mutateAsync({ activityId: "comment" });+ });+ await waitFor(() =>+ expect(result.current.activity.data).toEqual([{ id: "fresh" }]),+ );+ expect(mocks.activities).toHaveBeenCalledTimes(2);+ expect(mocks.assigned).toHaveBeenCalledOnce();+ client.clear();+ },+ );+it("refreshes remote edits and comments without a project socket or notification", async () => {vi.useFakeTimers();focusManager.setFocused(true);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.tsxindex 17fda3d53..fb71ec576 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@@ -74,6 +74,7 @@ function RouteComponent() {{selected ? (<InboxDetailnotification={selected}+ workspaceId={workspaceId}onBack={() => setSelectedId(undefined)}/>) : (diff --git a/tests/api-integration/assigned-tasks.test.ts b/tests/api-integration/assigned-tasks.test.tsindex d2eb93326..e38735da1 100644--- a/tests/api-integration/assigned-tasks.test.ts+++ b/tests/api-integration/assigned-tasks.test.ts@@ -215,6 +215,7 @@ describe("API integration: assigned tasks", () => {expect(await details.json()).toMatchObject({id: task.id,columnId: columns.todo.id,+ workspaceId: member.workspace.id,});expect(body.tasks).toEqual([expect.objectContaining({ id: task.id, statusName: columns.todo.name }),