NGU-Web/docs/updating-data-in-code.md
Zaldimmar b816203c0c Accessibility: reading and color blind modes, audit fixes, calendar window
- Accessibility panel: the switch knob stays in its track; the panel
  follows its button in the Tab order and opens on its first switch.
- Reading mode is the page as plain text: one column, no colors,
  pictures, cards or motion; descriptions stay in place.
- Color blind mode (protanopia, deuteranopia, tritanopia, monochrome):
  palette swaps chosen by simulation, applied to code, data and CSS
  colors on public pages only. The newsletter uses the stored palette.
- Audit fixes: focus not hidden by the header, focus on page change
  and in-page jumps, focus return for the menu, day list and people
  details, labelled admin fields and dialogs, keyboard map tiles,
  scrollable tables, and more.
- Calendar asks /events for its six weeks only (?from=&to=); carousels
  take their 12 most recent past events (?past=12).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-02 14:33:09 -05:00

337 lines
25 KiB
Markdown

# Updating data that isn't in the database
Most of the site's content lives in SQLite and is edited in the admin
(`/admin`). Some of it deliberately lives in code instead: labels,
navigation, fixed lists, and a few pieces of editorial copy. Changing
those means editing a file, committing it on a branch, and deploying.
This guide covers where each of those lives and how to change it
safely, starting with the question that comes up most: how to change
what a dropdown in the admin editor says.
- [Database or code?](#database-or-code)
- [Admin dropdowns](#admin-dropdowns)
- [Two kinds of dropdown](#two-kinds-of-dropdown)
- [Renaming what a dropdown shows](#renaming-what-a-dropdown-shows)
- [Adding, removing or renaming a stored value](#adding-removing-or-renaming-a-stored-value)
- [Every dropdown in the editor](#every-dropdown-in-the-editor)
- [Front page section names](#front-page-section-names)
- [Front page stat sources](#front-page-stat-sources)
- [Other content that lives in code](#other-content-that-lives-in-code)
- [Writing text in the editor](#writing-text-in-the-editor)
- [Making the change](#making-the-change)
---
## Database or code?
| If it's… | It lives in… | Change it by… |
| ------------------------------------------------------------ | ---------------- | ------------------------------------ |
| A record: an event, organization, person, team, award, timeline entry | the database | editing it in the admin |
| The front page's words, photos, bands, stats and paths | the database | Admin → Pages → Front page |
| Blog posts, and the Community page's blog settings (headings, pins, feeds) | the database | Admin → Data → Blog posts, and Admin → Pages → Community |
| The sections of Retreats, Community, Resources, Organization and History: titles, blurbs, accents, their content blocks and presets (the blog, groups map, regions, partners, events, timeline) | the database | Admin → Pages → the page. A section title is 30 characters at most (it's listed in the side nav); a front page heading fits about 60. Preset names: `PRESETS` in `src/lib/adminSchema/sitePages.ts`, what each draws: `PRESETS` in `src/pages/SitePage.tsx` |
| The **label** a dropdown shows in the admin | code | [one file](#renaming-what-a-dropdown-shows) |
| The **list of allowed values** behind a fixed dropdown | database CHECK + code | [a migration and three files](#adding-removing-or-renaming-a-stored-value) |
| Navigation, colors, the site banner, history decades, the map grid | code | [the file named below](#other-content-that-lives-in-code) |
| A static page's title and intro (also its search title and description), the site's name, description, preview image, icons, search indexing, privacy contact email | the database, over `site.json` | Admin → Panel → Site settings (superadmins). Blank uses `site.json`, which also holds the site's address and the pages' defaults. See `docs/seo.md` |
| Uploaded images | disk + the `media` table | Admin → Tools → Media, or any image field. See `docs/media-uploads.md` |
The rule of thumb from `CLAUDE.md`: data belongs in the database,
presentation belongs in code. A dropdown's *values* are data the
database enforces; its *labels* are presentation.
---
## Admin dropdowns
The admin editor is generated from two descriptor files that describe
each entity:
| File | What it holds |
| ----------------------------- | ----------------------------------------------------- |
| `src/lib/adminSchema/` (one file per entity, `shared.ts` for common fields; `src/lib/adminSchema.ts` lists them) | The **form**: field labels, help text, dropdown labels, list columns and filters |
| `server/src/admin-schema/` (one file per entity, `columns.js` for shared helpers; `server/src/admin-schema.js` lists them) | What the server **accepts**: columns, types, the allowed values of each `enumeration(...)` |
And the database itself holds the final word: most fixed lists are a
`CHECK (... IN (...))` constraint on the column (read them in
`server/src/migrations/023_schema.sql` and any later migration).
### Two kinds of dropdown
Every dropdown in the editor is one of these:
**1. Filled from records (`optionsFrom`).** The choices are rows in the
database: organizations, people, events, teams, awards, event scopes,
regions. The label is the record's own name. To change what one of
these shows, **edit the record in the admin**; there's nothing to
change in code. Adding a person adds them to every "Person" dropdown.
The queries behind them are `OPTION_QUERIES` in
`server/src/admin-schema.js`. Edit a query only to change *which*
records appear or their order, e.g. to put a disambiguating
organization name in the label, as the `awards` query does.
> Event scopes (National, Regional, Local…) are records in the
> `event_scopes` table, but there's no admin page for them. Their names
> are changed with a migration: `UPDATE event_scopes SET name = '…' WHERE id = '…';`
**2. A fixed list in code (`options`).** The choices are written in
the entity's file in `src/lib/adminSchema/`. Each option is one of two shapes:
```ts
options: ["speaker", "leader", "host"] // shows: speaker, leader, host
options: [["speaker", "Speaker"], ["leader", "Leader"]] // shows: Speaker, Leader
```
A bare string is shown exactly as stored. A `[value, label]` pair
stores the first and shows the second. That difference is what makes
relabeling cheap.
### Renaming what a dropdown shows
If the stored value stays the same and you only want the dropdown to
read differently, **only the file in `src/lib/adminSchema/` changes**. No
migration, no server change, and every existing row keeps working.
Find the field (search for its column name) and give the option a
label. For example, to make the event-people Role dropdown read nicely:
```ts
// before
options: ["speaker", "leader", "facilitator", "host", "musician", "volunteer", "attendee"],
// after: values unchanged, labels added
options: [
["speaker", "Speaker"],
["leader", "Leader"],
["facilitator", "Facilitator"],
["host", "Host"],
["musician", "Musician"],
["volunteer", "Volunteer"],
["attendee", "Attendee (not shown publicly)"],
],
```
Things to check while you're there:
- **The same list often appears twice**: once on the form field and
once in the entity's `list.filters` (the dropdowns above the list
view). Relabel both so they agree.
- **Several lists are shared constants.** Front page sections and stat
sources are `FRONT_PAGE_SECTIONS` and `STAT_SOURCES` near the top of
the front page block; change them there, once.
- **`blankLabel`** is the text of the empty first option, written as
`Default: …` saying what happens when it's left blank
(`"Default: brand"`, `"Default: none"`). It's also just a label. A
select with no `blankLabel` shows `- Please choose from the list -`
(set in `src/components/admin/fields.tsx`).
- The value (first item) **must not change**. It's what's stored in
the database and what the server and the CHECK constraint compare
against.
### Adding, removing or renaming a stored value
This changes what the database will accept, so four places move
together, in one branch:
1. **A new migration** (`server/src/migrations/0NN_description.sql`)
that changes the column's CHECK. A CHECK can't be altered in place,
so either:
- add a new column with the new CHECK, copy the data across, and
drop the old one (see `025_hero_backdrop_feature.sql`), or
- rebuild the table (see `024_front_page_video.sql`, and the
rebuild notes in `CLAUDE.md` under Migrations).
**Renaming** a value also needs an `UPDATE` in the same migration so
existing rows move to the new value. **Removing** one needs you to
decide what existing rows become first.
2. **`server/src/admin-schema/<entity>.js`**: the `enumeration("column", [...])`
list for that column.
3. **`src/lib/adminSchema/<entity>.ts`**: the `options` on the form field, and on
the list filter if there is one.
4. **Anywhere the public site renders or relies on the value**, listed in
the table below (for example `EVENT_TYPES` for event types, or the
`SECTIONS` map in `Home.tsx` for front page sections).
If the server descriptor and the database disagree, the API refuses to
start: `admin-schema-sync.js` compares them at boot and throws with a
message naming the column. That's deliberate. Fix whichever side is
wrong rather than working around it.
### Every dropdown in the editor
**Fixed lists** (`options`: labels in `src/lib/adminSchema/`, values
also in `server/src/admin-schema/` and a CHECK):
| Entity → field | Stored values | Labeled? | Also used on the public site by |
| --- | --- | --- | --- |
| Organizations → Kind (+ list filter) | national, region, group, partner | no, shows values | `ORG_BASE` in `src/lib/hrefs.ts` (the route each kind uses) and `orgListHref` there (its back link) |
| Organizations → Region → Scope | domestic, international, virtual | no | the Community page groups regions by it |
| Organizations → Region areas → Edge | top, bottom | no | the group map (`OrgList-Map.tsx`) |
| Events → Type (+ list filter) | retreat, class, workshop, meeting, other | no | `EVENT_TYPES` in `src/lib/eventTypes.ts` (public labels and plurals) |
| Events → Status (+ list filter) | upcoming, past, cancelled (shown as canceled) | no | `STATUS_LABEL` in `src/pages/EventDetail.tsx` |
| Events → Series → Repeats | weekly, monthly_date, monthly_weekday | **yes** | `src/lib/eventSeries.ts` |
| Events → People → Role | speaker, leader, facilitator, host, musician, volunteer, attendee | no | `ROLE_LABEL` in `src/pages/EventDetail.tsx` |
| People → Affiliations → Role; Teams → Members → Role | lead, board, staff, volunteer, member | no | `ROLE_LABEL` in `src/pages/PersonDetail.tsx` |
| Links → Kind (on organizations, events, people, teams) | action, social, website, email | no | `splitLinks` in `server/src/shape.js` |
| Links → Platform | instagram, facebook, discord, youtube, tiktok, x, substack, spotify, linkedin | **yes**, `PLATFORMS` | `PlatformIcon.tsx` draws the icon on the button. **No CHECK and no `enumeration`**: the column is plain text, so adding one is an entry in `PLATFORMS` (`src/lib/platforms.ts`) and its icon in `src/components/PlatformIcon.tsx`, no migration. |
| Content blocks → Shown in (slot) | card, body | **yes** | `paragraphs()` in `server/src/shape.js` (card), `ContentBlocks.tsx` (body) |
| Content blocks → Type | heading, subheading, paragraph, list, links, quote, image, divider, video, button, callout, schedule, table | **yes**, `BLOCK_TYPES` (with each type's description) | `ContentBlocks.tsx` (one renderer per type). Which fields each type shows is `when` on the fields in `blocksChild` (`src/lib/adminSchema/shared.ts`). |
| Timeline → Kind (+ list filter) | milestone, event, organization, award, people | no | `KIND_NAMES` in `src/pages/sections/history/TimelineEntry.tsx` |
| Timeline → Points at (+ list filter) | event, organization, award, person, team | no | `refHref` in `src/lib/hrefs.ts` |
| Timeline → Precision (and on events/orgs) | year, month, day | no | the history page's grouping |
| Front page → Countdown → Only this type | retreat, class, workshop, meeting, other | **yes** | `server/src/routes/home.js` (picks the countdown event). The same values as Events → Type, so adding a type widens both CHECKs. |
| Front page → Background | brand, photos | **yes** | `HeroStage.tsx` |
| Front page → Feature | none, livestream, video, event | **yes** | `HeroStage.tsx`; the event is picked in `server/src/routes/home.js` |
| Front page → Sections → Section | countdown, retreats, calendar, stats, timeline, connect, featured | **yes**, `FRONT_PAGE_SECTIONS` | `SECTIONS` in `src/pages/Home.tsx`; see [below](#front-page-section-names) |
| Front page → Stats → Number Source | manual, years_since, regions, … | **yes**, `STAT_SOURCES` | `STAT_QUERIES` in `server/src/routes/home.js`; see [below](#front-page-stat-sources) |
| Front page → Featured cards → Card type (Community → Community blog: pinned community posts offers link and video only) | record, link, video | **yes**, `FEATURED_KINDS` | `FeaturedCards.tsx` (how each kind draws), `loadFeaturedCards` in `server/src/shape.js` |
| Front page → Featured cards → Record type | event, organization, person, team, award | no | `FEATURED_REFS` in `server/src/shape.js` (what each fills the card with); the triggers in `030_featured_cards.sql` |
| Every list → Published / Listed / Featured filter | 1, 0 | **yes** | n/a |
"No, shows values" means the dropdown currently shows the raw value,
so relabeling it is just [adding labels](#renaming-what-a-dropdown-shows).
**Lists filled from records** (`optionsFrom`: edit the records, not
code):
| Dropdown | `optionsFrom` | Comes from |
| --- | --- | --- |
| Group → Region | `regions` | organizations of kind region |
| Event → Scope (+ list filter); Front page → Countdown → Only this scope | `event_scopes` | the `event_scopes` table (migration only) |
| Event hosts → Organization; affiliations; team and award "Organization" / "Awarded by"; person → Home organization | `organizations` | organizations, labeled by name |
| Event hosts / event people / team members / timeline people → Person | `people` | people |
| Community → Community blog: pinned posts (ours) → Post | `blog_posts` | blog posts, newest first |
| Timeline → Record; Featured cards → Record | `record_refs` | every event, organization, award, person and team, narrowed by the type picked beside it |
| Affiliations → Team | `teams` | teams, filtered to the chosen organization |
| Person awards → Award | `awards` | awards, labeled "Award (Organization)" |
| Person awards → Presented at; Front page → Count down to; Front page → Featured event | `events` | events |
---
## Front page section names
"Section name" means three different things on the front page, and
each is changed in a different place:
| What you see | Where it's set |
| --- | --- |
| **The heading on the page** ("National Retreats", "What's on") | **Admin → Pages → Front page → Page sections → Heading.** Blank uses the default below. |
| The default heading when that field is blank | `SECTIONS` in `src/pages/Home.tsx`, the `title` of each entry |
| **The name in the admin's Section dropdown** ("Events Carousel (National Retreats)") | `FRONT_PAGE_SECTIONS` in `src/lib/adminSchema/frontPage.ts` |
| The links in the header's Home dropdown | the bands shown, under their headings (`src/lib/navSections.ts`) |
To rename a band **for visitors**, use the admin. To rename how it
reads **in the editor's dropdown**, edit `FRONT_PAGE_SECTIONS`:
```ts
const FRONT_PAGE_SECTIONS = [
["countdown", "Event Countdown"],
["retreats", "Events Carousel (National Retreats)"], // ← the right-hand side is the label
["calendar", "Event Calendar"],
...
];
```
The subnav links jump to each band by its anchor: the `id` passed in
each band's `render` in `Home.tsx` (`#retreats`, `#calendar`,
`#numbers`, `#connect`, and `#hero` for the hero). If you rename a
subnav label in `navConfig.ts`, leave its `hash` alone unless you also
change the band's `id`.
**Adding a new kind of band** (not just renaming one) is a feature,
not a relabel: it needs a component, an entry in `SECTIONS` in
`Home.tsx`, the key added to `FRONT_PAGE_SECTIONS`, to the
`enumeration("section", …)` in `server/src/admin-schema/frontPage.js`, to the
`FrontPageSectionKey` type in `src/lib/useFrontPage.ts`, and to the
CHECK on `front_page_sections.section` via a migration.
---
## Front page stat sources
The numbers band's "Number Source" dropdown works the same way:
- **Relabel a source:** `STAT_SOURCES` in `src/lib/adminSchema/frontPage.ts`.
- **Change what a count counts:** its query in `STAT_QUERIES` in
`server/src/routes/home.js`. Keep it counting exactly what the
matching public page shows (published rows), or the number and the
page will disagree.
- **Add a source:** the CHECK on `front_page_stats.source` (migration),
the `enumeration("source", …)` in `server/src/admin-schema/frontPage.js`,
`STAT_SOURCES`, and a query in `STAT_QUERIES`.
---
## Other content that lives in code
| What | File | Notes |
| --- | --- | --- |
| Header and footer navigation, each page's sections (the header dropdowns, mobile menu and footer site map) | `src/navConfig.ts` | `PAGE_LINKS` (order), `NAV_ACTIONS`. Each page's sections aren't listed there: they follow the page itself, through `src/lib/navSections.ts` (the site pages' sections from Admin → Pages; the front page's bands it shows, with `src/lib/frontPageBands.ts` giving each band's anchor and default heading). A new page also needs a route in `src/App.tsx`. |
| Section titles, blurbs and colors on Feedback, Privacy, Terms | the page file in `src/pages/` | the `SECTIONS` array at the top. |
| Site-wide announcement banner | `src/data/bannerConfig.ts` | `enabled: false` hides it. Bump `id` when the message changes, so people who dismissed the old one see the new one. |
| History page decade headers | `src/data/historyDecades.ts` | Title, tagline and blurb per decade. |
| Group map tiles and area names | `src/data/mapGrid.ts` | `AREAS` (tile positions) and `AREA_NAMES`. Which region paints which tile is in the database (Admin → Data → Organizations → a region → Map areas). |
| Feedback form types | `src/data/feedbackTypes.ts` **and** `TYPES` in `server/src/routes/feedback.js` | Keep the ids identical in both; the server stores unknown ids as `general`. Labels and hints are client-only. `DATA_REQUEST` ('privacy') isn't a tile: the Privacy page's form sends it, and the server requires an email for it. |
| Request form types (what `/request` can ask for) | `src/data/requestTypes.ts` **and** `CATEGORIES` in `server/src/routes/requests.js` **and** the CHECK on `feedback.category` (`046_content_requests.sql`) | Ids and allowed actions (new, update) identical in all three; a new id needs a migration. Labels, hints, the name field's question and each type's `fields` (the details it asks for, and where each lands in the admin editor: a field path, a link row or a description paragraph) are client-only: the server stores whatever detail keys come as JSON (`feedback.details`, 049), so adding a field needs no migration. A button to the form opened on one type: `request: { type, label }` on a section manifest entry, or `<RequestLink>` (`src/components/RequestLink.tsx`). |
| The site's colors, light and dark | the database over `src/index.css` | Admin → Panel → Site settings → Colors (superadmins): pick a color, set its light and/or dark value; saving refuses anything that makes text hard to read. The defaults are `THEME_DEFAULTS` in `server/src/themeDefaults.js` (the admin and the contrast check read it) and the same values as CSS in `src/index.css`; the build stops if the two differ. The admin's labels for them are `THEME_LABELS` in `src/lib/adminSchema/siteSettings.ts`. Change a token's value in both modes and every use follows. Use the token utilities (`text-muted`, `bg-surface`, `border-brand/20`) or `var(--color-…)`, not hex. A color that arrives as data (a page accent, an event's or region's color) goes through `src/lib/color.ts`: `withAlpha` for tints, `accentText` for text in it, `readableOn` for text on it. |
| The icons a Front page "Find your way in" path can pick | `src/data/pathIcons.ts` (keys and labels) **and** `ICONS` in `src/pages/sections/home/Pathfinder.tsx` (the Phosphor icon for each key) | Add a line to both. A path saved with an emoji from before the list shows it as it is. |
| A page section's accent color | `BRAND` and `ACCENTS` in `src/lib/color.ts` | Pages pick from these (`accent: ACCENTS.green`); add a color there, not a hex in a page. Each is readable as text on white and the tints. |
| The palette (the 16-color grid the theme is drawn from) | `PALETTE` in `src/lib/color.ts` | Four families, a column each. `PALETTE_LIGHT` / `PALETTE_DARK` are the fills things colored by data use (a person's initials tile, `paletteFill`); the page background's layers (how many circles, their sizes and parallax speeds) are `LAYERS` in `src/components/PageBackdrop.tsx` and its shades are in `PageBackdrop.css`; the admin home's two alternating group colors are `BLOCK_COLORS` in `src/pages/admin/AdminHome.tsx`. |
| The accessibility panel's choices (bottom right of every public page) | `SETTINGS` in `src/components/AccessibilityPanel.tsx`; the color blind modes are `VISIONS` and `SWAPS` in `src/lib/color.ts` | Each choice is an attribute on `<html>` styled in `src/index.css`, and `index.html` sets it again before the first paint, so a new one goes in all three. A color blind mode swaps palette families (`SWAPS`, picked by simulating each type: see the comment there) in code, in data colors as they load (`src/lib/api.ts`, never under /admin) and in CSS (the `--green-*` variables in `src/index.css`); a hex from the green family in a component should be one of those variables. Something saved or sent (the newsletter's colors) uses `STORED_PALETTE`, which is never swapped. |
| Privacy Policy and Terms wording | `src/pages/Privacy.tsx`, `src/pages/Terms.tsx` | The `PARTS` list, and `LAST_UPDATED` whenever the wording changes. The Privacy page must stay true of the code: what the feedback form stores, what the browser keeps, which embeds wait for a click. |
| Event type labels and plurals (public site) | `src/lib/eventTypes.ts` | Also the order of the type filter chips. |
| Event and person role labels (public site) | `ROLE_LABEL` in `src/pages/EventDetail.tsx` and `src/pages/PersonDetail.tsx` | |
| Organization kind labels ("Region", "Group") | the Kind options in `src/lib/adminSchema/organizations.ts` (admin); `orgListHref` in `src/lib/hrefs.ts` (the public back link, "All regions") | |
| Admin account roles | `src/lib/roles.ts` (labels, notes) and `ROLES` in `server/src/auth.js` | Adding a role is also a CHECK change on `admin_users.role`. |
| Admin navigation | `src/pages/admin/adminNav.ts` | |
| Newsletter parts and their defaults (Tools → Newsletter) | `PARTS_SPEC`, `PART_TYPES` and `STARTER` in `src/pages/admin/AdminNewsletter.tsx`; `PICK_DEFAULTS`, `DEFAULT_TITLE` and `COLOR` in `src/lib/newsletter.ts` | A draft is one JSON list of parts (`newsletters.layout`, 060), so adding a part or a setting needs no migration: a field in `PARTS_SPEC` and its drawing in `newsletter.ts`. The color choices are `PALETTE`; `COLOR` holds the defaults as hex, since an inbox has no theme tokens. `STARTER` is what a new draft starts with. The social bar's icons are PNGs in `public/email/` (Gmail and Outlook don't show SVG), made from `PlatformIcon.tsx` by `node scripts/email-icons.mjs`: run it again after adding a platform. A social bar with no links shows the footer's, `SOCIAL_LINKS` in `src/data/socialLinks.ts`. The countdown picture is `server/src/routes/countdown.js`, counting to local midnight in its `TIME_ZONE` (America/Chicago). |
| The live site's address (used by QR codes) | `SITE_ORIGIN` in `src/lib/site.ts` | |
| Version shown on the admin home page | `src/lib/version.ts` | |
| Image directories (where logos and photos are looked up) | `src/lib/media.ts` | |
---
## Writing text in the editor
Conventions for any label, help text or option added to the admin, so
the editor reads consistently:
- **Blank options say what blank means:** `Default: none`,
`Default: weekly`, `Default: the next upcoming event`.
- **Examples in help text start with `eg.`:** `eg. Board Chair, Team Lead`.
- **Record ids are called "URL ID"**, not slug, in anything the editor
shows.
- **Cut-off text ends with an ellipsis.** Anywhere a paragraph is
shortened for a row title, list cell or card, use `preview(text, max)`
from `src/lib/text.ts` rather than `.slice()`. It cuts on a word and
adds `…`, and only when it actually shortened something.
- **No em-dashes** (the long dash, U+2014), in the editor or anywhere else: labels, help
text, placeholders, code comments and docs. Use a colon, a comma or
parentheses instead. An empty value in a table shows `-`.
---
## Making the change
1. Branch from `main` (never commit to `main` directly).
2. Edit the file(s). For a stored-value change, write the migration as
well, numbered after the last one in `server/src/migrations/`.
3. Check it:
```sh
pnpm exec tsc # type-check
pnpm build # the site still builds
```
For anything touching the server or a migration, also run it
locally against a scratch database:
```sh
cd server
DB_PATH=./dev.db pnpm migrate
DB_PATH=./dev.db pnpm dev # boot fails loudly if a descriptor and the schema disagree
```
and open the admin editor to see the dropdown.
4. Commit, push the branch, and open a pull request with `tea`.
5. After it's merged, deploy. A migration runs automatically when the
`ngu-api` service restarts; back up `/var/lib/ngu/ngu.db` first if
the change includes one.