- library list (kind/status/search, cursor paging) and detail: paths and roots, external identity mapping with lock, field-level metadata sources and locks, slot cards with rejection reasons, content units (provisional flag), downloads with verification; remap/lock/refresh/merge actions - subscriptions: list/create/update, slot rules editor (hard/soft/upgrade/completion), policy revision draft -> preview -> publish (grant warning) -> rollback - preferences: tag CRUD, disable/enable, suppression records and lift, history timeline - inbox: grouped by entity and kind, evidence/suggestion/impact/preview, resolve options, SSE refresh - identity: pool assign/dismiss/retry, external identity revisions and lock, title alias management - all responses validated against contracts zod schemas Co-Authored-By: Claude Opus 5.5 <[email protected]>
64 lines
2.4 KiB
TypeScript
64 lines
2.4 KiB
TypeScript
import { keepPreviousData, useInfiniteQuery, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import { cursorPage, Decision, DecisionKind, type DecisionResolveInput, type DecisionStatus, Id } from "@umt/contracts";
|
|
import { z } from "zod";
|
|
import { api } from "~/lib/api.ts";
|
|
import { getParsed, parseOrThrow } from "./library.ts";
|
|
|
|
// 待处理中心:按作品与问题类型聚合(summary),条目带证据/建议/影响范围,resolve 选项来自 decision.options。
|
|
|
|
export const decisionKeys = {
|
|
all: ["decisions"] as const,
|
|
list: (f: DecisionFilters) => ["decisions", "list", f] as const,
|
|
summary: (status?: DecisionStatus) => ["decisions", "summary", status ?? "open"] as const,
|
|
};
|
|
|
|
export type DecisionFilters = { status?: DecisionStatus; kind?: DecisionKind };
|
|
|
|
/** 服务端 /decisions/summary 的形状(路由内定义,未进 contracts) */
|
|
export const DecisionSummary = z.object({
|
|
total: z.number().int(),
|
|
groups: z.array(
|
|
z.object({
|
|
kind: DecisionKind,
|
|
mediaEntityId: Id.nullable(),
|
|
mediaEntityTitle: z.string().nullable(),
|
|
count: z.number().int(),
|
|
maxSeverity: z.enum(["info", "warning", "critical"]),
|
|
latestAt: z.string(),
|
|
}),
|
|
),
|
|
});
|
|
export type DecisionSummary = z.infer<typeof DecisionSummary>;
|
|
|
|
const Page = cursorPage(Decision);
|
|
|
|
export function useDecisions(filters: DecisionFilters) {
|
|
return useInfiniteQuery({
|
|
queryKey: decisionKeys.list(filters),
|
|
initialPageParam: undefined as string | undefined,
|
|
queryFn: ({ pageParam, signal }) =>
|
|
getParsed(Page, "/decisions", { ...filters, cursor: pageParam, limit: 100 }, signal),
|
|
getNextPageParam: (last) => last.nextCursor ?? undefined,
|
|
placeholderData: keepPreviousData,
|
|
});
|
|
}
|
|
|
|
export function useDecisionSummary(status?: DecisionStatus) {
|
|
return useQuery({
|
|
queryKey: decisionKeys.summary(status),
|
|
queryFn: ({ signal }) => getParsed(DecisionSummary, "/decisions/summary", { status }, signal),
|
|
});
|
|
}
|
|
|
|
export function useResolveDecision() {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: ({ id, ...body }: DecisionResolveInput & { id: string }) =>
|
|
api.post<unknown>(`/decisions/${id}/resolve`, body).then((d) => parseOrThrow(Decision, d, "/decisions")),
|
|
onSuccess: () => {
|
|
void qc.invalidateQueries({ queryKey: decisionKeys.all });
|
|
void qc.invalidateQueries({ queryKey: ["identity"] });
|
|
},
|
|
});
|
|
}
|