Skip to content

Aditya-feat: Add Side-by-Side Comparison Mode for Actual vs. Planned Expenditure Charts#4898

Open
Aditya-gam wants to merge 9 commits intodevelopmentfrom
Aditya-feat/Add-Side-by-Side-Comparison-Mode-for-Actual-vs-Planned-Expenditure-Charts
Open

Aditya-feat: Add Side-by-Side Comparison Mode for Actual vs. Planned Expenditure Charts#4898
Aditya-gam wants to merge 9 commits intodevelopmentfrom
Aditya-feat/Add-Side-by-Side-Comparison-Mode-for-Actual-vs-Planned-Expenditure-Charts

Conversation

@Aditya-gam
Copy link
Contributor

@Aditya-gam Aditya-gam commented Feb 26, 2026

Description

Adds a Side-by-Side Comparison Mode for Actual vs. Planned Expenditure pie charts in the Financials Tracking section. Users can toggle between Stacked View (Default) - two independent cards, each with one pie and its own project selector, and Comparison View (Side-by-Side), a single card with shared project filter and both pies side-by-side on desktop, or tab-switched on mobile.
IssueDescription

Category labels and percentages remain visible; colors are consistent (Labor = blue, Equipment = green, Materials = yellow). Charts use Recharts' ResponsiveContainer and CSS fluid layouts with max-width and max-height to avoid clipping. The Financials Tracking section now renders the new FinancialsTrackingSection (with toggle and ExpenditureChart-based cards) instead of the previous placeholder grid; the existing Actual vs Planned bar chart remains in the section.

Related PRs (if any):

Main changes explained:

Created/Updated Files:

  • src/utils/URL.js (+2 lines)
    • Added BM_EXPENDITURE_PROJECTS and BM_EXPENDITURE_PIE(projectId) to ENDPOINTS so expenditure API URLs are centralized and consistent with the backend.
  • src/components/BMDashboard/WeeklyProjectSummary/ExpenditureChart/ExpenditureChart.jsx
    • Fixed CSS module class names (use valid keys, e.g., styles['expenditure-chart-card'] instead of invalid hyphenated keys).
    • Introduced PieChartPanel - reusable subcomponent that renders one pie (Actual or Planned) with shared COLORS/CATEGORY_NAMES, dynamic in-slice labels (single-line or two-line by available width), tooltip, and legend; supports compact for comparison layout.
    • ExpenditureChart now accepts projectId, viewMode ('stacked'|'comparison'), and optional pieType ('actual'|'planned'). Single fetch to ENDPOINTS.BM_EXPENDITURE_PIE(projectId); normalized actual/planned arrays.
    • Stacked mode: Two cards in a flex wrapper, each with one PieChartPanel.
    • Comparison mode: One wrapper with tab bar (visible only on mobile via @media (max-width: 640px)), and two panes side-by-side on desktop; on mobile, only the active tab’s panel is shown (expenditure-chart-panel--hidden-mobile).
    • Guard states: no projectId → “Select a project”; loading → spinner + message; error → role="alert" message; empty data → “No expenditure data for this project”.
    • Uses ENDPOINTS from utils/URL; loading/error/empty uses new CSS classes.
  • **`src/components/BMDashboard/WeeklyProjectSummary/ExpenditureChart/ExpenditureChart.module.css
    • Styles for stacked wrapper/cards, comparison layout, tab bar, panes, chart-pane (title + container with fixed max height), loading spinner, error, and empty states.
    • Responsive: at 640px, comparison shows tab bar, stacks panes, hides inactive panel; stacked cards go full width; chart container heights reduced.
  • src/components/BMDashboard/WeeklyProjectSummary/ExpenditureChart/FinancialsTrackingCard.jsx
    • Used only in Comparison mode. Fetches project list from ENDPOINTS.BM_EXPENDITURE_PROJECTS; single shared project select; renders ExpenditureChart with projectId and viewMode="comparison". Loading/error states with semantic markup (<output>, role="alert"). Does not own the layout toggle (lives in FinancialsTrackingSection).
  • src/components/BMDashboard/WeeklyProjectSummary/ExpenditureChart/FinancialsTrackingCard.module.css
    • Card, controls row, select group/label/select, state messages, error style; responsive padding and full-width select on small screens.
  • src/components/BMDashboard/WeeklyProjectSummary/ExpenditureChart/FinancialsTrackingSection.jsx
    • Owns view mode state ('stacked' | 'comparison'). Renders toggle buttons: “Stacked View (Default)” and “Comparison View (Side-by-Side)” with aria-pressed and responsive labels (full → medium → icon+short).
    • Stacked: 2×2 grid — SingleExpenditureCard (actual), SingleExpenditureCard (planned), ActualVsPlannedCost, placeholder “Coming Soon”.
    • Comparison: Top full-width FinancialsTrackingCard; bottom row with ActualVsPlannedCost and placeholder.
    • Imports ActualVsPlannedCost, FinancialsTrackingCard, SingleExpenditureCard.
  • src/components/BMDashboard/WeeklyProjectSummary/ExpenditureChart/FinancialsTrackingSection.module.css
    • Section wrapper, toggle group/buttons (active state, focus-visible), grid for stacked, comparison layout, bottom row grid, chart card, and placeholder card; responsive label tiers and breakpoints (768px, 640px, 420px).
  • src/components/BMDashboard/WeeklyProjectSummary/ExpenditureChart/SingleExpenditureCard.jsx
    • Self-contained card for stacked mode: fetches project list, own project dropdown, renders ExpenditureChart with projectId and pieType ('actual' or 'planned') so only one pie is shown per card, unique id for select per pieType for a11y.
  • src/components/BMDashboard/WeeklyProjectSummary/ExpenditureChart/SingleExpenditureCard.module.css
    • Card, controls, select group, loading/error states; responsive.
  • src/components/BMDashboard/WeeklyProjectSummary/WeeklyProjectSummary.jsx
    • Replaced Financials Tracking content: no longer maps over four placeholder cards with only one showing ActualVsPlannedCost. Now renders a single full-width block containing FinancialsTrackingSection.
    • Import changed from ActualVsPlannedCost to FinancialsTrackingSection.
    • Minor PDF export cleanup (forEach callback formatting).

Key Implementation Details:

  • View mode: Single state in FinancialsTrackingSection ('stacked' | 'comparison'). Toggle is purely a layout; no duplicate API calls when switching.
  • Data flow: One project list fetch per card/section; one pie fetch per selected project via GET /bm/expenditure/:projectId/pie (returns { actual, planned }). ExpenditureChart normalizes to Labor/Equipment/Materials with zero fill for missing categories.
  • Color consistency: COLORS = ['#6777EF', '#A0CD61', '#F5CD4B'] and CATEGORY_NAMES = ['Labor', 'Equipment', 'Materials'] in ExpenditureChart.jsx used for both Actual and Planned pies.
  • Responsiveness: No hard component-level breakpoint for “stacked vs comparison” — that’s the user toggle. Within comparison mode, the 640px media query shows the tab bar and hides the inactive panel; stacked mode uses flex wrap and grid with responsive columns.
  • Accessibility: Project selects have htmlFor/id; toggle has aria-pressed and aria-label; comparison tabs use role="tablist", role="tab", aria-selected, aria-controls, role="tabpanel", aria-labelledby; error uses role="alert"; loading uses <output> (implicit live region).
  • Theme: All new CSS uses var(--card-bg), var(--text-color), var(--section-bg), var(--button-bg), etc., from WeeklyProjectSummary.module.css so dark mode is consistent.

How to test:

  1. Check out the current branch: Aditya-feat/Add-Side-by-Side-Comparison-Mode-for-Actual-vs-Planned-Expenditure-Charts
  2. Ensure backend with BM expenditure endpoints is running (e.g., HGNRest with PR 1417 or equivalent).
  3. Run npm install (or yarn install) to install dependencies.
  4. Start the app: npm run start:local (or vite / npm start).
  5. Test Financials Tracking:
    • Go to Dashboard → Reports → Total Construction Summary (e.g. http://localhost:5173/bmdashboard/totalconstructionsummary).
    • Open the Financials Tracking section.
    • Stacked View (default): Confirm two separate cards (Actual Expenditure, Planned Expenditure), each with its own project dropdown; select different projects and confirm pies update. Confirm Actual vs Planned bar chart and “Coming Soon” placeholder are in the grid.
    • Click Comparison View (Side-by-Side): Confirm one combined card with a single project dropdown and both pie charts side-by-side; the same project drives both pies.
    • Toggle back to Stacked and verify layout.
  6. Verify: Color consistency (Labor blue, Equipment green, Materials yellow) in both modes; no label overlap; loading/error/empty states show appropriate messages; dark mode styling matches section; PDF export still runs (toggle/buttons are stripped in clone; section content is present).

Screenshots or videos of changes:

  • Stacked View:
    StackedLightMode
    StackedDarkMode
  • Comparison View:
    ComparisonLightMode
    ComparisonDarkMode
  • Test Video:
TestVideo.mov

Note:

  • Performance Considerations: One pie fetch per selected project; no extra requests when toggling view mode. Chart containers use max height/width to avoid unbounded growth.
  • Validation: Empty or malformed API responses normalize to empty arrays; missing categories are filled with zero. Error state shown on fetch failure.
  • Backward Compatibility: Compatible with existing backend GET /bm/expenditure/projects and GET /bm/expenditure/:projectId/pie. The existing ActualVsPlannedCost component remains in use inside the section.

Aditya-gam and others added 7 commits February 21, 2026 21:11
Add BM_EXPENDITURE_PROJECTS and BM_EXPENDITURE_PIE to ENDPOINTS
for /bm/expenditure/projects and /bm/expenditure/:projectId/pie.

Co-authored-by: Cursor <cursoragent@cursor.com>
…, fix CSS

- Fix invalid CSS module class names (use bracket notation for kebab-case)
- Use ENDPOINTS.BM_EXPENDITURE_PIE for API calls; add request cancellation
- Add PieChartPanel with ResponsiveContainer and dynamic label sizing
- Support viewMode: stacked (two cards) vs comparison (side-by-side + mobile tabs)
- Support pieType prop for single-pie rendering (actual or planned)
- Add loading (spinner), error, and empty states with semantic markup
- Consistent Labor/Equipment/Materials colors; dark mode via Redux theme
- Responsive layout and max chart size; tab bar for comparison on narrow screens

Co-authored-by: Cursor <cursoragent@cursor.com>
- Use ENDPOINTS.BM_EXPENDITURE_PROJECTS; add request cancellation
- Add FinancialsTrackingCard.module.css for card, controls, and states
- Pass viewMode="comparison" to ExpenditureChart for side-by-side layout
- Accessible loading/error states with semantic elements

Co-authored-by: Cursor <cursoragent@cursor.com>
- Self-contained card with own project selector for one pie (actual or planned)
- Used in stacked view so each chart can have independent filters
- Uses ExpenditureChart with pieType prop; ENDPOINTS and cancellation
- SingleExpenditureCard.module.css for card, controls, loading/error

Co-authored-by: Cursor <cursoragent@cursor.com>
- FinancialsTrackingSection owns viewMode state and layout toggle
- Stacked: 2×2 grid with SingleExpenditureCard (actual/planned), ActualVsPlannedCost, placeholder
- Comparison: combined FinancialsTrackingCard on top, bottom row with bar chart and placeholder
- Toggle buttons with aria-pressed; responsive grid and toggle styles

Co-authored-by: Cursor <cursoragent@cursor.com>
…ls Tracking

- Replace placeholder cards with FinancialsTrackingSection (toggle + stacked/comparison layout)
- Remove ActualVsPlannedCost import; section now renders ActualVsPlannedCost inside section
- Minor PDF export: fix forEach callback style in selector cleanup

Co-authored-by: Cursor <cursoragent@cursor.com>
@netlify
Copy link

netlify bot commented Feb 26, 2026

Deploy Preview for highestgoodnetwork-dev ready!

Name Link
🔨 Latest commit adcdc51
🔍 Latest deploy log https://app.netlify.com/projects/highestgoodnetwork-dev/deploys/699fac512e55bb0008428c23
😎 Deploy Preview https://deploy-preview-4898--highestgoodnetwork-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

…on-Mode-for-Actual-vs-Planned-Expenditure-Charts
…penditureCard into ExpenditureCard

- Add ExpenditureCard.jsx with useProjectList hook and mode='comparison'|'stacked'
- Add ExpenditureCard.module.css with shared card styles and stacked variants
- Replace FinancialsTrackingCard with thin wrapper: <ExpenditureCard mode="comparison" />
- Replace SingleExpenditureCard with thin wrapper: <ExpenditureCard mode="stacked" pieType={…} />
- Remove duplicated FinancialsTrackingCard.module.css and SingleExpenditureCard.module.css

Fixes SonarQube duplication (~40 lines); API and behavior unchanged.

Made-with: Cursor
@sonarqubecloud
Copy link

@Aditya-gam Aditya-gam changed the title Add Side-by-Side Comparison Mode for Actual vs. Planned Expenditure Charts Aditya-feat: Add Side-by-Side Comparison Mode for Actual vs. Planned Expenditure Charts Feb 26, 2026
@one-community one-community added the High Priority - Please Review First This is an important PR we'd like to get merged as soon as possible label Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

High Priority - Please Review First This is an important PR we'd like to get merged as soon as possible

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants