Shared Content: offer the Shared library on ImageText, LinkPreview, ImageLinkGrid and other image slots

Aperta
#1,344 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
next.js, typescript
Ambito
backend, frontend

Direzione di ricerca

Start with src/fields/mediaSource.ts and src/utilities/resolveMediaSource.ts, then trace the block configs and components for ImageText, LinkPreview, ImageLinkGrid, and InlineMedia. The issue splits the work into a blocks PR and a later collections PR; begin with the block slots and their image readers, and check the shared-content prerequisites before starting. Done when adopted slots offer both sources, existing center images still render, readers resolve either library correctly, and migrations pass pnpm migrate:check.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

blocked enhancement needs-triage

Summary

Add the "Center library / Shared library" choice to the remaining image slots. #1335 (Shared Content: the SharedMedia collection and a source choice on the Media block) adds it to the Media block only. mediaSourceFields in src/fields/mediaSource.ts builds the three fields for a slot, and resolveMediaSource in src/utilities/resolveMediaSource.ts picks what to render. Each new slot needs one call to the first, and every place that reads the slot's image has to go through the second.

Refs #564. Blocked until the Shared Content stack (#1328, #1335, #1336, #1340) merges.

Before any slot: extend mediaSourceFields

  • Pass filterOptions through. ImageText, LinkPreview, ImageLinkGrid and the Events thumbnail all restrict the picker with getImageTypeFilter. Today the helper can't pass that on, so adopting it would let those slots pick videos.
  • Accept admin overrides such as description and allowCreate for both upload fields.
  • Accept distinct field names (e.g. featuredImageSource) for slots that are fields on a collection. Events has two image slots on one document, so their names can't collide.

Part 1: the blocks (one PR)

These are cheap: one block config and one component each.

Slot Where it lives Notes
ImageText image Layouts, Posts rich text Required. The component reads image in two places.
LinkPreview cards[].image Layouts Inside an array, which works because the source choice only depends on sibling fields.
ImageLinkGrid columns[].image Layouts Inside an array, same as LinkPreview.
InlineMedia media Announcements rich text (inline block) No migration. The component does its own type narrowing on media.

Migration: source (default 'center') and shared_media_id on 12 tables. Those are the block, link_preview_cards and image_link_grid_columns tables for pages and home_pages and their _v version twins. Rich-text copies are stored as JSON, so they need no migration and no backfill, since a slot with no source value already means the center's library.

Add ON DELETE set null to each ADD ... REFERENCES by hand. migrate:create drops it from ALTERs; see 20260923_033051_add_shared_media.ts and its explanation file.

Seed: put one shared-source instance of each block on the All Blocks page so the "Where this is used" panel and the References column show them.

Part 2: images on collections (later PR)

These are more expensive: each needs its own migration, and more code reads each field.

  • Posts featuredImage: built with the SEO plugin's MetaImageField, so it has to be replaced or wrapped. It is in defaultPopulate. Readers:
    • src/utilities/queries/getPosts.ts
    • src/components/PostPreview/index.tsx
    • src/components/PostPreviewSmallRow.tsx
    • src/app/api/[center]/og/getOgDocData.ts, where getImgAttrsFromMediaResource and the WebP conversion are typed for Media only
  • Events featuredImage and thumbnailImage: featuredImage is a MetaImageField with hasGenerateFn. Readers:
    • the event page
    • getOgDocData.ts
    • EventPreview
    • EventPreviewSmallRow
  • Biographies photo: required. AuthorAvatar hard-codes getDocumentById('media', ...), and the Team block reads the photo in two places.
  • Sponsors photo: required. The Sponsors block validator checks the photo's aspect ratio, and the Banner, Static and Carousel components read it.

Out of scope for now:

  • Galleries items[].media: the array item already has its own type radio, so the conditions would nest.
  • Pages meta.image: no frontend reader.
  • Settings brand assets: they are per-center by nature.

Acceptance

  • Every adopted slot offers the choice, and an existing slot with no source value still renders the center image.
  • Switching back to "Center library" clears the shared reference. The References count and the "Where this is used" panel both follow the change.
  • Every reader of an adopted slot goes through resolveMediaSource. No reader narrows the value to Media without checking which library it came from.
  • pnpm migrate:check has been run, and the migration's explanation file records the hand-added ON DELETE clauses.
Lingua principale
TypeScript
Stelle
6
Fork
2
Merge medio
1g 11h
PR unite (30g)
35

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di NWACus/web

Tutte le issue di NWACus/web

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.