Skip to content

Add fertilizer application#16

Merged
SvenVw merged 68 commits into
mainfrom
add-fertilizer-application
Dec 17, 2024
Merged

Add fertilizer application#16
SvenVw merged 68 commits into
mainfrom
add-fertilizer-application

Conversation

@SvenVw
Copy link
Copy Markdown
Collaborator

@SvenVw SvenVw commented Dec 5, 2024

Summary by CodeRabbit

Release Notes for Version 0.4.0

  • New Features

    • Introduced the FertilizerApplicationsForm for managing fertilizer applications, including listing, adding, and deleting entries.
    • Enhanced user feedback through toast notifications across the application.
    • Added a new component for displaying cover crop information.
  • Improvements

    • Default selection for fertilizers now selects all options.
    • Streamlined form components by removing unnecessary fields related to organic and mineral fertilizers.
    • Updated navigation structure from tabs to pagination for better user experience.
  • Bug Fixes

    • Various dependency updates to ensure better performance and stability.
  • Documentation

    • Updated changelogs and documentation for new features and changes.

@SvenVw SvenVw self-assigned this Dec 5, 2024
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Dec 5, 2024

⚠️ No Changeset found

Latest commit: 87e0c8a

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 5, 2024

Warning

Rate limit exceeded

@SvenVw has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 10 minutes and 31 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 098e8d0 and 87e0c8a.

📒 Files selected for processing (7)
  • fdm-app/app/routes/app.addfarm.$b_id_farm.cultivations.$b_lu_catalogue.fertilizers.tsx (1 hunks)
  • fdm-app/app/routes/app.addfarm.new.tsx (5 hunks)
  • fdm-calculator/CHANGELOG.md (1 hunks)
  • fdm-calculator/package.json (1 hunks)
  • fdm-calculator/tsconfig.json (1 hunks)
  • fdm-core/CHANGELOG.md (1 hunks)
  • fdm-data/CHANGELOG.md (1 hunks)

Walkthrough

Version 0.4.0 of the FDM application introduces enhancements to fertilizer management, including the new FertilizerApplicationsForm component for listing, adding, and deleting fertilizer applications. The application has streamlined its architecture by removing previous fertilizer selection methods and focusing on managing fertilizer data. Key changes include updates to database schemas, new functions for fertilizer application management, and modifications to existing components to support these features.

Changes

File/Path Change Summary
package.json - Version updated to 0.4.0
- Added dependencies: next-themes, remix-toast, sonner
CHANGELOG.md - Updated to include version 0.4.0 and its changes
app/components/blocks/farm.tsx - Removed fertilizer-related properties from farmType interface
app/components/custom/combobox-fertilizers.tsx - Deleted file containing the ComboboxFertilizers component
app/components/custom/combobox.tsx - Updated props to use form-based state management
app/components/custom/fertilizer-applications.tsx - Added FertilizerApplicationsForm component for managing fertilizer applications
app/root.tsx - Added toast notification functionality
app/routes/app.addfarm.$b_id_farm.cultivations.$b_lu_catalogue.covercrop.tsx - Introduced new Index component with a message
app/routes/app.addfarm.$b_id_farm.cultivations.$b_lu_catalogue.crop.tsx - Removed SidebarNav component and renamed main export to Index
app/routes/app.addfarm.$b_id_farm.cultivations.$b_lu_catalogue.fertilizers.tsx - New route for managing fertilizer applications with loader and action functions
app/routes/app.addfarm.new.tsx - Added logic for adding fertilizers during farm creation
fdm-core/CHANGELOG.md - Updated to include version 0.7.0 and its changes
fdm-core/package.json - Version updated to 0.7.0
fdm-core/src/cultivation.d.ts - Added new cultivationPlanType interface
fdm-core/src/fertilizer.d.ts - Renamed property in getFertilizerType interface and removed getFertilizersType interface
fdm-core/src/index.ts - Expanded exports from the fertilizer module

Sequence Diagram

