Skip to content

Add BAAT catalogue#177

Merged
SvenVw merged 8 commits into
developmentfrom
add-baat-catalogue
Jun 26, 2025
Merged

Add BAAT catalogue#177
SvenVw merged 8 commits into
developmentfrom
add-baat-catalogue

Conversation

@SvenVw
Copy link
Copy Markdown
Collaborator

@SvenVw SvenVw commented Jun 25, 2025

Summary by CodeRabbit

  • New Features

    • Added support for a new fertilizer catalogue source, "baat", including a comprehensive set of fertilizer data.
    • Forms for adding or editing fertilizers now include two new parameters: p_no3_rt and p_nh4_rt.
  • Improvements

    • New farms now use the "baat" catalogue as the default fertilizer source.
    • Fertilizer catalogue synchronization now aggregates both "srm" and "baat" sources.
  • Documentation

    • Updated documentation and examples to reference the "baat" fertilizer catalogue.
    • Clarified catalogue source identifiers and data contribution guidelines.
  • Tests

    • Added and updated tests to cover the new "baat" fertilizer catalogue and its integration.

@SvenVw SvenVw self-assigned this Jun 25, 2025
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jun 25, 2025

🦋 Changeset detected

Latest commit: c0422ac

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@svenvw/fdm-core Minor
@svenvw/fdm-app Minor
@svenvw/fdm-data Minor
@svenvw/fdm-calculator Patch

Not sure what this means? Click here to learn what changesets are.

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 25, 2025

Walkthrough

This update introduces support for the "baat" fertilizer catalogue throughout the system. It adds the "baat" dataset, enables its selection and syncing, updates relevant types, documentation, and tests, and extends form handling to support new fertilizer parameters. Existing logic is adapted to accommodate this new catalogue source.

Changes

Files/Paths Change Summary
.changeset/lucky-candies-push.md, .changeset/tame-jokes-enjoy.md, .changeset/witty-areas-decide.md Add changeset entries documenting minor updates for "baat" catalogue support and default source changes.
fdm-data/src/fertilizers/catalogues/baat.json Add comprehensive "baat" fertilizer catalogue dataset as a new JSON file.
fdm-data/src/fertilizers/catalogues/baat.ts Add getCatalogueBaat async function to load and process "baat" catalogue data.
fdm-data/src/fertilizers/d.ts Update CatalogueFertilizerName type to include "baat".
fdm-data/src/fertilizers/index.ts, fdm-data/src/fertilizers/index.test.ts Extend catalogue logic and tests to support "baat" as a valid catalogue source.
fdm-data/README.md, fdm-docs/docs/getting-started/04-using-catalogues-fdm-data.md Update documentation examples to use "baat" as the fertilizer catalogue.
fdm-docs/docs/core-concepts/02-schema.md, fdm-docs/docs/core-concepts/03-catalogues.md Update documentation to reference "baat" as a source and clarify catalogue contributions.
fdm-core/src/catalogues.ts Update syncing logic to aggregate and process both "srm" and "baat" catalogues.
fdm-app/app/routes/farm.$b_id_farm.fertilizers.$p_id.tsx, fdm-app/app/routes/farm.$b_id_farm.fertilizers.new.$p_id.tsx, fdm-app/app/routes/farm.$b_id_farm.fertilizers.new.custom.tsx Add support for new fertilizer parameters (p_no3_rt, p_nh4_rt, p_ef_nh3) in forms and backend logic.
fdm-app/app/routes/farm.create._index.tsx Change default fertilizer catalogue source for new farms from "srm" to "baat".

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App (fdm-app)
    participant Core (fdm-core)
    participant Data (fdm-data)
    Note over User: Creates new farm or requests fertilizer catalogue
    User->>App (fdm-app): Initiate farm creation or fetch fertilizers
    App (fdm-app)->>Core (fdm-core): enableFertilizerCatalogue("baat")
    App (fdm-app)->>Data (fdm-data): getFertilizersCatalogue("baat")
    Data (fdm-data)->>Data (fdm-data): getCatalogueBaat()
    Data (fdm-data)->>Data (fdm-data): Load and hash baat.json entries
    Data (fdm-data)-->>App (fdm-app): Return baat catalogue
    App (fdm-app)-->>User: Show catalogue/fertilizer options
Loading

Possibly related PRs

Suggested labels

fdm-app, fdm-core, fdm-data

Suggested reviewers

  • gerardhros

Poem

A new catalogue hops in, called "baat",
Fertilizer data—so rich, never flat!
With NO₃ and NH₄,
The forms now go far,
Farms grow smarter—imagine that!
🥕✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch add-baat-catalogue

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 25, 2025

Codecov Report

Attention: Patch coverage is 97.77778% with 2 lines in your changes missing coverage. Please review.

Project coverage is 93.49%. Comparing base (5ffa05a) to head (c0422ac).
Report is 9 commits behind head on development.

Files with missing lines Patch % Lines
fdm-data/src/fertilizers/catalogues/baat.ts 97.56% 2 Missing ⚠️
Additional details and impacted files
@@               Coverage Diff               @@
##           development     #177      +/-   ##
===============================================
+ Coverage        93.45%   93.49%   +0.04%     
===============================================
  Files               73       74       +1     
  Lines             8784     8872      +88     
  Branches          1088     1120      +32     
===============================================
+ Hits              8209     8295      +86     
- Misses             573      575       +2     
  Partials             2        2              
Flag Coverage Δ
fdm-calculator 95.15% <ø> (ø)
fdm-core 93.04% <100.00%> (+<0.01%) ⬆️
fdm-data 94.21% <97.70%> (+1.42%) ⬆️

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.

@SvenVw SvenVw changed the base branch from add-ammonia-emissions to development June 26, 2025 07:45
@SvenVw SvenVw marked this pull request as ready for review June 26, 2025 07:45
@SvenVw
Copy link
Copy Markdown
Collaborator Author

SvenVw commented Jun 26, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 26, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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: 1

🧹 Nitpick comments (1)
fdm-data/src/fertilizers/index.test.ts (1)

21-21: Improve type assertion to address static analysis warning

The as any type assertion triggers a linting warning. Consider using a more specific type assertion for better type safety.

-            getFertilizersCatalogue("invalid-catalogue" as any),
+            getFertilizersCatalogue("invalid-catalogue" as CatalogueFertilizerName),

This maintains the same testing behavior while being more explicit about the type violation being tested.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5ffa05a and c0422ac.

📒 Files selected for processing (17)
  • .changeset/lucky-candies-push.md (1 hunks)
  • .changeset/tame-jokes-enjoy.md (1 hunks)
  • .changeset/witty-areas-decide.md (1 hunks)
  • fdm-app/app/routes/farm.$b_id_farm.fertilizers.$p_id.tsx (1 hunks)
  • fdm-app/app/routes/farm.$b_id_farm.fertilizers.new.$p_id.tsx (3 hunks)
  • fdm-app/app/routes/farm.$b_id_farm.fertilizers.new.custom.tsx (5 hunks)
  • fdm-app/app/routes/farm.create._index.tsx (1 hunks)
  • fdm-core/src/catalogues.ts (1 hunks)
  • fdm-data/README.md (1 hunks)
  • fdm-data/src/fertilizers/catalogues/baat.json (1 hunks)
  • fdm-data/src/fertilizers/catalogues/baat.ts (1 hunks)
  • fdm-data/src/fertilizers/d.ts (1 hunks)
  • fdm-data/src/fertilizers/index.test.ts (4 hunks)
  • fdm-data/src/fertilizers/index.ts (3 hunks)
  • fdm-docs/docs/core-concepts/02-schema.md (1 hunks)
  • fdm-docs/docs/core-concepts/03-catalogues.md (2 hunks)
  • fdm-docs/docs/getting-started/04-using-catalogues-fdm-data.md (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
fdm-core/src/catalogues.ts (2)
fdm-data/src/fertilizers/index.ts (1)
  • getFertilizersCatalogue (25-36)
fdm-core/src/db/schema.ts (1)
  • fertilizersCatalogue (187-247)
fdm-data/src/fertilizers/index.ts (1)
fdm-data/src/fertilizers/catalogues/baat.ts (1)
  • getCatalogueBaat (19-102)
fdm-data/src/fertilizers/catalogues/baat.ts (1)
fdm-data/src/fertilizers/d.ts (3)
  • CatalogueFertilizer (70-70)
  • CatalogueFertilizerItem (15-68)
  • ApplicationMethods (3-13)
🪛 LanguageTool
.changeset/tame-jokes-enjoy.md

[uncategorized] ~5-~5: Possible missing comma found.
Context: ...- "@svenvw/fdm-app": minor --- For new farms use the baat catalogue for fertilizer...

(AI_HYDRA_LEO_MISSING_COMMA)

🪛 GitHub Check: codecov/patch
fdm-data/src/fertilizers/catalogues/baat.ts

[warning] 29-29: fdm-data/src/fertilizers/catalogues/baat.ts#L29
Added line #L29 was not covered by tests


[warning] 36-36: fdm-data/src/fertilizers/catalogues/baat.ts#L36
Added line #L36 was not covered by tests

🪛 Biome (1.9.4)
fdm-data/src/fertilizers/index.test.ts

[error] 21-21: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)

