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 | 7x 74x 7x 222x 7x 74x 296x 296x 296x 296x 296x 296x 296x 296x 4x 7x 12x 48x 48x 48x | import { Skeleton } from "@/components/detail";
import { RuleCatalogue, RuleLayer, ruleLayerSpec } from "@/objects/Rule";
import { ChevronRight, Sparkles } from "lucide-react";
import React from "react";
import { LAYER_CLASSES, RULE_LAYERS, ruleLayerMeta } from "./ruleLayer";
/**
* The path a request takes through the rules, as a strip of steps: each
* layer's icon, label, question and how many rules it holds, with the model
* marked where it answers. It is the Rules tab's overview and its layer
* filter in one — a step filters the page to its layer (`?layer=`), and the
* selected step again shows them all.
*
* Neutral, like every surface on the page: a layer is named by its icon,
* label and place, and the selected step by the builder's outline.
*/
export interface LayerFlowProps {
/** Rules per layer; a layer missing from it holds none. */
counts: Partial<Record<RuleLayer, number>>;
selected: RuleLayer | "all";
onSelect: (layer: RuleLayer | "all") => void;
/** Labels and questions; the registry's labels until it resolves. */
catalogue?: RuleCatalogue | null;
loading?: boolean;
}
/** Where the model answers: between the last layer that acts before it and
* the first that reads what it wrote. */
const ModelMarker: React.FC = () => (
<span className="inline-flex items-center gap-1 rounded-full border border-dashed border-gray-300 dark:border-gray-600 px-2 py-0.5 text-[11px] font-medium text-gray-500 dark:text-gray-400 whitespace-nowrap">
<Sparkles className="size-3" aria-hidden="true" />
Model
</span>
);
const Joint: React.FC<{ model: boolean }> = ({ model }) => (
<li
aria-hidden="true"
className="hidden sm:flex items-center gap-1 px-1.5 text-gray-300 dark:text-gray-600"
>
<ChevronRight className="size-4" />
{model && (
<>
<ModelMarker />
<ChevronRight className="size-4" />
</>
)}
</li>
);
const LayerFlow: React.FC<LayerFlowProps> = ({
counts,
selected,
onSelect,
catalogue,
loading,
}) => (
<nav aria-label="Where rules act in a request">
<ol className="grid grid-cols-2 gap-2 sm:flex sm:items-stretch sm:gap-0">
{RULE_LAYERS.map((layer, index) => {
const meta = ruleLayerMeta(layer);
const spec = ruleLayerSpec(catalogue, layer);
const Icon = meta.Icon;
const label = spec?.label ?? meta.label;
const count = counts[layer] ?? 0;
const isSelected = selected === layer;
const previous = index > 0 ? ruleLayerMeta(RULE_LAYERS[index - 1]) : null;
return (
<React.Fragment key={layer}>
{previous && (
<Joint model={!previous.afterModel && meta.afterModel} />
)}
<li className="min-w-0 sm:flex-1">
<button
type="button"
aria-pressed={isSelected}
onClick={() => onSelect(isSelected ? "all" : layer)}
className={`flex h-full w-full items-start gap-3 rounded-xl border px-3.5 py-3 text-left transition-all ${
isSelected
? "border-gray-900 dark:border-white bg-gray-50 dark:bg-gray-800"
: "border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 hover:border-gray-300 dark:hover:border-gray-500"
}`}
>
<span className={`shrink-0 rounded-lg p-1.5 ${LAYER_CLASSES.iconTile}`}>
<Icon className="size-4" aria-hidden="true" />
</span>
<span className="min-w-0 flex-1">
<span className="flex items-baseline gap-1.5">
<span className="text-[11px] font-medium text-gray-400 dark:text-gray-500 tabular-nums">
{meta.step}
</span>
<span className="truncate text-sm font-semibold text-gray-900 dark:text-gray-100">
{label}
</span>
</span>
{spec?.summary && (
<span className="mt-0.5 block truncate text-xs text-gray-500 dark:text-gray-400">
{spec.summary}
</span>
)}
</span>
{loading ? (
<Skeleton className="h-5 w-5" />
) : (
<span className="shrink-0 text-base font-semibold text-gray-900 dark:text-gray-100 tabular-nums">
{count}
<span className="sr-only">
{count === 1 ? " rule" : " rules"}
</span>
</span>
)}
</button>
</li>
</React.Fragment>
);
})}
</ol>
</nav>
);
export default LayerFlow;
/**
* Where one rule acts, as its place among the layers: every layer named in
* flow order, this rule's filled. For a rule's page, under its title — the
* flow strip's shape without its counts.
*/
export const LayerPosition: React.FC<{
layer: string;
catalogue?: RuleCatalogue | null;
}> = ({ layer, catalogue }) => (
<ol
aria-label="Where it acts in a request"
className="flex flex-wrap items-center gap-x-2 gap-y-1 text-xs"
>
{RULE_LAYERS.map((step, index) => {
const here = step === layer;
const label = ruleLayerSpec(catalogue, step)?.label ?? ruleLayerMeta(step).label;
return (
<React.Fragment key={step}>
{index > 0 && (
<li aria-hidden="true" className="h-px w-4 bg-gray-200 dark:bg-gray-700" />
)}
<li
aria-current={here ? "step" : undefined}
className={`inline-flex items-center gap-1.5 ${
here
? "font-semibold text-gray-900 dark:text-gray-100"
: "text-gray-400 dark:text-gray-500"
}`}
>
<span
aria-hidden="true"
className={`size-2 rounded-full ${
here
? "bg-gray-900 dark:bg-gray-100"
: "border border-gray-300 dark:border-gray-600"
}`}
/>
{label}
</li>
</React.Fragment>
);
})}
</ol>
);
|