Organizations block: the Partners page's cards, picked one by one or every one of a kind
Migration 093 adds the 'organizations' block type (rebuilding content_blocks for its CHECK, as 088 did), content_blocks.org_kind and content_block_items.org_id. OrgListCards takes `nested` for a block: no page gutter, names a level under the block's heading. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
e9ea75a68d
commit
bd271ef02d
8 changed files with 182 additions and 13 deletions
|
|
@ -157,6 +157,8 @@ export const blocksChild = (ownerKind) => ({
|
|||
// A venue's map, and event cards (088).
|
||||
"map",
|
||||
"events",
|
||||
// Organization cards (093).
|
||||
"organizations",
|
||||
],
|
||||
{ required: true },
|
||||
),
|
||||
|
|
@ -177,6 +179,8 @@ export const blocksChild = (ownerKind) => ({
|
|||
text("venue_id"),
|
||||
// List blocks (092): null bold text, 'plain' the old look.
|
||||
enumeration("list_style", ["plain"]),
|
||||
// Organizations blocks (093): the kind listed when none are picked.
|
||||
enumeration("org_kind", ["region", "group", "partner", "ministry"]),
|
||||
],
|
||||
children: [
|
||||
{
|
||||
|
|
@ -212,6 +216,8 @@ export const blocksChild = (ownerKind) => ({
|
|||
// A featured event's heading and subheading (090).
|
||||
text("heading"),
|
||||
text("subheading"),
|
||||
// An organizations block's organization (093).
|
||||
text("org_id"),
|
||||
],
|
||||
children: [
|
||||
{
|
||||
|
|
|
|||
91
server/src/migrations/093_organizations_block.sql
Normal file
91
server/src/migrations/093_organizations_block.sql
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
-- ═══════════════════════════════════════════════════════════════
|
||||
-- 093 ORGANIZATIONS BLOCK
|
||||
--
|
||||
-- An 'organizations' content block shows organizations as the
|
||||
-- Partners page's cards (OrgList-Card.tsx): the ones picked as its
|
||||
-- items, in their order (content_block_items.org_id), else every
|
||||
-- published, listed one of its kind (content_blocks.org_kind), by
|
||||
-- name.
|
||||
--
|
||||
-- content_blocks.type's CHECK can't change in place, so the table
|
||||
-- is rebuilt (as in 088), then its index and owner trigger made
|
||||
-- again.
|
||||
-- ═══════════════════════════════════════════════════════════════
|
||||
|
||||
ALTER TABLE content_block_items ADD COLUMN org_id TEXT
|
||||
REFERENCES organizations (id) ON DELETE SET NULL;
|
||||
|
||||
CREATE TABLE content_blocks_new (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
owner_kind TEXT NOT NULL
|
||||
CHECK (owner_kind IN ('organization', 'event', 'person', 'team', 'blog_post', 'page_section',
|
||||
'newsletter')),
|
||||
owner_id TEXT NOT NULL,
|
||||
slot TEXT NOT NULL DEFAULT 'body' CHECK (slot IN ('card', 'body', 'both')),
|
||||
sort_order INTEGER NOT NULL DEFAULT 0,
|
||||
|
||||
type TEXT NOT NULL
|
||||
CHECK (type IN ('heading', 'subheading', 'paragraph',
|
||||
'list', 'links', 'quote', 'image', 'divider',
|
||||
'video', 'button', 'callout', 'schedule', 'table', 'cards',
|
||||
'people', 'tab', 'map', 'events', 'organizations')),
|
||||
text TEXT,
|
||||
media TEXT,
|
||||
href TEXT,
|
||||
alt TEXT,
|
||||
cite TEXT,
|
||||
team_id TEXT REFERENCES teams (id) ON DELETE SET NULL,
|
||||
captions TEXT,
|
||||
word_motion TEXT CHECK (word_motion IN ('slide', 'flip', 'fade', 'type', 'mirror')),
|
||||
word_direction TEXT CHECK (word_direction IN ('top', 'bottom')),
|
||||
word_seconds INTEGER CHECK (word_seconds BETWEEN 1 AND 20),
|
||||
-- Map and schedule blocks: whose map, and whose locations.
|
||||
venue_id TEXT REFERENCES venues (id) ON DELETE SET NULL,
|
||||
-- List blocks (092): null bold text, 'plain' the old look.
|
||||
list_style TEXT CHECK (list_style IN ('plain')),
|
||||
-- Organizations blocks: the kind listed when none are picked.
|
||||
org_kind TEXT CHECK (org_kind IN ('region', 'group', 'partner', 'ministry'))
|
||||
) STRICT;
|
||||
|
||||
INSERT INTO content_blocks_new
|
||||
(id, owner_kind, owner_id, slot, sort_order, type, text, media, href, alt, cite, team_id, captions,
|
||||
word_motion, word_direction, word_seconds, venue_id, list_style)
|
||||
SELECT id, owner_kind, owner_id, slot, sort_order, type, text, media, href, alt, cite, team_id, captions,
|
||||
word_motion, word_direction, word_seconds, venue_id, list_style
|
||||
FROM content_blocks;
|
||||
|
||||
PRAGMA legacy_alter_table = ON;
|
||||
DROP TABLE content_blocks;
|
||||
ALTER TABLE content_blocks_new RENAME TO content_blocks;
|
||||
PRAGMA legacy_alter_table = OFF;
|
||||
|
||||
CREATE INDEX content_blocks_owner_idx
|
||||
ON content_blocks (owner_kind, owner_id, slot, sort_order);
|
||||
|
||||
CREATE TRIGGER content_blocks_owner_exists
|
||||
BEFORE INSERT ON content_blocks
|
||||
BEGIN
|
||||
SELECT CASE
|
||||
WHEN new.owner_kind = 'event'
|
||||
AND NOT EXISTS (SELECT 1 FROM events WHERE id = new.owner_id)
|
||||
THEN RAISE(ABORT, 'content_blocks: no such event')
|
||||
WHEN new.owner_kind = 'organization'
|
||||
AND NOT EXISTS (SELECT 1 FROM organizations WHERE id = new.owner_id)
|
||||
THEN RAISE(ABORT, 'content_blocks: no such organization')
|
||||
WHEN new.owner_kind = 'person'
|
||||
AND NOT EXISTS (SELECT 1 FROM people WHERE id = new.owner_id)
|
||||
THEN RAISE(ABORT, 'content_blocks: no such person')
|
||||
WHEN new.owner_kind = 'team'
|
||||
AND NOT EXISTS (SELECT 1 FROM teams WHERE id = new.owner_id)
|
||||
THEN RAISE(ABORT, 'content_blocks: no such team')
|
||||
WHEN new.owner_kind = 'blog_post'
|
||||
AND NOT EXISTS (SELECT 1 FROM blog_posts WHERE id = new.owner_id)
|
||||
THEN RAISE(ABORT, 'content_blocks: no such blog post')
|
||||
WHEN new.owner_kind = 'page_section'
|
||||
AND NOT EXISTS (SELECT 1 FROM page_sections WHERE CAST(id AS TEXT) = new.owner_id)
|
||||
THEN RAISE(ABORT, 'content_blocks: no such page section')
|
||||
WHEN new.owner_kind = 'newsletter'
|
||||
AND NOT EXISTS (SELECT 1 FROM newsletters WHERE CAST(id AS TEXT) = new.owner_id)
|
||||
THEN RAISE(ABORT, 'content_blocks: no such newsletter')
|
||||
END;
|
||||
END;
|
||||
|
|
@ -71,7 +71,7 @@ export function loadBlocks(db, ownerKind, ids, slot = "body", depth = 0) {
|
|||
const blockRows = db
|
||||
.prepare(
|
||||
`SELECT id, owner_id, type, text, media, href, alt, cite, captions, team_id, venue_id,
|
||||
word_motion, word_direction, word_seconds, list_style
|
||||
word_motion, word_direction, word_seconds, list_style, org_kind
|
||||
FROM content_blocks
|
||||
WHERE owner_kind = ? AND slot IN (?, 'both') AND owner_id IN (${placeholders(ids.length)})
|
||||
ORDER BY owner_id, sort_order`,
|
||||
|
|
@ -94,6 +94,7 @@ export function loadBlocks(db, ownerKind, ids, slot = "body", depth = 0) {
|
|||
team_id: row.team_id,
|
||||
venue_id: row.venue_id,
|
||||
list_style: row.list_style,
|
||||
org_kind: row.org_kind,
|
||||
// Its rotating words' motion (084), when it has its own.
|
||||
words: row.word_motion || row.word_direction || row.word_seconds
|
||||
? { motion: row.word_motion, direction: row.word_direction, seconds: row.word_seconds }
|
||||
|
|
@ -117,7 +118,7 @@ export function loadBlocks(db, ownerKind, ids, slot = "body", depth = 0) {
|
|||
|
||||
const itemRows = db
|
||||
.prepare(
|
||||
`SELECT i.id, i.block_id, i.day, i.kind, i.heading, i.subheading, ${ENTRY_FIELDS}
|
||||
`SELECT i.id, i.block_id, i.day, i.kind, i.heading, i.subheading, i.org_id, ${ENTRY_FIELDS}
|
||||
FROM content_block_items i
|
||||
LEFT JOIN v_people_public p ON p.id = i.person_id AND p.is_published = 1
|
||||
WHERE i.block_id IN (${placeholders(blockIds.length)})
|
||||
|
|
@ -135,6 +136,7 @@ export function loadBlocks(db, ownerKind, ids, slot = "body", depth = 0) {
|
|||
kind: row.kind ?? "entry",
|
||||
heading: row.heading,
|
||||
subheading: row.subheading,
|
||||
org_id: row.org_id,
|
||||
items: [],
|
||||
};
|
||||
itemsById.set(row.id, item);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue