fa86328ec9
Phase 6 (subset) of multi-repository task support. The kanban now exposes the per-task repository list to the UI and renders a compact "+N" badge on cards whose tasks span more than one repository. - KanbanState.tasks[].repositories slim shape (id, repository_id, base_branch, checkout_branch, position). - SSR mapper hydrates the full list and uses primaryTaskRepository() to pick the position-aware primary instead of [0]. - useKanbanData passes repositories through to the card props. - KanbanCard renders the primary repo name with a small "+N" chip when len(repositories) > 1; tooltip names the count. - useTaskRepositories / useTaskPrimaryRepository hooks return the slim KanbanTaskRepository shape so multi-repo consumers share one read path. Larger UI surfaces (task-create dialog, diff view, file browser, mobile sheets) still target the primary repo only — they will be ported as the multi-repo task creation flow lands. No visible change for single-repo tasks. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
108 lines
3.4 KiB
TypeScript
108 lines
3.4 KiB
TypeScript
import type { AppState, KanbanState } from "@/lib/state/store";
|
|
import { primaryTaskRepository } from "@/lib/types/http";
|
|
import type { WorkflowSnapshot, Message, Task } from "@/lib/types/http";
|
|
import {
|
|
isPRReviewFromMetadata,
|
|
isIssueWatchFromMetadata,
|
|
issueFieldsFromMetadata,
|
|
} from "@/lib/metadata-utils";
|
|
|
|
type KanbanTask = KanbanState["tasks"][number];
|
|
|
|
export function snapshotToState(snapshot: WorkflowSnapshot): Partial<AppState> {
|
|
// Handle empty snapshot (ephemeral tasks have no workflow)
|
|
if (!snapshot.workflow) {
|
|
return {
|
|
kanban: {
|
|
workflowId: "",
|
|
isLoading: false,
|
|
steps: [],
|
|
tasks: [],
|
|
},
|
|
};
|
|
}
|
|
|
|
const tasks = snapshot.tasks
|
|
.filter((task) => !task.is_ephemeral) // Filter out ephemeral tasks (e.g., quick chat)
|
|
.map((task) => {
|
|
const workflowStepId = task.workflow_step_id;
|
|
if (!workflowStepId) return null;
|
|
const primary = primaryTaskRepository(task.repositories);
|
|
return {
|
|
id: task.id,
|
|
workflowStepId,
|
|
title: task.title,
|
|
description: task.description ?? undefined,
|
|
position: task.position ?? 0,
|
|
state: task.state,
|
|
repositoryId: primary?.repository_id ?? undefined,
|
|
repositories: task.repositories?.map((r) => ({
|
|
id: r.id,
|
|
repository_id: r.repository_id,
|
|
base_branch: r.base_branch,
|
|
checkout_branch: r.checkout_branch,
|
|
position: r.position,
|
|
})),
|
|
primarySessionId: task.primary_session_id ?? undefined,
|
|
primarySessionState: task.primary_session_state ?? undefined,
|
|
sessionCount: task.session_count ?? undefined,
|
|
reviewStatus: task.review_status ?? undefined,
|
|
parentTaskId: task.parent_id ?? undefined,
|
|
updatedAt: task.updated_at,
|
|
isPRReview: isPRReviewFromMetadata(task.metadata),
|
|
isIssueWatch: isIssueWatchFromMetadata(task.metadata),
|
|
...issueFieldsFromMetadata(task.metadata),
|
|
} as KanbanTask;
|
|
})
|
|
.filter((task): task is KanbanTask => task !== null);
|
|
|
|
return {
|
|
kanban: {
|
|
workflowId: snapshot.workflow.id,
|
|
isLoading: false,
|
|
steps: snapshot.steps.map((step) => ({
|
|
id: step.id,
|
|
title: step.name,
|
|
color: step.color ?? "bg-neutral-400",
|
|
position: step.position,
|
|
events: step.events,
|
|
allow_manual_move: step.allow_manual_move,
|
|
prompt: step.prompt,
|
|
is_start_step: step.is_start_step,
|
|
show_in_command_panel: step.show_in_command_panel,
|
|
agent_profile_id: step.agent_profile_id,
|
|
})),
|
|
tasks,
|
|
},
|
|
};
|
|
}
|
|
|
|
export function taskToState(
|
|
task: Task,
|
|
sessionId?: string | null,
|
|
messages?: { items: Message[]; hasMore?: boolean; oldestCursor?: string | null },
|
|
): Partial<AppState> {
|
|
const resolvedSessionId = sessionId ?? messages?.items[0]?.session_id ?? null;
|
|
return {
|
|
tasks: {
|
|
activeTaskId: task.id,
|
|
activeSessionId: resolvedSessionId,
|
|
},
|
|
messages:
|
|
resolvedSessionId && messages
|
|
? {
|
|
bySession: {
|
|
[resolvedSessionId]: messages.items,
|
|
},
|
|
metaBySession: {
|
|
[resolvedSessionId]: {
|
|
isLoading: false,
|
|
hasMore: messages.hasMore ?? false,
|
|
oldestCursor: messages.oldestCursor ?? messages.items[0]?.id ?? null,
|
|
},
|
|
},
|
|
}
|
|
: undefined,
|
|
};
|
|
}
|