fix(dashboard): compute StatCard trends from sparkline history (#92) - #99
Open
annieolivia61-ux wants to merge 1 commit into
Open
fix(dashboard): compute StatCard trends from sparkline history (#92)#99annieolivia61-ux wants to merge 1 commit into
annieolivia61-ux wants to merge 1 commit into
Conversation
|
@annieolivia61-ux is attempting to deploy a commit to the chonilius' projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #92
Removes the hardcoded trend literals (
12/8/18) from the contributor and sponsor dashboards and computes the trend from the same history array already rendered as each card's sparkline.What changed
New
src/lib/trend.ts—computeTrend(history)Week-over-week percentage change:
((latest - prior) / prior) * 100, rounded to a whole number to match StatCard'sN% vs last perioddisplay.historyfewer than 2 points or a zero prior period → returnsundefined(the trend row is hidden, never a fabricated placeholder).0→undefinedambiguity: a genuine flat period returns0.src/app/dashboard/contributor/page.tsxtrend={fetchStatus === "loaded" ? computeTrend(contributorEarningsHistory) : undefined}(was12).trend={fetchStatus === "loaded" ? computeTrend(contributorSparkline) : undefined}(was8).src/app/dashboard/sponsor/page.tsxtrend={fetchStatus === "loaded" ? computeTrend(sponsorSpendHistory) : undefined}(was18).Tests
src/lib/trend.test.ts— unit tests for up/down/flat/short/zero-prior/rounding cases.src/components/ui/StatCard.test.tsx— negative and zero-trend rendering coverage (previously every caller passed a positive literal, so the down/rose path was never exercised).Not changed (from the audit in the issue)
platformStats.*values are derived live from fetched stats — not hardcoded.trend={5}is intentionally static sample data for the component gallery, matching its other hardcoded sample props — left as-is.Pre-existing behavior acknowledged in the issue
StatCardrenders a genuine0trend with the green up arrow becausetrendUp = typeof trend === "number" && trend >= 0.computeTrendcan now legitimately return0for a flat week; the component's>= 0arrow choice is pre-existing and out of scope for this fix (documented intrend.tsJSDoc and covered by a test).Drive-by fix: duplicate
validateTeamSplitsinsrc/lib/utils.tssrc/lib/utils.tscontained twovalidateTeamSplitsexports (introduced in commit7c8260c2, "Fix #5"). The first only acceptednumberpercentages and had no tolerance parameter; the second (kept) acceptsstring | numberpercentages with a tolerance param. The duplicate makesnext buildfail with "the namevalidateTeamSplitsis defined multiple times", so CI's build step was already red onmain. Removed the older, less-capable copy — no behavior change for existing callers.Verification
npm test— 21 passed / 21 (2 suites).npm run lint— clean.npm run build— compiles, TypeScript check passes, all 13 routes generated.next buildon this machine needsNEXT_FONT_GOOGLE_MOCKED_RESPONSESbecause the sandbox has no network access tofonts.googleapis.com/fonts.gstatic.com(fonts are downloaded at build time). CI has network access and downloads the real Geist/Geist Mono fonts.