NGU-Web/docs/updating-data-in-code.md
Zaldimmar 54bf649b8d Tidy the admin editor's text: previews, blank options, no em-dashes
Your wording pass on adminSchema.ts and fields.tsx: "Default: ..."
blank options, "eg." examples, "URL ID" for slugs, and relabelled
front page sections, stat sources and hero fields.

On top of it:

- Content block row titles end with an ellipsis when the paragraph
  is cut. preview() in src/lib/text.ts does it for anything that
  shortens text: it collapses whitespace, cuts on a word and adds
  "..." only when it actually shortened.
- No em-dashes in the editor, front end or server: placeholders
  ("Internal note: ..."), the Organizations blurb, the URL ID help,
  empty table cells (now "-"), the Award dropdown ("Torch Award
  (NGU)" in OPTION_QUERIES), a boot error message, and every comment
  in the admin files. Also cleared from the files added this branch
  (QR page, directory route, embeds, hero, migration 024), and the
  QR page's team labels read "Board (NGU)".
- A few comments where removing the dash had run two sentences
  together get a comma, colon or parentheses back.
- docs/updating-data-in-code.md matches the new labels and gains a
  "Writing text in the editor" section with these conventions;
  CLAUDE.md lists them under Rules and gotchas.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 19:38:24 -05:00

320 lines
17 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 → Front page |
| 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) |
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.ts` | 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
`src/lib/adminSchema.ts`. 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 `src/lib/adminSchema.ts` 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.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.ts`, 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` |
| Content blocks → Slot | card, body | no | `ContentBlocks.tsx` |
| Content blocks → Type | heading, subheading, paragraph, list, links, quote, image, divider | no | `ContentBlocks.tsx` (one renderer per type) |
| 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 → Background | brand, photos | **yes** | `HeroStage.tsx` |
| Front page → Feature | none, livestream, video | **yes** | `HeroStage.tsx` |
| Front page → Sections → Section | countdown, retreats, calendar, stats, timeline, connect | **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) |
| Every list → Published / 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) | `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 |
| 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 | `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 → 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.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.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 → 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. |
| 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.