sequenceDiagram
    participant User
    participant FertilizerApplicationsForm
    participant Backend
    
    User->>FertilizerApplicationsForm: Open form
    FertilizerApplicationsForm->>Backend: Fetch existing applications
    Backend-->>FertilizerApplicationsForm: Return applications
    User->>FertilizerApplicationsForm: Add new application
    FertilizerApplicationsForm->>Backend: Submit application details
    Backend-->>FertilizerApplicationsForm: Confirm submission
    User->>FertilizerApplicationsForm: Delete application
    FertilizerApplicationsForm->>Backend: Request deletion
    Backend-->>FertilizerApplicationsForm: Confirm deletion
Loading

Possibly related PRs

  • Upgrade forms with zod validation #17: The changes in this PR involve the integration of Zod for form validation, which directly relates to the addition of the FertilizerApplicationsForm in the main PR, as both involve enhancements to form handling and validation processes.

Poem

🥕 Fertilizer Frolics 🌱

In fields of green, a rabbit's delight,
Fertilizer forms now shine so bright!
Applications added with a hop and a leap,
No more complex choices to keep.
A farmer's friend, both simple and neat!

🐰✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

@SvenVw SvenVw added enhancement New feature or request fdm-app fdm-core labels Dec 5, 2024
@SvenVw SvenVw added this to the Alpha release milestone Dec 5, 2024
@SvenVw SvenVw linked an issue Dec 5, 2024 that may be closed by this pull request
4 tasks
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: 3

🧹 Nitpick comments (6)
fdm-app/app/components/custom/combobox.tsx (1)

101-101: Remove empty FormDescription component

The <FormDescription /> component is empty and serves no purpose.

-    <FormDescription />
fdm-app/app/routes/app.addfarm.$b_id_farm.cultivations.$b_lu_catalogue.fertilizers.tsx (1)

168-171: Enhance error messages with specific details

The current error handling uses a generic message. Including specific error details would help with debugging.

Apply this diff to improve error messages:

-            console.error("Error deleting fertilizer application:", error);
-            return dataWithError(null, "Oops! Something went wrong. Please try again later.");
+            console.error("Error deleting fertilizer application:", error);
+            return dataWithError(
+                error instanceof Error ? error.message : "Unknown error",
+                "Er is een fout opgetreden bij het verwijderen van de bemesting. Probeer het later opnieuw."
+            );
fdm-app/app/components/custom/fertilizer-applications.tsx (1)

43-43: Consider implementing validation against available options.

The TODO comment indicates missing validation against available fertilizer options. This validation would prevent submission of invalid fertilizer IDs.

Would you like me to help implement the validation logic for checking against the available options?

fdm-core/src/cultivation.test.ts (1)

310-342: Consider adding edge case tests.

While the happy path is well tested, consider adding tests for:

  • Invalid fertilizer amounts
  • Invalid application methods
  • Overlapping application dates
fdm-core/src/fertilizer.ts (2)

320-357: Consider adding input validation.

While the function validates entity existence, consider adding validation for:

  • Non-negative application amount
  • Valid application method values
  • Application date within reasonable range

449-462: Consider enhancing data retrieval.

The function could be more useful by including fertilizer details in the response:

  • Join with fertilizers table
  • Include fertilizer name and properties
  • Add sorting options
 const fertilizerApplications = await fdm
-    .select()
+    .select({
+        ...schema.fertilizerApplication,
+        p_name_nl: schema.fertilizersCatalogue.p_name_nl,
+        p_name_en: schema.fertilizersCatalogue.p_name_en,
+    })
     .from(schema.fertilizerApplication)
+    .leftJoin(schema.fertilizers, eq(schema.fertilizerApplication.p_id, schema.fertilizers.p_id))
+    .leftJoin(schema.fertilizerPicking, eq(schema.fertilizers.p_id, schema.fertilizerPicking.p_id))
+    .leftJoin(schema.fertilizersCatalogue, eq(schema.fertilizerPicking.p_id_catalogue, schema.fertilizersCatalogue.p_id_catalogue))
     .where(eq(schema.fertilizerApplication.b_id, b_id));
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2623632 and 3dd4f44.

📒 Files selected for processing (9)
  • fdm-app/app/components/custom/combobox.tsx (3 hunks)
  • fdm-app/app/components/custom/fertilizer-applications.tsx (1 hunks)
  • fdm-app/app/routes/app.addfarm.$b_id_farm.cultivations.$b_lu_catalogue.fertilizers.tsx (1 hunks)
  • fdm-app/app/routes/app.addfarm.$b_id_farm.cultivations.tsx (3 hunks)
  • fdm-app/app/routes/app.addfarm.new.tsx (5 hunks)
  • fdm-core/src/cultivation.test.ts (6 hunks)
  • fdm-core/src/fertilizer.ts (9 hunks)
  • fdm-core/tsconfig.json (1 hunks)
  • fdm-data/tsconfig.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • fdm-core/tsconfig.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • fdm-app/app/routes/app.addfarm.$b_id_farm.cultivations.tsx
🧰 Additional context used
📓 Learnings (3)
fdm-app/app/routes/app.addfarm.$b_id_farm.cultivations.$b_lu_catalogue.fertilizers.tsx (1)
Learnt from: SvenVw
PR: SvenVw/fdm#16
File: fdm-app/app/routes/app.addfarm.$b_id_farm.cultivations.$b_lu_catalogue.fertilizers.tsx:1-1
Timestamp: 2024-12-16T10:56:07.561Z
Learning: The project uses `react-router` v7, and the `data` function is exported and used for error handling in loaders and actions.
fdm-app/app/routes/app.addfarm.new.tsx (1)
Learnt from: SvenVw
PR: SvenVw/fdm#16
File: fdm-app/app/routes/app.addfarm.$b_id_farm.cultivations.$b_lu_catalogue.fertilizers.tsx:1-1
Timestamp: 2024-12-16T10:56:07.561Z
Learning: The project uses `react-router` v7, and the `data` function is exported and used for error handling in loaders and actions.
fdm-app/app/components/custom/combobox.tsx (1)
Learnt from: SvenVw
PR: SvenVw/fdm#16
File: fdm-app/app/components/custom/combobox.tsx:35-37
Timestamp: 2024-12-16T10:56:33.616Z
Learning: When using `useRemixForm`, the correct type for the `form` prop is `UseRemixFormReturn<T>` from `remix-hook-form`, not `UseFormReturn` from `react-hook-form`.
🔇 Additional comments (9)
fdm-app/app/routes/app.addfarm.new.tsx (2)

Line range hint 1-43: LGTM! Clean and focused loader implementation.

The loader has been simplified to only handle the essential farm name data.


Line range hint 44-81: LGTM! Clean component implementation.

The component properly passes the required props to the Farm component.

fdm-app/app/routes/app.addfarm.$b_id_farm.cultivations.$b_lu_catalogue.fertilizers.tsx (1)

131-141: ⚠️ Potential issue

Fix async operations in fields.map

The current implementation uses map with async operations without properly handling the promises. This could lead to the success response being sent before all operations complete.

Apply this diff to properly handle async operations:

-    fields.map(async (field) => {
-        const b_id = field.b_id
-        await addFertilizerApplication(
-            fdm,
-            b_id,
-            p_id,
-            p_app_amount,
-            undefined,
-            p_app_date
-        )
-    })
+    await Promise.all(
+        fields.map(async (field) => {
+            const b_id = field.b_id
+            return addFertilizerApplication(
+                fdm,
+                b_id,
+                p_id,
+                p_app_amount,
+                undefined,
+                p_app_date
+            )
+        })
+    )

Likely invalid or redundant comment.

fdm-app/app/components/custom/fertilizer-applications.tsx (4)

48-66: LGTM! Well-structured interfaces.

The interfaces are properly typed and provide good type safety for the component props.


68-94: LGTM! Robust form handling implementation.

The form initialization and handlers are well implemented with:

  • Proper form state management
  • Form reset after successful submission
  • Loading state handling for delete operations

156-165: Enable date range validation.

The calendar currently allows selection of any date, including future dates. The commented validation suggests this wasn't intended.

 <Calendar
     mode="single"
     selected={field.value}
     onSelect={field.onChange}
-    // disabled={(date) =>
-    //     date > new Date() || date < new Date("1900-01-01")
-    // }
+    disabled={(date) =>
+        date > new Date() || date < new Date("1900-01-01")
+    }
     initialFocus
 />

211-224: LGTM! Well-implemented delete button.

The delete button implementation includes proper loading states and error handling.

fdm-core/src/cultivation.test.ts (1)

Line range hint 1-84: LGTM! Comprehensive test setup.

The test setup includes proper environment validation and database connection handling.

fdm-core/src/fertilizer.ts (1)

374-412: 🛠️ Refactor suggestion

Standardize error handling across functions.

The error handling in update and remove functions should match addFertilizerApplication:

  1. Add entity existence validation
  2. Use ES2022 error cause consistently
 } catch (error) {
-    throw new Error(`Failed to update fertilizer application: ${error}`);
+    throw new Error(`Failed to update fertilizer application: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
 }

Likely invalid or redundant comment.

Comment thread fdm-data/tsconfig.json
Comment thread fdm-app/app/routes/app.addfarm.new.tsx Outdated
SvenVw and others added 2 commits December 16, 2024 13:18
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Sven Verweij <37927107+SvenVw@users.noreply.github.com>
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

♻️ Duplicate comments (1)
fdm-app/app/routes/app.addfarm.new.tsx (1)

108-111: 🛠️ Refactor suggestion

Enhance error handling with specific error scenarios

The current error handling is too generic. Consider handling specific error scenarios differently.

🧹 Nitpick comments (1)
fdm-app/app/routes/app.addfarm.new.tsx (1)

29-31: Consider internationalizing validation messages

The validation messages are currently hardcoded in Dutch. Consider moving these to a translation file for better maintainability and future internationalization support.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3dd4f44 and 098e8d0.

📒 Files selected for processing (1)
  • fdm-app/app/routes/app.addfarm.new.tsx (5 hunks)
🧰 Additional context used
📓 Learnings (1)
fdm-app/app/routes/app.addfarm.new.tsx (1)
Learnt from: SvenVw
PR: SvenVw/fdm#16
File: fdm-app/app/routes/app.addfarm.$b_id_farm.cultivations.$b_lu_catalogue.fertilizers.tsx:1-1
Timestamp: 2024-12-16T10:56:07.561Z
Learning: The project uses `react-router` v7, and the `data` function is exported and used for error handling in loaders and actions.
🔇 Additional comments (2)
fdm-app/app/routes/app.addfarm.new.tsx (2)

36-42: LGTM! Good simplification of the loader function

The removal of fertilizer lists from the loader function aligns well with the architectural changes and follows the single responsibility principle.


75-78: LGTM! Clean component interface

The Farm component's props have been appropriately simplified to match the loader changes, making the interface cleaner and more focused.

Comment thread fdm-app/app/routes/app.addfarm.new.tsx Outdated
@SvenVw
Copy link
Copy Markdown
Collaborator Author

SvenVw commented Dec 16, 2024

@coderabbitai generate docstrings

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 16, 2024

✅ Actions performed

Docstrings generation started.

coderabbitai Bot added a commit that referenced this pull request Dec 16, 2024
> [!WARNING]
> The [docstrings feature](https://docs.coderabbit.ai/finishing-touches/docstrings) is in [beta](https://docs.coderabbit.ai/early-access/#beta).

Docstrings generation was requested by @SvenVw.

* #16 (comment)

The following files were modified:

* `fdm-core/src/cultivation.ts`
* `fdm-core/src/fertilizer.ts`
@SvenVw SvenVw merged commit 6b2a7d1 into main Dec 17, 2024
@coderabbitai coderabbitai Bot mentioned this pull request Jun 3, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add functionality to FertilizationCombobox

1 participant