mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 23:52:24 +00:00
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:
1 parent
0ff1340ff4
commit
dc86c42bef
7 files changed
+156
-12
No files matched your search
@@ -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) =>
|
||||
|
||||
Reference in new issue
Block a user