feat(timeline): fit the default window to the record

Without a zoom in the URL the window now follows the record: one that
starts inside the last three months opens on three months clamped to
its first entry (at least four weeks up to today), an older one with
entries there opens on three months, an older one without opens on
everything, and an empty one keeps the empty state. The choice is made
from the first answer before anything is drawn, so the page does not
jump between windows.
This commit is contained in:
Marc-André Bombeck committed 2026-10-11 15:08:57 +02:00
1 parent 0ff1340ff4
commit dc86c42bef
7 files changed
+156 -12

No files matched your search

+11 -3
View File
@@ -826,12 +826,15 @@ export interface TimelineMockLog {
* `onlyOld`: the record's entries all lie before the last year, so a
* quarter or year window answers empty (with the record's `dataFrom`) and
* only everything, or a chosen range, carries them.
*
* `dataFrom`: the record's first entry as the answers name it, to stand in
* for a young record.
*/
export async function mockTimeline(
page: Page,
state: "full" | "ready",
today: string,
options: { onlyOld?: boolean } = {},
options: { onlyOld?: boolean; dataFrom?: string } = {},
): Promise<TimelineMockLog> {
const log: TimelineMockLog = { timelineQueries: [], lifeEventPosts: [] };
await page.route(/\/api\/timeline\/readiness(\?|$)/, (route) =>
@@ -848,7 +851,8 @@ export async function mockTimeline(
const from = url.searchParams.get("from");
const to = url.searchParams.get("to");
const bucket = bucketFor(zoom, from, to);
const dataFrom = state === "full" ? "2019-01-01" : "2024-05-01";
const dataFrom =
options.dataFrom ?? (state === "full" ? "2019-01-01" : "2024-05-01");
if (options.onlyOld && (zoom === "quarter" || zoom === "year")) {
return json(route, 200, {
...body,
@@ -870,7 +874,11 @@ export async function mockTimeline(
...body,
zoom,
bucket,
...(chosen ? { range: { from, to, dataFrom } } : {}),
...(chosen
? { range: { from, to, dataFrom } }
: options.dataFrom
? { range: { ...body.range, dataFrom } }
: {}),
// Any other value the menu offers answers a flat line of its own.
series: values.map(
(key) =>