🔇 Additional comments (23)
.changeset/witty-areas-decide.md (1)

1-6: LGTM! Clear and concise changeset documentation.

The changeset correctly documents the addition of the new baat fertilizer catalogue as a minor version update to the @svenvw/fdm-data package.

.changeset/tame-jokes-enjoy.md (1)

5-6: Verify impact of changing default fertilizer catalogue.

The changeset documents switching new farms from srm to baat catalogue. While this appears intentional based on the broader PR context, ensure this change won't break existing integrations or workflows that might expect srm as the default catalogue.

.changeset/lucky-candies-push.md (1)

1-6: LGTM! Appropriate infrastructure change documented.

The changeset correctly documents the addition of syncing functionality for the new baat fertilizer catalogue in the core package.

fdm-app/app/routes/farm.create._index.tsx (1)

206-207: ```shell
#!/bin/bash
echo "Scanning fdm-app for 'srm' references..."
rg -n -i --glob '.ts' --glob '.tsx' 'srm' fdm-app/

echo -e "\nScanning fdm-app for 'baat' references..."
rg -n -i --glob '.ts' --glob '.tsx' 'baat' fdm-app/

echo -e "\nScanning fdm-app for 'getFertilizersFromCatalogue' usage..."
rg -n --glob '.ts' --glob '.tsx' 'getFertilizersFromCatalogue' fdm-app/


</details>
<details>
<summary>fdm-data/README.md (1)</summary>

`30-34`: **LGTM! Documentation examples properly updated.**

The README example has been consistently updated to use the new `"baat"` catalogue instead of `"srm"`, including the variable names, comments, and console output message. This ensures the documentation reflects the current default behavior.

</details>
<details>
<summary>fdm-app/app/routes/farm.$b_id_farm.fertilizers.$p_id.tsx (1)</summary>

`164-165`: **LGTM: New fertilizer parameters added correctly.**

The addition of `p_no3_rt` and `p_nh4_rt` parameters follows the existing pattern and is positioned logically among other nitrogen-related parameters.

</details>
<details>
<summary>fdm-docs/docs/getting-started/04-using-catalogues-fdm-data.md (1)</summary>

`20-20`: **LGTM: Documentation updated to use BAAT catalogue.**

The import and console log changes correctly reflect the switch from SRM to BAAT fertilizer catalogue.



Also applies to: 24-24

</details>
<details>
<summary>fdm-docs/docs/core-concepts/02-schema.md (1)</summary>

`247-247`: **LGTM: Schema documentation aligned with implementation.**

The change from uppercase to lowercase example values correctly reflects the actual type definition that uses lowercase strings.

</details>
<details>
<summary>fdm-data/src/fertilizers/d.ts (1)</summary>

`1-1`: **LGTM: Type definition correctly extended for BAAT catalogue.**

The union type addition is backward compatible and properly enables support for the new "baat" fertilizer catalogue source.

</details>
<details>
<summary>fdm-docs/docs/core-concepts/03-catalogues.md (1)</summary>

`26-26`: **LGTM: Documentation updated to include BAAT catalogue.**

The additions correctly recognize "baat" as a valid source identifier and update examples to reflect the new fertilizer catalogue integration.



Also applies to: 41-41

</details>
<details>
<summary>fdm-core/src/catalogues.ts (1)</summary>

`380-382`: **LGTM: Clean implementation of multi-catalogue support**

The implementation correctly fetches both "srm" and "baat" catalogues and combines them using the spread operator. This maintains the existing transaction logic while extending functionality to support multiple fertilizer data sources.

</details>
<details>
<summary>fdm-app/app/routes/farm.$b_id_farm.fertilizers.new.$p_id.tsx (1)</summary>

`159-160`: **LGTM: Consistent addition of nitrate and ammonium parameters**

The new fertilizer parameters `p_no3_rt` and `p_nh4_rt` are correctly added to both form defaults and action data, maintaining consistency between UI and backend processing. These parameters enhance the fertilizer data model for better agricultural management.




Also applies to: 241-242

</details>
<details>
<summary>fdm-data/src/fertilizers/index.ts (1)</summary>

`1-1`: **LGTM: Clean extension of catalogue dispatcher**

The implementation correctly adds "baat" catalogue support following the same pattern as the existing "srm" catalogue. The documentation update and import addition are appropriate, and error handling remains robust.




Also applies to: 12-12, 32-34

</details>
<details>
<summary>fdm-data/src/fertilizers/catalogues/baat.ts (1)</summary>

`19-102`: **LGTM: Well-implemented catalogue loader with proper data transformation**

The `getCatalogueBaat` function is well-structured with proper:
- Async processing using `Promise.all` for performance
- Null handling for undefined JSON properties  
- String splitting for application methods
- Type safety with explicit `CatalogueFertilizerItem` interface
- Hash generation for data integrity

The static analysis warnings about test coverage on conditional branches (lines 29, 36) are acceptable as they handle edge cases for undefined values.

</details>
<details>
<summary>fdm-data/src/fertilizers/index.test.ts (2)</summary>

`3-3`: **LGTM: Comprehensive test coverage for BAAT catalogue**

The test additions provide excellent coverage for the new "baat" catalogue functionality, including validation of catalogue retrieval, non-empty results, and correct source attribution. The tests follow the established patterns and ensure the new catalogue works correctly.




Also applies to: 13-17, 31-35, 44-49

---

`119-184`: **LGTM: Thorough property validation for BAAT catalogue items**

The comprehensive test validates all expected properties of `CatalogueFertilizerItem` objects returned by `getCatalogueBaat`, ensuring data structure integrity and type conformance.

</details>
<details>
<summary>fdm-app/app/routes/farm.$b_id_farm.fertilizers.new.custom.tsx (4)</summary>

`76-77`: **LGTM! Consistent parameter addition.**

The new nitrogen parameters `p_no3_rt` and `p_nh4_rt` are properly initialized following the established pattern for fertilizer properties.

---

`161-162`: **LGTM! Form default values properly updated.**

The new parameters are correctly included in the form's default values, maintaining consistency with the loader data structure.

---

`211-212`: **LGTM! Form reset logic updated correctly.**

The new parameters are properly included in the form reset logic, ensuring consistent form state management when fertilizer data changes.

---

`288-289`: **Verify the `p_ef_nh3` parameter handling.**

The new nitrogen parameters `p_no3_rt` and `p_nh4_rt` are correctly extracted from form values. However, `p_ef_nh3` is only added in the action handler (line 314) but doesn't appear in the loader, form defaults, or form reset logic. Please verify this is intentional.




```shell
#!/bin/bash
# Description: Check if p_ef_nh3 is handled elsewhere in the codebase or if it's a backend-computed field

# Search for p_ef_nh3 usage across the codebase
echo "=== Searching for p_ef_nh3 usage ==="
rg -A 3 -B 3 "p_ef_nh3"

# Check if p_ef_nh3 appears in form schemas
echo "=== Checking form schemas ==="
fd -e ts -e tsx -e js -e jsx | xargs rg -l "FormSchema\|formschema" | xargs rg -A 10 -B 5 "p_ef_nh3"

# Check fertilizer parameter descriptions
echo "=== Checking fertilizer parameter descriptions ==="
rg -A 5 -B 5 "getFertilizerParametersDescription\|ParametersDescription"

Also applies to: 314-314

fdm-data/src/fertilizers/catalogues/baat.json (3)

1-100: LGTM! Well-structured fertilizer catalog data.

The JSON structure is consistent and well-organized with:

  • Systematic ID scheme (BAAT001, BAAT002, etc.)
  • Consistent property naming and data types
  • Proper use of null for missing values
  • Clear source attribution ("baat")

18-21: LGTM! Nitrogen speciation data is chemically consistent.

The new nitrogen parameters p_no3_rt and p_nh4_rt show chemically sound relationships with total inorganic nitrogen (p_n_if). For example, in ammonium nitrate (BAAT002), the nitrate and ammonium values sum to the total inorganic nitrogen (170+170=340), which is expected for this fertilizer type.

Also applies to: 58-61, 98-101


37-40: LGTM! Application methods and type classifications are agriculturally sound.

The application methods are appropriately matched to fertilizer types:

  • Solid mineral fertilizers: broadcasting, pocket placement, incorporation
  • Liquid fertilizers: spoke wheel, spraying
  • Manures: various injection and incorporation methods

Type classifications are mutually exclusive and correctly applied.

Also applies to: 117-120, 397-400

Comment thread fdm-docs/docs/getting-started/04-using-catalogues-fdm-data.md
@SvenVw SvenVw merged commit 2a1c043 into development Jun 26, 2025
10 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.

1 participant