mirror of
https://github.com/multica-ai/multica.git
synced 2026-08-02 10:05:41 +02:00
* feat(projects): scheduled-only Gantt data source + WS reactivity (MUL-1881) Project Gantt now fetches its own scheduled-only data instead of riding the Board/List pagination cache. The Unscheduled drawer and pagination warning banner are gone, and any WS-driven issue change (create / update / delete) invalidates the new cache so the timeline stays live. - Backend: `GET /api/issues?scheduled=true` adds an `(i.start_date IS NOT NULL OR i.due_date IS NOT NULL)` predicate on both ListIssues and CountIssues. New SQL filter is plumbed through sqlc + handler. - Frontend: new `projectGanttIssuesOptions(wsId, projectId)` issues a single fetch and lives under its own cache key. WS handlers and mutations invalidate the prefix on create/update/delete so the bar reacts to start_date / due_date changes from other tabs and from this tab without waiting on the WS round-trip. - GanttView: drops the Unscheduled section, the pagination warning banner, and the load-all button; renders only scheduled rows. - Removes now-dead `useLoadAllRemaining`, `myIssueListPaginationOptions`, `summarizeIssueListPagination`, and the gantt locale strings that supported the old plumbing. Co-authored-by: multica-agent <github@multica.ai> * fix(projects): page through Gantt fetch and isolate per-view data sources - Walk paginated `scheduled=true` issues until total is reached so projects with more than 500 scheduled bars no longer silently truncate. - Gantt mode disables the bucketed Board/List query and reads its own scheduled cache for the project empty-state check, so the page never short-circuits Gantt with a Board-derived "no issues" CTA. - `onIssueLabelsChanged` patches matching rows in the Project Gantt cache in-place, keeping label filters consistent after attach/detach from other tabs or agents. MUL-1881 Co-authored-by: multica-agent <github@multica.ai> --------- Co-authored-by: multica-agent <github@multica.ai>
132 lines
4.1 KiB
TypeScript
132 lines
4.1 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { QueryClient } from "@tanstack/react-query";
|
|
|
|
import { setApiInstance } from "../api";
|
|
import type { ApiClient } from "../api/client";
|
|
import type { Issue, ListIssuesParams, ListIssuesResponse } from "../types";
|
|
import {
|
|
PROJECT_GANTT_MAX_ISSUES,
|
|
PROJECT_GANTT_PAGE_LIMIT,
|
|
issueKeys,
|
|
projectGanttIssuesOptions,
|
|
} from "./queries";
|
|
|
|
const WS_ID = "ws-1";
|
|
const PROJECT_ID = "project-1";
|
|
|
|
function makeIssue(idx: number): Issue {
|
|
return {
|
|
id: `issue-${idx}`,
|
|
workspace_id: WS_ID,
|
|
number: idx,
|
|
identifier: `MUL-${idx}`,
|
|
title: `Issue ${idx}`,
|
|
description: null,
|
|
status: "todo",
|
|
priority: "none",
|
|
assignee_type: null,
|
|
assignee_id: null,
|
|
creator_type: "member",
|
|
creator_id: "user-1",
|
|
parent_issue_id: null,
|
|
project_id: PROJECT_ID,
|
|
position: idx,
|
|
start_date: "2026-05-01T00:00:00Z",
|
|
due_date: null,
|
|
labels: [],
|
|
created_at: "2025-01-01T00:00:00Z",
|
|
updated_at: "2025-01-01T00:00:00Z",
|
|
};
|
|
}
|
|
|
|
// Type-only shim — only the methods the queries.ts code path under test calls.
|
|
function installFakeApi(listIssues: (params?: ListIssuesParams) => Promise<ListIssuesResponse>) {
|
|
setApiInstance({ listIssues } as unknown as ApiClient);
|
|
}
|
|
|
|
describe("projectGanttIssuesOptions", () => {
|
|
let qc: QueryClient;
|
|
|
|
beforeEach(() => {
|
|
qc = new QueryClient({
|
|
defaultOptions: { queries: { retry: false } },
|
|
});
|
|
});
|
|
|
|
afterEach(() => {
|
|
qc.clear();
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
it("returns the first page directly when it fits under PROJECT_GANTT_PAGE_LIMIT", async () => {
|
|
const listIssues = vi
|
|
.fn<(params?: ListIssuesParams) => Promise<ListIssuesResponse>>()
|
|
.mockResolvedValue({
|
|
issues: [makeIssue(1), makeIssue(2)],
|
|
total: 2,
|
|
});
|
|
installFakeApi(listIssues);
|
|
|
|
const data = await qc.fetchQuery(projectGanttIssuesOptions(WS_ID, PROJECT_ID));
|
|
|
|
expect(listIssues).toHaveBeenCalledTimes(1);
|
|
expect(listIssues).toHaveBeenCalledWith({
|
|
project_id: PROJECT_ID,
|
|
scheduled: true,
|
|
limit: PROJECT_GANTT_PAGE_LIMIT,
|
|
offset: 0,
|
|
});
|
|
expect(data).toHaveLength(2);
|
|
});
|
|
|
|
it("loops through pages until total is satisfied (no silent truncation)", async () => {
|
|
const total = PROJECT_GANTT_PAGE_LIMIT + 7;
|
|
const firstPage = Array.from({ length: PROJECT_GANTT_PAGE_LIMIT }, (_, i) =>
|
|
makeIssue(i),
|
|
);
|
|
const secondPage = Array.from({ length: 7 }, (_, i) =>
|
|
makeIssue(PROJECT_GANTT_PAGE_LIMIT + i),
|
|
);
|
|
|
|
const listIssues = vi
|
|
.fn<(params?: ListIssuesParams) => Promise<ListIssuesResponse>>()
|
|
.mockImplementation(async (params) => {
|
|
if (!params) throw new Error("expected params");
|
|
const offset = params.offset ?? 0;
|
|
if (offset === 0)
|
|
return { issues: firstPage, total };
|
|
if (offset === PROJECT_GANTT_PAGE_LIMIT)
|
|
return { issues: secondPage, total };
|
|
throw new Error(`unexpected offset ${offset}`);
|
|
});
|
|
installFakeApi(listIssues);
|
|
|
|
const data = await qc.fetchQuery(projectGanttIssuesOptions(WS_ID, PROJECT_ID));
|
|
|
|
expect(listIssues).toHaveBeenCalledTimes(2);
|
|
expect(data).toHaveLength(total);
|
|
});
|
|
|
|
it("stops looping when the server reports a smaller-than-limit page (safety net for total drift)", async () => {
|
|
// Server says `total` is huge but only ever returns short pages — the
|
|
// loop must terminate on the first short page to avoid an infinite fetch.
|
|
const listIssues = vi
|
|
.fn<(params?: ListIssuesParams) => Promise<ListIssuesResponse>>()
|
|
.mockResolvedValue({
|
|
issues: [makeIssue(1)],
|
|
total: PROJECT_GANTT_MAX_ISSUES,
|
|
});
|
|
installFakeApi(listIssues);
|
|
|
|
const data = await qc.fetchQuery(projectGanttIssuesOptions(WS_ID, PROJECT_ID));
|
|
|
|
expect(listIssues).toHaveBeenCalledTimes(1);
|
|
expect(data).toHaveLength(1);
|
|
});
|
|
|
|
it("uses the project-scoped Gantt cache key", () => {
|
|
const options = projectGanttIssuesOptions(WS_ID, PROJECT_ID);
|
|
expect(options.queryKey).toEqual(issueKeys.projectGantt(WS_ID, PROJECT_ID));
|
|
});
|
|
});
|