From e060153798b5c515c5276e3a1af336c89a83c95e Mon Sep 17 00:00:00 2001 From: Zaldimmar Date: Mon, 5 Oct 2026 00:39:52 -0500 Subject: [PATCH] Newsletter: Pick a redirect on every link field Link fields with redirects: true get a list of Data > Links/redirects that fills in the short link's full address; the newsletter turns it on for its blocks' links and their items' links. Co-Authored-By: Claude Opus 5.5 --- server/src/admin-schema.js | 2 ++ src/components/admin/fields.tsx | 20 ++++++++++++++++++++ src/pages/admin/AdminNewsletter.tsx | 22 +++++++++++++++++++--- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/server/src/admin-schema.js b/server/src/admin-schema.js index 347fc66..8ac58f7 100644 --- a/server/src/admin-schema.js +++ b/server/src/admin-schema.js @@ -106,6 +106,8 @@ export const OPTION_QUERIES = { people: "SELECT id, display_name AS label FROM people ORDER BY sort_name, display_name", person_tag_types: "SELECT id, name AS label FROM person_tag_types ORDER BY sort_order, name", contact_types: "SELECT id, name AS label FROM contact_types ORDER BY sort_order, name", + // Link fields with `redirects: true` pick from these (068). + redirects: "SELECT id, id || ' (' || target_url || ')' AS label FROM redirects ORDER BY id", blog_posts: "SELECT id, title AS label FROM blog_posts ORDER BY published_on DESC, title", // org_id rides along so the affiliation row can filter the list diff --git a/src/components/admin/fields.tsx b/src/components/admin/fields.tsx index d6b6b14..371758d 100644 --- a/src/components/admin/fields.tsx +++ b/src/components/admin/fields.tsx @@ -62,6 +62,10 @@ the file's name and first-page preview. `filesWhen` limits it to rows that match, as `when` does for the field. + `redirects: true` on a link field adds "Pick a redirect": a list of + Data → Links/redirects (the `redirects` options) that fills the + field with the short link's full address, /go/. + `widget: "testNotice"` is a text box of email addresses with a "Send a test notice" button (TestNoticeInput below), for Site settings → Notices. @@ -97,6 +101,7 @@ import ContentBlocks from "../ContentBlocks.tsx"; import { FILTER_FROM, OptionFilter, narrow } from "../OptionFilter.tsx"; import { ImageInput, LinkPreviewInput } from "./MediaLibrary.tsx"; import { ChooseFileButton } from "./DriveFiles.tsx"; +import { siteUrl } from "../../lib/site.ts"; /* Live previews a collection can name with `preview`. Each gets the row as the form holds it, which is the API's shape. */ @@ -434,6 +439,21 @@ export function Field({ field, value, row, options, error, onChange, onPatch }: )} + {field.redirects && !locked && options?.redirects?.length > 0 && ( + + )} {error ? ( diff --git a/src/pages/admin/AdminNewsletter.tsx b/src/pages/admin/AdminNewsletter.tsx index 788e3dd..406caeb 100644 --- a/src/pages/admin/AdminNewsletter.tsx +++ b/src/pages/admin/AdminNewsletter.tsx @@ -103,7 +103,18 @@ const sourceOf = (part: NewsletterPart): PickSource => (SOURCES.includes(part.so /* Every part is a row: one editor for blocks and the email's own parts, so any of them can be moved, copied or removed. */ -const blockFields = blocksChild.fields.filter((field) => !['slot', 'team_id', 'type', 'captions'].includes(field.path)) +/* Every link a block or its items carry can be a short link + (Data → Links/redirects), so its clicks are counted. */ +const LINK_PATHS = ['href', 'url'] +const withRedirects = (field: any) => (LINK_PATHS.includes(field.path) ? { ...field, redirects: true } : field) +const withRedirectsChild = (child: any) => ({ + ...child, + fields: child.fields.map(withRedirects), + children: child.children?.map(withRedirectsChild), +}) +const blockFields = blocksChild.fields + .filter((field) => !['slot', 'team_id', 'type', 'captions'].includes(field.path)) + .map(withRedirects) const PARTS_SPEC = { key: 'parts', label: 'Parts', @@ -188,7 +199,7 @@ const PARTS_SPEC = { { path: 'space', label: 'Space above', widget: 'number', when: { path: 'type', value: 'divider' }, help: 'In pixels, 0 to 64. Default: 24' }, ], children: [ - ...(blocksChild.children ?? []), + ...(blocksChild.children ?? []).map(withRedirectsChild), { key: 'socials', label: 'Links', @@ -254,6 +265,7 @@ export default function AdminNewsletter() { const [posts, setPosts] = useState(null) const [postDetails, setPostDetails] = useState>({}) const [copied, setCopied] = useState<'html' | 'text' | null>(null) + const [redirects, setRedirects] = useState<{ id: string; label: string }[]>([]) // The draft being edited: null is a new one, not saved yet. const [drafts, setDrafts] = useState([]) @@ -269,6 +281,9 @@ export default function AdminNewsletter() { get('/admin/blog_posts?is_published=1&is_listed=1&limit=200', { ttl: 0 }) .then((data: { rows: PostRow[] }) => setPosts(data.rows)) .catch(() => setPosts([])) + get('/admin/options?only=redirects', { ttl: 0 }) + .then((data: { options: { redirects: { id: string; label: string }[] } }) => setRedirects(data.options.redirects)) + .catch(() => setRedirects([])) }, []) const loadDrafts = () => @@ -411,8 +426,9 @@ export default function AdminNewsletter() { countdownEvents: events .filter((event) => !event.is_series && event.starts_on) .map((event) => ({ id: event.id, label: [event.title, event.date_label].filter(Boolean).join(', ') })), + redirects, }), - [events, posts, cards], + [events, posts, cards, redirects], ) const newsletter = useMemo(() => {