Skip to content

feat(frontend): Trends view consuming GET /api/analytics/trends #30

Closed

Description

@cristim

Problem

The savings-snapshot historical time-series is now collected and exposed via
GET /api/analytics/trends (PR for LeanerCloud/cloud-commitments-cli#1023/#1033), but there is no frontend view
consuming it. Users cannot yet see coverage %, utilization, committed spend, or
realized savings over time by account/provider/service.

Proposed work

Add a basic "Trends" view in frontend/src that consumes
/api/analytics/trends:

  • Render the monthly series (coverage %, committed spend, usage, realized
    savings) and the by-provider / by-service breakdowns.
  • Account scoping: pass the top-bar chip account_id through to the endpoint
    (the backend already enforces allowed_accounts scope).
  • Escape every API field rendered into any innerHTML template via
    escapeHtml() (feedback_innerhtml_xss).
  • Install event listeners once per element (stored ref / AbortController), never
    re-add on a repeatedly-called render (feedback_event_listener_dedup).
  • Do NOT touch frontend/src/dashboard.ts ServiceSavings or
    handler_dashboard.go / types.go ServiceSavings (owned elsewhere).

References

Filed as the deferred frontend follow-up noted in the analytics historical-savings PR.

Activity

  1. IAmJSD commented on Oct 24, 2026

    @IAmJSD
    Collaborator

    Claiming: working on this

  2. self-assigned this
    on Oct 24, 2026
  3. IAmJSD commented on Oct 28, 2026

    @IAmJSD
    Collaborator

    Status update (2026-10-28): #1563 merged: each monthly row of GET /api/analytics/trends now has total_commitment (upfront amortized per month) and total_usage (recurring fees), with unknown kept unknown. Committed spend is their sum.

    Left: showing them on the Trends view (UI owner), and a coverage data source (design call: the collector has no on-demand baseline).

  4. cristim commented on Nov 11, 2026

    @cristim
    MemberAuthor

    Claimed by claude-platform-2.

  5. cristim commented on Nov 11, 2026

    @cristim
    MemberAuthor

    Checked against main: the Trends view already exists (trends.ts, #1317 and later fixes, a sub-tab of Inventory & Coverage). Landed a503e37 (Part of #30): the monthly table now shows Committed spend (total_commitment + total_usage per month; unknown when any bucket is missing either part, never 0). Remaining: the coverage data source (the collector writes coverage_percentage nil because purchase_history has no on-demand baseline), which is a design call. Releasing my claim (claude-platform-2).

  6. cristim commented on Nov 12, 2026

    @cristim
    MemberAuthor

    Verified on origin/main 447a98b: the Trends view is met.

    • Consumes the endpoint: frontend/src/api/analytics.ts (GET /analytics/trends), frontend/src/trends.ts:83-99 passes the chip account_id(s), provider and window.
    • Monthly series (savings, committed spend, coverage) and by-provider / by-service tables: trends.ts:139-180; chart in trends.ts. Tab: frontend/src/index.html:321 and :361.
    • XSS: trends.ts:10 builds everything with DOM methods and textContent, never innerHTML.
    • Listener dedup: trends.ts:61-70 wires change/click once per element via data-wired.
    • Landed in e3f2062 (feat(frontend): add a Trends sub-tab for the analytics trends endpoint).
      Closing as completed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions