Case archive/restore with Paperclip sync
All checks were successful
Build & Deploy / build-and-deploy (push) Successful in 1m27s

Adds a comprehensive archive flow for closed cases — separate /archive
screen in the UI, archive/restore actions on the case detail page, and
automatic two-way sync with Paperclip.

Backend (web/app.py + mcp-server/services/db.py):
- New SCHEMA_V6 migration: cases.archived_at TIMESTAMPTZ + partial index
- list_cases gains include_archived/archived_only flags; default excludes
  archived rows so the main /api/cases list hides closed cases
- archive_case / restore_case helpers in db.py
- POST /api/cases/{n}/archive sets archived_at and calls
  pc_archive_project (sets Paperclip projects.archived_at via direct DB)
- POST /api/cases/{n}/restore clears archived_at and calls
  pc_restore_project (clears Paperclip archived_at)
- archive_project / restore_project in paperclip_client.py — name-based
  match consistent with create_project's lookup

Frontend (web-ui):
- cases.ts: scope param ("active"|"archived"|"all") on useCases;
  useArchiveCase / useRestoreCase mutations
- /archive page (new): table of archived cases with restore button +
  search, sort, empty state matching the editorial aesthetic of /
- case-archive-action.tsx: button on case detail header. Active case →
  confirm dialog → archive. Archived case → restore (no confirm).
  Toast announces both legal-ai and Paperclip outcomes (synced, not
  found in pc, error)
- case-header shows "בארכיון" badge when archived_at is set
- Nav: ארכיון link added to AppShell after בית

Tested end-to-end against the live DB:
- 1130-25 archive → list_cases(include_archived=False) excludes it,
  list_cases(archived_only=True) includes it, restore reverses
- pc archive/restore on 1194-25 verified via direct DB lookup
- TypeScript compiles clean

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-27 18:54:52 +00:00
parent 8b816c8b61
commit 2b7f291928
8 changed files with 629 additions and 21 deletions

View File

@@ -40,6 +40,8 @@ export type Case = {
expected_outcome?: string | null;
created_at?: string;
updated_at?: string;
/** ISO timestamp; null when active */
archived_at?: string | null;
/* Multi-tenant axis — populated by backfill + server-side derive */
practice_area?: PracticeArea;
appeal_subtype?: AppealSubtype;
@@ -70,20 +72,60 @@ export type CaseDetail = Case & {
blocks?: Array<{ code: string; status?: string; char_count?: number }>;
};
export type CasesScope = "active" | "archived" | "all";
export const casesKeys = {
all: ["cases"] as const,
list: (detail: boolean) => [...casesKeys.all, "list", { detail }] as const,
list: (detail: boolean, scope: CasesScope = "active") =>
[...casesKeys.all, "list", { detail, scope }] as const,
detail: (caseNumber: string) =>
[...casesKeys.all, "detail", caseNumber] as const,
};
export function useCases(detail = false) {
export function useCases(detail = false, scope: CasesScope = "active") {
return useQuery({
queryKey: casesKeys.list(detail),
queryFn: ({ signal }) =>
apiRequest<Case[]>(`/api/cases${detail ? "?detail=true" : ""}`, {
signal,
queryKey: casesKeys.list(detail, scope),
queryFn: ({ signal }) => {
const params = new URLSearchParams();
if (detail) params.set("detail", "true");
if (scope === "archived") params.set("archived_only", "true");
else if (scope === "all") params.set("include_archived", "true");
const qs = params.toString();
return apiRequest<Case[]>(`/api/cases${qs ? `?${qs}` : ""}`, { signal });
},
});
}
export type ArchiveResult = {
status: string;
case_number: string;
archived_at?: string | null;
paperclip?: { status: string; project_id?: string; archived_at?: string | null; message?: string };
};
export function useArchiveCase(caseNumber: string | undefined) {
const qc = useQueryClient();
return useMutation({
mutationFn: () =>
apiRequest<ArchiveResult>(`/api/cases/${caseNumber}/archive`, {
method: "POST",
}),
onSuccess: () => {
qc.invalidateQueries({ queryKey: casesKeys.all });
},
});
}
export function useRestoreCase(caseNumber: string | undefined) {
const qc = useQueryClient();
return useMutation({
mutationFn: () =>
apiRequest<ArchiveResult>(`/api/cases/${caseNumber}/restore`, {
method: "POST",
}),
onSuccess: () => {
qc.invalidateQueries({ queryKey: casesKeys.all });
},
});
}