fix(studio): a map of the whole journey says so, and templates keep a map's scope

A map without the revision 12 scope fields is read as one saved before them,
and its scope is guessed off what it holds. New whole-journey and trip maps
wrote none of the fields, so a map placed on a one-country journey was taken
for a map of that country once the journey reached a second one, and never
widened again. bookTravelMap and the auto layout's journey map now write
country, dayDate and stop as null, and a refresh writes the scope of an old
map down once it is plain (its trip, a recorded track, several countries).

Applying a template drops what a page's map is of and its own view; they now
travel with its stops. Saving a page as a template strips them, like the
stops themselves.

Parity digests regenerated for the pages that hold a journey map: 2 in
auto-layout.parity.json, 12 in design-templated.parity.json.
This commit is contained in:
Maurice
2026-11-30 14:50:40 +01:00
parent 0dbd27f644
commit 94b2352cb3
9 changed files with 129 additions and 29 deletions
+5
View File
@@ -182,6 +182,11 @@ export function mapEl(newId: NewId, frame: BookFrame, stats: JourneyStats, opts:
fitPadding: 0.5,
fitToCountries: true,
clip: 'rect',
// A map of the whole journey, said in so many words (revision 12): without them it reads as a map saved before,
// and one of a journey that later reaches a second country would be taken for a map of the first.
country: null,
dayDate: null,
stop: null,
...opts,
} as BookElement;
}
+2 -2
View File
@@ -4,7 +4,7 @@
"A/full/head": "e030d61f8d2aa9c5",
"A/full/spread/0": "6036ca6b48d6e248",
"A/full/spread/1": "bf4b62404c36aa0e",
"A/full/spread/2": "688f4ce239f0eb65",
"A/full/spread/2": "9b59b4cb758c2f63",
"A/full/spread/3": "3bc5ecd3ad02ad83",
"A/full/spread/4": "6fdb7d865a3534c5",
"A/full/spread/5": "79c58347ba49449c",
@@ -33,7 +33,7 @@
"A/plain/head": "e030d61f8d2aa9c5",
"A/plain/spread/0": "6036ca6b48d6e248",
"A/plain/spread/1": "bf4b62404c36aa0e",
"A/plain/spread/2": "688f4ce239f0eb65",
"A/plain/spread/2": "9b59b4cb758c2f63",
"A/plain/spread/3": "3bc5ecd3ad02ad83",
"A/plain/spread/4": "6fdb7d865a3534c5",
"A/plain/spread/5": "637abb25cc53282f",
+42 -3
View File
@@ -359,16 +359,23 @@ describe('the scope of a map', () => {
const iceland = bookTravelMap(ctx, stats, { id: 'mp-c', frame, scope: { country: 'is' } });
expect(valid(iceland)).toBe(true);
expect(iceland).toMatchObject({ country: 'IS', countries: ['IS'], tripId: null, path: [] });
expect(iceland).not.toHaveProperty('stop');
expect(iceland).toMatchObject({ stop: null, dayDate: null });
expect(refreshPatch(iceland, stats)).toMatchObject({ countries: ['IS'] });
expect(refreshPatch(iceland, stats)).not.toHaveProperty('country');
const day = bookTravelMap(ctx, dated, { id: 'mp-d', frame, scope: { dayDate: '2026-06-06', tripId: 11 } });
expect(day).toMatchObject({ dayDate: '2026-06-06', tripId: 11, countries: ['IS'] });
expect(day.points.map((p) => p.label)).toEqual(['Akureyri']);
expect(isStale(day, dated)).toBe(false);
// A map of the whole journey or of a trip writes nothing new: what it wrote before revision 12.
// A map of the whole journey or of a trip says so too, so it is never read as a map saved before revision 12.
const whole = bookTravelMap(ctx, stats, { id: 'mp-w', frame, scope: 'journey' });
for (const key of ['stop', 'country', 'dayDate', 'view', 'coastDetail']) expect(whole).not.toHaveProperty(key);
expect(whole).toMatchObject({ stop: null, country: null, dayDate: null, tripId: null });
for (const key of ['view', 'coastDetail']) expect(whole).not.toHaveProperty(key);
expect(bookTravelMap(ctx, stats, { id: 'mp-t', frame, scope: { tripId: 11 } })).toMatchObject({
tripId: 11,
stop: null,
country: null,
dayDate: null,
});
});
it('BOOKTRV-017: widens a map to the journey only when it is told it is of the journey', () => {
@@ -379,6 +386,38 @@ describe('the scope of a map', () => {
expect(routeFor(stats, null)).toContainEqual(lisboa);
});
it('BOOKTRV-019: keeps a new map of a one-country journey the journey once it reaches a second country', () => {
const iceland = { ...stats, countries: stats.countries.slice(0, 1), points: stats.points.slice(0, 2) };
const placed = bookTravelMap({ ...ctx, path: [] }, iceland, { id: 'mp-w', frame, scope: 'journey' });
expect(placed.path).toEqual([]);
// Read back from the store, as the next session gets it.
const saved = bookMapElementSchema.parse(JSON.parse(JSON.stringify(placed)));
expect(bookMapScopeOf(saved, stats)).toMatchObject({ country: null, stop: null, inferred: false });
expect(isStale(saved, stats)).toBe(true);
expect((refreshPatch(saved, stats) as { countries: string[] }).countries).toEqual(['IS', 'PT']);
// One stop at first is no different.
const first = { ...iceland, points: stats.points.slice(0, 1) };
const single = bookTravelMap({ ...ctx, path: [] }, first, { id: 'mp-1', frame, scope: 'journey' });
expect((refreshPatch(single, stats) as { points: unknown[] }).points).toHaveLength(3);
});
it('BOOKTRV-020: writes down a plain scope of an old map, and leaves an ambiguous one to be read', () => {
// A trip map and a tracked journey map from before revision 12 settle as what they are.
const oldTrip = asMap({ tripId: 11, countries: ['IS'], points: [point(reykjavik), point(akureyri)] });
expect(refreshPatch(oldTrip, stats)).toMatchObject({ country: null, dayDate: null, stop: null });
const tracked = asMap({
countries: ['IS', 'PT'],
points: [point(reykjavik), point(akureyri), point(lisboa)],
path: [[[64, -21]]],
});
expect(refreshPatch(tracked, stats)).toMatchObject({ country: null, dayDate: null, stop: null });
// An old country map is read as its country and says so from then on.
expect(refreshPatch(oldCountryMap, stats)).toMatchObject({ country: 'IS', dayDate: null, stop: null });
// Two stops in one country on a one-country journey could be the country's map or the journey's: not settled.
const oneCountry = { ...stats, countries: stats.countries.slice(0, 1) };
expect(refreshPatch(oldCountryMap, oneCountry)).not.toHaveProperty('country');
});
it('BOOKTRV-018: finds the stop of an entry on the route, else where the entry says, else none', () => {
expect(bookMapStopFor(stats, [], 3)).toEqual({ entryId: 3, lat: 38.72, lng: -9.14 });
expect(bookMapStopFor(null, [entry], 2)).toEqual({ entryId: 2, lat: 65.68, lng: -18.12 });
+24 -9
View File
@@ -195,13 +195,28 @@ function mapCountries(stats: JourneyStats, whole: boolean, route: readonly Journ
const mapPoints = (route: readonly JourneyStatsPoint[]) =>
route.map((p) => ({ lat: p.lat, lng: p.lng, label: p.label, photoId: p.photoId ?? null }));
/** What a map of these parts writes down beside its stops: only the parts that narrow it. */
function scopeFields(parts: BookMapScopeParts): Pick<Partial<BookMapElement>, 'country' | 'dayDate' | 'stop'> {
return {
...(parts.country ? { country: parts.country } : {}),
...(parts.dayDate ? { dayDate: parts.dayDate } : {}),
...(parts.stop ? { stop: parts.stop } : {}),
};
/**
* What a map of these parts writes down beside its stops: every part, null
* where it does not narrow the map. A map of the whole journey says so too,
* since a map without the fields reads as one saved before revision 12 and
* has its scope guessed off what it holds (`bookMapScopeOf`).
*/
function bookMapScopeFields(
parts: Pick<BookMapScopeParts, 'country' | 'dayDate' | 'stop'>,
): Pick<BookMapElement, 'country' | 'dayDate' | 'stop'> {
return { country: parts.country ?? null, dayDate: parts.dayDate ?? null, stop: parts.stop ?? null };
}
/**
* Whether a refresh writes an old map's scope down: when it was read off the
* map, and when the map plainly is of its trip or of the journey (several
* stops across several countries, or a recorded track). A map that could be
* either a country's or a one-country journey's keeps being read afresh.
*/
function settlesScope(el: BookMapElement, scope: BookMapScopeParts & { inferred: boolean }): boolean {
if (!fromBeforeScopes(el)) return false;
if (scope.inferred || scope.tripId != null) return true;
return el.points.length > 1 && (el.countries.length > 1 || el.path.length > 0);
}
/** A map of one stop brought up to date: the stop where it is now, and its picture where it had one. */
@@ -246,7 +261,7 @@ export function refreshPatch(el: BookElement, stats: JourneyStats): Partial<Book
const countries = scope.country ? [scope.country] : mapCountries(stats, whole, live);
return {
stale: false,
...(scope.inferred ? scopeFields(scope) : {}),
...(settlesScope(el, scope) ? bookMapScopeFields(scope) : {}),
countries: countries.slice(0, MAX_BOOK_COUNTRIES),
points: mapPoints(live.slice(0, MAX_MAP_POINTS)),
};
@@ -426,7 +441,7 @@ export function bookTravelMap(
fitToCountries: true,
clip: 'rect',
tripId,
...scopeFields(parts),
...bookMapScopeFields(parts),
};
}
@@ -13,7 +13,7 @@
"A/fabric-classic/spread/17": "78ae60620ae287a3",
"A/fabric-classic/spread/18": "c73e813888a28cd1",
"A/fabric-classic/spread/19": "d98cc9a891bf2141",
"A/fabric-classic/spread/2": "8278d3c2507527f9",
"A/fabric-classic/spread/2": "54976a0fe368700e",
"A/fabric-classic/spread/20": "e1dfa3eeb056189b",
"A/fabric-classic/spread/21": "b18be5f5e1696caf",
"A/fabric-classic/spread/22": "98a8cab370aeb8fa",
@@ -40,7 +40,7 @@
"A/midnight/spread/17": "f75b6c80be848ac6",
"A/midnight/spread/18": "029d7d07ce5cb3c3",
"A/midnight/spread/19": "14c04aa51da497cd",
"A/midnight/spread/2": "b00839cd0dc1451b",
"A/midnight/spread/2": "9ab1311ab2e302f0",
"A/midnight/spread/20": "ea8aa8da12cad00a",
"A/midnight/spread/21": "68057d81fd4903b4",
"A/midnight/spread/22": "eba329fd185958b3",
@@ -66,7 +66,7 @@
"A/riso/spread/17": "00caa407cb2a0677",
"A/riso/spread/18": "def2a9dde53f3e26",
"A/riso/spread/19": "3cea577870cdc23d",
"A/riso/spread/2": "5c9a93de9e6467d6",
"A/riso/spread/2": "47f09dd598f42d12",
"A/riso/spread/20": "c851d704ccca068e",
"A/riso/spread/21": "be8c5194461daa01",
"A/riso/spread/22": "dcd4a1dfde54cef9",
@@ -83,7 +83,7 @@
"B/fabric-classic/plan": "cae85517611abbca",
"B/fabric-classic/spread/0": "9da4b641b0f81264",
"B/fabric-classic/spread/1": "b3f8e9c5043f8302",
"B/fabric-classic/spread/2": "61f0914a7ee1fabf",
"B/fabric-classic/spread/2": "773b5fdc1963be20",
"B/fabric-classic/spread/3": "bdb01dc38f94e0d0",
"B/fabric-classic/spread/4": "4e949ebeb4098598",
"B/fabric-classic/spread/5": "fa7289a87111f6a2",
@@ -96,7 +96,7 @@
"B/midnight/spread/0": "ee90988cd45ab2c4",
"B/midnight/spread/1": "d9f5d78659332b45",
"B/midnight/spread/10": "db97ebe8475e0371",
"B/midnight/spread/2": "4fd4d34f9ab77551",
"B/midnight/spread/2": "34374c17845aac96",
"B/midnight/spread/3": "b9fb3f915cffb57d",
"B/midnight/spread/4": "9f0467b6921de638",
"B/midnight/spread/5": "7e3d7de6ef19180c",
@@ -108,7 +108,7 @@
"B/riso/plan": "d8906a53b3532db8",
"B/riso/spread/0": "867edf084f05a873",
"B/riso/spread/1": "8de92788de29277b",
"B/riso/spread/2": "66790d2283ba2f77",
"B/riso/spread/2": "99f873ffdb05d891",
"B/riso/spread/3": "1fc8aedc7486cbeb",
"B/riso/spread/4": "cedfcf22d3331d4a",
"B/riso/spread/5": "51562d8f08f46011",
@@ -175,8 +175,8 @@
"D/fabric-classic/spread/14": "8ed5b5e96e4f5696",
"D/fabric-classic/spread/15": "b11b5b3fb34a34eb",
"D/fabric-classic/spread/16": "c40cdcb18e2ef0bc",
"D/fabric-classic/spread/2": "86dd9a101af346f4",
"D/fabric-classic/spread/3": "1433b8ee15387e1b",
"D/fabric-classic/spread/2": "467a575cfd3d8bf1",
"D/fabric-classic/spread/3": "b24a716729d46bde",
"D/fabric-classic/spread/4": "9fcb7ff2c09e7e05",
"D/fabric-classic/spread/5": "512f64afa749875d",
"D/fabric-classic/spread/6": "d909172ca9306881",
@@ -197,8 +197,8 @@
"D/midnight/spread/17": "69924ede00c784f9",
"D/midnight/spread/18": "eba329fd185958b3",
"D/midnight/spread/19": "6e6e6c877443c5e7",
"D/midnight/spread/2": "cef4235690d44e53",
"D/midnight/spread/3": "3922eeb7ddb4c95a",
"D/midnight/spread/2": "43e6d3f330ff2853",
"D/midnight/spread/3": "ce2d004929a505c7",
"D/midnight/spread/4": "f332e826ccb518b8",
"D/midnight/spread/5": "545524d900a6d68e",
"D/midnight/spread/6": "ea5db0eab1087429",
@@ -217,8 +217,8 @@
"D/riso/spread/15": "4be16c00138d027d",
"D/riso/spread/16": "a748ada7a028818e",
"D/riso/spread/17": "ed87c0a4c77f241c",
"D/riso/spread/2": "78f24755fb7ad38a",
"D/riso/spread/3": "d26d68d5f33114d7",
"D/riso/spread/2": "213f7602498daa4d",
"D/riso/spread/3": "730b58ea47db248e",
"D/riso/spread/4": "42d13c4cc22154a9",
"D/riso/spread/5": "c2dcc1ba31041587",
"D/riso/spread/6": "93846db9c48faa0f",
@@ -230,6 +230,11 @@ describe('pouring a page into a template', () => {
const map = out.elements.find((e) => e.kind === 'map');
expect(map).toMatchObject({ countries: ['PT'], style: 'minimal' });
expect(map?.kind === 'map' && map.points[0]?.label).toBe('Lisbon');
// What the page's map is of and the ground it was framed to go into the template with its stops.
const view = { west: -10, south: 38, east: -8, north: 40 };
const lisbon = bookMapElementSchema.parse({ ...own, country: 'PT', dayDate: null, stop: null, view });
const poured = lay(page('inner', [lisbon, photo('ph1', 51)]), 'map-tickets').elements.find((e) => e.kind === 'map');
expect(poured).toMatchObject({ country: 'PT', dayDate: null, stop: null, view, points: [{ label: 'Lisbon' }] });
const mapless = lay(
page(
'inner',
+24 -1
View File
@@ -74,7 +74,30 @@ function pouredMap(
(travel?.stats ? bookTravelMap(travel, travel.stats, { id: slot.id, frame: slot.frame, scope: 'journey' }) : null);
if (!from) return null;
const { countries, points, path, roads, tripId, source, tileUrl, attribution, zoom } = from;
return { ...slot, countries, points, path, roads, tripId, source, tileUrl, attribution, zoom };
/*
* What the map is of and the ground it was framed to travel with its stops
* (revision 12), or a country map poured into the template would come out
* as a map of nothing in particular, and the first refresh would widen it.
* A field the map never had stays absent, so an older map is still read off
* what it holds.
*/
const { country, dayDate, stop, view } = from;
return {
...slot,
countries,
points,
path,
roads,
tripId,
source,
tileUrl,
attribution,
zoom,
country,
dayDate,
stop,
view,
};
}
/** A role's text in the template's look, set in the page's words and keeping their link to the journal. */
@@ -102,7 +102,15 @@ describe('a drawn page as a template', () => {
fillPaint: { type: 'photo', photoId: 5 },
}),
bookTextElementSchema.parse({ id: 'c', kind: 'text', frame, text: '“' }),
bookMapElementSchema.parse({ id: 'd', kind: 'map', frame, countries: ['PT'], tileUrl: 'https://tiles' }),
bookMapElementSchema.parse({
id: 'd',
kind: 'map',
frame,
countries: ['PT'],
tileUrl: 'https://tiles',
stop: { entryId: 4, lat: 38.7, lng: -9.1 },
view: { west: -10, south: 38, east: -8, north: 40 },
}),
bookShapeElementSchema.parse({ id: 'e', kind: 'shape', frame, hidden: true }),
];
const tpl = bookTemplateFromSpread(spreadOf('cover', els), square, meta);
@@ -112,6 +120,8 @@ describe('a drawn page as a template', () => {
expect(title).toMatchObject({ kind: 'text', text: '', binding: null, fillPaint: null, fillPhoto: 'photo:1' });
expect(quote).toMatchObject({ kind: 'text', text: '“' });
expect(map).toMatchObject({ kind: 'map', countries: [], tileUrl: '', role: 'map' });
// Where the map was and what of are the journey's, not the template's.
for (const key of ['stop', 'country', 'dayDate', 'view']) expect(map).not.toHaveProperty(key);
expect(tpl.kind).toBe('single');
expect(tpl.labelKey).toBe('studio.templates.name.drawnOne');
});
@@ -165,8 +165,11 @@ function frameToFractions(el: BookElement, keep: boolean, m: Measures) {
/** The content taken out of an element that takes a role: its picture, its words, its journey. */
function withoutContent(out: Loose, role: BookTemplateRole | undefined): void {
if (out.kind === 'photo') out.photoId = null;
if (out.kind === 'map')
if (out.kind === 'map') {
Object.assign(out, { countries: [], points: [], path: [], roads: [], tileUrl: '', attribution: '' });
// What the map was of and where it was framed are the journey's too: a stop's place, a country, a day.
for (const key of ['stop', 'country', 'dayDate', 'view']) delete out[key];
}
if (out.kind === 'text' && role && (BOOK_TEMPLATE_TEXT_ROLES as readonly string[]).includes(role)) {
Object.assign(out, { text: '', binding: null, overridden: false });
}