Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 | 5x 5x 90x 90x 5x 90x 5x 90x 5x 97x 97x 97x 5x 97x 96x 97x 96x 5x 87x 87x 87x 87x 87x 5x 10x 10x 10x 5x 81x 5x 9x 5x 7x 5x 5x 7x 5x 6x 5x 1x 5x 5x 5x 5x 68x 68x 40x 68x 68x 68x 68x 54x 36x 68x 58x 87x 68x 58x 9x 68x 56x 56x 81x 6x 56x 68x 56x 81x 56x 98x 98x 68x 68x 68x 5x 5x 5x 3x 5x 68x 87x 68x 10x 68x 272x 263x 263x 358x 263x 263x 263x 263x 5x 97x 87x 68x 68x 68x 2x | import {
OriginBadge,
} from "@/components/owner";
import GeneratedMark from "@/components/badge/GeneratedMark";
import {
collectionSection,
CreateButton,
FilterSelect,
GenerateButton,
ResourceCollection,
useCollectionFilters,
} from "@/components/collection";
import { RULE_STATE, StatusBadge } from "@/components/detail";
import { isSystemManaged } from "@/objects/Doc";
import {
describeScope,
Rule,
RuleCatalogue,
RuleLayer,
ruleLayerSpec,
RuleScope,
RuleScopeTargets,
ruleScopes,
} from "@/objects/Rule";
import GenerateRuleModal from "@/apps/user/pages/rules/GenerateRuleModal";
import LayerFlow from "@/apps/user/pages/rules/LayerFlow";
import {
builtInRuleHref,
newRuleHref,
ruleHref,
} from "@/apps/user/pages/rules/links";
import {
LAYER_CLASSES,
RULE_LAYERS,
ruleLayerMeta,
} from "@/apps/user/pages/rules/ruleLayer";
import { APP_ROUTES } from "@/routes/const";
import { ChevronRight, Crosshair, Plus, ShieldCheck } from "lucide-react";
import React, { useMemo, useState } from "react";
import { Link } from "react-router-dom";
// ─── Pills ────────────────────────────────────────────────────────────────────
const PILL =
"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-lg bg-gray-50 dark:bg-gray-900/40 border border-gray-200 dark:border-gray-700 text-xs text-gray-600 dark:text-gray-300 font-medium max-w-full";
/**
* What a rule covers, in words.
*
* This is the piece that makes one list work where two used to. A rule is no
* longer identified by the page it was found on, so "which of my things does
* this govern?" has to be answerable from the row itself — and a pinned rule
* has to name its target rather than show a UUID, or the reader learns
* nothing they could not have guessed.
*/
const ScopePill: React.FC<{
rule: Rule;
catalogue?: RuleCatalogue | null;
targets?: RuleScopeTargets | null;
}> = ({ rule, catalogue, targets }) => {
const pinned = !!rule.scope_id;
return (
<span className={PILL}>
{pinned && <Crosshair className="size-3 shrink-0" />}
<span className="truncate">
{describeScope(rule, catalogue, targets)}
</span>
</span>
);
};
/** When it applies: always, or when its conditions hold. */
const whenLabel = (rule: Rule) =>
rule.conditions.length === 0
? "Always"
: `When ${rule.conditions.length} condition${
rule.conditions.length === 1 ? " holds" : "s hold"
}`;
const RuleState: React.FC<{ rule: Rule }> = ({ rule }) => (
<StatusBadge
status={rule.is_active ? "active" : "off"}
scale={RULE_STATE}
label={rule.is_active ? "Active" : "Off"}
/>
);
/** The layer's glyph, named for a screen reader: the section around a card
* already says the layer in words, so the cell does not repeat it. */
const LayerIcon: React.FC<{ rule: Rule; size?: "sm" | "md" }> = ({
rule,
size = "md",
}) => {
const meta = ruleLayerMeta(rule.layer);
const Icon = meta.Icon;
return (
<div
role="img"
aria-label={`${meta.label} layer`}
className={`${size === "sm" ? "p-1.5" : "p-2"} rounded-lg shrink-0 ${LAYER_CLASSES.iconTile}`}
>
<Icon className={size === "sm" ? "size-4" : "size-5"} aria-hidden="true" />
</div>
);
};
// ─── What it does ─────────────────────────────────────────────────────────────
/** How many of a rule's lines a card shows before "+N more". */
const SHOWN_LINES = 3;
/**
* What a rule does, one line per action: svc-core's own words ("Caps spend
* at $100 a month", `Rule.summaries`), or — from a server too old to say —
* each action's label. A rule is read by what it does; "2 conditions · 1
* action" told a reader nothing they could act on.
*/
export function ruleLines(rule: Rule, catalogue?: RuleCatalogue | null): string[] {
if (rule.summaries && rule.summaries.length > 0) return rule.summaries;
const actions = ruleLayerSpec(catalogue, rule.layer)?.actions ?? [];
return rule.actions.map(
(action) => actions.find((spec) => spec.type === action.type)?.label ?? action.type,
);
}
const RuleLines: React.FC<{
rule: Rule;
catalogue?: RuleCatalogue | null;
muted?: boolean;
}> = ({ rule, catalogue, muted }) => {
const lines = ruleLines(rule, catalogue);
Iif (lines.length === 0) {
return (
<p className="text-xs text-gray-400 dark:text-gray-500 italic">
No actions yet — it does nothing.
</p>
);
}
const hidden = lines.length - SHOWN_LINES;
return (
<ul className="space-y-1">
{lines.slice(0, SHOWN_LINES).map((line, i) => (
<li
key={i}
className={`flex items-start gap-2 text-sm leading-snug ${
muted
? "text-gray-600 dark:text-gray-300"
: "text-gray-800 dark:text-gray-100"
}`}
>
<span
aria-hidden="true"
className="mt-[0.45rem] size-1 shrink-0 rounded-full bg-gray-400 dark:bg-gray-500"
/>
<span className="min-w-0">{line}</span>
</li>
))}
{hidden > 0 && (
<li className="pl-3 text-xs text-gray-400 dark:text-gray-500">
+{hidden} more
</li>
)}
</ul>
);
};
/** The first line, and how many more, for a row. */
const firstLine = (rule: Rule, catalogue?: RuleCatalogue | null) => {
const lines = ruleLines(rule, catalogue);
Iif (lines.length === 0) return rule.description || "No actions yet.";
return lines.length > 1 ? `${lines[0]} · +${lines.length - 1} more` : lines[0];
};
// ─── Rule card ────────────────────────────────────────────────────────────────
interface RuleItemProps {
rule: Rule;
catalogue?: RuleCatalogue | null;
targets?: RuleScopeTargets | null;
}
/** A neutral card: what the rule does, when, over what, and whether it is
* on. The section it sits in says where in a request it acts. */
const RuleCard: React.FC<RuleItemProps> = ({ rule, catalogue, targets }) => (
<Link
to={ruleHref(rule.id)}
className="group flex h-full flex-col gap-4 p-5 rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 shadow-sm hover:shadow-md hover:border-gray-300 dark:hover:border-gray-600 transition-all"
>
<div className="flex items-start justify-between gap-3">
<div className="flex items-center gap-3 min-w-0">
<GeneratedMark generated={rule.is_ai_generated} label="AI generated rule">
<LayerIcon rule={rule} />
</GeneratedMark>
<div className="flex items-center gap-1.5 min-w-0">
<div className="text-sm font-semibold text-gray-900 dark:text-gray-100 truncate">
{rule.name}
</div>
<OriginBadge resource={rule} />
</div>
</div>
<RuleState rule={rule} />
</div>
<div className="space-y-2">
<RuleLines rule={rule} catalogue={catalogue} />
{rule.description && (
<p className="text-xs text-gray-500 dark:text-gray-400 line-clamp-2 leading-relaxed">
{rule.description}
</p>
)}
</div>
<div className="mt-auto flex items-center gap-2 flex-wrap">
<span className={PILL}>{whenLabel(rule)}</span>
<ScopePill rule={rule} catalogue={catalogue} targets={targets} />
{/* Only when it is not the default: it orders rules within a layer,
which most rules never need. */}
{rule.priority !== 0 && (
<span className="text-xs text-gray-400 dark:text-gray-500 tabular-nums">
Priority {rule.priority}
</span>
)}
</div>
</Link>
);
// ─── Rule row ─────────────────────────────────────────────────────────────────
const RuleRow: React.FC<RuleItemProps> = ({ rule, catalogue, targets }) => (
<Link
to={ruleHref(rule.id)}
className="flex items-center gap-4 px-4 py-3 rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 hover:border-gray-300 dark:hover:border-gray-600 hover:shadow-sm transition-all group"
>
<GeneratedMark
generated={rule.is_ai_generated}
size="sm"
label="AI generated rule"
>
<LayerIcon rule={rule} size="sm" />
</GeneratedMark>
<div className="flex-1 min-w-0">
<div className="flex items-center gap-1.5 min-w-0">
<div className="text-sm font-medium text-gray-900 dark:text-gray-100 truncate">
{rule.name}
</div>
<OriginBadge resource={rule} />
</div>
<div className="text-xs text-gray-500 dark:text-gray-400 truncate mt-0.5">
{firstLine(rule, catalogue)}
</div>
</div>
<span className="hidden lg:inline shrink-0 text-xs text-gray-500 dark:text-gray-400">
{whenLabel(rule)}
</span>
{/* The scope is the column a reader scans a merged list by, so it keeps
its place on every row rather than being folded into the line below
the name, where a long name would push it out of view. */}
<div className="hidden md:block shrink-0 max-w-[14rem]">
<ScopePill rule={rule} catalogue={catalogue} targets={targets} />
</div>
<span className="hidden sm:inline shrink-0">
<RuleState rule={rule} />
</span>
<ChevronRight className="size-3.5 text-gray-400 dark:text-gray-500 group-hover:text-gray-700 dark:group-hover:text-gray-300 shrink-0 transition-colors" />
</Link>
);
// ─── Template card ────────────────────────────────────────────────────────────
//
// A built-in rule is a template: it governs nobody until the user creates a
// rule of their own from it, so it shows neither a scope nor an active state —
// both would read as "this is in force". It sits in its layer beside the
// rules made from it, offering the one thing a reader can do with it and
// saying how many of their rules already started from it. A dashed edge says
// the same thing before a word is read.
interface TemplateItemProps {
rule: Rule;
catalogue?: RuleCatalogue | null;
/** How many of the user's rules were created from this one. */
adopted: number;
}
// Short enough to sit beside "Use" on a three-column card.
const adoptedLabel = (adopted: number) =>
adopted === 0
? "Not in use"
: `Used in ${adopted} rule${adopted === 1 ? "" : "s"}`;
const TEMPLATE_TAG =
"shrink-0 text-[11px] font-medium px-1.5 py-px rounded border border-dashed border-gray-300 dark:border-gray-600 text-gray-500 dark:text-gray-400";
const UseTemplateLink: React.FC<{ rule: Rule }> = ({ rule }) => (
<Link
to={builtInRuleHref(rule.id)}
aria-label={`Use the template ${rule.name}`}
className="shrink-0 flex items-center gap-1 text-xs font-medium text-gray-700 dark:text-gray-200 hover:text-gray-900 dark:hover:text-white transition-colors"
>
<Plus className="size-3.5" />
Use
</Link>
);
const TemplateCard: React.FC<TemplateItemProps> = ({ rule, catalogue, adopted }) => (
<div className="group flex h-full flex-col rounded-xl border border-dashed border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 hover:border-gray-400 dark:hover:border-gray-500 transition-all overflow-hidden">
<Link to={ruleHref(rule.id)} className="flex-1 p-5 flex flex-col gap-4">
<div className="flex items-center gap-3 min-w-0">
<LayerIcon rule={rule} />
<div className="flex items-center gap-1.5 min-w-0">
<div className="text-sm font-semibold text-gray-900 dark:text-gray-100 truncate">
{rule.name}
</div>
<span className={TEMPLATE_TAG}>Template</span>
</div>
</div>
<RuleLines rule={rule} catalogue={catalogue} muted />
</Link>
<div className="flex items-center justify-between gap-3 px-5 py-3 border-t border-dashed border-gray-200 dark:border-gray-700">
<span className="text-xs text-gray-500 dark:text-gray-400 truncate">
{adoptedLabel(adopted)}
</span>
<UseTemplateLink rule={rule} />
</div>
</div>
);
const TemplateRow: React.FC<TemplateItemProps> = ({ rule, catalogue, adopted }) => (
<div className="flex items-center gap-4 px-4 py-3 rounded-xl border border-dashed border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 hover:border-gray-400 dark:hover:border-gray-500 transition-all">
<Link to={ruleHref(rule.id)} className="flex flex-1 items-center gap-4 min-w-0">
<LayerIcon rule={rule} size="sm" />
<div className="flex-1 min-w-0">
<div className="flex items-center gap-1.5 min-w-0">
<div className="text-sm font-medium text-gray-900 dark:text-gray-100 truncate">
{rule.name}
</div>
<span className={TEMPLATE_TAG}>Template</span>
</div>
<div className="text-xs text-gray-500 dark:text-gray-400 truncate mt-0.5">
{firstLine(rule, catalogue)}
</div>
</div>
<span className="hidden md:block shrink-0 text-xs text-gray-500 dark:text-gray-400">
{adoptedLabel(adopted)}
</span>
</Link>
<UseTemplateLink rule={rule} />
</div>
);
// ─── Filters ──────────────────────────────────────────────────────────────────
type RuleLayerFilter = "all" | RuleLayer;
type RuleStatusFilter = "all" | "active" | "inactive";
type RuleScopeFilter = "all" | RuleScope;
const STATUS_FILTER_OPTIONS = [
{ value: "all", label: "Any status" },
{ value: "active", label: "Active" },
{ value: "inactive", label: "Off" },
];
const SECTION_LINK =
"inline-flex items-center gap-1 text-xs font-medium text-gray-500 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 transition-colors";
// ─── RulesGrid ────────────────────────────────────────────────────────────────
export interface RulesGridProps {
/** The user's own rules — every count on the page is of these. */
rules: Rule[];
/** The built-in rules: templates, drawn in their layer, none in force. */
builtIn?: Rule[];
loading?: boolean;
/**
* The scope and layer vocabulary, for labels and the scope filter's
* options. Optional so the grid still renders — unfiltered and with
* plain-kind labels — before the catalogue resolves, or if it fails.
*/
catalogue?: RuleCatalogue | null;
/** Resolves a pinned `scope_id` to the name of the thing it governs. */
targets?: RuleScopeTargets | null;
}
const NO_BUILT_INS: Rule[] = [];
/**
* The Rules tab: the layer flow (each layer's count, and the layer filter),
* then one section per layer in the order a request meets them — the user's
* rules first, then the layer's templates. A layer that already holds rules
* of the user's folds its templates behind "Show N templates"; one that holds
* none shows them, as the place to start.
*/
const RulesGrid: React.FC<RulesGridProps> = ({
rules,
builtIn = NO_BUILT_INS,
loading,
catalogue,
targets,
}) => {
const [showGenerateModal, setShowGenerateModal] = useState(false);
// Layers whose folded templates the reader opened.
const [openTemplates, setOpenTemplates] = useState<ReadonlySet<RuleLayer>>(
() => new Set(),
);
const collection = useCollectionFilters<{
layer: RuleLayerFilter;
scope: RuleScopeFilter;
status: RuleStatusFilter;
}>({
defaults: { layer: "all", scope: "all", status: "all" },
});
const { filters, setFilter, matches } = collection;
const searching = collection.search.trim() !== "";
// Scope options come from the catalogue, so a scope added to the backend
// registry becomes filterable without a release here — and a scope the
// engine does not know can never be offered.
const scopeOptions = useMemo(
() => [
{ value: "all", label: "Any scope" },
...ruleScopes(catalogue).map((spec) => ({
value: spec.key,
label: spec.label,
})),
],
[catalogue],
);
const filtered = useMemo(
() =>
rules.filter(
(r) =>
(filters.layer === "all" || r.layer === filters.layer) &&
(filters.scope === "all" || r.scope_type === filters.scope) &&
(filters.status === "all" ||
(filters.status === "active") === r.is_active) &&
matches(r.name, r.description, ...(r.summaries ?? [])),
),
[rules, filters.layer, filters.scope, filters.status, matches],
);
// Scope and status describe rules in force, which a template never is, so
// either filter narrows the page to the user's own rules. Layer and search
// still apply: "which Output templates are there?" is a fair question.
const visibleTemplates = useMemo(
() =>
filters.scope !== "all" || filters.status !== "all"
? []
: builtIn.filter(
(r) =>
(filters.layer === "all" || r.layer === filters.layer) &&
matches(r.name, r.description, ...(r.summaries ?? [])),
),
[builtIn, filters.layer, filters.scope, filters.status, matches],
);
const adoptedCounts = useMemo(() => {
const counts = new Map<string, number>();
for (const rule of rules) {
if (rule.based_on_rule_id) {
counts.set(
rule.based_on_rule_id,
(counts.get(rule.based_on_rule_id) ?? 0) + 1,
);
}
}
return counts;
}, [rules]);
// The flow counts every rule of the user's, whatever the filters: it is the
// overview the filters are chosen from.
const layerCounts = useMemo(() => {
const counts: Partial<Record<RuleLayer, number>> = {};
for (const rule of rules) counts[rule.layer] = (counts[rule.layer] ?? 0) + 1;
return counts;
}, [rules]);
const activeCount = rules.filter((r) => r.is_active).length;
// Counted separately from "active" because they answer different questions:
// how much is switched on, and how much of it is aimed at one resource
// rather than at everything.
const pinnedCount = rules.filter((r) => !!r.scope_id).length;
const createButton = (
<CreateButton label="New Rule" to={APP_ROUTES.USER.GOVERNANCE.RULES.new} />
);
const generateButton = (
<GenerateButton onClick={() => setShowGenerateModal(true)} />
);
const toggleTemplates = (layer: RuleLayer) =>
setOpenTemplates((open) => {
const next = new Set(open);
if (next.has(layer)) next.delete(layer);
else next.add(layer);
return next;
});
// A template and a rule share a section, so one renderer tells them apart.
const renderCard = (rule: Rule) =>
isSystemManaged(rule) ? (
<TemplateCard
rule={rule}
catalogue={catalogue}
adopted={adoptedCounts.get(rule.id) ?? 0}
/>
) : (
<RuleCard rule={rule} catalogue={catalogue} targets={targets} />
);
const renderRow = (rule: Rule) =>
isSystemManaged(rule) ? (
<TemplateRow
rule={rule}
catalogue={catalogue}
adopted={adoptedCounts.get(rule.id) ?? 0}
/>
) : (
<RuleRow rule={rule} catalogue={catalogue} targets={targets} />
);
const layerSections = RULE_LAYERS.filter(
(layer) => filters.layer === "all" || filters.layer === layer,
).map((layer) => {
const spec = ruleLayerSpec(catalogue, layer);
const label = spec?.label ?? ruleLayerMeta(layer).label;
const own = filtered.filter((rule) => rule.layer === layer);
const templates = visibleTemplates.filter((rule) => rule.layer === layer);
// Folded only where the user already has rules of their own here — and
// never under a search, which would hide a match behind a toggle.
const folds = (layerCounts[layer] ?? 0) > 0 && !searching;
const open = !folds || openTemplates.has(layer);
return collectionSection<Rule>({
label,
hint: spec?.summary,
count: own.length,
action: (
<div className="flex shrink-0 items-center gap-3">
{folds && templates.length > 0 && (
<button
type="button"
aria-expanded={open}
onClick={() => toggleTemplates(layer)}
className={SECTION_LINK}
>
{open
? "Hide templates"
: `Show ${templates.length} template${templates.length === 1 ? "" : "s"}`}
</button>
)}
<Link
to={newRuleHref(layer)}
aria-label={`Add a rule to ${label}`}
className={SECTION_LINK}
>
<Plus className="size-3.5" />
Add
</Link>
</div>
),
items: open ? [...own, ...templates] : own,
itemKey: (rule) => rule.id,
renderCard,
renderRow,
loading,
listVariant: "rows",
skeletonCount: 2,
hideWhenEmpty: true,
empty: { Icon: ShieldCheck, title: "No rules in this layer." },
});
});
// With nothing to show in any layer — no rules or templates yet, or none
// the filters keep — one section carries the empty state instead.
const nothingShown =
!loading && layerSections.every((section) => section.items.length === 0);
const sections = nothingShown
? [
collectionSection<Rule>({
label: "Your rules",
items: [],
itemKey: (rule) => rule.id,
renderCard,
renderRow,
listVariant: "rows",
empty: {
Icon: ShieldCheck,
title: "No rules configured.",
hint: "Write a rule yourself — or describe what you want governed and let the platform draft the rules for you.",
dashed: true,
action: (
<div className="flex items-center gap-2">
{generateButton}
{createButton}
</div>
),
},
emptyFilteredTitle: "No rules match your search.",
}),
]
: layerSections;
// An account with no rules yet starts from the templates each layer shows.
const firstVisit =
!loading && rules.length === 0 && visibleTemplates.length > 0;
return (
<>
{showGenerateModal && (
<GenerateRuleModal onClose={() => setShowGenerateModal(false)} />
)}
<ResourceCollection<Rule>
stats={[
{ label: "Rules", value: rules.length, loading },
{ label: "Active", value: activeCount, loading },
{ label: "Targeted", value: pinnedCount, loading },
]}
summary={
<LayerFlow
counts={layerCounts}
selected={filters.layer}
onSelect={(layer) => setFilter("layer", layer)}
catalogue={catalogue}
loading={loading}
/>
}
shown={filtered.length}
search={{
value: collection.search,
onChange: collection.setSearch,
placeholder: "Search by name, description or what it does…",
}}
filters={
<>
<FilterSelect
value={filters.scope}
onValueChange={(value) =>
setFilter("scope", value as RuleScopeFilter)
}
placeholder="Any scope"
options={scopeOptions}
active={filters.scope !== "all"}
/>
<FilterSelect
value={filters.status}
onValueChange={(value) =>
setFilter("status", value as RuleStatusFilter)
}
placeholder="Any status"
options={STATUS_FILTER_OPTIONS}
active={filters.status !== "all"}
/>
</>
}
{...collection.toolbarProps}
actions={
<>
{generateButton}
{createButton}
</>
}
sections={sections}
>
{firstVisit && (
<div className="flex flex-col gap-3 rounded-xl border border-dashed border-gray-300 dark:border-gray-600 px-4 py-3 sm:flex-row sm:items-center sm:justify-between">
<p className="text-sm text-gray-600 dark:text-gray-300">
You have no rules yet. Start from a template in any layer
below, write one yourself, or describe what you want governed
and let the platform draft the rules for you.
</p>
<div className="flex shrink-0 items-center gap-2">
{generateButton}
{createButton}
</div>
</div>
)}
</ResourceCollection>
</>
);
};
export default RulesGrid;
|