Files
CatoandClaude Opus 5 c6cdd59003 The company page becomes modules (#59)
* refactor(profile): the company page becomes modules, and numbering stops being hand-kept

314 lines to 155. What it makes, where this matters, what could change its
position, the questions the profile does not answer, and the timeline were five
hand-written sections; they are modules now. The page keeps what is genuinely
its own — the identity header, the follow button, the evidence callout — and
asks the registry for the rest.

What this buys, concretely: offering any of these on another kind is a change to
`appliesTo` rather than a second copy of the markup, a section that has nothing
to say leaves no trace instead of rendering an empty shell, and the order is a
number on a module rather than its position in a file.

Section numbers are derived from render order now. They used to come from a
`next()` counter kept by hand, so inserting a section meant renumbering the rest
and a conditional section could leave a gap in the sequence.

`load` may return undefined as well as null — the lookup helpers naturally
return undefined, and forcing every one of them to normalise was noise that
would eventually be got wrong.

Two things the tests now hold: a company profile still carries all five of its
original sections in reading order, and company modules do not leak onto kinds
with no such data — asking `products` about a country must not throw or invent a
row.

Caught by looking at the rendered page: the replaceability footnote had drifted
to the very bottom, below the discussion, explaining a grade shown six sections
earlier. It sits with the grade now.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y6ecRd91ZsPPcjuNkKTFV2

* chore: drop the import the module split left behind

Splitting the registry out of shared.tsx left defineModule and AnyProfileModule
imported but unused. CI warned; lint is silent now.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y6ecRd91ZsPPcjuNkKTFV2

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-17 01:03:25 -07:00

51 lines
2.1 KiB
TypeScript

import type { ReactNode } from 'react';
import type { Entity, EntityKind } from '../entities/types';
/**
* A profile is an ordered list of modules, not a bespoke page per kind.
*
* The point is that adding a section — leadership, stock performance, an
* analyst view — is one file and one registry line, and it then appears on
* every kind it declares. Fifteen hand-written pages cannot offer that, and
* they drift: the same fact ends up presented three ways because three pages
* grew separately.
*
* Two rules keep profiles comparable:
* - `load` returns null when a module has nothing to say, and the module is
* then not rendered at all. Empty shells teach a reader nothing and make two
* entities look different when only the data differs.
* - a module states how its own data is evidenced, so a section can never
* imply more certainty than the corpus has.
*/
export interface ProfileModule<T = unknown> {
/** Stable id, used for anchors, ordering overrides and tests. */
id: string;
title: string;
/** Which kinds this module can render for. `'*'` means every kind. */
appliesTo: readonly EntityKind[] | '*';
/**
* Lower sorts earlier. Also drives progressive disclosure: the first few
* modules answer "what is this and why does it matter" and stay open, the
* rest collapse behind a one-line summary.
*/
importance: number;
/**
* Return null (or undefined) to render nothing. Never return an empty object
* to fill space: a module with no data should leave no trace.
*/
load(entity: Entity): T | null | undefined;
Render(props: { entity: Entity; data: T }): ReactNode;
/** How this module's data is evidenced, in the corpus's vocabulary. */
evidence?(data: T): string | undefined;
/**
* True when the module renders its own heading. Discussion does, because the
* same component is mounted directly on article pages, and wrapping it in a
* second heading printed "Discussion" twice.
*/
ownsHeading?: boolean;
}
export function appliesTo(module: ProfileModule<unknown>, kind: EntityKind): boolean {
return module.appliesTo === '*' || module.appliesTo.includes(kind);
}