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: retain workflow identity and avoid unrelated reorder refreshes

Tin8b7ad3283e71
diff --git a/apps/api/src/task/controllers/get-task.ts b/apps/api/src/task/controllers/get-task.ts
index e742e216f..940332512 100644
--- a/apps/api/src/task/controllers/get-task.ts
+++ b/apps/api/src/task/controllers/get-task.ts
@@ -26,6 +26,7 @@ async function getTask(taskId: string, board = false) {
}
: {}),
status: taskTable.status,
+ columnId: taskTable.columnId,
priority: taskTable.priority,
startDate: taskTable.startDate,
dueDate: taskTable.dueDate,
diff --git a/apps/api/src/task/response.ts b/apps/api/src/task/response.ts
index 62b255336..803616dd1 100644
--- a/apps/api/src/task/response.ts
+++ b/apps/api/src/task/response.ts
@@ -37,6 +37,10 @@ export const taskSchema = z
export const taskWithAssigneeSchema = taskSchema
.extend({
+ columnId: z.string().nullable().openapi({
+ description:
+ "The referenced workflow column; null for virtual statuses and legacy tasks without a column reference.",
+ }),
subtaskCounts: z
.object({ completed: z.number(), total: z.number() })
.optional(),
diff --git a/apps/docs/openapi.json b/apps/docs/openapi.json
index 19df741b3..3debf07b0 100644
--- a/apps/docs/openapi.json
+++ b/apps/docs/openapi.json
@@ -1173,6 +1173,13 @@
{
"type": "object",
"properties": {
+ "columnId": {
+ "type": [
+ "string",
+ "null"
+ ],
+ "description": "The referenced workflow column; null for virtual statuses and legacy tasks without a column reference."
+ },
"subtaskCounts": {
"type": "object",
"properties": {
@@ -1224,6 +1231,7 @@
}
},
"required": [
+ "columnId",
"assigneeName",
"assigneeId"
]
diff --git a/apps/web/src/components/inbox/inbox-task.test.tsx b/apps/web/src/components/inbox/inbox-task.test.tsx
index 4d618243b..89d423f3d 100644
--- a/apps/web/src/components/inbox/inbox-task.test.tsx
+++ b/apps/web/src/components/inbox/inbox-task.test.tsx
@@ -20,6 +20,7 @@ beforeEach(() => {
id: "task",
title: "Custom workflow",
status: "review",
+ columnId: "review-column",
projectId: "project",
},
});
@@ -29,6 +30,13 @@ vi.mock("@/hooks/queries/task/use-get-task", () => ({ default: queries.task }));
vi.mock("@/hooks/queries/column/use-get-columns", () => ({
useGetColumns: () => ({
data: [
+ {
+ id: "other-column",
+ slug: "review",
+ name: "Other queue",
+ icon: "Circle",
+ isFinal: true,
+ },
{
id: "review-column",
slug: "review",
diff --git a/apps/web/src/components/inbox/inbox-task.tsx b/apps/web/src/components/inbox/inbox-task.tsx
index 381ce06b6..e8131285b 100644
--- a/apps/web/src/components/inbox/inbox-task.tsx
+++ b/apps/web/src/components/inbox/inbox-task.tsx
@@ -39,9 +39,10 @@ export function InboxTask({ taskId }: InboxTaskProps) {
isError: activityError,
} = useGetActivitiesByTaskId(taskId, true, VISIBLE_ACTIVITIES);
const { data: columns = [] } = useGetColumns(task?.projectId ?? "");
- const statusColumn = columns.find(
- (column) => column.slug === task?.status || column.id === task?.status,
- );
+ const slugColumns = columns.filter((column) => column.slug === task?.status);
+ const statusColumn =
+ columns.find((column) => column.id === task?.columnId) ??
+ (slugColumns.length === 1 ? slugColumns[0] : undefined);
const { canUpdateTasks } = useWorkspacePermission();
if (isLoading) {
diff --git a/apps/web/src/components/kanban-board/filtered-drag.test.tsx b/apps/web/src/components/kanban-board/filtered-drag.test.tsx
index 86d9ca2b5..7105e428d 100644
--- a/apps/web/src/components/kanban-board/filtered-drag.test.tsx
+++ b/apps/web/src/components/kanban-board/filtered-drag.test.tsx
@@ -7,6 +7,7 @@ import {
it,
vi,
} from "vite-plus/test";
+import type { TaskReorder } from "@/fetchers/task/reorder-tasks";
import type { ProjectWithTasks } from "@/types/project";
import KanbanBoard from "./index";
@@ -15,14 +16,25 @@ const mocks = vi.hoisted(() => ({
setProject: vi.fn(),
reorder: vi.fn(),
setQueryData: vi.fn(),
+ invalidateQueries: vi.fn(),
+ success: undefined as
+ | ((
+ result: unknown,
+ variables: TaskReorder & { previousBoard: ProjectWithTasks },
+ ) => void)
+ | undefined,
}));
vi.mock("@tanstack/react-query", () => ({
useQueryClient: () => ({
setQueryData: mocks.setQueryData,
+ invalidateQueries: mocks.invalidateQueries,
getQueryData: () => mocks.project,
getQueryState: () => undefined,
}),
- useMutation: () => ({ mutate: mocks.reorder, isPending: false }),
+ useMutation: ({ onSuccess }: { onSuccess: typeof mocks.success }) => {
+ mocks.success = onSuccess;
+ return { mutate: mocks.reorder, isPending: false };
+ },
}));
vi.mock("@kaneo/libs", () => ({ client: {} }));
vi.mock("@tanstack/react-router", () => ({ useNavigate: () => vi.fn() }));
@@ -112,6 +124,13 @@ describe("filtered board dragging", () => {
),
).toEqual(["hidden", "b", "a"]);
expect(mocks.reorder).toHaveBeenCalledOnce();
+ mocks.success?.(null, mocks.reorder.mock.calls[0]?.[0]);
+ expect(mocks.invalidateQueries).not.toHaveBeenCalledWith({
+ queryKey: ["assigned-tasks"],
+ });
+ expect(mocks.invalidateQueries).not.toHaveBeenCalledWith({
+ queryKey: ["workspace-activity"],
+ });
view.unmount();
});
});
@@ -141,3 +160,34 @@ it("rejects an in-flight Kanban drop after a failed refresh disables dragging",
expect(mocks.setProject).not.toHaveBeenCalled();
expect(mocks.setQueryData).not.toHaveBeenCalled();
});
+
+it("refreshes personal work after a cross-column status change", () => {
+ const project = {
+ id: "p",
+ columns: [
+ {
+ id: "todo",
+ slug: "todo",
+ tasks: [{ id: "a", status: "todo", position: 0 }],
+ },
+ {
+ id: "done",
+ slug: "done",
+ tasks: [{ id: "b", status: "done", position: 0 }],
+ },
+ ],
+ plannedTasks: [],
+ archivedTasks: [],
+ } as unknown as ProjectWithTasks;
+ mocks.project = project;
+ const view = render(<KanbanBoard project={project} />);
+ fireEvent.click(view.getByText("drop"));
+ expect(mocks.reorder).toHaveBeenCalledOnce();
+ mocks.success?.(null, mocks.reorder.mock.calls[0]?.[0]);
+ expect(mocks.invalidateQueries).toHaveBeenCalledWith({
+ queryKey: ["assigned-tasks"],
+ });
+ expect(mocks.invalidateQueries).toHaveBeenCalledWith({
+ queryKey: ["workspace-activity"],
+ });
+});
diff --git a/apps/web/src/components/kanban-board/index.tsx b/apps/web/src/components/kanban-board/index.tsx
index d7cdef6c2..4f9d5f85e 100644
--- a/apps/web/src/components/kanban-board/index.tsx
+++ b/apps/web/src/components/kanban-board/index.tsx
@@ -69,7 +69,8 @@ function KanbanBoard({
reorderTasks(request),
onMutate: (variables) => ({ previousBoard: variables.previousBoard }),
onSuccess: (_result, variables) => {
- invalidateMyWork(queryClient);
+ if (variables.tasks.some((task) => task.status !== undefined))
+ invalidateMyWork(queryClient);
void queryClient.invalidateQueries({
queryKey: ["tasks", variables.projectId],
});
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 eca339325..34cf16ac6 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
@@ -349,6 +349,24 @@ describe("CreateTaskModal", () => {
expect(createTask).not.toHaveBeenCalled();
});
+ it("uses planned instead of an ambiguous open/final status slug", async () => {
+ projectColumns = [
+ { id: "done", slug: "shared", name: "Finished", isFinal: true },
+ { id: "open", slug: "shared", name: "Open", isFinal: false },
+ ];
+ render(<CreateTaskModal open onClose={vi.fn()} />, {
+ wrapper: createWrapper(),
+ });
+ await chooseBeta();
+ enterTitle();
+ submit();
+ await vi.waitFor(() =>
+ expect(createTask).toHaveBeenCalledWith(
+ expect.objectContaining({ status: "planned" }),
+ ),
+ );
+ });
+
it("uses planned when every column is final", async () => {
projectColumns = [
{ id: "done", slug: "done", name: "Finished", isFinal: true },
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 8711cd8f5..d86a131f1 100644
--- a/apps/web/src/components/shared/modals/create-task-modal.tsx
+++ b/apps/web/src/components/shared/modals/create-task-modal.tsx
@@ -281,7 +281,12 @@ function CreateTaskModalContent({
} = useGetColumns(open ? resolvedProjectId : "");
const initialColumn = status
? projectColumns?.find((column) => column.slug === status)
- : projectColumns?.find((column) => !column.isFinal);
+ : projectColumns?.find(
+ (column) =>
+ !column.isFinal &&
+ projectColumns.filter((other) => other.slug === column.slug)
+ .length === 1,
+ );
const taskStatus = status ?? initialColumn?.slug ?? "planned";
const awaitingColumns =
!status && Boolean(resolvedProjectId) && !projectColumns;
diff --git a/tests/api-integration/assigned-tasks.test.ts b/tests/api-integration/assigned-tasks.test.ts
index a849a4286..d2eb93326 100644
--- a/tests/api-integration/assigned-tasks.test.ts
+++ b/tests/api-integration/assigned-tasks.test.ts
@@ -210,6 +210,12 @@ describe("API integration: assigned tasks", () => {
expect(response.status).toBe(200);
const body = (await response.json()) as AssignedTasksResponse;
expect(body.total).toBe(1);
+ const details = await app.request(`/api/task/${task.id}`);
+ expect(details.status).toBe(200);
+ expect(await details.json()).toMatchObject({
+ id: task.id,
+ columnId: columns.todo.id,
+ });
expect(body.tasks).toEqual([
expect.objectContaining({ id: task.id, statusName: columns.todo.name }),
]);