NGU-Web/docs/updating-data-in-code.md
Zaldimmar 048c7599ce Fix dark mode and bring the public design in line with the taste audit
- Dark mode: the countdown card, timeline section, Giving text, error
  text, the Leadership button, skeletons and the admin's dark text all
  follow the tokens; logos get a light plate in dark mode
- One BRAND accent (the button token, so the admin palette reaches
  every page) and one ACCENTS family in color.ts, replacing 20 local
  teal constants and the purple, ochre and rust section colours;
  neon green and gold become mint and brand green
- Shadows are tinted with the site's ink; glow shadows are gone
- One giving label, Give, in the nav, footer and Giving page
- Phosphor icons replace the hand-drawn SVGs and the glyph icons;
  Pathfinder paths pick a named icon (emoji still shown) and lose the
  watermark
- Home keeps two eyebrows; StatsBand's title is a real heading;
  section headings step down under the page title
- Nav links switch to the menu below lg, so they never wrap; jump
  links land clear of the header; press feedback on buttons
- Empty sections say what's coming and who to ask; loading is a
  skeleton; form placeholders and borders are readable; one
  corner-radius rule; theme-color for both modes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 02:54:03 -05:00

333 lines
21 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 section (headings, pins, feeds) | the database | Admin → Pages → Blog posts, and Community blog section |
| 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, page section titles, colours, 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.js` | 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
relabelling 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.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 `admin-schema.js` and a CHECK):
| Entity → field | Stored values | Labelled? | Also used on the public site by |
| --- | --- | --- | --- |
| Organizations → Kind (+ list filter) | national, region, chapter, partner | no, shows values | `ORG_KIND_LABEL` in `src/lib/hrefs.ts`, and the route each kind uses |
| Organizations → Region → Scope | domestic, international, virtual | no | the Community page groups regions by it |
| Organizations → Region areas → Edge | top, bottom | no | the chapter 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 | 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 | **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 blog section → 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 relabelling it is just [adding labels](#renaming-what-a-dropdown-shows).
**Lists filled from records** (`optionsFrom`: edit the records, not
code):
| Dropdown | `optionsFrom` | Comes from |
| --- | --- | --- |
| Chapter → 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, labelled by name |
| Event hosts / event people / team members / timeline people → Person | `people` | people |
| Community blog section → Pinned posts → 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, labelled "Award (Organization)" |
| Person awards → Presented at; Front page → Count down to; Front page → Featured event | `events` | events |
| Timeline → Record | `timeline_refs` | all five kinds, filtered by "Points at" |
---
## 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 subnav links under the header ("#Retreats", "#Calendar") | `PAGE_SECTIONS["/"]` in `src/navConfig.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.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.js`,
`STAT_SOURCES`, and a query in `STAT_QUERIES`.
---
## Other content that lives in code
| What | File | Notes |
| --- | --- | --- |
| Header and footer navigation, page subnav links | `src/navConfig.ts` | `PAGE_LINKS`, `PAGE_SECTIONS`, `NAV_ACTIONS`. A new page also needs a route in `src/App.tsx`. |
| Section titles, blurbs and colours on Retreats, Community, Leadership, Resources, Feedback, Privacy, Terms | the page file in `src/pages/` | the `SECTIONS` array at the top. A section's `id` must match its subnav `hash`. |
| 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. |
| Chapter 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. |
| The site's colours, light and dark | the database over `src/index.css` | Admin → Panel → Site settings → Colours (superadmins): pick a colour, set its light and/or dark value; saving refuses anything that makes text hard to read. The defaults are the `@theme` tokens and dark block in `src/index.css`, and must stay the same in `THEME_DEFAULTS` (`server/src/theme.js`) and `THEME_COLORS` (`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 colour that arrives as data (a page accent, an event's or region's colour) 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 colour | `BRAND` and `ACCENTS` in `src/lib/color.ts` | Pages pick from these (`accent: ACCENTS.green`); add a colour there, not a hex in a page. Each is readable as text on white and the tints. |
| 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", "Chapter") | `ORG_KIND_LABEL` in `src/lib/hrefs.ts` | |
| 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` | |
| 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.