Skip to content

Rithika taking over for Aditya-feat: Implement Material Usage vs Cost Correlation Chart for BM Dashboard - #4587

Open
Aditya-gam wants to merge 44 commits into
developmentfrom
Aditya-feat/material-cost-correlation-chart
Open

Rithika taking over for Aditya-feat: Implement Material Usage vs Cost Correlation Chart for BM Dashboard#4587
Aditya-gam wants to merge 44 commits into
developmentfrom
Aditya-feat/material-cost-correlation-chart

Conversation

@Aditya-gam

@Aditya-gam Aditya-gam commented Dec 19, 2025

Copy link
Copy Markdown
Contributor

Description

Implements a new Material Usage vs Cost Correlation chart component for the BM Dashboard. The chart visualizes material quantity used vs total material cost per project using a combined bar/line chart (Recharts ComposedChart). Features include filtering (projects, material types, date ranges), dark mode support, responsive design, and error handling. Integrated into the Weekly Project Summary → Material Consumption section.

IssueDescription1 IssueDescription2 ExpectedGraph

Related PRs (if any):

  • This PR is the Frontend PR for the backend PR #1957.

Main changes explained:

Created Files:

  • src/constants/bmdashboard/materialCostCorrelationConstants.js

    • Redux action type constants
  • src/reducers/bmdashboard/materialCostCorrelationReducer.js

    • Redux reducer for loading, data, error, and filter state management
  • src/actions/bmdashboard/materialCostCorrelationActions.js

    • Thunk action with client-side validation (date ranges, ObjectId format)
    • Error handling (401→login redirect after 2s, 403→permission error, network→retry button)
    • Query params: projectId (comma-separated), materialType (comma-separated), startDate (YYYY-MM-DD), endDate (YYYY-MM-DD)
    • Toast notifications for validation errors and API errors
  • src/components/BMDashboard/MaterialCostCorrelation/MaterialCostCorrelationChart.jsx

    • Main chart component (Recharts ComposedChart with dual Y-axes)
    • Bar chart: totalCostK (blue #0088FE) on left Y-axis, Line chart: quantityUsed (orange #FF8042) on right Y-axis
    • X-axis: project names rotated -45° with truncation (>15 chars)
    • Responsive margins/heights: mobile (450px) to desktop (600px)
    • Loading, error, and no-data states with custom tooltip (project name, cost in dollars, quantity)
  • src/components/BMDashboard/MaterialCostCorrelation/FilterPanel.jsx

    • Multi-select filters (projects, material types) with react-select
    • Fetches from Redux state: state.bmProjects and state.bmInvTypes.list
    • Date range picker with preset buttons: Last Week, Last Month, Last 3 Months, All Time
    • "All Projects/Materials" options and Reset button clear filters (empty array = all items)
  • src/components/BMDashboard/MaterialCostCorrelation/MaterialCostCorrelationChart.module.css

  • src/components/BMDashboard/MaterialCostCorrelation/FilterPanel.module.css

    • CSS modules with dark mode support via CSS custom properties
    • Responsive breakpoints, animations, and styling for React-Select components in both themes
  • src/components/BMDashboard/MaterialCostCorrelation/index.jsx

    • Barrel export

Modified Files:

  • src/utils/URL.js - Added BM_MATERIAL_COST_CORRELATION endpoint constant
  • src/reducers/index.js - Added materialCostCorrelation reducer to root reducer
  • src/components/BMDashboard/WeeklyProjectSummary/WeeklyProjectSummary.jsx - Integrated chart into Material Consumption section (index 0)

Key Implementation Details:

  • API: /api/bm/materials/cost-correlation (GET) - Response: { meta, data: [{ projectId, projectName, totals: { totalCostK, quantityUsed } }] }. Cost in USD, totalCostK pre-calculated. Empty filter arrays = fetch all items.
  • Chart: Recharts ComposedChart - Bar (blue #0088FE, cost ×1000$) + Line (orange #FF8042, quantity) with dual Y-axes. X-axis: projects rotated -45°, truncated >15 chars. Data transformation via useMemo.
  • State: Redux slice materialCostCorrelation manages loading, data, error, filters. Filter changes trigger auto-refetch via useEffect.
  • Responsive: Dynamic margins/heights: mobile ≤480px (40px/70px, 450px) to desktop >1024px (60px/80px, 600px). Window resize listener with cleanup.
  • Errors: Client-side validation (date range, ObjectId format). Categorized errors: 401→login redirect (2s), 403→permission, network→retry, validation→toast. Logger service replaces console statements.
  • Dark Mode: CSS custom properties with conditional classes based on state.theme.darkMode

How to test:

  1. Checkout branch: Aditya-feat/material-cost-correlation-chart
  2. Reinstall dependencies and clear cache: rm -rf node_modules && yarn cache clean
  3. Run yarn install and start the app: yarn start:local
  4. Clear browser cache/site data
  5. Log in as an admin user
  6. Navigate to BM Dashboard → Weekly Project Summary → Material Consumption section
  7. Test filters: Projects/Material Types (multi-select with "All" options), Date Range (preset buttons + manual), Reset button
  8. Test chart: Hover for tooltip (project name, cost in dollars, quantity), verify Y-axis labels and X-axis project names (-45° rotation, truncated >15 chars)
  9. Test responsive: Resize browser (mobile ≤480px, tablet ≤768px, desktop >1024px) - verify margins/heights adjust
  10. Test dark mode: Toggle theme - verify chart, filters, tooltips adapt correctly
  11. Test error states: Network error (retry button), validation error (date range toast), no data state, authentication (401 redirect after 2s)
  12. Verify integration: Chart appears as the first card (index 0) in the Material Consumption section

Screenshots:

  1. Light Mode:
LightModeChart
  1. Dark Mode:
DarkModeChart
  1. Test Video:
TestVideo.mov

Notes:

  • Performance: Uses useMemo for data transformation, API calls triggered on filter changes, and window resize listener cleaned up. Consider pagination for >100 projects.
  • Validation: Client-side (date range, ObjectId format), server-side handled by backend API. Invalid inputs show toast notifications.
  • Logging: Uses logger service with [MaterialCostCorrelation] prefix (replaces console statements)

@netlify

netlify Bot commented Dec 19, 2025

Copy link
Copy Markdown

Deploy Preview for highestgoodnetwork-dev ready!

Name Link
🔨 Latest commit fbcf8ff
🔍 Latest deploy log https://app.netlify.com/projects/highestgoodnetwork-dev/deploys/6a6a4123d3a6b90008afbd7e
😎 Deploy Preview https://deploy-preview-4587--highestgoodnetwork-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

@sonarqubecloud

Copy link
Copy Markdown

@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 8, 2026

@Anusha-Gali Anusha-Gali left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hi Aditya,

I have reviewed your PR locally and the functionality works as expected in both the modes. However the chart is not mobile responsive.

Image Image Image Image Image Image Image

@Aditya-gam

Copy link
Copy Markdown
Contributor Author

Hi Aditya,

I have reviewed your PR locally and the functionality works as expected in both the modes. However the chart is not mobile responsive.

Image Image Image Image Image Image Image

Hi Anusha,
I fixed the chart's responsiveness on smaller screens.

Screen.Recording.2026-02-18.at.8.06.51.PM.mov

@Anusha-Gali Anusha-Gali left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hi Aditya,

Thank you fixing the issue but this led to other issues popping up i.e
Image

The below is how it looks on my mac with browser at 75% setting, you can compare this with my older images to see the difference
Image
Image

The below is how it looks on my mac with browser at 100% setting
Image

You can also see how the toggle pretty much covers the chart
Image
Image

@sonarqubecloud

sonarqubecloud Bot commented Mar 3, 2026

Copy link
Copy Markdown

@Aditya-gam

Copy link
Copy Markdown
Contributor Author

Hi Aditya,

Thank you fixing the issue but this led to other issues popping up i.e Image

The below is how it looks on my mac with browser at 75% setting, you can compare this with my older images to see the difference Image Image

The below is how it looks on my mac with browser at 100% setting Image

You can also see how the toggle pretty much covers the chart Image Image

Hi Anusha,
Please review the latest changes.

Screen.Recording.2026-03-02.at.8.01.53.PM.mov

@Aditya-gam
Aditya-gam requested a review from Anusha-Gali March 3, 2026 04:06
@rithika-paii rithika-paii changed the title Aditya-feat: Implement Material Usage vs Cost Correlation Chart for BM Dashboard Rithika taking over for Aditya-feat: Implement Material Usage vs Cost Correlation Chart for BM Dashboard May 1, 2026
@rithika-paii
rithika-paii force-pushed the Aditya-feat/material-cost-correlation-chart branch 2 times, most recently from f166112 to 40ee4a8 Compare May 9, 2026 21:05

@DeepighaJ DeepighaJ left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  • X-axis currently displays project names instead of Quantity of materials used as specified in design requirements.
  • Tooltip does not include Cost per Unit information.
  • Legend differentiates metrics rather than material types.
  • On selecting All material or All project its not shown selected in the dropdown.
Image Image Image Image Image

@rithika-paii

Copy link
Copy Markdown
Contributor

Hi @DeepighaJ,

All the requested changes have been addressed:

  1. X-axis now displays material type names instead of project names.
  2. Tooltip now includes Cost per Unit information.
  3. Legend now differentiates by material types (Total Material Cost and Quantity of Materials Used).
  4. Selecting All Materials or All Projects now shows as selected in the dropdown.

Also resolved the merge conflict with development and fixed all SonarQube issues. Please re-review when you get a chance. Thank you!

@rithika-paii
rithika-paii force-pushed the Aditya-feat/material-cost-correlation-chart branch from 4f52710 to 4cf399f Compare May 30, 2026 18:38
@sonarqubecloud

Copy link
Copy Markdown

@rithika-paii
rithika-paii force-pushed the Aditya-feat/material-cost-correlation-chart branch from 8afb26a to 5aefbd4 Compare June 24, 2026 19:39

@kzou55 kzou55 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ran and tested the following PR locally

Verified the following:

  • Test chart has the tooltip when hovered
  • Dark Mode works

Testing in Light Mode

Recording.2026-06-27.003458.mp4

Testing in Dark Mode

Recording.2026-06-27.004023.mp4

Issues:

  • Expanding the Materical Consumption section causes the section to expand but everything after the Material Usage vs. Cost Correlation component gets deformed. And there's a bunch of empty white space.

    Image image image
  • The Projects and Material Types filter isn't fully working. I believe it is filtering given the bar chart visually changes, but the filter selection always states "All Projects" and "All Materials" are always filtered. Tried removing the filter, clearing it or selecting other filter options , and Reset All Filters, but same outcome.
    image

    image
  • In smaller browser sizes, there's a lot of empty space that could be used.
    image

  • Hover tooltip has some issues

    • Quantity in the hover tool tip has .00. Should just be a whole number.
      image
    • Instead of Project Name for the X axis label, it uses Project ID and some are blank
      image

@rithika-paii
rithika-paii force-pushed the Aditya-feat/material-cost-correlation-chart branch from c2e9c5e to b123dac Compare June 30, 2026 20:04

@DeepighaJ DeepighaJ left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  • The chart does not fully reflect the selected filters. Multiple material types are selected, but only Cement and Sand are displayed. If other selected materials have no data, the UI should indicate this; otherwise, all selected materials should be represented.
  • The calendar needs improvement.
Image Image Image

@HemanthNidamanuru HemanthNidamanuru left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hi,

I tested this PR locally.

The chart does not fully reflect the selected filters. Multiple material types are selected, but only Cement and Sand are displayed.

Also, the selected date styling needs improvement in dark mode, and the typed values in the Projects and Material Types fields are not clearly visible in dark mode.

Image Image Image Image

@kzou55 kzou55 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hi Rithika,

I ran and tested the PR alongside its associated backend again.

Issues

  1. The Projects and Material Types filter has some issues. When the user first filters by one of the dropdown and the chooses the filter "All Projects" or "All Material", those options fail to get selected.
Recording.2026-07-04.185759.mp4
  1. The bar chart/graph isn't showing all the materials sometimes.

    Image
  2. If the chart shows no data, shouldn't it "No data available for selected filters"?

    Image
  3. Date filter error. Can't reset the section if there was an error. Clicking retry just causes the same issue to occur. Have to refresh to revert back the error. A bit inconsistent to replicate. But this occurs when a user selects a valid start and end date. Only to clear the start date, which makes it think the start date is today. Sometimes clearing the start date is fine, other times, it gets the issue below.

Image
Recording.2026-07-04.185506.mp4

@rithika-paii
rithika-paii force-pushed the Aditya-feat/material-cost-correlation-chart branch from 6849a9d to 434e1d2 Compare July 6, 2026 17:21
@rithika-paii

Copy link
Copy Markdown
Contributor

Hi @DeepighaJ @kzou55 @HemanthNidamanuru,

Thanks for the detailed feedback — all issues reported across these reviews are now fixed:

"All Projects"/"All Materials" reset bug: root cause was that handleProjectChange/handleMaterialTypeChange couldn't distinguish "user picked a real option while 'All' was showing" from "user picked 'All' while a real option was showing" — both produced identical intermediate state, so clicking "All" after a real selection silently did nothing. Fixed by comparing against the previous filter state to tell these cases apart.
Chart not showing all selected materials / missing "no data" messaging: the chart now always renders every selected material type as a category. If a material has no matching data, it still shows up with a zero-value bar, and the tooltip clearly says "No data available for this material" instead of silently omitting it.
Date filter crash / stuck retry loop: this turned out to be two bugs. First, the start-date picker had no maxDate constraint, so it was possible to pick a start date after the end date, producing an invalid range. Second, the frontend's error classifier didn't recognize the backend's exact error message format for that case, so it fell through to a generic crash screen with only a non-functional "Retry" button that just resent the same broken request. Fixed the missing calendar constraint so the invalid state can't happen anymore, broadened the error classifier as defense-in-depth, and added a "Reset Filters" button to the error screen as a safety net regardless of error type.
Calendar needs improvement: covered by the maxDate fix above, plus a dark mode styling fix for the calendar's keyboard-navigation highlight, which previously fell back to broken light-theme colors.
Dark mode styling: fixed invisible typed text in the Projects and Material Types search fields (react-select's input text color wasn't themed) and the date picker's focused-day highlight, both now consistent with dark mode.

All frontend tests pass (2104 passed, 9 skipped) and stylelint is clean. Let me know if anything else comes up on retest.

@HemanthNidamanuru HemanthNidamanuru left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hi Aditya,

I tested this PR locally on the Aditya-feat/material-cost-correlation-chart branch.

I was able to navigate to BM Dashboard → Weekly Project Summary → Material Consumption section, but the Material Usage vs Cost Correlation title and graph are not loading/rendering even after clicking retry and reset filters buttons.

Because of this, I’m unable to properly verify the filters, tooltip, Y-axis/X-axis labels, responsive behavior, dark mode, error states, and chart integration.

Image Image

@DeepighaJ DeepighaJ left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hi

  • Tested the PR locally and the previously mentioned issues are resolved and the graph is loading. 0 or No data avaialble is handled and the issue is fixed.
  • The calendar allows future dates as well and the icon is not calendar icon, a circle is shown instead.
  • The total Material Cost per project graph values needs improvement in dark mode. Does this come under scope for this PR?
Image Image Image

kzou55
kzou55 previously approved these changes Jul 11, 2026

@kzou55 kzou55 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hi Rithika,

I ran and tested the PR and its associated backend locally again.

Verified

  • Confirmed that all the functionality remains the same
  • The issue where the user first filters by one of the dropdown and then chooses the filter "All Projects" or "All Material", previously those options fail to get selected, but the issue has been resolved
  • The issue with the chart not including certain material types when selected in the filter has been fixed.
  • Unable to replicate the start date clearing that caused the issue where it would make the chart crash. Believe this issue is fixed now.
Recording.2026-07-10.230653.mp4

Aditya-gam and others added 27 commits July 29, 2026 11:53
…le and tablet

- Add breakpoints for mobile (≤480), iPad Mini (≤768), iPad Pro (≤1024)
- X-axis: vertical labels (-90°) on mobile/tablet small, interval to show ~5-8 labels
- X-axis: shorter truncation on small screens (8/10/12 chars)
- Y-axis: short labels (Cost ×1k$, Qty Used) and narrower width on ≤768px
- Responsive margins and chart height by viewport

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

- Add min-width: 0 on container and chartContainer for flex shrink
- Add overflow-x: auto and touch scrolling on chart container
- Add box-sizing: border-box on container

Co-authored-by: Cursor <cursoragent@cursor.com>
…ter grid

- Move preset date-range shortcuts to full-width row below filter grid
- Reduce filter grid min column width (280px -> 160px) and gap for flexibility
- Simplify preset button layout; remove mobile-only column/full-width overrides

Made-with: Cursor
- Replace window resize listener with ResizeObserver on chart container
- Breakpoints now based on rendered container width (narrow <500px, medium <700px)
- Reduces min-heights so chart height adapts to grid column width

Made-with: Cursor
…yout

- Render Material Consumption as single grid with three cards (chart, quantity, cost)
- Add materialConsumptionGrid styles; single column on viewport <=768px
- Add padding-bottom to container so scroll-to-top button does not obscure content

Made-with: Cursor
…px for tablets

Add media query so materialConsumptionGrid uses single column on tablet
screens for better readability before the existing 768px small-screen breakpoint.

Made-with: Cursor
…ark mode issues in Material Cost Correlation chart
@rithika-paii
rithika-paii force-pushed the Aditya-feat/material-cost-correlation-chart branch from 4c64054 to cf213fd Compare July 29, 2026 17:56
@sonarqubecloud

Copy link
Copy Markdown

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.

7 participants