From fd7e1b6fc1e75ff9612f18d420ead490f7ca5b94 Mon Sep 17 00:00:00 2001 From: Zaldimmar Date: Sun, 4 Oct 2026 22:40:24 -0500 Subject: [PATCH] Organization cards: list partners, ministries or a hand-picked set (migration 067) The Partners section's preset gets "Cards: list" (partners by default, ministries, or both) and an optional hand-picked list (page_section_orgs, partners or ministries only, enforced by trigger) that replaces it in its own order. /organizations takes kind=ministry and ids=; the plain list still leaves ministries out. Ministry cards link to their website only. Co-Authored-By: Claude Opus 5.5 --- docs/updating-data-in-code.md | 3 +- server/src/admin-schema.js | 3 ++ server/src/admin-schema/sitePages.js | 14 +++++++- server/src/migrations/067_section_orgs.sql | 42 ++++++++++++++++++++++ server/src/routes/content.js | 29 +++++++++------ server/src/routes/sitePages.js | 13 ++++++- src/lib/adminSchema/sitePages.ts | 30 +++++++++++++++- src/lib/organizations.ts | 11 +++--- src/lib/useSitePages.ts | 4 +++ src/pages/SitePage.tsx | 9 +++-- src/pages/sections/OrgList-Card.tsx | 11 ++++-- 11 files changed, 146 insertions(+), 23 deletions(-) create mode 100644 server/src/migrations/067_section_orgs.sql diff --git a/docs/updating-data-in-code.md b/docs/updating-data-in-code.md index cb2fa80..409ba54 100644 --- a/docs/updating-data-in-code.md +++ b/docs/updating-data-in-code.md @@ -167,7 +167,7 @@ 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, ministry | no, shows values | `ORG_BASE` in `src/lib/hrefs.ts` (the route each kind uses). A ministry has no page or list on the public site (the public routes, `pageMeta.js` and the sitemap leave it out, `ORG_KINDS` in `server/src/routes/content.js` doesn't take it); only its groups name it. `KINDS` in `src/components/admin/NewsletterRecipients.tsx` (the export's filter) lists every kind too. | +| Organizations → Kind (+ list filter) | national, region, group, partner, ministry | no, shows values | `ORG_BASE` in `src/lib/hrefs.ts` (the route each kind uses). A ministry has no page on the public site (the public routes, `pageMeta.js` and the sitemap leave it out); its groups name it, and an organization cards section lists it when asked to (below). `/organizations` returns ministries only when asked by kind or id. `KINDS` in `src/components/admin/NewsletterRecipients.tsx` (the export's filter) lists every kind too. | | 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) | @@ -190,6 +190,7 @@ also in `server/src/admin-schema/` and a CHECK): | 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` | | Pages → Sections → Preset | community_blog, group_map, region_list, partner_list, events, timeline, people_directory | **yes**, `PRESETS` in `src/lib/adminSchema/sitePages.ts` (which pages offer which, the list passed to each `sitePage`) | `PRESETS` in `src/pages/SitePage.tsx`. A People directory shows its tag's first `DIRECTORY_PREVIEW` people (`src/pages/sections/PeopleDirectory.tsx`), linking to `/directory/`. | +| Pages → Sections → Cards: list (organization cards preset, 067) | partner, ministry, partner,ministry | **yes**, inline in `src/lib/adminSchema/sitePages.ts` | `partner_list` in `PRESETS` in `src/pages/SitePage.tsx` passes it as the kind to `OrgListCards`; a section's hand-picked Cards: organizations (`page_section_orgs`) replace it | | Every list → Published / Listed / Featured filter | 1, 0 | **yes** | n/a | "No, shows values" means the dropdown currently shows the raw value, diff --git a/server/src/admin-schema.js b/server/src/admin-schema.js index eb89bc1..6fe7796 100644 --- a/server/src/admin-schema.js +++ b/server/src/admin-schema.js @@ -96,6 +96,9 @@ export const OPTION_QUERIES = { "SELECT id, name AS label FROM organizations WHERE kind = 'region' ORDER BY name", ministries: "SELECT id, name AS label FROM organizations WHERE kind = 'ministry' ORDER BY name", + // What an organization cards section can hand-pick (067). + card_orgs: + "SELECT id, name || ' (' || kind || ')' AS label FROM organizations WHERE kind IN ('partner', 'ministry') ORDER BY kind, name", event_scopes: "SELECT id, name AS label FROM event_scopes ORDER BY sort_order", events: "SELECT id, title AS label FROM events ORDER BY starts_on DESC, title", people: "SELECT id, display_name AS label FROM people ORDER BY sort_name, display_name", diff --git a/server/src/admin-schema/sitePages.js b/server/src/admin-schema/sitePages.js index 0a79f2d..bee81c2 100644 --- a/server/src/admin-schema/sitePages.js +++ b/server/src/admin-schema/sitePages.js @@ -36,8 +36,20 @@ const sectionsChild = { enumeration("event_type", ["retreat", "class", "workshop", "meeting", "other"]), enumeration("view", ["carousel", "grid", "map"]), text("tag_id"), + // Organization cards (067): the kinds listed by themselves. + enumeration("org_kinds", ["partner", "ministry", "partner,ministry"]), + ], + children: [ + blocksChild("page_section"), + { + // Organization cards (067): a hand-picked list, shown instead. + key: "orgs", + table: "page_section_orgs", + owner: { column: "section_id" }, + order: "sort_order", + columns: [text("org_id", { required: true })], + }, ], - children: [blocksChild("page_section")], }; const sitePage = (id, more = {}) => ({ diff --git a/server/src/migrations/067_section_orgs.sql b/server/src/migrations/067_section_orgs.sql new file mode 100644 index 0000000..6402de9 --- /dev/null +++ b/server/src/migrations/067_section_orgs.sql @@ -0,0 +1,42 @@ +-- ═══════════════════════════════════════════════════════════════ +-- 067 ORGANIZATION CARDS: WHICH ORGANIZATIONS +-- +-- The organization cards preset (page_sections.preset 'partner_list', +-- the Community page's Partners) can list ministries as well as +-- partners, chosen two ways: +-- +-- page_sections.org_kinds which kinds it lists by itself, every +-- published, listed one by name: +-- 'partner', 'ministry' or both +-- ('partner,ministry'). Blank: partners +-- page_section_orgs a hand-picked list, in order; when a +-- section has any, it shows those instead +-- (published ones, listed or not). Only +-- partners and ministries (triggers below) +-- ═══════════════════════════════════════════════════════════════ + +ALTER TABLE page_sections ADD COLUMN org_kinds TEXT + CHECK (org_kinds IN ('partner', 'ministry', 'partner,ministry')); + +CREATE TABLE page_section_orgs ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + section_id INTEGER NOT NULL REFERENCES page_sections (id) ON DELETE CASCADE, + sort_order INTEGER NOT NULL DEFAULT 0, + org_id TEXT NOT NULL REFERENCES organizations (id) ON DELETE CASCADE +) STRICT; + +CREATE INDEX page_section_orgs_section_idx ON page_section_orgs (section_id, sort_order); + +CREATE TRIGGER page_section_orgs_kind +BEFORE INSERT ON page_section_orgs +FOR EACH ROW WHEN (SELECT kind FROM organizations WHERE id = new.org_id) NOT IN ('partner', 'ministry') +BEGIN + SELECT RAISE(ABORT, 'Organization cards can list partners and ministries only.'); +END; + +CREATE TRIGGER page_section_orgs_kind_update +BEFORE UPDATE OF org_id ON page_section_orgs +FOR EACH ROW WHEN (SELECT kind FROM organizations WHERE id = new.org_id) NOT IN ('partner', 'ministry') +BEGIN + SELECT RAISE(ABORT, 'Organization cards can list partners and ministries only.'); +END; diff --git a/server/src/routes/content.js b/server/src/routes/content.js index d03fdb3..5c026f8 100644 --- a/server/src/routes/content.js +++ b/server/src/routes/content.js @@ -72,7 +72,7 @@ const content = new Hono(); // Kinds with a public page. A ministry (063_ministries.sql) has none: // it's only named on its groups' pages, so no route here serves one. -const ORG_KINDS = ["national", "region", "group", "partner"]; +const ORG_KINDS = ["national", "region", "group", "partner", "ministry"]; /* ── Loaders ───────────────────────────────────────────────── */ @@ -597,6 +597,11 @@ content.get("/events/:id", (c) => { GET /organizations every published, listed org GET /organizations?kind=region one kind GET /organizations?kind=region,group + GET /organizations?ids=a,b these, published, listed or + not (a hand-picked list, 067) + + Ministries come only when asked for, by kind or id: they have no + page, so the plain list leaves them out. Whatever the kind, the common card fields are in the same places, so a list component reads `name`, `color`, `logo` and @@ -616,19 +621,21 @@ content.get("/organizations", (c) => { return c.json({ error: `kind must be one of ${ORG_KINDS.join(", ")}` }, 400); } - const filter = kinds.length > 0 ? `AND kind IN (${marks(kinds.length)})` : ""; + const ids = (c.req.query("ids") ?? "").split(",").map((id) => id.trim()).filter(Boolean).slice(0, 100); + const [where, params] = + ids.length > 0 + ? [`id IN (${marks(ids.length)})`, ids] + : kinds.length > 0 + ? [`is_listed = 1 AND kind IN (${marks(kinds.length)})`, kinds] + : [`is_listed = 1 AND kind <> 'ministry'`, []]; const rows = db - .prepare( - `SELECT * FROM organizations - WHERE is_published = 1 AND is_listed = 1 AND kind <> 'ministry' ${filter} - ORDER BY kind, sort_order, name`, - ) - .all(...kinds); + .prepare(`SELECT * FROM organizations WHERE is_published = 1 AND ${where} ORDER BY kind, sort_order, name`) + .all(...params); - const ids = rows.map((row) => row.id); - const links = loadLinks(db, "organization", ids); - const cards = loadBlocks(db, "organization", ids, "card"); + const found = rows.map((row) => row.id); + const links = loadLinks(db, "organization", found); + const cards = loadBlocks(db, "organization", found, "card"); // No body blocks or leadership: they grow with every organization // and only a group's own detail panel or page shows them, which diff --git a/server/src/routes/sitePages.js b/server/src/routes/sitePages.js index 1eb76d7..43e8f35 100644 --- a/server/src/routes/sitePages.js +++ b/server/src/routes/sitePages.js @@ -37,11 +37,21 @@ sitePages.get("/site-pages/:id", (c) => { const rows = db .prepare( - `SELECT id, anchor, title, blurb, accent, preset, scope_id, event_type, view, tag_id + `SELECT id, anchor, title, blurb, accent, preset, scope_id, event_type, view, tag_id, org_kinds FROM page_sections WHERE page_id = ? ORDER BY sort_order, id`, ) .all(id); const blocks = loadBlocks(db, "page_section", rows.map((row) => String(row.id))); + const picked = new Map(); + for (const { section_id, org_id } of db + .prepare( + `SELECT o.section_id, o.org_id FROM page_section_orgs o + JOIN page_sections s ON s.id = o.section_id + WHERE s.page_id = ? ORDER BY o.section_id, o.sort_order, o.id`, + ) + .all(id)) { + picked.set(section_id, [...(picked.get(section_id) ?? []), org_id]); + } return json(c, { page: { @@ -49,6 +59,7 @@ sitePages.get("/site-pages/:id", (c) => { sections: rows.map(({ id: sectionId, ...section }) => ({ ...section, blocks: blocks.get(String(sectionId)) ?? [], + org_ids: picked.get(sectionId) ?? [], })), }, }); diff --git a/src/lib/adminSchema/sitePages.ts b/src/lib/adminSchema/sitePages.ts index ef5006c..8f0d8fc 100644 --- a/src/lib/adminSchema/sitePages.ts +++ b/src/lib/adminSchema/sitePages.ts @@ -15,7 +15,7 @@ const PRESETS = { community_blog: "Community blog (its settings are below)", group_map: "Local groups map", region_list: "Unity Regions list", - partner_list: "Partner organization cards", + partner_list: "Organization cards (partners, ministries)", events: "Event carousel or grid", timeline: "Timeline", people_directory: "People directory (a tag's people)", @@ -37,6 +37,7 @@ const EVENT_TYPES = [ ]; const EVENTS = { path: "preset", value: "events" }; +const CARDS = { path: "preset", value: "partner_list" }; const sectionsChild = (presets: string[]) => ({ key: "sections", @@ -113,6 +114,23 @@ const sectionsChild = (presets: string[]) => ({ }, ] : []), + ...(presets.includes("partner_list") + ? [ + { + path: "org_kinds", + label: "Cards: list", + widget: "select", + options: [ + ["partner", "Partners"], + ["ministry", "Ministries"], + ["partner,ministry", "Partners and ministries"], + ], + blankLabel: "Default: Partners", + help: "Every published, listed one, by name. Organizations picked below replace this list.", + when: CARDS, + }, + ] + : []), ...(presets.includes("group_map") ? [ { @@ -127,6 +145,16 @@ const sectionsChild = (presets: string[]) => ({ : []), ], children: [ + { + key: "orgs", + label: "Cards: organizations", + note: "Picked here, these show instead of the list above, in this order: partners or ministries, published ones, listed or not.", + addLabel: "Add organization", + when: CARDS, + title: (row, options) => options?.card_orgs?.find((o) => o.id === row.org_id)?.label ?? "New organization", + blank: { org_id: "" }, + fields: [{ path: "org_id", label: "Organization", widget: "select", optionsFrom: "card_orgs", required: true }], + }, { ...blocksChild, label: "Blocks", diff --git a/src/lib/organizations.ts b/src/lib/organizations.ts index ecaaba0..71ff651 100644 --- a/src/lib/organizations.ts +++ b/src/lib/organizations.ts @@ -27,10 +27,13 @@ import { isBadId, orgHref } from "./hrefs.ts"; import { useResource } from "./useResource.ts"; -export function useOrganizations(kind) { - const path = kind - ? `/organizations?kind=${encodeURIComponent(kind)}` - : "/organizations"; +/* `ids` (a hand-picked list) wins over `kind`. */ +export function useOrganizations(kind, ids?: string[]) { + const path = ids?.length + ? `/organizations?ids=${ids.map(encodeURIComponent).join(",")}` + : kind + ? `/organizations?kind=${encodeURIComponent(kind)}` + : "/organizations"; const { data, error, loading } = useResource(path); diff --git a/src/lib/useSitePages.ts b/src/lib/useSitePages.ts index 80435ef..27eeae5 100644 --- a/src/lib/useSitePages.ts +++ b/src/lib/useSitePages.ts @@ -17,6 +17,10 @@ export type SitePageSection = { view?: string | null /** A people_directory preset's tag (Data → People tags). */ tag_id?: string | null + /** Organization cards: the kinds listed ('partner', 'ministry' or both, comma separated). */ + org_kinds?: string | null + /** Organization cards: a hand-picked list, in order, shown instead. */ + org_ids: string[] blocks: ContentBlock[] } diff --git a/src/pages/SitePage.tsx b/src/pages/SitePage.tsx index 7a826d3..b4a1b5a 100644 --- a/src/pages/SitePage.tsx +++ b/src/pages/SitePage.tsx @@ -66,10 +66,15 @@ const PRESETS: Record Record> ], }, }), - partner_list: () => ({ + partner_list: (section) => ({ Component: OrgListCards, request: { type: 'partner', label: 'Request a partner listing' }, - props: { kind: 'partner', pageLabel: 'Partner page', empty: '· Partner organizations coming soon ·' }, + props: { + kind: section.org_kinds || 'partner', + ids: section.org_ids, + pageLabel: 'Partner page', + empty: '· Organizations coming soon ·', + }, }), events: (section) => ({ Component: EventListCards, diff --git a/src/pages/sections/OrgList-Card.tsx b/src/pages/sections/OrgList-Card.tsx index b8d44e5..27d2ca1 100644 --- a/src/pages/sections/OrgList-Card.tsx +++ b/src/pages/sections/OrgList-Card.tsx @@ -18,6 +18,7 @@ import { useReadingMode } from '../../lib/readingMode.ts' page manifest and gets no control in its heading. + in that order Where the vertical list expands in place, a card links out. The card carries as much as fits at a glance and the organization's @@ -152,6 +153,7 @@ function Block({ title, orgs, accent, pageLabel, siteLabel }) { export default function OrgListCards({ kind, + ids, title, groups, groupBy, @@ -161,7 +163,7 @@ export default function OrgListCards({ sort = byName, empty = "Nothing to show here yet.", }) { - const { organizations, loading, error } = useOrganizations(kind); + const { organizations, loading, error } = useOrganizations(kind, ids); const shell = children => (
@@ -191,7 +193,12 @@ export default function OrgListCards({ ); } - const sorted = sort ? [...organizations].sort(sort) : organizations; + // A hand-picked list keeps its order; anything else is sorted. + const sorted = ids?.length + ? ids.flatMap((id) => organizations.filter((org) => org.id === id)) + : sort + ? [...organizations].sort(sort) + : organizations; // No groups given means one undivided grid. if (!groups || !groupBy) {