Skip to content

fix(ui): route tag clicks to /plots and track tag_click on /stats#7516

Merged
MarkusNeusinger merged 3 commits into
mainfrom
fix/tag-link-routes-to-plots
May 20, 2026
Merged

fix(ui): route tag clicks to /plots and track tag_click on /stats#7516
MarkusNeusinger merged 3 commits into
mainfrom
fix/tag-link-routes-to-plots

Conversation

@MarkusNeusinger
Copy link
Copy Markdown
Owner

Summary

  • Tag chips on spec/impl detail (under the image) and on /stats (tag distribution block) built URLs as /?<param>=<value>. Since the page split, / is LandingPage and only /plots handles filter query params, so the links broke. Route them to /plots instead.
  • StatsPage was silent on tag_click while SpecTabs already fired it — added the event with source: 'stats' so Plausible coverage matches the spec.
  • Drive-by: crypto was missing from the eslint browser-globals list, making FeedbackWidget.tsx's crypto.randomUUID()/getRandomValues() fail no-undef. Added it.

Files

  • app/src/components/SpecTabs.tsxhandleTagClick now navigates to /plots?…. Covers both spec-overview and impl-detail (both routes go through SpecPage<SpecTabs>).
  • app/src/pages/StatsPage.tsx — link target → /plots, encodeURIComponent on the value, fire tag_click with source: 'stats'.
  • docs/reference/plausible.mdtag_click source list now includes StatsPage.tsx and documents source ∈ spec_detail, stats.
  • app/eslint.config.jscrypto: 'readonly' added to browser globals.

Test plan

  • On a spec page (e.g. /scatter-basic), click a tag chip under the image → URL is /plots?<param>=<value>, grid is filtered, Plausible fires tag_click with source: spec_detail.
  • On an impl page (e.g. /scatter-basic/python/matplotlib), repeat → same behaviour (same component, but verify explicitly).
  • On /stats, click a tag in the tag-distribution block → URL is /plots?<param>=<value>, grid is filtered, Plausible fires tag_click with source: stats.
  • Tag with a special character (e.g. with + or a space) URL-encodes correctly.
  • yarn tsc --noEmit, yarn lint, yarn test all clean.

🤖 Generated with Claude Code

Tag chips on the spec/impl detail page and on the /stats tag-distribution
block built URLs as /?<param>=<value>. Since the page split, / is the
LandingPage and no longer accepts filter query params — only /plots does.
The links resolved to the landing page with stray query params and lost
the filter intent.

Fixes:
- SpecTabs.handleTagClick: navigate("/plots?…") instead of "/?…". One
  call site covers both spec-overview and impl-detail since SpecPage
  mounts <SpecTabs> for both router modes.
- StatsPage tag links: target /plots, encodeURIComponent the value, and
  fire `tag_click` with `source: 'stats'` (StatsPage was silent on this
  event — only spec_detail was tracked before).
- docs/reference/plausible.md: list StatsPage.tsx as a tag_click source
  and document the `source ∈ spec_detail, stats` enum.

Drive-by: add `crypto` to the eslint browser-globals list so
FeedbackWidget.tsx (uses crypto.randomUUID / getRandomValues) stops
failing `no-undef`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 20, 2026 12:29
@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes broken tag-filter links after the landing page split by routing tag clicks from spec/impl detail views and the stats tag distribution to /plots, and aligns analytics coverage by emitting tag_click from the Stats page.

Changes:

  • Update SpecTabs tag-chip navigation to /plots?... instead of /?....
  • Update StatsPage tag links to /plots?..., URL-encode tag values, and emit tag_click with source: 'stats'.
  • Update Plausible event reference docs and add crypto to ESLint browser globals to satisfy no-undef.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
docs/reference/plausible.md Documents tag_click sources and includes StatsPage as an emitter.
app/src/pages/StatsPage.tsx Routes tag links to /plots, URL-encodes tag values, and tracks tag_click from stats.
app/src/components/SpecTabs.tsx Routes spec/impl tag-chip navigation to /plots?... while keeping analytics tracking.
app/eslint.config.js Adds crypto to browser globals to avoid no-undef for Web Crypto usage.

Comment on lines 466 to +470
<Link
key={tag}
component={RouterLink}
to={param ? `/?${param}=${tag}` : '/'}
to={param ? `/plots?${param}=${encodeURIComponent(tag)}` : '/plots'}
onClick={() => { if (param) trackEvent('tag_click', { param, value: tag, source: 'stats' }); }}
MarkusNeusinger and others added 2 commits May 20, 2026 14:35
Addresses Copilot review feedback on #7516: the StatsPage tag-link
behavior changed in the parent commit had no test coverage (also flagged
by codecov/patch/frontend). Adds one test that locks in:
- the link's href is /plots?plot=scatter (regression guard for the
  pre-fix /?plot=scatter that silently dropped the filter intent), and
- clicking fires trackEvent('tag_click', { param, value, source: 'stats' }).

The useAnalytics mock is hoisted into a module-level mockTrackEvent so
the assertion can see the call. Cleared per test via mockClear() because
vi.restoreAllMocks() does not reset hoisted vi.fn() instances on its own.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The prior test asserted href === '/plots?plot=scatter', which proves
the /plots routing but does not exercise encodeURIComponent — 'scatter'
has no special chars, so the assertion would still pass if the encoding
were removed.

Copilot's review explicitly called out '/plots?{param}={encodedTag}',
so add a 'time series' tag (space in the value) under data_type. The
new assertion locks in href === '/plots?data=time%20series', which
fails the moment encodeURIComponent is dropped from the source. Also
clicks both links and asserts trackEvent receives the raw (unencoded)
value, matching the documented plausible.md contract.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 20, 2026 12:42
@MarkusNeusinger MarkusNeusinger merged commit bab3e3d into main May 20, 2026
11 checks passed
@MarkusNeusinger MarkusNeusinger deleted the fix/tag-link-routes-to-plots branch May 20, 2026 12:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants