Skip to content

Update nitrogen balance with fieldInput data#303

Merged
SvenVw merged 2 commits into
developmentfrom
FDM294-1
Oct 23, 2025
Merged

Update nitrogen balance with fieldInput data#303
SvenVw merged 2 commits into
developmentfrom
FDM294-1

Conversation

@SvenVw
Copy link
Copy Markdown
Collaborator

@SvenVw SvenVw commented Oct 23, 2025

fix: exception introduced by #294 at nitrogen balance field page

Summary by CodeRabbit

  • Bug Fixes
    • Nitrogen balance display now correctly shows field-specific input alongside computed balance results.
    • Details view updated to use the field input and the precise balance data, ensuring accurate and consistent presentation.

@SvenVw SvenVw self-assigned this Oct 23, 2025
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Oct 23, 2025

⚠️ No Changeset found

Latest commit: c3dfb63

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.12%. Comparing base (7c42bf5) to head (c3dfb63).
⚠️ Report is 3 commits behind head on development.

Additional details and impacted files
@@             Coverage Diff              @@
##           development     #303   +/-   ##
============================================
  Coverage        93.12%   93.12%           
============================================
  Files               81       81           
  Lines            13314    13314           
  Branches          1360     1360           
============================================
  Hits             12398    12398           
  Misses             914      914           
  Partials             2        2           
Flag Coverage Δ
fdm-calculator 94.65% <ø> (ø)
fdm-core 92.02% <ø> (ø)
fdm-data 94.02% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Oct 23, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Loader now locates and returns the field-specific fieldInput alongside fieldResult. The NitrogenBalance component consumes fieldInput and passes fieldResult.balance and fieldInput into NitrogenBalanceDetails (props updated).

Changes

Cohort / File(s) Summary
Route loader & component update
fdm-app/app/routes/farm.$b_id_farm.$calendar.balance.nitrogen.$b_id.tsx
Loader now finds the matching field input in input.fields and returns fieldInput alongside fieldResult; NitrogenBalance destructures fieldInput and passes fieldResult.balance and fieldInput into NitrogenBalanceDetails (prop shapes adjusted).

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Browser
    participant Loader
    participant NitrogenBalance
    participant NitrogenBalanceDetails

    Browser->>Loader: request /farm/.../balance/nitrogen/:b_id
    Loader-->>Browser: { fieldResult, fieldInput, ... }
    Browser->>NitrogenBalance: render with loader data
    NitrogenBalance->>NitrogenBalanceDetails: props(balance=fieldResult.balance, fieldInput=fieldInput)
    NitrogenBalanceDetails-->>Browser: render details
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

bug, branch:development

Suggested reviewers

  • gerardhros

Poem

🐰 In rows of code I nibble through,
I split the inputs — tidy, true.
Balance and field now hop in line,
Passed along, concise and fine. 🌱🐇

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Update nitrogen balance with fieldInput data" directly describes the primary technical changes in the pull request. The changeset adds fieldInput to the loader, destructures it in the NitrogenBalance component, and refactors how props are passed to use fieldInput alongside fieldResult. The title is concise, clear, and accurately reflects these modifications. While the PR objectives frame this as a fix for an exception introduced by PR #294, the title focuses on the technical nature of the change itself rather than its classification, which is appropriate for a commit history entry.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7409e2d and c3dfb63.

📒 Files selected for processing (1)
  • fdm-app/app/routes/farm.$b_id_farm.$calendar.balance.nitrogen.$b_id.tsx (3 hunks)

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 and usage tips.

@coderabbitai coderabbitai Bot changed the title @coderabbitai Update nitrogen balance with fieldInput data Oct 23, 2025
@coderabbitai coderabbitai Bot added the fdm-app label Oct 23, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
fdm-app/app/routes/farm.$b_id_farm.$calendar.balance.nitrogen.$b_id.tsx (1)

136-139: Return only the current field’s input instead of the full dataset.

Reducing the payload and coupling here will avoid accidental mismatches later and makes the consumer simpler. Compute the per‑field input in the loader and return just that.

Apply this focused change inside the existing then:

-            return {
-                fieldResult: fieldResult,
-                fieldInput: input,
-            }
+            const fieldInputForField =
+                input.fields?.find((f: any) => (f.b_id ?? f?.meta?.b_id) === b_id) ?? null
+            return {
+                fieldResult,
+                fieldInput: fieldInputForField,
+            }

Please confirm the correct identifier path on items in input.fields (e.g., f.b_id vs f.meta.b_id) and adjust the predicate accordingly.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7c42bf5 and 7409e2d.

📒 Files selected for processing (1)
  • fdm-app/app/routes/farm.$b_id_farm.$calendar.balance.nitrogen.$b_id.tsx (3 hunks)
🔇 Additional comments (2)
fdm-app/app/routes/farm.$b_id_farm.$calendar.balance.nitrogen.$b_id.tsx (2)

181-181: LGTM: correct Suspense + use() pattern.

Destructuring the resolved promise from use(nitrogenBalanceResult) is idiomatic in React 19 and fits the router’s deferred pattern.


391-393: The review comment is valid. Index-based field selection is brittle.

Looking at the loader (lines 55–138), collectInputForNitrogenBalance() returns an input object with a fields array that may contain multiple fields. The loader receives a specific b_id from route params and already correctly filters the nitrogen balance result to find the matching field (lines 113–117):

let fieldResult = nitrogenBalanceResult.fields.find(
    (field: { b_id: string }) => field.b_id === b_id,
)

However, at line 392, the code passes fieldInput.fields[0] unconditionally, assuming the first field is correct. This breaks if:

  • The fields array ordering changes
  • Multiple fields are present and the first isn't the one being displayed
  • The array is empty

The loader has access to both b_id (params) and the matched field object (line 75). The fix should either:

  1. In the loader (preferred): Filter input.fields to only the matching field before returning, or return a pointer to the selected field.
  2. In the component: Use .find() to match the field by b_id, with a fallback to the first element or null.

The suggestion in the review is sound. Apply either option depending on whether the loader refactor is feasible in your context.

@SvenVw SvenVw merged commit 3fffd4d into development Oct 23, 2025
8 of 10 checks passed
@coderabbitai coderabbitai Bot added branch:development Issue only affecting development, not the main branch (yet) bug Something isn't working labels Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

branch:development Issue only affecting development, not the main branch (yet) bug Something isn't working fdm-app

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant