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(board): refresh moved parents and stabilize page revisions

Tin1a1a0a8f1392
diff --git a/apps/api/src/task/controllers/get-tasks.ts b/apps/api/src/task/controllers/get-tasks.ts
index 4b02c5efc..fb60199a0 100644
--- a/apps/api/src/task/controllers/get-tasks.ts
+++ b/apps/api/src/task/controllers/get-tasks.ts
@@ -57,27 +57,28 @@ const priorityCaseExpr = sql<number>`CASE
ELSE 0
END`;
-function buildOrderBy(
- sortBy: GetTasksOptions["sortBy"],
- sortOrder: GetTasksOptions["sortOrder"],
-): SQL {
- const direction = sortOrder === "desc" ? desc : asc;
-
+function sortValue(sortBy: GetTasksOptions["sortBy"]): SQLWrapper {
switch (sortBy) {
case "createdAt":
- return direction(taskTable.createdAt);
+ return taskTable.createdAt;
case "priority":
- return direction(priorityCaseExpr);
+ return priorityCaseExpr;
case "dueDate":
- return direction(taskTable.dueDate);
+ return taskTable.dueDate;
case "title":
- return direction(taskTable.title);
+ return taskTable.title;
case "number":
- return direction(taskTable.number);
+ return taskTable.number;
default:
- return direction(taskTable.position);
+ return taskTable.position;
}
}
+function buildOrderBy(
+ sortBy: GetTasksOptions["sortBy"],
+ sortOrder: GetTasksOptions["sortOrder"],
+): SQL {
+ return (sortOrder === "desc" ? desc : asc)(sortValue(sortBy));
+}
function membershipRevision(
publicOnly: boolean | undefined,
@@ -150,8 +151,7 @@ async function getTasksPage(
count: sql<number>`count(*)`,
revision: membershipRevision(options.publicOnly, [
taskTable.id,
- taskTable.updatedAt,
- taskTable.position,
+ sortValue(options.sortBy),
taskTable.status,
]),
})
@@ -308,7 +308,6 @@ async function getTasksPage(
count: sql<number>`count(*)`,
revision: membershipRevision(options.publicOnly, [
columnTable.id,
- columnTable.updatedAt,
columnTable.slug,
columnTable.position,
columnTable.name,
@@ -328,7 +327,6 @@ async function getTasksPage(
count: sql<number>`count(*)`,
revision: membershipRevision(options.publicOnly, [
labelTable.id,
- labelTable.updatedAt,
labelTable.taskId,
labelTable.name,
labelTable.color,
@@ -341,7 +339,6 @@ async function getTasksPage(
count: sql<number>`count(*)`,
revision: membershipRevision(options.publicOnly, [
externalLinkTable.id,
- externalLinkTable.updatedAt,
externalLinkTable.taskId,
]),
})
diff --git a/apps/api/src/ws/index.ts b/apps/api/src/ws/index.ts
index 3d8d1256b..6b560c4b8 100644
--- a/apps/api/src/ws/index.ts
+++ b/apps/api/src/ws/index.ts
@@ -415,7 +415,7 @@ subscribeToEvent<{
{ type: "TASK_MOVED", projectId: fromProjectId, taskId },
initiatorId,
);
- refreshParentBoards(await getSubtaskParentProjects([taskId]), fromProjectId);
+ refreshParentBoards(await getSubtaskParentProjects([taskId]), toProjectId);
});
subscribeToEvent<{
diff --git a/tests/api-integration/subtask-counts.test.ts b/tests/api-integration/subtask-counts.test.ts
index 6c7b144b6..6c86d505c 100644
--- a/tests/api-integration/subtask-counts.test.ts
+++ b/tests/api-integration/subtask-counts.test.ts
@@ -433,60 +433,65 @@ describe("API integration: subtask counters", () => {
describe("subtask counter mutation paths", () => {
beforeEach(resetTestDatabase);
- it("refreshes a parent after moving a child into a nonfinal workflow", async () => {
- const member = await createWorkspaceMember();
- const parentProject = await createProjectFixture({
- workspaceId: member.workspace.id,
- });
- const source = await createProjectFixture({
- workspaceId: member.workspace.id,
- });
- const destination = await createProjectFixture({
- workspaceId: member.workspace.id,
- });
- await db
- .update(schema.columnTable)
- .set({ isFinal: false })
- .where(eq(schema.columnTable.id, destination.columns.done.id));
- const parent = await addTask(parentProject.project.id);
- const child = await addTask(source.project.id, "done");
- await relate(parent.id, child.id);
- expect(await countsFor(parentProject.project.id, parent.id)).toEqual({
- completed: 1,
- total: 1,
- });
- await initializeWebSocketAdapter();
- const send = vi.fn();
- const connection = addConnection(
- parentProject.project.id,
- { send } as never,
- member.user.id,
- "same-window",
- member.workspace.id,
- );
- try {
- await eventContext.run({ initiatorId: "same-window" }, () =>
- moveTask({
- taskId: child.id,
- destinationProjectId: destination.project.id,
- currentUserId: member.user.id,
- }),
- );
- await vi.waitFor(() => expect(send).toHaveBeenCalled());
- expect(JSON.parse(send.mock.calls[0][0])).toEqual({
- type: "TASK_RELATION_UPDATED",
- projectId: parentProject.project.id,
- taskId: "",
+ it.each([false, true])(
+ "refreshes a parent after moving a child into a nonfinal workflow (sameSource=%s)",
+ async (sameSource) => {
+ const member = await createWorkspaceMember();
+ const parentProject = await createProjectFixture({
+ workspaceId: member.workspace.id,
});
+ const source = sameSource
+ ? parentProject
+ : await createProjectFixture({
+ workspaceId: member.workspace.id,
+ });
+ const destination = await createProjectFixture({
+ workspaceId: member.workspace.id,
+ });
+ await db
+ .update(schema.columnTable)
+ .set({ isFinal: false })
+ .where(eq(schema.columnTable.id, destination.columns.done.id));
+ const parent = await addTask(parentProject.project.id);
+ const child = await addTask(source.project.id, "done");
+ await relate(parent.id, child.id);
expect(await countsFor(parentProject.project.id, parent.id)).toEqual({
- completed: 0,
+ completed: 1,
total: 1,
});
- } finally {
- removeConnection(parentProject.project.id, connection);
- await shutdownWebSocketAdapter();
- }
- });
+ await initializeWebSocketAdapter();
+ const send = vi.fn();
+ const connection = addConnection(
+ parentProject.project.id,
+ { send } as never,
+ member.user.id,
+ "same-window",
+ member.workspace.id,
+ );
+ try {
+ await eventContext.run({ initiatorId: "same-window" }, () =>
+ moveTask({
+ taskId: child.id,
+ destinationProjectId: destination.project.id,
+ currentUserId: member.user.id,
+ }),
+ );
+ await vi.waitFor(() => expect(send).toHaveBeenCalled());
+ expect(JSON.parse(send.mock.calls[0][0])).toEqual({
+ type: "TASK_RELATION_UPDATED",
+ projectId: parentProject.project.id,
+ taskId: "",
+ });
+ expect(await countsFor(parentProject.project.id, parent.id)).toEqual({
+ completed: 0,
+ total: 1,
+ });
+ } finally {
+ removeConnection(parentProject.project.id, connection);
+ await shutdownWebSocketAdapter();
+ }
+ },
+ );
it("refreshes same-project parents in other windows after child deletion", async () => {
const member = await createWorkspaceMember();
const { project } = await createProjectFixture({
diff --git a/tests/api-integration/task-pagination.test.ts b/tests/api-integration/task-pagination.test.ts
index dc26eb7dd..6c337d458 100644
--- a/tests/api-integration/task-pagination.test.ts
+++ b/tests/api-integration/task-pagination.test.ts
@@ -245,3 +245,23 @@ it.each(["create", "delete", "move", "reorder"])(
expect((await later.json()).pagination.revision).not.toBe(before);
},
);
+
+it("detects title-order boundary shifts while ordinary position-order edits remain stable", async () => {
+ const { app, project, tasks } = await fixture(237, true);
+ mockAnonymousSession();
+ const path = `/api/public-project/${project.id}?limit=100`;
+ const position = (await (await app.request(path)).json()).pagination.revision;
+ const title = (await (await app.request(path + "&sortBy=title")).json())
+ .pagination.revision;
+ await db
+ .update(schema.taskTable)
+ .set({ title: "ZZZ new title" })
+ .where(eq(schema.taskTable.id, tasks[0].id));
+ expect(
+ (await (await app.request(path + "&page=2")).json()).pagination.revision,
+ ).toBe(position);
+ expect(
+ (await (await app.request(path + "&page=2&sortBy=title")).json()).pagination
+ .revision,
+ ).not.toBe(title);
+});
diff --git a/tests/api-integration/task-related-pages.test.ts b/tests/api-integration/task-related-pages.test.ts
index 641ff5ad4..f88111b76 100644
--- a/tests/api-integration/task-related-pages.test.ts
+++ b/tests/api-integration/task-related-pages.test.ts
@@ -256,3 +256,28 @@ it.each(
}
},
);
+
+it("does not restart public related pagination for ordinary text and integration stamps", async () => {
+ const { app, project, task } = await fixture();
+ mockAnonymousSession();
+ const path = `/api/public-project/${project.id}?limit=100`;
+ const before = (await (await app.request(path)).json()).pagination;
+ await db
+ .update(schema.taskTable)
+ .set({ title: "Edited title", description: "Edited body" })
+ .where(eq(schema.taskTable.id, task.id));
+ await db
+ .update(schema.externalLinkTable)
+ .set({
+ metadata: JSON.stringify({
+ lastSync: { title: { source: "kaneo", value: "Edited title" } },
+ }),
+ })
+ .where(eq(schema.externalLinkTable.id, "link-000"));
+ const after = (await (await app.request(path + "&relatedPage=2")).json())
+ .pagination;
+ expect(after).toMatchObject({
+ revision: before.revision,
+ relatedRevision: before.relatedRevision,
+ });
+});