Skip to content

feat: pool health score widget with trend indicators and suggestions - #245

Open
benzy018 wants to merge 2 commits into
JointSave-org:mainfrom
benzy018:feat/pool-health-score-widget
Open

feat: pool health score widget with trend indicators and suggestions#245
benzy018 wants to merge 2 commits into
JointSave-org:mainfrom
benzy018:feat/pool-health-score-widget

Conversation

@benzy018

Copy link
Copy Markdown

Summary

Implements the pool health score widget for the dashboard My Groups tab as described in issue #224.

Changes

frontend/lib/pool-health.ts

  • Added calculatePoolHealth(pool, members, activities) → PoolHealthScore with score (0–100), grade (A–F), factors, trend, and suggestions
  • Added types: PoolHealthScore, PoolHealthInput, HealthFactors, HealthGrade, HealthTrend
  • Added getCachedPoolHealth() — 5-minute client-side cache per pool
  • All existing exports (computePoolHealth, PoolHealth, etc.) are unchanged

frontend/components/dashboard/pool-health-widget.tsx (new)

  • Horizontal scrollable row of pool health cards (mobile-friendly snap scroll)
  • Each card: pool name, type badge, SVG circular progress ring, letter grade, trend arrow, top suggestion, View Details link
  • "Overall Health" summary card showing average score across all pools
  • Loading skeleton state while data is fetching
  • Top-5 cards shown by default; "View All" toggle for users with >20 pools
  • Hidden entirely when user has no pools

frontend/components/dashboard/health-suggestion-list.tsx (new)

  • Expandable section listing actionable suggestions sorted by urgency (declining pools first)
  • Suggestion icon changes by severity (✓ green / ℹ amber / ⚠ red)
  • Animated expand/collapse with framer-motion

frontend/components/dashboard/my-groups.tsx

  • Integrated PoolHealthWidget and HealthSuggestionList below the search bar, above the pool grid

Acceptance criteria

Criterion Status
Health score widget renders at top of My Groups tab
Each card shows score, grade, trend, top suggestion
Overall health summary shows average score
Calculation uses all specified factors
Grade mapping A–F correct
Trend indicator: improving/stable/declining
Suggestions are actionable and pool-specific
Health suggestion list expands below cards
Scores cached 5 minutes client-side
Widget degrades gracefully during loading
Mobile: cards scroll horizontally
Widget hidden when no pools

Testing

  • All 7 existing pool-health.test.ts unit tests pass
  • No TypeScript errors introduced in new/modified files
  • ESLint passes on all changed files

Closes #224

@Sendi0011 Sendi0011 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review: Pool Health Score Widget — CHANGES REQUESTED

Well-designed UI component with circular progress rings, trend indicators, and actionable suggestions. However, CI is failing (Playwright + Lint).

CI Failures (Must Fix)

  • Playwright: Likely related to the new components not having proper mock data in E2E tests
  • Lint/Format: Likely prettier formatting issues on new files

Architecture

  • lib/pool-health.ts — Health score computation engine (new)
  • components/dashboard/pool-health-widget.tsx (390 lines) — Horizontal scrollable card grid with SVG circular rings, trend icons, grade badges
  • components/dashboard/health-suggestion-list.tsx (227 lines) — Expandable suggestion list sorted by urgency
  • Modified my-groups.tsx — Integrates both widgets at the top of the dashboard

Code Quality

  • Uses getCachedPoolHealth() for memoized score computation
  • Proper framer-motion animations for card entrance and list expand/collapse
  • SVG circular ring is well-implemented with strokeDashoffset animation
  • Grade styles (A-F) use consistent color scheme (emerald/lime/amber/orange/rose)
  • Proper ARIA attributes (role="img", aria-label, aria-expanded, aria-controls)

Non-blocking Notes

  • poolToHealthInput() is duplicated between widget and suggestion list — could extract to shared utility
  • TVL trend is approximated (assumes flat 7-day history) since pool list API doesn't expose historical data
  • pool-health.ts health scoring algorithm may overlap with the admin dashboard's computeHealthScore in PR #244 — worth consolidating later

Required Changes

  1. Fix Playwright failures — add mock data for pool health endpoints in test fixtures
  2. Fix lint/format issues — run pnpm format on new files
  3. Consider extracting poolToHealthInput() to a shared utility to avoid duplication

Implements the pool health score widget on the My Groups tab as
described in issue JointSave-org#224.

Changes:
- frontend/lib/pool-health.ts: Add calculatePoolHealth() utility that
  computes a 0-100 composite score from depositCompliance,
  memberActivity, tvlTrend, deadlineProximity, and disputeCount
  factors. Includes grade mapping (A-F), trend detection
  (improving/stable/declining), suggestion engine, and a 5-minute
  client-side score cache.  Existing computePoolHealth() (reputation
  system) is preserved unchanged.

- frontend/components/dashboard/pool-health-widget.tsx: New
  PoolHealthWidget component. Renders a horizontal-scrollable row of
  per-pool health cards (circular SVG ring, letter grade, trend arrow,
  top suggestion, View Details link) plus an OverallHealthCard showing
  the average score. Includes skeleton loaders for the loading state.
  For users with >20 pools only the top-5 are shown with a 'View All'
  toggle. Widget is hidden when the user has no pools.

- frontend/components/dashboard/health-suggestion-list.tsx: New
  HealthSuggestionList component. Expandable accordion below the health
  cards listing all suggestions across all pools, sorted by urgency
  (high → medium → low). Each row shows the suggestion, pool name, and
  an urgency badge. Animated expand/collapse via framer-motion.

- frontend/components/dashboard/my-groups.tsx: Integrate
  PoolHealthWidget at the top of the My Groups tab, rendered above the
  search input when pools are present. Skeleton variant shown while
  data loads.

- frontend/e2e/fixtures/mock-pools.ts: Add mock handler for
  /api/pools/:id/members so the health widget's member fetch resolves
  correctly in Playwright tests.

All 168 existing unit tests pass. No TypeScript errors in modified
files. Prettier formatting applied.

Closes JointSave-org#224
@benzy018
benzy018 force-pushed the feat/pool-health-score-widget branch from 0134102 to ef1b1a3 Compare August 25, 2026 02:29
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.

[Feature] Add a real-time pool health score widget on the dashboard with trend indicators and actionable suggestions

2 participants