Archived
建组/改组:逐岗位选人,留空即回落四策略。绑定先于策略,起单时快照进工作流; 实测改绑定后新起单的 work_group 快照即含新成员表,在途不受影响。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KeDBx2PHLavbURXB8LJJ7m
159 lines
6.1 KiB
TypeScript
159 lines
6.1 KiB
TypeScript
/**
|
|
* 治理台取数 —— 每个查询一把键,写动作后按键失效。
|
|
* 前端零过程状态:所有画面都是服务端投影的函数,刷新即重建(§9.2)。
|
|
*/
|
|
import { useQuery } from '@tanstack/react-query';
|
|
import type { UseQueryResult } from '@tanstack/react-query';
|
|
import type {
|
|
ClosureReport,
|
|
GovActivitiesOutput,
|
|
GovApprovalsOutput,
|
|
GovChannelsOutput,
|
|
GovGrantsOutput,
|
|
GovLedgerPageOutput,
|
|
GovLlmOutput,
|
|
GovMemoryOutput,
|
|
GovMetricsOutput,
|
|
GovObjectsOutput,
|
|
GovPackagesOutput,
|
|
GovStaffOutput,
|
|
GovTaskLogOutput,
|
|
GovTasksOutput,
|
|
GovToolsOutput,
|
|
GovTriggersOutput,
|
|
GovWorkGroupsOutput,
|
|
GovWorkflowOutput,
|
|
ProcessPackage,
|
|
} from '@contracts';
|
|
import {
|
|
browseLedgerRoute,
|
|
govMetricsRoute,
|
|
govTaskLogRoute,
|
|
govWorkflowRoute,
|
|
listActivitiesRoute,
|
|
listActivityMemoryRoute,
|
|
listApprovalsRoute,
|
|
listChannelsRoute,
|
|
listGovTasksRoute,
|
|
listGrantsRoute,
|
|
listLedgerObjectsRoute,
|
|
listLlmInstancesRoute,
|
|
listProcessPackagesRoute,
|
|
listStaffRoute,
|
|
listToolsRoute,
|
|
listTriggersRoute,
|
|
listWorkGroupsRoute,
|
|
validateProcessRoute,
|
|
} from '@contracts';
|
|
import { call } from '@web-shared/typed-fetch.ts';
|
|
|
|
export type GovTasks = GovTasksOutput;
|
|
export type GovApprovals = GovApprovalsOutput;
|
|
export type GovStaff = GovStaffOutput;
|
|
export type GovActivities = GovActivitiesOutput;
|
|
export type GovTools = GovToolsOutput;
|
|
export type GovObjects = GovObjectsOutput;
|
|
export type GovLedgerPage = GovLedgerPageOutput;
|
|
export type GovMemory = GovMemoryOutput;
|
|
export type GovMetrics = GovMetricsOutput;
|
|
export type GovChannels = GovChannelsOutput;
|
|
export type GovLlm = GovLlmOutput;
|
|
export type GovWorkflow = GovWorkflowOutput;
|
|
export type GovTaskLog = GovTaskLogOutput;
|
|
export type GovGrants = GovGrantsOutput;
|
|
|
|
/** `enabled: false` 供设计中心用 —— 那一面不看运行态,别去要一份自己无权也无用的数据 */
|
|
export const useGovTasks = (opts?: { enabled?: boolean }): UseQueryResult<GovTasks> =>
|
|
useQuery({
|
|
queryKey: ['gov', 'tasks'],
|
|
queryFn: () => call<GovTasks>(listGovTasksRoute),
|
|
enabled: opts?.enabled ?? true,
|
|
});
|
|
|
|
export const useGovApprovals = (): UseQueryResult<GovApprovals> =>
|
|
useQuery({ queryKey: ['gov', 'approvals'], queryFn: () => call<GovApprovals>(listApprovalsRoute) });
|
|
|
|
export const useGovStaff = (): UseQueryResult<GovStaff> =>
|
|
useQuery({ queryKey: ['gov', 'staff'], queryFn: () => call<GovStaff>(listStaffRoute) });
|
|
|
|
export const useGovGrants = (positionId: string | undefined): UseQueryResult<GovGrants> =>
|
|
useQuery({
|
|
queryKey: ['gov', 'grants', positionId],
|
|
queryFn: () => call<GovGrants>(listGrantsRoute, { params: { positionId: positionId! } }),
|
|
enabled: positionId !== undefined,
|
|
});
|
|
|
|
export const useGovPackages = (): UseQueryResult<GovPackagesOutput> =>
|
|
useQuery({ queryKey: ['gov', 'process'], queryFn: () => call<GovPackagesOutput>(listProcessPackagesRoute) });
|
|
|
|
/**
|
|
* 每个包一份闭合报告 —— 磁贴上的「边 n/m」、待补清单、发布门、驾驶舱的未闭合草稿数都读它。
|
|
* 一处算、多处读:两张首页各算一遍就会各说各话。
|
|
*/
|
|
export const useGovPkgReports = (
|
|
packages: readonly ProcessPackage[],
|
|
): UseQueryResult<Map<string, ClosureReport>> =>
|
|
useQuery({
|
|
queryKey: ['gov', 'process-reports', packages.map((p) => `${p.id}@${p.version}`).join(',')],
|
|
enabled: packages.length > 0,
|
|
queryFn: async () => {
|
|
const entries = await Promise.all(
|
|
packages.map(
|
|
async (p) =>
|
|
[`${p.id}@${p.version}`, await call<ClosureReport>(validateProcessRoute, { body: { pkg: p } })] as const,
|
|
),
|
|
);
|
|
return new Map(entries);
|
|
},
|
|
});
|
|
|
|
export type GovWorkGroups = GovWorkGroupsOutput;
|
|
|
|
export const useGovWorkGroups = (): UseQueryResult<GovWorkGroups> =>
|
|
useQuery({ queryKey: ['gov', 'work-groups'], queryFn: () => call<GovWorkGroups>(listWorkGroupsRoute) });
|
|
|
|
export const useGovTriggers = (): UseQueryResult<GovTriggersOutput> =>
|
|
useQuery({ queryKey: ['gov', 'triggers'], queryFn: () => call<GovTriggersOutput>(listTriggersRoute) });
|
|
|
|
export const useGovActivities = (): UseQueryResult<GovActivities> =>
|
|
useQuery({ queryKey: ['gov', 'activities'], queryFn: () => call<GovActivities>(listActivitiesRoute) });
|
|
|
|
export const useGovTools = (): UseQueryResult<GovTools> =>
|
|
useQuery({ queryKey: ['gov', 'tools'], queryFn: () => call<GovTools>(listToolsRoute) });
|
|
|
|
export const useGovObjects = (opts?: { enabled?: boolean }): UseQueryResult<GovObjects> =>
|
|
useQuery({
|
|
queryKey: ['gov', 'objects'],
|
|
queryFn: () => call<GovObjects>(listLedgerObjectsRoute),
|
|
enabled: opts?.enabled ?? true,
|
|
});
|
|
|
|
export const useGovLedger = (domain: string | undefined, object: string | undefined): UseQueryResult<GovLedgerPage> =>
|
|
useQuery({
|
|
queryKey: ['gov', 'ledger', domain, object],
|
|
queryFn: () => call<GovLedgerPage>(browseLedgerRoute, { params: { domain: domain!, object: object! } }),
|
|
enabled: domain !== undefined && object !== undefined,
|
|
});
|
|
|
|
export const useGovMemory = (activityId: string | undefined): UseQueryResult<GovMemory> =>
|
|
useQuery({
|
|
queryKey: ['gov', 'memory', activityId],
|
|
queryFn: () => call<GovMemory>(listActivityMemoryRoute, { params: { activityId: activityId! } }),
|
|
enabled: activityId !== undefined,
|
|
});
|
|
|
|
export const useGovMetrics = (): UseQueryResult<GovMetrics> =>
|
|
useQuery({ queryKey: ['gov', 'metrics'], queryFn: () => call<GovMetrics>(govMetricsRoute) });
|
|
|
|
export const useGovChannels = (): UseQueryResult<GovChannels> =>
|
|
useQuery({ queryKey: ['gov', 'channels'], queryFn: () => call<GovChannels>(listChannelsRoute) });
|
|
|
|
export const useGovLlm = (): UseQueryResult<GovLlm> =>
|
|
useQuery({ queryKey: ['gov', 'llm'], queryFn: () => call<GovLlm>(listLlmInstancesRoute) });
|
|
|
|
export const useGovWorkflow = (id: string): UseQueryResult<GovWorkflow> =>
|
|
useQuery({ queryKey: ['gov', 'workflow', id], queryFn: () => call<GovWorkflow>(govWorkflowRoute, { params: { id } }) });
|
|
|
|
export const useGovTaskLog = (taskId: string): UseQueryResult<GovTaskLog> =>
|
|
useQuery({ queryKey: ['gov', 'tasklog', taskId], queryFn: () => call<GovTaskLog>(govTaskLogRoute, { params: { taskId } }) });
|