示例工程 28-project-approval-panel
28-project-approval-panel/app/.tsc/src/views/ApprovalReact.js
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { useSyncExternalStore } from "react";
import { remainingSeconds, riskLabel } from "../lib/store";
export function ApprovalReact({ store }) {
const state = useSyncExternalStore(store.subscribe, store.getState);
const current = state.pending[0];
const queue = state.pending.slice(1);
const remaining = current
? remainingSeconds(current.expiresAt, state.now)
: 0;
const decide = (decision) => {
if (current)
void store.decide(current.id, decision);
};
return (_jsxs("div", { className: "panel", children: [_jsxs("div", { className: "panel-head", children: [_jsxs("div", { children: [_jsx("div", { className: "muted small", children: "\u5F53\u524D\u8BF7\u6C42" }), _jsx("h2", { "data-testid": "approval-title", children: current ? current.tool : "没有待审批请求" })] }), current && (_jsxs("div", { className: "countdown", "data-testid": "approval-countdown", children: [remaining, "s"] }))] }), current ? (_jsxs(_Fragment, { children: [_jsxs("div", { className: "request-meta", children: [_jsx("span", { className: `risk risk-${current.risk}`, children: riskLabel(current.risk) }), _jsx("span", { className: "muted small", "data-testid": "approval-detail", children: current.detail })] }), _jsxs("div", { className: "actions", children: [_jsx("button", { className: "btn primary", "data-testid": "approval-allow", onClick: () => decide("allow"), children: "\u5141\u8BB8\u4E00\u6B21\uFF081\uFF09" }), _jsx("button", { className: "btn danger", "data-testid": "approval-deny", onClick: () => decide("deny"), children: "\u62D2\u7EDD\uFF082\uFF09" }), _jsx("button", { className: "btn", "data-testid": "approval-always", onClick: () => decide("always"), children: "\u6C38\u4E45\u5141\u8BB8\uFF083\uFF09" })] })] })) : (_jsx("p", { className: "empty muted", "data-testid": "approval-empty", children: "\u961F\u5217\u5DF2\u6E05\u7A7A\u3002\u7528\u4E0A\u65B9\u6309\u94AE\u6A21\u62DF\u65B0\u7684\u5DE5\u5177\u8C03\u7528\u3002" })), _jsxs("div", { className: "columns", children: [_jsxs("div", { children: [_jsxs("div", { className: "muted small", children: ["\u6392\u961F ", _jsx("span", { "data-testid": "approval-queue-count", children: queue.length })] }), _jsx("ul", { className: "queue", children: queue.map((item) => (_jsxs("li", { children: [_jsx("code", { children: item.tool }), _jsx("span", { className: "muted", children: riskLabel(item.risk) })] }, item.id))) })] }), _jsxs("div", { children: [_jsxs("div", { className: "muted small", children: ["\u6C38\u4E45\u5141\u8BB8", " ", _jsx("span", { "data-testid": "approval-policies", children: state.policies.length })] }), _jsx("ul", { className: "queue", "data-testid": "approval-policy-list", children: state.policies.map((tool) => (_jsx("li", { children: _jsx("code", { children: tool }) }, tool))) })] })] }), _jsxs("div", { className: "history", children: [_jsx("div", { className: "muted small", children: "\u6700\u8FD1\u51B3\u5B9A" }), _jsx("ul", { "data-testid": "approval-history", children: state.history.slice(0, 6).map((record) => (_jsxs("li", { children: [_jsx("code", { children: record.tool }), _jsx("span", { className: `outcome outcome-${record.outcome}`, children: record.outcome }), record.auto && _jsx("span", { className: "muted", children: "\u81EA\u52A8" })] }, record.id))) })] })] }));
}
//# sourceMappingURL=ApprovalReact.js.map