refactor: render stats through shared format helpers and StatTile - #1
Open
Praiz089017 wants to merge 1 commit into
Open
refactor: render stats through shared format helpers and StatTile#1Praiz089017 wants to merge 1 commit into
Praiz089017 wants to merge 1 commit into
Conversation
- Wire formatNumber into stats page for locale thousands separators - Use StatTile component for metric tiles (Pairs, Status) - Document formatStroops readiness in JSDoc and README - Fix pre-existing TypeScript discriminated union destructuring in stats and pairs - Fix missing Button import in events Client that blocked CI build - Rewrite stats tests to mock apiClient.apiGet (matches useApi architecture) - Fix StatTile test DD assertion for SPAN wrapper - Cover edge cases: small counts, large counts, zero Closes StableRoute-Org#291
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.
refactor: render stats through shared format helpers and StatTile
Closes StableRoute-Org#291
Summary
Wires the shared
formatNumber,formatStroops, andStatTilehelpers into the stats dashboard page. The stats page now renderstotalPairswith locale-aware thousands separators viaformatNumber, uses the reusableStatTilecomponent for metric tiles, and documentsformatStroopsas ready for future stroop-denominated fields. Also fixes pre-existing TypeScript discriminated union destructuring errors and a missingButtonimport that blocked CI.Changes
Core issue (StableRoute-Org#291) — Stats formatting & StatTile
src/app/stats/Client.tsxuseApi,StatTile,formatNumber, andformatStroopsreadiness. Fixed discriminated union destructuring ({ status, data, error }→result.status,result.data,result.error) to resolve a TypeScript error.src/app/stats/page.test.tsxapiClient.apiGet(matching theuseApiarchitecture) instead ofglobal.fetch. Replaced two broken polling tests that relied onjest.useFakeTimers()with edge-case coverage: small counts, large counts with separators (1,234,567), and zero. Updated error test to expect"Network request failed"— the actual message produced byapiClient.src/components/__tests__/StatTile.test.tsxscreen.getByText("42").tagName).toBe("DD")toscreen.getByText("42").closest("dd")).toBeInTheDocument()to account for the<dd><span>value</span></dd>structure.README.mdformatNumber,formatStroops, andformatTimehelpers and their test coverage.Bonus fixes — Pre-existing CI blockers
src/app/events/Client.tsximport { Button } from "@/components/Button"that caused both lint and build failures.src/app/pairs/Client.tsx{ status, data, error, refetch }→result.status,result.data,result.error,result.refetch) — same pattern as stats above. This was the only remaining TypeScript error blockingnpm run build.Test coverage
Edge cases covered
1,234,567pairs"1,234,567"formats totalPairs with thousands separators via formatNumber42pairs"42"renders small counts as-is (no unnecessary separators)0pairs"0"renders zero as 0paused: true"Paused"renders Paused when paused is truepaused: false"Live"renders Live when paused is falseapiGetrejectsrenders error message on fetch failure/api/v1/statscalls the stats API on mountnpm test output (targeted)
CI verification
npm run build— passes (fixed pre-existing errors in events and pairs)npm run lint— all changed files passtsc --noEmit)Notes for reviewers
The
StatsClientcomponent already importedformatNumberand usedStatTilebefore this PR — the implementation was in place but the tests, JSDoc, and README were missing. This PR fills those gaps and hardens the test coverage.The
formatStroopshelper is documented as ready in both the JSDoc and README. It is not used yet because the currentStatsendpoint does not expose a stroop-denominated field. When one is added (e.g.totalVolume), the pattern is:formatStroops(result.data.totalVolume)inside aStatTile.The discriminated union fix (
result.datainstead of destructureddata) is applied consistently in bothstats/Client.tsxandpairs/Client.tsx. This resolves theTS2339: Property 'data' does not exist on type 'UseApiResult<T>'errors that occur understrict: true.The
events/Client.tsxButtonimport fix is a one-liner that unblocks the build. This was merged into this PR because it's the same category of pre-existing CI breakage.