Skip to content

Commit dccd6a7

Browse files
san360Copilot
andcommitted
fix(timeline): open Timeline links on load, keep picked dates without activity
- A #view=… address opens the Timeline at that view on load, without a click on the sidebar; leaving the Timeline clears it, so a reload elsewhere doesn't reopen the Timeline. - A picked or restored date within the loaded days stays when the Timeline loads again, with or without activity; only a missing, invalid or out-of-range date falls back to the nearest active day. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 1d018bd commit dccd6a7

4 files changed

Lines changed: 60 additions & 9 deletions

File tree

‎docs/content/observe/timeline.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Click the date at the top to open a calendar:
2525

2626
A range is drawn whole: its axis marks every 6 hours over two or three days, each day up to two weeks, every other day up to a month, then each Monday. The lanes, KPIs, callouts, impact table and the strip's highlight all describe the range. Over more than a month the lanes get dense, and the page suggests picking fewer days.
2727

28-
The view is kept by its dates, so reopening the dashboard shows it again; in a browser, the address holds it as a link, for example `#view=range&from=2026-11-10&to=2026-11-17` (also `#view=day&date=…`, `#view=week&date=…` and `#view=families`). A linked range is kept within the loaded days; one with no loaded day opens the Day view.
28+
The view is kept by its dates, so reopening the dashboard shows it again, also a picked day with no activity. In a browser, the address holds it as a link that opens the Timeline at that view, for example `#view=range&from=2026-11-10&to=2026-11-17` (also `#view=day&date=…`, `#view=week&date=…` and `#view=families`). A linked range is kept within the loaded days; one with no loaded day opens the Day view.
2929

3030
## Definitions
3131

‎src/webview/app.ts‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,16 @@ if (!FF_TOKEN_REPORTING_ENABLED) {
5858
}
5959

6060
/* ---- Global state ---- */
61-
let currentPage = new URLSearchParams(window.location.search).get('page') === 'curiosity' ? 'curiosity' : 'dashboard';
61+
/** A Timeline link in the address (`#view=range&from=…&to=…`, or a day, week or the families). */
62+
const TIMELINE_LINK = /^#view=(day|week|range|families)(&|$)/;
63+
64+
/** The page the dashboard opens on: the one its address names, else the Dashboard. */
65+
function startPage(): string {
66+
if (new URLSearchParams(window.location.search).get('page') === 'curiosity') return 'curiosity';
67+
return TIMELINE_LINK.test(window.location.hash) ? 'timeline' : 'dashboard';
68+
}
69+
70+
let currentPage = startPage();
6271
const currentFilter: DateFilter = {};
6372
let _dataIsReady = false;
6473
let matchedWorkspaceId: string | undefined;
@@ -436,6 +445,14 @@ export function navigateTo(page: string): void {
436445
page = normalizePageForFeatureFlags(page);
437446
if (!llmAvailable() && (page === 'skills' || page === 'level-up')) page = 'dashboard';
438447
currentPage = page;
448+
// A Timeline link names the Timeline's view; on another page it would open the Timeline again on reload.
449+
if (page !== 'timeline' && TIMELINE_LINK.test(window.location.hash)) {
450+
try {
451+
history.replaceState(history.state, '', window.location.pathname + window.location.search);
452+
} catch {
453+
// A host that doesn't allow it keeps the address as it is.
454+
}
455+
}
439456
document.body.classList.toggle('github-app-view', isGitHubAppPage(page));
440457
for (const a of $$<HTMLAnchorElement>('.nav-links a')) a.classList.toggle('active', a.dataset.page === page);
441458
void renderPage(page);

‎src/webview/page-timeline.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,11 @@ export async function renderTimeline(container: HTMLElement, currentFilter: Date
115115
rootEl = root;
116116
root.replaceChildren();
117117
applyNavHint(consumeNavHint() ?? firstLoadLink(), loaded.prepared);
118-
if (!loaded.prepared.days.includes(state.date)) state.date = nearestDay(state.date, loaded.prepared.days, loaded.prepared.bounds[0]);
118+
// A picked date stays, with or without activity, while it's within the loaded days; else the nearest active day.
119+
const [lo, hi] = selectable(loaded.prepared);
120+
if (!isDate(state.date) || state.date < lo || state.date > hi) {
121+
state.date = nearestDay(state.date, loaded.prepared.days, loaded.prepared.bounds[0]);
122+
}
119123
keepRange(loaded.prepared);
120124
draw();
121125
}

‎tests/e2e/timeline-range.spec.ts‎

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { harnessUrl } from './harness-url';
55

66
const HARNESS_URL = harnessUrl();
77

8-
async function openTimeline(page: Page, hash = ''): Promise<void> {
9-
await page.goto(HARNESS_URL + hash);
8+
async function openTimeline(page: Page): Promise<void> {
9+
await page.goto(HARNESS_URL);
1010
await page.waitForFunction(() => {
1111
const content = document.getElementById('content');
1212
return content && content.innerHTML.length > 200 && !content.querySelector('.loading-spinner') && !content.querySelector('.error-boundary');
@@ -135,24 +135,54 @@ test.describe('Timeline date picker', () => {
135135
await page.mouse.click(5, 5);
136136
await expect(page.locator('#tlxCal')).toHaveCount(0);
137137
});
138+
139+
test('keeps a picked date without activity when the Timeline loads again', async ({ page }) => {
140+
type MockWindow = { mockTimelineData: () => { sessions: { turns: { t: number }[] }[] }; mockTimelineDataOverride?: unknown };
141+
// Activity on 2, 3 and 17 May: 11 May lies between, with none.
142+
await page.evaluate(() => {
143+
const w = window as unknown as MockWindow;
144+
const data = w.mockTimelineData();
145+
const flaky = data.sessions[5];
146+
w.mockTimelineDataOverride = { ...data, sessions: [...data.sessions, { ...flaky, id: 'tl-late', turns: [{ ...flaky.turns[0], t: new Date(2026, 4, 17, 10).getTime() }] }] };
147+
});
148+
await page.locator('[data-page="dashboard"]').first().click();
149+
await page.locator('[data-page="timeline"]').first().click();
150+
await page.locator('#tlxView button[data-value="week"]').click();
151+
await page.locator('#tlxDateLabel').click();
152+
await day(page, '2026-05-11').click();
153+
await expect(page.locator('#tlxDateLabel')).toContainText('May 11 – May 17, 2026');
154+
await page.locator('[data-page="dashboard"]').first().click();
155+
await page.locator('[data-page="timeline"]').first().click();
156+
await expect(page.locator('#tlxDateLabel')).toContainText('May 11 – May 17, 2026');
157+
});
138158
});
139159

160+
/** Opens the dashboard at a Timeline link, as a copied link would: no click on the sidebar. */
161+
async function openLink(page: Page, hash: string): Promise<void> {
162+
await page.goto(HARNESS_URL + hash);
163+
await expect(page.locator('#tlxKpis')).toBeVisible({ timeout: 10000 });
164+
}
165+
140166
test.describe('Timeline range links', () => {
141-
test('opens a range from its link and keeps it in the address', async ({ page }) => {
142-
await openTimeline(page, '#view=range&from=2026-05-02&to=2026-05-03');
167+
test('opens the Timeline at a range from its link, and keeps the view in the address', async ({ page }) => {
168+
await openLink(page, '#view=range&from=2026-05-02&to=2026-05-03');
169+
await expect(page.locator('.nav-links a.active[data-page="timeline"]')).toHaveCount(1);
143170
await expect(page.locator('#tlxView button[data-value="range"]')).toHaveAttribute('aria-pressed', 'true');
144171
await expect(kpi(page, 'Turns you typed')).toHaveText('7 of 14');
145172
await page.locator('#tlxView button[data-value="week"]').click();
146173
await expect(page).toHaveURL(/#view=week&date=2026-05-03$/);
174+
// On another page the address no longer names a Timeline view.
175+
await page.locator('[data-page="dashboard"]').first().click();
176+
await expect(page).not.toHaveURL(/#view=/);
147177
});
148178

149179
test('cuts a linked range to the loaded days', async ({ page }) => {
150-
await openTimeline(page, '#view=range&from=2026-04-20&to=2026-05-02');
180+
await openLink(page, '#view=range&from=2026-04-20&to=2026-05-02');
151181
await expect(page).toHaveURL(/#view=range&from=2026-05-02&to=2026-05-02$/);
152182
});
153183

154184
test('opens the Day view for a linked range with no loaded day', async ({ page }) => {
155-
await openTimeline(page, '#view=range&from=2026-01-01&to=2026-01-31');
185+
await openLink(page, '#view=range&from=2026-01-01&to=2026-01-31');
156186
await expect(page.locator('#tlxView button[data-value="day"]')).toHaveAttribute('aria-pressed', 'true');
157187
await expect(page).toHaveURL(/#view=day&date=2026-05-03$/);
158188
});

0 commit comments

Comments
 (0)