fix(tickets): normalise assignedAgentIds/links/attachments manquants sur les payloads legacy
Les lignes de ticket persistées avant l'introduction de ces champs peuvent arriver sans assignedAgentIds (ni links/attachments), ce que TicketsPanel déréférence sans garde côté rendu : la fenêtre de liste rend quelques lignes puis devient noire dès qu'une ligne legacy est itérée. Les deux gateways (Tauri et HTTP/stream) normalisent désormais chaque ticket et chaque item de liste avant de les retourner à l'UI. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@ -42,11 +42,36 @@ export function isTicketVersionConflict(error: unknown): boolean {
|
||||
return typeof message === "string" && message.includes("version conflict");
|
||||
}
|
||||
|
||||
function normalizeTicket(ticket: Ticket): Ticket {
|
||||
return {
|
||||
...ticket,
|
||||
links: Array.isArray(ticket.links) ? ticket.links : [],
|
||||
assignedAgentIds: Array.isArray(ticket.assignedAgentIds)
|
||||
? ticket.assignedAgentIds
|
||||
: [],
|
||||
attachments: Array.isArray(ticket.attachments) ? ticket.attachments : [],
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeTicketList(list: TicketList): TicketList {
|
||||
return {
|
||||
...list,
|
||||
items: Array.isArray(list.items)
|
||||
? list.items.map((item) => ({
|
||||
...item,
|
||||
assignedAgentIds: Array.isArray(item.assignedAgentIds)
|
||||
? item.assignedAgentIds
|
||||
: [],
|
||||
}))
|
||||
: [],
|
||||
};
|
||||
}
|
||||
|
||||
export class TauriTicketGateway implements TicketGateway {
|
||||
async create(projectId: string, input: CreateTicketInput): Promise<Ticket> {
|
||||
return invoke<Ticket>("ticket_create", {
|
||||
return normalizeTicket(await invoke<Ticket>("ticket_create", {
|
||||
request: { projectId, ...input },
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
async read(
|
||||
@ -54,23 +79,23 @@ export class TauriTicketGateway implements TicketGateway {
|
||||
ref: string,
|
||||
includeCarnet = false,
|
||||
): Promise<Ticket> {
|
||||
return invoke<Ticket>("ticket_read", {
|
||||
return normalizeTicket(await invoke<Ticket>("ticket_read", {
|
||||
request: { projectId, ref, includeCarnet },
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
async list(projectId: string, query?: TicketListQuery): Promise<TicketList> {
|
||||
const { statuses, priorities, ...rest } = query ?? {};
|
||||
// Multi-select facets (ticket #12): the backend expects `statuses`/
|
||||
// `priorities` arrays (empty ⇒ no constraint on that facet).
|
||||
return invoke<TicketList>("ticket_list", {
|
||||
return normalizeTicketList(await invoke<TicketList>("ticket_list", {
|
||||
request: {
|
||||
projectId,
|
||||
statuses: statuses ?? [],
|
||||
priorities: priorities ?? [],
|
||||
...rest,
|
||||
},
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
async update(
|
||||
@ -78,9 +103,9 @@ export class TauriTicketGateway implements TicketGateway {
|
||||
ref: string,
|
||||
input: UpdateTicketInput,
|
||||
): Promise<Ticket> {
|
||||
return invoke<Ticket>("ticket_update", {
|
||||
return normalizeTicket(await invoke<Ticket>("ticket_update", {
|
||||
request: { projectId, ref, ...input },
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
async delete(projectId: string, ref: string): Promise<void> {
|
||||
@ -130,9 +155,9 @@ export class TauriTicketGateway implements TicketGateway {
|
||||
carnet: string,
|
||||
expectedVersion: number,
|
||||
): Promise<Ticket> {
|
||||
return invoke<Ticket>("ticket_update_carnet", {
|
||||
return normalizeTicket(await invoke<Ticket>("ticket_update_carnet", {
|
||||
request: { projectId, ref, carnet, expectedVersion },
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
async addAttachment(
|
||||
@ -142,9 +167,9 @@ export class TauriTicketGateway implements TicketGateway {
|
||||
expectedVersion: number,
|
||||
mime?: string | null,
|
||||
): Promise<Ticket> {
|
||||
return invoke<Ticket>("ticket_attachment_add", {
|
||||
return normalizeTicket(await invoke<Ticket>("ticket_attachment_add", {
|
||||
request: { projectId, ref, path, expectedVersion, mime },
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
async readAttachment(
|
||||
@ -163,9 +188,9 @@ export class TauriTicketGateway implements TicketGateway {
|
||||
attachmentId: string,
|
||||
expectedVersion: number,
|
||||
): Promise<Ticket> {
|
||||
return invoke<Ticket>("ticket_attachment_mark_summarized", {
|
||||
return normalizeTicket(await invoke<Ticket>("ticket_attachment_mark_summarized", {
|
||||
request: { projectId, ref, attachmentId, expectedVersion },
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
async link(
|
||||
@ -175,9 +200,9 @@ export class TauriTicketGateway implements TicketGateway {
|
||||
kind: TicketLinkKind,
|
||||
expectedVersion: number,
|
||||
): Promise<Ticket> {
|
||||
return invoke<Ticket>("ticket_link", {
|
||||
return normalizeTicket(await invoke<Ticket>("ticket_link", {
|
||||
request: { projectId, ref, targetRef, kind, expectedVersion },
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
async unlink(
|
||||
@ -187,9 +212,9 @@ export class TauriTicketGateway implements TicketGateway {
|
||||
expectedVersion: number,
|
||||
kind?: TicketLinkKind,
|
||||
): Promise<Ticket> {
|
||||
return invoke<Ticket>("ticket_unlink", {
|
||||
return normalizeTicket(await invoke<Ticket>("ticket_unlink", {
|
||||
request: { projectId, ref, targetRef, expectedVersion, kind },
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
async assign(
|
||||
@ -199,9 +224,9 @@ export class TauriTicketGateway implements TicketGateway {
|
||||
assigned: boolean,
|
||||
expectedVersion: number,
|
||||
): Promise<Ticket> {
|
||||
return invoke<Ticket>("ticket_assign", {
|
||||
return normalizeTicket(await invoke<Ticket>("ticket_assign", {
|
||||
request: { projectId, ref, agentId, assigned, expectedVersion },
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
async listSprints(projectId: string): Promise<Sprint[]> {
|
||||
@ -220,13 +245,13 @@ export class TauriTicketGateway implements TicketGateway {
|
||||
): Promise<Ticket> {
|
||||
// Two backend commands: assign to a sprint, or unassign (clear membership).
|
||||
if (sprintId === null) {
|
||||
return invoke<Ticket>("ticket_unassign_sprint", {
|
||||
return normalizeTicket(await invoke<Ticket>("ticket_unassign_sprint", {
|
||||
request: { projectId, ref, expectedVersion },
|
||||
});
|
||||
}));
|
||||
}
|
||||
return invoke<Ticket>("ticket_assign_sprint", {
|
||||
return normalizeTicket(await invoke<Ticket>("ticket_assign_sprint", {
|
||||
request: { projectId, ref, sprintId, expectedVersion },
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
async createSprint(projectId: string, name: string): Promise<Sprint> {
|
||||
|
||||
Reference in New Issue
Block a user