Plugin now mounts two React components inside Paperclip via the
SDK's UI slot mechanism. Both are read-only views over data the
plugin worker fetches from legal-ai on demand.
## Slots
* **LegalCaseTab** (type: detailTab, entityTypes: ["issue"])
Mounted as a "ערר" tab on every issue page. Shows case summary
(status / practice_area / appeal_subtype), legal_arguments
grouped by party (עוררים/ועדה/משיבה/מבקשי היתר), attached
precedents, and open missing_precedents.
* **LegalCasesWidget** (type: dashboardWidget)
Dashboard tile with case counts by status + 7-day activity.
## Worker handlers (ctx.data.register)
Five handlers added at the end of setup() — all read-only over the
existing legal-ai HTTP API, all wrapped in try/catch so a transient
failure shows a placeholder instead of crashing the host:
- legal-case-summary → /api/cases/{n}/details
- legal-case-arguments → /api/cases/{n}/legal-arguments
- legal-case-precedents → /api/cases/{n}/precedents
- legal-case-missing-precedents → /api/missing-precedents?case_number=&status=open
- legal-dashboard-stats → in-memory aggregation over /api/cases
case_number is resolved from plugin state (scopeKind=issue,
stateKey=legal-case-number) — populated by legal_case_create.
## Build pipeline
- esbuild.ui.config.mjs uses createPluginBundlerPresets from the SDK
to build src/ui/index.tsx → dist/ui/index.js (13.5kb, react +
@paperclipai/plugin-sdk/ui externalized)
- package.json: build = "build:worker" (tsc) + "build:ui" (esbuild)
- tsconfig.json: jsx=react-jsx, lib += DOM
- New deps: react@19, @types/react, esbuild
## Manifest
- capabilities += ui.detailTab.register, ui.dashboardWidget.register
- entrypoints.ui = "dist/ui"
- ui.slots declared with entityTypes (not "entities" — fixed against
PluginUiSlotDeclaration validator)
## Verified
- tsc + esbuild + biome clean
- Plugin re-installs (20 capabilities) and activates with worker
+ 8 tools + 3 jobs + 1 webhook + 2 event subs
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
133 lines
3.2 KiB
TypeScript
133 lines
3.2 KiB
TypeScript
import type { PluginWidgetProps } from "@paperclipai/plugin-sdk/ui";
|
||
import { usePluginData } from "@paperclipai/plugin-sdk/ui/hooks";
|
||
import type { DashboardStats } from "./types.js";
|
||
|
||
const widgetStyle: React.CSSProperties = {
|
||
padding: 12,
|
||
fontFamily:
|
||
"system-ui, -apple-system, 'Segoe UI', 'Noto Sans Hebrew', sans-serif",
|
||
color: "inherit",
|
||
};
|
||
|
||
const headingStyle: React.CSSProperties = {
|
||
margin: "0 0 8px 0",
|
||
fontSize: 15,
|
||
fontWeight: 600,
|
||
};
|
||
|
||
const totalStyle: React.CSSProperties = {
|
||
fontSize: 22,
|
||
fontWeight: 700,
|
||
margin: "4px 0",
|
||
};
|
||
|
||
const ulStyle: React.CSSProperties = {
|
||
listStyle: "none",
|
||
paddingInlineStart: 0,
|
||
margin: 0,
|
||
display: "grid",
|
||
gridTemplateColumns: "1fr max-content",
|
||
rowGap: 2,
|
||
fontSize: 13,
|
||
};
|
||
|
||
const labelStyle: React.CSSProperties = {
|
||
color: "rgba(127,127,127,0.85)",
|
||
};
|
||
|
||
const STATUS_LABELS: Record<string, string> = {
|
||
new: "תיק חדש",
|
||
uploading: "העלאת מסמכים",
|
||
processing: "עיבוד מסמכים",
|
||
documents_ready: "מסמכים מוכנים",
|
||
outcome_set: "תוצאה הוזנה",
|
||
brainstorming: "סיעור מוחות",
|
||
direction_approved: "כיוון אושר",
|
||
drafting: "כתיבה",
|
||
qa_review: "בדיקת איכות",
|
||
drafted: "טיוטה מוכנה",
|
||
exported: "DOCX נוצר",
|
||
reviewed: "נבדק",
|
||
final: "סופי",
|
||
};
|
||
|
||
export function LegalCasesWidget(_props: PluginWidgetProps) {
|
||
const { data, loading, error } = usePluginData<DashboardStats | null>(
|
||
"legal-dashboard-stats",
|
||
{},
|
||
);
|
||
|
||
if (loading) {
|
||
return (
|
||
<div dir="rtl" style={widgetStyle}>
|
||
<h3 style={headingStyle}>תיקי ערר</h3>
|
||
<p style={labelStyle}>טוען…</p>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
if (error) {
|
||
return (
|
||
<div dir="rtl" style={widgetStyle}>
|
||
<h3 style={headingStyle}>תיקי ערר</h3>
|
||
<p style={{ color: "crimson", fontSize: 13 }}>{error.message}</p>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
if (!data) {
|
||
return (
|
||
<div dir="rtl" style={widgetStyle}>
|
||
<h3 style={headingStyle}>תיקי ערר</h3>
|
||
<p style={labelStyle}>אין נתונים זמינים.</p>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
const entries = Object.entries(data.byStatus).sort(([, a], [, b]) => b - a);
|
||
|
||
return (
|
||
<div dir="rtl" style={widgetStyle}>
|
||
<h3 style={headingStyle}>תיקי ערר</h3>
|
||
<div style={totalStyle}>{data.totalCases}</div>
|
||
<div style={{ fontSize: 12, color: "rgba(127,127,127,0.85)" }}>
|
||
סה"כ תיקים פעילים
|
||
</div>
|
||
<hr
|
||
style={{
|
||
margin: "8px 0",
|
||
border: 0,
|
||
borderTop: "1px solid rgba(127,127,127,0.25)",
|
||
}}
|
||
/>
|
||
{entries.length > 0 ? (
|
||
<ul style={ulStyle}>
|
||
{entries.map(([status, count]) => (
|
||
<li
|
||
key={status}
|
||
style={{ display: "contents" }}
|
||
aria-label={`${STATUS_LABELS[status] ?? status}: ${count}`}
|
||
>
|
||
<span style={labelStyle}>{STATUS_LABELS[status] ?? status}</span>
|
||
<span>{count}</span>
|
||
</li>
|
||
))}
|
||
</ul>
|
||
) : (
|
||
<p style={labelStyle}>אין תיקים פעילים.</p>
|
||
)}
|
||
<hr
|
||
style={{
|
||
margin: "8px 0",
|
||
border: 0,
|
||
borderTop: "1px solid rgba(127,127,127,0.25)",
|
||
}}
|
||
/>
|
||
<p style={{ margin: 0, fontSize: 13 }}>
|
||
<span style={labelStyle}>פעילות שבועית: </span>
|
||
<strong>{data.weekActivity}</strong>
|
||
</p>
|
||
</div>
|
||
);
|
||
}
|