feat(contracts): add accessible escrow progress and totals panel (#355)#826
Open
omolobamoyinoluwa-max wants to merge 1 commit into
Open
Conversation
…enttrust#355) Adds src/components/ContractProgress.tsx and the supporting useContractProgress hook, ContractProgressSkeleton, comprehensive tests and documentation. The panel reports milestone completion, paid vs outstanding amounts, and uses a role=progressbar with aria-valuenow/min/max; placed above MilestonesList on the contract detail page without breaking the two-column grid. Closes Talenttrust#355.
|
@omolobamoyinoluwa-max Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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 #355 — feat(contracts): add accessible escrow progress and totals panel
Summary
This PR resolves #355 by adding an accessible, math-driven escrow progress panel to the Contract Detail page. The panel reports (a) how many milestones are complete, (b) the percentage of work paid out, and (c) the paid vs. outstanding dollar amounts — all derived from the milestone data already loaded by the resolver, with no extra fetches.
The change introduces
src/components/ContractProgress.tsx, a colocatedContractProgressSkeleton, and anaria-valuenow-awarerole="progressbar"indicator. Rendering, currency formatting, and accessibility are wired consistently with the existingContractSummary/MilestonesList/ActionPanelpage composition so the two-column responsive grid on/contracts/[id]is preserved.Linked issue
Closes #355 — Show aggregate escrow totals and milestone progress on the contract detail page
Branch
feature/contracts-03-escrow-progress(matching the suggested name in the issue body)Scope
Repository scope:
Talenttrust/Talenttrust-Frontendonly.What changed
src/components/ContractProgress.tsxsrc/hooks/useContractProgress.tssrc/components/ContractProgressSkeleton.tsxaria-busy="true"src/app/contracts/[id]/page.tsxContractProgress(with skeleton fallback) aboveMilestonesListsrc/components/__tests__/ContractProgress.test.tsxsrc/hooks/__tests__/useContractProgress.test.tscalculateContractProgresspurity tests +useMemoreference-stability testssrc/components/__tests__/ContractProgressSkeleton.test.tsxdocs/components/ContractProgress.mdWhy these files
Per the issue's Suggested execution section:
src/components/ContractProgress.tsx— computes paid vs. outstanding amounts and the completed/total milestone count, formatting money viaformatAmountfromsrc/lib/preferences.tsx.src/app/contracts/[id]/page.tsx— mount the panel above/beside the existing summary without breaking the two-column responsive grid.src/components/__tests__/ContractProgress.test.tsx— totals math, empty list, all-paid, progressbar ARIA.docs/components/ContractProgress.md— reviewer-focused doc with props, math, edge cases, a11y table, and integration notes.calculateContractProgressanduseContractProgressinsrc/hooks/useContractProgress.ts.Behavioural contract
Math (in
src/hooks/useContractProgress.ts➜calculateContractProgress):completedCountcounts milestones whosestatusis"Completed"or"Paid".paidAmountsumspayoutfor"Completed"and"Paid"milestones.outstandingAmountsumspayoutfor all other milestones ("Active","Pending","Disputed").progressPercent = Math.round((completedCount / totalCount) * 100).currency=milestones[0].currency, falling back to"USD"when the array is empty.Number.MAX_SAFE_INTEGER. Empty/undefined input returns zeroed metrics without throwing.Rendering (in
src/components/ContractProgress.tsx):<section aria-labelledby="contract-progress-title">landmark with a visible<h2>.<div role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow={progressPercent} aria-label="{n} of {total} milestones completed, {pct}%">— not a bare styled<div>(as required by the issue).<span className="sr-only">{pct}% complete</span>so AT tools that read inner text always get a value.Milestones completed {n} / {total}label beside the bar.sm:grid-cols-2cards: Paid (emerald) and Outstanding (amber), each formatted throughformatAmountso they respect the user's selected currency/locale preference.Empty state:
milestones.length === 0we render an explicit"No milestones yet"paragraph in place of the progressbar.aria-valuenow="0"indeterminate bar with no milestones reads as broken to both sighted users and screen readers, so therole="progressbar"element is intentionally omitted in the empty branch.Integration (in
src/app/contracts/[id]/page.tsx):ContractSummaryandMilestonesList, inside the existingSafeBoundary.isLoading ? <ContractProgressSkeleton /> : <ContractProgress milestones={milestones} />swap used by the other panels.Milestonecarries its owncurrencyfield, andcontractResolver.resolveContractDataaligns them.lg:grid-cols-[minmax(0,1.6fr)_minmax(320px,1fr)]is unchanged; the panel slots into the existing 1.6fr column without reflow.Accessibility (WCAG 2.1 AA at AA level)
<section aria-labelledby="contract-progress-title"><h2 id="contract-progress-title">Escrow Progress</h2>role="progressbar"on the track element (live component only)aria-valuemin="0",aria-valuemax="100"aria-valuenow={progressPercent}(integer 0–100)aria-label="{n} of {total} milestones completed, {pct}%"<span className="sr-only">{pct}% complete</span>for AT that prefers innerTextaria-busy="true"andaria-label="Loading escrow progress"on the skeletonaria-labelledby="contract-progress-title"so the accessible name stays stable across the loading→loaded transition (a deliberate design trade-off — see Trade-offs below)The progress bar conveys meaning through both the visible fill and the ARIA numeric attributes, satisfying WCAG 2.1 SC 1.3.1 (Info & Relationships) and SC 4.1.2 (Name, Role, Value).
Validation
Pre-flight CI runs (local, against
feature/contracts-03-escrow-progress):npx tsc --noEmitnpx eslint .(incl. test files)npm test(full suite)npm test -- ContractProgress ContractProgressSkeleton useContractProgress(targeted)npm test -- ... --coverageon impacted trionpm audit --audit-level=high --productionnpm run buildoptional native depsinstall bug, not by source. Resolvable byrm -rf node_modules && npm iin CI. Not caused by these changes; reproduces onmain.jest-axea11y sweepsrc/test-utils/a11y.tsxnot invoked from scratch because the existing tests already pin every ARIA valueCoverage on impacted modules
ContractProgress.tsxContractProgressSkeleton.tsxuseContractProgress.tsAll three exceed the 95% threshold mandated by
docs/COPYWRITING_GUIDE.md-adjacent coverage policy and the PR template.Edge cases covered by tests
role="progressbar"is intentionally absent; financial cards still show $0.00).2/2,aria-valuenow="100", paid total equals sum of payouts, outstanding = $0.0/N,aria-valuenow="0", paid = $0, outstanding equals the full sum.1/3 → 33%,1/2 → 50%,2/3 → 67%,1/6 → 17%(every Math.round edge case the issue hinted at).EUR/GBP(first milestone's currency wins, percalculateContractProgress).9_000_000 + 1_000_000summed without overflow.StatusTypevalues classified againstpaidAmount/outstandingAmount.aria-valuemin,aria-valuemax,aria-valuenow, andaria-labelcontent asserted on every rendering branch.aria-labelledby="contract-progress-title"and the matching heading id are both asserted.useContractProgressmemoizes on array reference; tests confirm stable returns across rerenders and recomputation on new references.Failures resolved during this branch
ContractProgressSkeleton.tsxat 0% linesaria-busy,aria-label, sharedaria-labelledbyid,animate-pulse, and the no-heading-while-loading invariantuseContractProgress.tsat 90% branch coveragetotalCount > 0 ? … : 0ternary guard (the empty-array early-return guaranteestotalCount > 0below). Added a comment documenting the invariant. Behaviour is provably equivalent under the documented invariantTrade-offs and notes
aria-labelledbyon the skeleton: the skeleton'saria-labelledby="contract-progress-title"references an id not present in the skeleton's own DOM. This is intentional — it keeps the accessible name stable across the loading→loaded transition. A screen reader that scans the skeleton in isolation may warn; an a11y linter ran against the full page tree (loading+loaded) does not. Alternative: droparia-labelledbyfrom the skeleton (rely onaria-label) — see code-reviewer note.useMemoarray-reference equality:useContractProgressmemoizes on the array reference. Callers must pass a stable reference (the page-level state already does); if a parent ever passes a freshly-allocated array each render, memoization will not help. No defensive copy is performed to avoid hiding such bugs.currencyis derived frommilestones[0]. If milestones are intentionally heterogeneous, this is a single-line tweak and a unit test addition.Out of scope
--status-success-*/--status-warning-*variables where possible and the existing emerald/amber pair on the fund cards matchesContractSummary.resolveContractDataand the local repository merge insrc/app/contracts/[id]/page.tsx.How to verify locally
Then drive the UI:
/contracts/c-1(or anyc-*ID) — observe the Escrow Progress panel between the summary and the milestones list, with the progress bar, paid/outstanding cards, and clean dollar/translation throughformatAmount.ContractProgressSkeletonshimmer while the resolver is in-flight.milestones: [](e.g. delete the seeded milestones) to see the explicit "No milestones yet" message; confirm no<div role="progressbar">is in the rendered tree.Files touched (summary)
Definition of Done
ContractProgress.tsxderives paid/outstanding + completion count, formats viaformatAmount).role="progressbar"with validaria-valuemin/max/nowand visible label, not a bare styled<div>.lg:grid-cols-[minmax(0,1.6fr)_minmax(320px,1fr)]) preserved.docs/components/ContractProgress.mdwith props, math, empty state, accessibility, integration.calculateContractProgressanduseContractProgress.npm run lint,npm test,npm audit --audit-level=high --productionall pass locally.npm run buildrequires a cleannode_modules(an upstream env quirk, not introduced by this PR).Reviewer notes
git diff main -- src/hooks/useContractProgress.ts src/components/__tests__/ContractProgressSkeleton.test.tsx.jest.setup.tsif reviewers want a deeper sweep.ContractSummary/MilestonesList/ActionPanel; the new panel slots in between them.Post-merge
MilestonesListrather than the dedicated panel — this PR keeps separation of concerns.ContractDetailLayoutshell if a fourth panel is added.ContractProgressmath helper is intentionally exported fromsrc/hooks/useContractProgress.tsso the contracts-list page or a future summary notification can reuse it without code duplication.