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(tasks): keep nested keyboard actions in the correct status group

Tin2fd1c8eb414e
diff --git a/apps/web/src/components/list-view/index.tsx b/apps/web/src/components/list-view/index.tsx
index d5a5fc940..29ec3b074 100644
--- a/apps/web/src/components/list-view/index.tsx
+++ b/apps/web/src/components/list-view/index.tsx
@@ -307,6 +307,13 @@ function ListView({
taskIds: shownTaskIds(column),
collapsed: !isExpanded(column.id),
})),
+ // Repeated children follow their parent for navigation, but reordering
+ // must use their actual status and position rather than their nested row.
+ getMoveGroups: () =>
+ project.columns.map((column) => ({
+ id: column.id,
+ taskIds: column.tasks.map((task) => task.id),
+ })),
project,
enabled: activeId === null,
canMove: !disableDragDrop,
diff --git a/apps/web/src/components/list-view/keyboard.test.tsx b/apps/web/src/components/list-view/keyboard.test.tsx
new file mode 100644
index 000000000..06455dd64
--- /dev/null
+++ b/apps/web/src/components/list-view/keyboard.test.tsx
@@ -0,0 +1,138 @@
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import {
+ act,
+ cleanup,
+ fireEvent,
+ render,
+ screen,
+} from "@testing-library/react";
+import { afterEach, expect, it, vi } from "vite-plus/test";
+import { writeExpandedRows } from "@/lib/expanded-rows-storage";
+import { shortcutRegistry } from "@/lib/shortcuts/registry";
+import { ShortcutTestWrapper } from "@/lib/shortcuts/shortcut-test-wrapper";
+import useBulkSelectionStore from "@/store/bulk-selection";
+import type { ProjectWithTasks } from "@/types/project";
+import ListView from ".";
+
+const mocks = vi.hoisted(() => ({ mutate: vi.fn(), setProject: vi.fn() }));
+vi.mock("@tanstack/react-router", () => ({
+ useNavigate: () => vi.fn(),
+ useRouter: () => ({ preloadRoute: () => Promise.resolve() }),
+}));
+vi.mock("react-i18next", () => ({
+ useTranslation: () => ({ t: (key: string) => key }),
+}));
+vi.mock("@/hooks/mutations/task/use-update-task", () => ({
+ useUpdateTask: () => ({ mutate: mocks.mutate }),
+}));
+vi.mock("@/store/project", () => ({
+ default: () => ({ setProject: mocks.setProject }),
+}));
+vi.mock("@/hooks/queries/task-relation/use-get-project-task-relations", () => ({
+ default: () => ({
+ data: [
+ {
+ sourceTaskId: "parent",
+ targetTaskId: "child",
+ relationType: "subtask",
+ },
+ ],
+ isLoading: false,
+ isError: false,
+ }),
+}));
+vi.mock("./task-row", () => ({ default: () => null }));
+vi.mock("../bulk-selection/bulk-toolbar", () => ({ default: () => null }));
+vi.mock("../shared/modals/create-task-modal", () => ({ default: () => null }));
+vi.mock("../shared/modals/archive-tasks-modal", () => ({
+ ArchiveTasksModal: () => null,
+}));
+
+function mount() {
+ writeExpandedRows("keyboard-project", { parent: true });
+ const project = {
+ id: "keyboard-project",
+ workspaceId: "workspace",
+ columns: [
+ {
+ id: "todo",
+ slug: "todo",
+ name: "To do",
+ tasks: [
+ { id: "parent", status: "todo", position: 0 },
+ { id: "sibling", status: "todo", position: 1 },
+ ],
+ },
+ {
+ id: "doing",
+ slug: "doing",
+ name: "Doing",
+ tasks: [
+ { id: "child", status: "doing", position: 0 },
+ { id: "last", status: "doing", position: 1 },
+ ],
+ },
+ ],
+ } as ProjectWithTasks;
+ render(
+ <QueryClientProvider client={new QueryClient()}>
+ <ShortcutTestWrapper>
+ <ListView project={project} />
+ </ShortcutTestWrapper>
+ </QueryClientProvider>,
+ );
+}
+const press = (key: string, code: string, altKey = false) =>
+ fireEvent.keyDown(document.body, { key, code, altKey });
+
+afterEach(() => {
+ cleanup();
+ shortcutRegistry.reset();
+ localStorage.clear();
+ useBulkSelectionStore.getState().clearFocus();
+ useBulkSelectionStore.getState().clearSelection();
+ vi.clearAllMocks();
+});
+
+it("visits a child repeated across status groups once without looping", () => {
+ mount();
+ const visited: (string | null)[] = [];
+ for (let index = 0; index < 5; index++) {
+ press("j", "KeyJ");
+ visited.push(useBulkSelectionStore.getState().focusedTaskId);
+ }
+ expect(visited).toEqual(["parent", "child", "sibling", "last", "last"]);
+});
+
+it("navigates to a child's own row when its parent group is collapsed", () => {
+ mount();
+ fireEvent.click(screen.getByRole("button", { name: /^To do/ }));
+ press("j", "KeyJ");
+ expect(useBulkSelectionStore.getState().focusedTaskId).toBe("child");
+ press("j", "KeyJ");
+ expect(useBulkSelectionStore.getState().focusedTaskId).toBe("last");
+ press("t", "KeyT");
+ expect(screen.getByRole("button", { name: /^Doing/ })).toHaveAttribute(
+ "aria-expanded",
+ "false",
+ );
+ expect(screen.getByRole("button", { name: /^To do/ })).toHaveAttribute(
+ "aria-expanded",
+ "false",
+ );
+});
+
+it("reorders a repeated child within its own status group", () => {
+ mount();
+ act(() => useBulkSelectionStore.getState().setFocusedTask("child"));
+ press("ArrowDown", "ArrowDown", true);
+ expect(
+ mocks.mutate.mock.calls.map(([task]) => ({
+ id: task.id,
+ status: task.status,
+ })),
+ ).toEqual([
+ { id: "last", status: "doing" },
+ { id: "child", status: "doing" },
+ ]);
+});
diff --git a/apps/web/src/components/project/task-view-keys/task-groups.ts b/apps/web/src/components/project/task-view-keys/task-groups.ts
index fa33269f5..9d8ae688e 100644
--- a/apps/web/src/components/project/task-view-keys/task-groups.ts
+++ b/apps/web/src/components/project/task-view-keys/task-groups.ts
@@ -30,7 +30,9 @@ function stepList(
direction: FocusDirection,
) {
if (direction === "left" || direction === "right") return null;
- const ids = visibleGroups(groups).flatMap((group) => group.taskIds);
+ const ids = [
+ ...new Set(visibleGroups(groups).flatMap((group) => group.taskIds)),
+ ];
if (ids.length === 0) return null;
const index = taskId ? ids.indexOf(taskId) : -1;
if (index === -1) return direction === "down" ? ids[0] : ids.at(-1);
diff --git a/apps/web/src/components/project/task-view-keys/use-task-view-shortcuts.ts b/apps/web/src/components/project/task-view-keys/use-task-view-shortcuts.ts
index 604176b2f..9b0aaf8c2 100644
--- a/apps/web/src/components/project/task-view-keys/use-task-view-shortcuts.ts
+++ b/apps/web/src/components/project/task-view-keys/use-task-view-shortcuts.ts
@@ -23,6 +23,7 @@ type TaskViewShortcutsOptions = {
layout: TaskLayout;
selection: TaskSelectionStore;
getGroups: () => TaskGroup[];
+ getMoveGroups?: () => TaskGroup[];
project: { id: string; workspaceId: string } | null | undefined;
enabled?: boolean;
canMove?: boolean;
@@ -38,6 +39,7 @@ export function useTaskViewShortcuts({
layout,
selection,
getGroups,
+ getMoveGroups = getGroups,
project,
enabled = true,
canMove = false,
@@ -84,14 +86,17 @@ export function useTaskViewShortcuts({
const move = (direction: MoveDirection) => {
const taskId = focused();
if (!taskId || !onMove) return;
- const overId = moveTarget(getGroups(), layout, taskId, direction);
+ const overId = moveTarget(getMoveGroups(), layout, taskId, direction);
if (!overId) return;
onMove(taskId, overId);
requestAnimationFrame(() => focusTaskElement(taskId, !peekedTaskId()));
};
const withFocusedGroup = (run: (group: TaskGroup) => void) => {
- const found = findTaskGroup(getGroups(), focused());
+ const found = findTaskGroup(
+ getGroups().filter((group) => !group.collapsed),
+ focused(),
+ );
if (found) run(found.group);
};
diff --git a/tests/api-integration/project-access.test.ts b/tests/api-integration/project-access.test.ts
index baf977f4b..06eddf6c4 100644
--- a/tests/api-integration/project-access.test.ts
+++ b/tests/api-integration/project-access.test.ts
@@ -42,6 +42,7 @@ describe("project access enforcement", () => {
`/label/task/${ctx.betaTask.id}`,
`/time-entry/task/${ctx.betaTask.id}`,
`/task-relation/${ctx.betaTask.id}`,
+ `/task-relation/project/${ctx.beta.id}`,
`/custom-field/project/${ctx.beta.id}`,
`/external-link/task/${ctx.betaTask.id}`,
`/workflow-rule/${ctx.beta.id}`,
@@ -57,6 +58,7 @@ describe("project access enforcement", () => {
`/project/${ctx.alpha.id}`,
`/task/tasks/${ctx.alpha.id}`,
`/task/${ctx.alphaTask.id}`,
+ `/task-relation/project/${ctx.alpha.id}`,
]) {
expect({ path, status: (await request(path)).status }).toEqual({
path,
diff --git a/tests/api-integration/task-relation-project.test.ts b/tests/api-integration/task-relation-project.test.ts
index 0fcf1c753..5e7dd0089 100644
--- a/tests/api-integration/task-relation-project.test.ts
+++ b/tests/api-integration/task-relation-project.test.ts
@@ -1,7 +1,8 @@
+import { createHash, randomUUID } from "node:crypto";
import { beforeEach, describe, expect, it } from "vite-plus/test";
import db, { schema } from "../../apps/api/src/database";
import { createApp } from "../../apps/api/src/index";
-import { mockAuthenticatedSession } from "./helpers/auth";
+import { mockAnonymousSession, mockAuthenticatedSession } from "./helpers/auth";
import { resetTestDatabase } from "./helpers/database";
import {
createProjectFixture,
@@ -168,6 +169,47 @@ describe("API integration: project task relations", () => {
expect(payload.map((row) => row.id)).toEqual([relation.id]);
});
+ it.each([false, true])(
+ "requires task:read on API keys (granted: %s)",
+ async (canReadTasks) => {
+ const member = await createWorkspaceMember({ role: "owner" });
+ const { project } = await createProjectFixture({
+ workspaceId: member.workspace.id,
+ });
+ const parent = await seedTask(member.user.id, project.id, "Parent");
+ const child = await seedTask(member.user.id, project.id, "Child");
+ const relation = await relate(parent.id, child.id);
+ mockAnonymousSession();
+ const key = `kaneo_test_${randomUUID()}`;
+ await db.insert(schema.apikeyTable).values({
+ referenceId: member.user.id,
+ userId: member.user.id,
+ key: createHash("sha256").update(key).digest("base64url"),
+ name: "project relations key",
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ permissions: JSON.stringify({
+ project: ["read"],
+ ...(canReadTasks ? { task: ["read"] } : {}),
+ }),
+ enabled: true,
+ });
+ const { app } = createApp();
+ const response = await app.request(
+ `/api/task-relation/project/${project.id}`,
+ {
+ headers: { Authorization: `Bearer ${key}` },
+ },
+ );
+ expect(response.status).toBe(canReadTasks ? 200 : 403);
+ if (canReadTasks) {
+ expect(await response.json()).toEqual([
+ expect.objectContaining({ id: relation.id }),
+ ]);
+ }
+ },
+ );
+
it("refuses a caller outside the project's workspace", async () => {
const owner = await createWorkspaceMember({ role: "owner" });
const { project } = await createProjectFixture({