mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-14 10:34:06 +02:00
## Summary Adds the **Policies** feature (proprietary, behind the `POLICIES_ENABLED` flag): backend-driven enforcement that runs a fixed tool pipeline on documents, docked in the right tool sidebar alongside Tools. ## Highlights - **Policy catalog** — 5 categories; **Security** is wired (redact PII + sanitize), the others are marked "Coming soon". - **Backend as source of truth** — policies persist via the Policies engine (`/api/v1/policies`), one policy per category, with a local cache + offline fallback. - **Auto-run** — enabled policies run on every uploaded file: dispatch → poll → import outputs into the workspace. - **Security redact config** — PII preset dropdown + custom word/regex entry + advanced options; tool params map to the backend endpoint fields. - **Activity feed** with retry on failures; **file badges** showing which policies ran on a file (sidebar + files page), tinted to the policy colour. - Reuses the **Watched Folders** engine for each policy's backing folder; policy-owned folders are filtered out of the Watched Folders UI. ## Notes - Gated by `POLICIES_ENABLED` (true in proprietary, false in core) — unreachable in the open-source build. - Frontend-only diff; depends on the backend Policies engine and the merged Watched Folders feature.
103 lines
2.9 KiB
TypeScript
103 lines
2.9 KiB
TypeScript
import type { ReactNode } from "react";
|
|
import "@shared/components/MetricCard.css";
|
|
|
|
export type DeltaDirection = "up" | "down" | "flat";
|
|
|
|
export interface MetricCardProps {
|
|
label: string;
|
|
value: string | number;
|
|
/** Optional description shown under the delta line. */
|
|
description?: string;
|
|
/** Numeric delta as a fraction (0.12 = +12%). The sign drives direction unless `deltaDirection` is set. */
|
|
delta?: number;
|
|
/** Override the inferred direction — useful when you only want the colour, not the value. */
|
|
deltaDirection?: DeltaDirection;
|
|
/** Visual emphasis. `primary` = darker surface, used for hero metrics. */
|
|
emphasis?: "default" | "primary";
|
|
/** Density. `sm` tightens padding + value size for narrow rails/strips. */
|
|
size?: "sm" | "md";
|
|
/** Optional icon shown in the top-right corner. */
|
|
icon?: ReactNode;
|
|
onClick?: () => void;
|
|
className?: string;
|
|
}
|
|
|
|
function inferDirection(delta?: number): DeltaDirection {
|
|
if (delta === undefined || delta === 0) return "flat";
|
|
return delta > 0 ? "up" : "down";
|
|
}
|
|
|
|
function formatDelta(delta: number) {
|
|
const pct = Math.round(Math.abs(delta) * 100);
|
|
return `${pct}%`;
|
|
}
|
|
|
|
/**
|
|
* Stirling's standard KPI card. Used on Home, Sources, Documents, Audit and
|
|
* every Infrastructure tab — the prototype calls these the metric strip.
|
|
*/
|
|
export function MetricCard({
|
|
label,
|
|
value,
|
|
description,
|
|
delta,
|
|
deltaDirection,
|
|
emphasis = "default",
|
|
size = "md",
|
|
icon,
|
|
onClick,
|
|
className,
|
|
}: MetricCardProps) {
|
|
const dir = deltaDirection ?? inferDirection(delta);
|
|
const interactive = !!onClick;
|
|
|
|
const classes = [
|
|
"sui-metric",
|
|
`sui-metric--${size}`,
|
|
emphasis === "primary" ? "sui-metric--primary" : "",
|
|
interactive ? "sui-metric--interactive" : "",
|
|
className ?? "",
|
|
]
|
|
.filter(Boolean)
|
|
.join(" ");
|
|
|
|
const body = (
|
|
<>
|
|
<div className="sui-metric__header">
|
|
<span className="sui-metric__label">{label}</span>
|
|
{icon && (
|
|
<span className="sui-metric__icon" aria-hidden>
|
|
{icon}
|
|
</span>
|
|
)}
|
|
</div>
|
|
<div className="sui-metric__value">{value}</div>
|
|
{(delta !== undefined || description) && (
|
|
<div className="sui-metric__footer">
|
|
{delta !== undefined && (
|
|
<span className={`sui-metric__delta sui-metric__delta--${dir}`}>
|
|
<span className="sui-metric__delta-arrow" aria-hidden>
|
|
{dir === "up" ? "↑" : dir === "down" ? "↓" : "·"}
|
|
</span>
|
|
{formatDelta(delta)}
|
|
</span>
|
|
)}
|
|
{description && (
|
|
<span className="sui-metric__desc">{description}</span>
|
|
)}
|
|
</div>
|
|
)}
|
|
</>
|
|
);
|
|
|
|
if (interactive) {
|
|
return (
|
|
<button type="button" className={classes} onClick={onClick}>
|
|
{body}
|
|
</button>
|
|
);
|
|
}
|
|
|
|
return <div className={classes}>{body}</div>;
|
|
}
|