Prune files not in the deploy set (stale build context)
Browse files
web/src/connectors/DirectoryChips.tsx
DELETED
|
@@ -1,122 +0,0 @@
|
|
| 1 |
-
// ---------------------------------------------------------------------------
|
| 2 |
-
// connectors/DirectoryChips.tsx — W49-T18, ruling R27, contract C4.
|
| 3 |
-
//
|
| 4 |
-
// THE CATEGORY RAIL over the connector directory: Monid's fourteen sidebar
|
| 5 |
-
// categories as filter chips, each with the number of cards behind it.
|
| 6 |
-
//
|
| 7 |
-
// ⭐⭐ THE NUMBER IS A COUNT OF CARDS, NOT A SUM OF ENDPOINTS, and this file does
|
| 8 |
-
// not invent categories: the server supplies their names, order and row tags.
|
| 9 |
-
// W58-T08 projects counts onto the operational rows the page actually offers,
|
| 10 |
-
// using the same `inCategory` predicate as the card filter.
|
| 11 |
-
//
|
| 12 |
-
// ⛔ THE CATEGORY NAMES ARE PROPER NOUNS AND ARE NOT RE-CASED. "Search & SEO",
|
| 13 |
-
// "Crypto & DeFi", "E-commerce", "AI" and "Phone & Messaging" are how Monid
|
| 14 |
-
// writes them; DESIGN.md's no-ALL-CAPS rule is about app chrome, and a name is
|
| 15 |
-
// not chrome. Nothing here calls `toUpperCase`.
|
| 16 |
-
//
|
| 17 |
-
// ⚠ NO CLIENT UNION OVER THE CATEGORY NAMES. They are the server's vocabulary
|
| 18 |
-
// and arrive as strings (the wave-9 law): a `type Category = "AI" | …` here
|
| 19 |
-
// turns "the taxonomy gained a row" into "the chip disappears".
|
| 20 |
-
//
|
| 21 |
-
// ⚠ THE HIDDEN PROVIDER LABEL IS NOT IN THIS FILE AND MUST NOT BE. C4 keeps
|
| 22 |
-
// `provider` (`native` | `monid`) server-side; R27's design rule is that it
|
| 23 |
-
// never renders, so there is no badge, no tooltip and no title attribute for it
|
| 24 |
-
// anywhere in this component.
|
| 25 |
-
// ---------------------------------------------------------------------------
|
| 26 |
-
|
| 27 |
-
import type { ConnectorRow } from "./ConnectorsPage";
|
| 28 |
-
|
| 29 |
-
/** One chip: a category name and the number of cards carrying it. Both the server's. */
|
| 30 |
-
export interface DirectoryCategory {
|
| 31 |
-
name: string;
|
| 32 |
-
count: number;
|
| 33 |
-
}
|
| 34 |
-
|
| 35 |
-
/** The everything chip. Declared once so the page and this file cannot disagree about it. */
|
| 36 |
-
export const ALL_CATEGORIES = "All";
|
| 37 |
-
|
| 38 |
-
/**
|
| 39 |
-
* The chips, read the way `parseDirectory` reads a row: anything without a name is dropped, and
|
| 40 |
-
* a payload with no `categories` at all yields `[]`.
|
| 41 |
-
*
|
| 42 |
-
* ⚠ AN OLDER SERVER THEREFORE SHOWS NO RAIL, which is the honest degradation: a server that does
|
| 43 |
-
* not send the taxonomy has no counts to render, and inventing them on the client would be a
|
| 44 |
-
* second answer to a question the server already answers (this repo's `one-question-two-
|
| 45 |
-
* normalizers` shape). The grid still renders every card.
|
| 46 |
-
*/
|
| 47 |
-
export function parseCategories(body: unknown): DirectoryCategory[] {
|
| 48 |
-
const raw = (body as { categories?: unknown } | null)?.categories;
|
| 49 |
-
if (!Array.isArray(raw)) return [];
|
| 50 |
-
const out: DirectoryCategory[] = [];
|
| 51 |
-
for (const item of raw) {
|
| 52 |
-
if (!item || typeof item !== "object") continue;
|
| 53 |
-
const c = item as Record<string, unknown>;
|
| 54 |
-
const name = typeof c.name === "string" ? c.name.trim() : "";
|
| 55 |
-
if (!name) continue;
|
| 56 |
-
out.push({ name, count: typeof c.count === "number" ? c.count : 0 });
|
| 57 |
-
}
|
| 58 |
-
return out;
|
| 59 |
-
}
|
| 60 |
-
|
| 61 |
-
/**
|
| 62 |
-
* Does this card belong under this chip?
|
| 63 |
-
*
|
| 64 |
-
* ⛔ THE PREDICATE IS MEMBERSHIP IN `categories`, THE PLURAL FIELD, and that is the whole reason
|
| 65 |
-
* the row carries both. `category` is the ONE name the card is filed under and reads well beside
|
| 66 |
-
* the label; `categories` is the tag list a provider can carry several of, and the rail is built
|
| 67 |
-
* from tags because Monid's categories overlap. Filtering on the singular would empty a chip of
|
| 68 |
-
* every card whose primary category is a different one.
|
| 69 |
-
*/
|
| 70 |
-
export function inCategory(row: ConnectorRow, name: string): boolean {
|
| 71 |
-
if (!name || name === ALL_CATEGORIES) return true;
|
| 72 |
-
return (row.categories || []).includes(name);
|
| 73 |
-
}
|
| 74 |
-
|
| 75 |
-
/** Preserve server taxonomy/order, counting only the page's operational projection. */
|
| 76 |
-
export function projectCategories(chips: DirectoryCategory[], rows: ConnectorRow[]): DirectoryCategory[] {
|
| 77 |
-
return chips.map((chip) => ({
|
| 78 |
-
name: chip.name,
|
| 79 |
-
count: rows.filter((row) => inCategory(row, chip.name)).length,
|
| 80 |
-
}));
|
| 81 |
-
}
|
| 82 |
-
|
| 83 |
-
/**
|
| 84 |
-
* The rail itself.
|
| 85 |
-
*
|
| 86 |
-
* ⛔ ONE CONTROL SHAPE (DESIGN.md §4: *"a filter rail keeps one control shape"*). Every chip is
|
| 87 |
-
* the same `<button>` with the same class; the selected one differs by state, never by being a
|
| 88 |
-
* different kind of control. The base rule in `styles/wave49/connectors.css` resets the native
|
| 89 |
-
* chrome the way §4 demands, because a `<button>` styled by class that forgets to do so wears the
|
| 90 |
-
* platform's own grey pill under our paint.
|
| 91 |
-
*/
|
| 92 |
-
export default function DirectoryChips({
|
| 93 |
-
chips,
|
| 94 |
-
active,
|
| 95 |
-
onPick,
|
| 96 |
-
}: {
|
| 97 |
-
chips: DirectoryCategory[];
|
| 98 |
-
active: string;
|
| 99 |
-
onPick: (name: string) => void;
|
| 100 |
-
}) {
|
| 101 |
-
if (!chips.length) return null;
|
| 102 |
-
return (
|
| 103 |
-
<div className="conn-chips" role="group" aria-label="Filter connectors by category">
|
| 104 |
-
{chips.map((chip) => {
|
| 105 |
-
const on = (active || ALL_CATEGORIES) === chip.name;
|
| 106 |
-
return (
|
| 107 |
-
<button
|
| 108 |
-
key={chip.name}
|
| 109 |
-
type="button"
|
| 110 |
-
className={"conn-chip" + (on ? " is-on" : "")}
|
| 111 |
-
aria-pressed={on}
|
| 112 |
-
aria-label={`${chip.name}, ${chip.count.toLocaleString("en-US")} connectors`}
|
| 113 |
-
onClick={() => onPick(chip.name)}
|
| 114 |
-
>
|
| 115 |
-
<span className="conn-chip-name">{chip.name}</span>
|
| 116 |
-
<span className="conn-chip-n">{chip.count.toLocaleString("en-US")}</span>
|
| 117 |
-
</button>
|
| 118 |
-
);
|
| 119 |
-
})}
|
| 120 |
-
</div>
|
| 121 |
-
);
|
| 122 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|