feat(sprints): surface frontend du modèle de sprints
Ticket #10 — volet frontend des sprints. - Domaine et ports frontend étendus au modèle de sprints (domain/index.ts, ports/index.ts). - Adaptateurs : ticket.ts et mock/index.ts câblent les opérations sprints. - UI tickets : useTickets + TicketsPanel exposent le rattachement/gestion des sprints, avec tests Vitest associés. Typecheck / vitest / build verts. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -5,22 +5,41 @@
|
||||
* `Issue*` domain events (via {@link SystemGateway}) to refresh the list on any
|
||||
* ticket mutation — including those made by agents through MCP. Filters/search
|
||||
* are part of the query and drive a re-fetch when they change.
|
||||
*
|
||||
* Sprints (ticket #10): the hook also loads the project's sprints so the panel
|
||||
* can group tickets by sprint, and exposes `assignSprint` to move a ticket into
|
||||
* or out of a sprint. Sprint lifecycle events refresh the sprint list.
|
||||
*/
|
||||
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
|
||||
import { isTicketEvent, type GatewayError, type Ticket, type TicketList } from "@/domain";
|
||||
import {
|
||||
isSprintEvent,
|
||||
isTicketEvent,
|
||||
type GatewayError,
|
||||
type Sprint,
|
||||
type Ticket,
|
||||
type TicketList,
|
||||
} from "@/domain";
|
||||
import type { CreateTicketInput, TicketListQuery } from "@/ports";
|
||||
import { useGateways } from "@/app/di";
|
||||
|
||||
export interface TicketsViewModel {
|
||||
list: TicketList | null;
|
||||
/** The project's sprints, ordered by `order` (ticket #10). */
|
||||
sprints: Sprint[];
|
||||
error: string | null;
|
||||
busy: boolean;
|
||||
query: TicketListQuery;
|
||||
setQuery: (next: TicketListQuery) => void;
|
||||
refresh: () => Promise<void>;
|
||||
create: (input: CreateTicketInput) => Promise<Ticket | null>;
|
||||
/**
|
||||
* Assigns a ticket to a sprint (or clears it with `sprintId === null`). Reads
|
||||
* the ticket's current version first so the summary-based list needs no
|
||||
* version column. Refreshes on the resulting `issueSprintChanged` event.
|
||||
*/
|
||||
assignSprint: (ref: string, sprintId: string | null) => Promise<boolean>;
|
||||
}
|
||||
|
||||
function describe(e: unknown): string {
|
||||
@ -33,6 +52,7 @@ function describe(e: unknown): string {
|
||||
export function useTickets(projectId: string): TicketsViewModel {
|
||||
const { ticket, system } = useGateways();
|
||||
const [list, setList] = useState<TicketList | null>(null);
|
||||
const [sprints, setSprints] = useState<Sprint[]>([]);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [query, setQuery] = useState<TicketListQuery>({});
|
||||
@ -55,6 +75,14 @@ export function useTickets(projectId: string): TicketsViewModel {
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [projectId, ticket, queryKey]);
|
||||
|
||||
const refreshSprints = useCallback(async () => {
|
||||
try {
|
||||
setSprints(await ticket.listSprints(projectId));
|
||||
} catch (e) {
|
||||
setError(describe(e));
|
||||
}
|
||||
}, [projectId, ticket]);
|
||||
|
||||
const create = useCallback(
|
||||
async (input: CreateTicketInput): Promise<Ticket | null> => {
|
||||
setError(null);
|
||||
@ -70,10 +98,32 @@ export function useTickets(projectId: string): TicketsViewModel {
|
||||
[projectId, ticket, refresh],
|
||||
);
|
||||
|
||||
const assignSprint = useCallback(
|
||||
async (ref: string, sprintId: string | null): Promise<boolean> => {
|
||||
setError(null);
|
||||
try {
|
||||
const current = await ticket.read(projectId, ref);
|
||||
await ticket.setTicketSprint(projectId, ref, sprintId, current.version);
|
||||
// The `issueSprintChanged` event refreshes the list; refresh the sprint
|
||||
// counts too (and update immediately in case events are not wired).
|
||||
await Promise.all([refresh(), refreshSprints()]);
|
||||
return true;
|
||||
} catch (e) {
|
||||
setError(describe(e));
|
||||
return false;
|
||||
}
|
||||
},
|
||||
[projectId, ticket, refresh, refreshSprints],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
void refresh();
|
||||
}, [refresh]);
|
||||
|
||||
useEffect(() => {
|
||||
void refreshSprints();
|
||||
}, [refreshSprints]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!system) return;
|
||||
let unsubscribe: (() => void) | undefined;
|
||||
@ -81,6 +131,11 @@ export function useTickets(projectId: string): TicketsViewModel {
|
||||
void system
|
||||
.onDomainEvent((event) => {
|
||||
if (isTicketEvent(event)) void refresh();
|
||||
// Sprint membership (`issueSprintChanged`) and sprint lifecycle events
|
||||
// both change the grouping → refresh the sprint list.
|
||||
if (isSprintEvent(event) || event.type === "issueSprintChanged") {
|
||||
void refreshSprints();
|
||||
}
|
||||
})
|
||||
.then((u) => {
|
||||
if (cancelled) u();
|
||||
@ -90,7 +145,17 @@ export function useTickets(projectId: string): TicketsViewModel {
|
||||
cancelled = true;
|
||||
unsubscribe?.();
|
||||
};
|
||||
}, [refresh, system]);
|
||||
}, [refresh, refreshSprints, system]);
|
||||
|
||||
return { list, error, busy, query, setQuery, refresh, create };
|
||||
return {
|
||||
list,
|
||||
sprints,
|
||||
error,
|
||||
busy,
|
||||
query,
|
||||
setQuery,
|
||||
refresh,
|
||||
create,
|
||||
assignSprint,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user