Admin preview: a map block's sections made as the API makes them
The preview handed MapBlock the form's sections (location_keys text), so adding one crashed the page on section.keys. It now builds them as shape.js does: keys the venue still has, empty ones dropped, the venue cut to them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
56a6e11655
commit
a79559d290
1 changed files with 18 additions and 2 deletions
|
|
@ -135,9 +135,21 @@ const PREVIEWS = {
|
|||
// the person, so it's looked up in the select options (a name, no
|
||||
// photo: the options carry no more).
|
||||
// A venue and an item's event and map location come from the
|
||||
// options the same way (088): an event as its title only.
|
||||
// options the same way (088): an event as its title only. A map
|
||||
// block's sections (094) are made as the API makes them (shape.js):
|
||||
// their keys the venue still has, the venue cut to those.
|
||||
contentBlock: (row, options) => {
|
||||
const venue = venueFromOption(options?.venues?.find((v) => v.id === row.venue_id));
|
||||
const known = new Map((venue?.locations ?? []).map((l) => [l.key, l]));
|
||||
const sections = (row.map_sections ?? [])
|
||||
.map((section) => ({
|
||||
name: section.name,
|
||||
keys: (section.location_keys ?? "").split(",").filter((key) => known.has(key)),
|
||||
}))
|
||||
.filter((section) => section.keys.length);
|
||||
const mapped = venue && sections.length
|
||||
? { ...venue, locations: [...new Set(sections.flatMap((section) => section.keys))].map((key) => known.get(key)) }
|
||||
: venue;
|
||||
const shape = (item) => {
|
||||
const person = item.person_id ? options?.people?.find((p) => p.id === item.person_id) : null;
|
||||
const event = item.event_id ? options?.events?.find((e) => e.id === item.event_id) : null;
|
||||
|
|
@ -151,7 +163,11 @@ const PREVIEWS = {
|
|||
items: (item.items ?? []).map(shape),
|
||||
};
|
||||
};
|
||||
return <ContentBlocks blocks={[{ ...row, venue, items: (row.items ?? []).map(shape) }]} />;
|
||||
return (
|
||||
<ContentBlocks
|
||||
blocks={[{ ...row, venue: mapped, map_sections: sections, items: (row.items ?? []).map(shape) }]}
|
||||
/>
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue