Skip to content

[FEAT] Allow users to add custom/override emission factors (#152)#167

Merged
arghya29 merged 23 commits into
arghya29:devfrom
Dev1822:feat/custom-emission-factors-152
Jul 22, 2026
Merged

[FEAT] Allow users to add custom/override emission factors (#152)#167
arghya29 merged 23 commits into
arghya29:devfrom
Dev1822:feat/custom-emission-factors-152

Conversation

@Dev1822

@Dev1822 Dev1822 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Description

This PR implements a full custom and override emission factor management feature. Authenticated users/organizations can now create, edit, list, and delete custom emission factors that take precedence over standard seeded system factors during carbon footprint calculations.

Key changes included:

  • Primary Sidebar Access: Added an "Emission Factors" link (/settings/factors) in the dashboard sidebar menu.
  • System Factors API: Created GET /api/system-factors route to expose seeded standard emission factors.
  • Visual Factor Identification: Enhanced FactorRow component with clear origin badges (System vs Custom), overridden badges, and active override details.
  • Redesigned Emission Factors Page:
    • Summary metrics cards (System Factors, Custom Factors, Active Overrides).
    • Search bar (by category, unit, or source) and Scope filter dropdown (SCOPE_1, SCOPE_2, SCOPE_3).
    • Three viewing tabs: All Factors, Custom Factors, and System Factors.
    • Form workflow supporting new custom factor entry, inline editing of existing custom factors, and pre-filling the form when overriding system factors.
    • Replaced window.confirm() with ConfirmDialog for safe deletion UX.

Related Issue

Closes #152

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactor
  • Tests

Checklist

  • I have read CONTRIBUTING.md
  • My code follows the existing style
  • I have run npm test and all tests pass (15 test suites, 83 tests passed)
  • I have run npm run lint with no errors
  • I have added/updated tests for my changes (if applicable)
  • I have tested on mobile (320px width) if this is a UI change

Summary by CodeRabbit

  • New Features

    • Added an Emission Factors section to dashboard settings.
    • Browse custom and system factors with search, scope filters, and All/Custom/System tabs.
    • Create, edit, delete, and override emission factors.
    • Add units and data source citations to factors.
    • System factors display override status and related details.
  • Bug Fixes

    • Added clear loading, empty, and error states for factor listings.
    • Added confirmation prompts and success/error notifications for deletions and saves.

arghya29 and others added 20 commits June 19, 2026 10:16
fix: wrap login form in Suspense for useSearchParams build requirement
ci: run checks on Node 18.x and 20.x
ci: add coderabbit config and run checks on dev and main branches
Fix instructions for Open Source Contributions
Merging Pull request from dev
Merging from dev to main branch
Merging dev into main branch 
Date: 28 june 2026
Merging dev into main branch (1 july 2026)
merging dev into main (7 july 2026)
Merging dev into main branch (8 july 2026)
…-tests

test: Add unit tests for core functionality
…ub-actions

ci: Implement GitHub Action for automated CI testing
…erfile

build: Add Dockerfile for containerized development
…itecture

docs: Create ARCHITECTURE.md documentation
@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown

@Dev1822 is attempting to deploy a commit to the Arghya's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@arghya29, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 42 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 9ed81468-4c9d-4661-8202-b30c2cd0fc14

📥 Commits

Reviewing files that changed from the base of the PR and between e1807da and 96c72aa.

📒 Files selected for processing (10)
  • .dockerignore
  • .github/workflows/test-check.yml
  • ARCHITECTURE.md
  • Dockerfile
  • __tests__/unit/core.test.ts
  • app/[locale]/(dashboard)/settings/factors/page.tsx
  • app/api/factors/route.ts
  • components/dashboard/dashboard-nav.tsx
  • messages/en.json
  • messages/es.json
📝 Walkthrough

Walkthrough

The emission factors settings page now loads system and custom factors separately, combines them with override metadata, and supports tabs, search, scope filtering, create/update forms, citations, controlled deletion, and system-factor overrides. A protected system-factors API route and dashboard navigation entry were added.

Changes

Emission Factor Management

Layer / File(s) Summary
System factor data access
app/api/system-factors/route.ts
Adds an organization-protected endpoint that returns database emission factors ordered by category.
Settings entry and factor model
components/dashboard/dashboard-nav.tsx, app/(dashboard)/settings/factors/page.tsx
Adds the Emission Factors navigation entry and separates system/custom data with derived override-aware lists.
Factor form and mutation flow
app/(dashboard)/settings/factors/page.tsx
Adds unit and citation fields, create/update state, contextual notifications, refetching, and controlled delete confirmation.
Tabbed listing and row actions
app/(dashboard)/settings/factors/page.tsx, components/ui/factor-row.tsx
Adds All/Custom/System tabs, search and scope filtering, dataset states, custom edit/delete actions, and system override actions with override indicators.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Suggested labels: VETERAN, ELUSOC, feature, frontend, backend, API

Suggested reviewers: kgfch2

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Linked Issues check ❓ Inconclusive The PR covers the dashboard page, custom/system separation, and org-scoped API, but the summary doesn't verify override-priority calculations or schema linkage for #152. Add evidence of the calculation path that prefers custom overrides and the Prisma/schema changes that bind factors to organizations/accounts.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: custom and override emission factors.
Description check ✅ Passed The description matches the template and includes the required sections, issue link, change type, and checklist.
Out of Scope Changes check ✅ Passed The changes stay focused on emission-factor management, navigation, and related UI/API support with no unrelated additions evident.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 5ee38386-5c55-4a1f-8a7a-c0bf5901b005

📥 Commits

Reviewing files that changed from the base of the PR and between 34e9880 and e1807da.

📒 Files selected for processing (4)
  • app/(dashboard)/settings/factors/page.tsx
  • app/api/system-factors/route.ts
  • components/dashboard/dashboard-nav.tsx
  • components/ui/factor-row.tsx
📜 Review details
⚠️ CI failures not shown inline (1)

Commit Status: Vercel: Vercel

Conclusion: failure

Authorization required to deploy.
🔇 Additional comments (5)
app/api/system-factors/route.ts (1)

5-21: LGTM!

components/dashboard/dashboard-nav.tsx (1)

23-23: LGTM!

Also applies to: 41-41

app/(dashboard)/settings/factors/page.tsx (2)

27-34: LGTM!


156-201: LGTM!

components/ui/factor-row.tsx (1)

8-134: LGTM!

Comment thread app/[locale]/(dashboard)/settings/factors/page.tsx
Comment thread app/(dashboard)/settings/factors/page.tsx Outdated
Dev1822 and others added 2 commits July 22, 2026 18:45
Signed-off-by: Arghyadeep Bag <arghyadeep192@gmail.com>
@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
eco-sphere Ready Ready Preview, Comment Jul 22, 2026 7:00pm

@arghya29 arghya29 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@Dev1822 LGTM, I have fixed the Merge Conflicts.

One thing, the commit history is messy. Please always make branch from the latest dev branch to avoid such messy commit history.

I am doing squash and merge due to that reason for this PR

@arghya29
arghya29 merged commit 889d1b8 into arghya29:dev Jul 22, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT] Allow users to add custom/override emission factors

3 participants