Skip to content

fix: generalize access-request service classification and stat cards in static analytics template #4922

Description

@frano-m

Part of the triage of #4909 (items 1–4). All four findings live in the same ~90 lines of the shared static analytics template (analytics/analytics_package/analytics/static_site/template/index.html), so they are fixed together.

Problems

  1. Hardcoded stat cards (index.html:898-921): the access-requests stats grid renders exactly three cards — dbGaP, DUOS, Total — while the serviceName()/services-Set mechanism is generic over N services. A third or unclassified service is counted in Total but gets no card, so the cards visibly fail to sum.
  2. serviceName() fallback (index.html:365-369): returns "" for a missing click_url and the raw URL for unknown hosts, so every distinct unknown URL counts as a separate "service" in the showService gate.
  3. Case-sensitivity asymmetry: serviceName() matches duos.org / dbgap.ncbi.nlm.nih.gov case-sensitively, while the Python generator filters click URLs case-insensitively (fetch.py:188, str.contains(..., case=False)). A mixed-case URL passes the generator but fails JS classification.
  4. Non-array guard + un-awaited render (index.html:887 / index.html:419): the !data || data.length === 0 guard passes a non-array object, which then crashes at data.reduce; the call site is un-awaited, so the rejection bypasses loadData's error UI — silent failure.

Fix

  • Make serviceName() case-insensitive, normalize unknown hosts to hostname, and bucket missing/unparseable URLs.
  • Reduce access-request rows into a service→count map and render one stat card per present service (plus Total).
  • Guard with Array.isArray, and await the call so failures surface through loadData's error handling.

Found during review of anvilproject/anvil-portal#4075; the fix belongs here in the shared template, not per-site copies.

Activity

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions