Skip to content

Update FDM app to use calendar-based dataset selection and new env variable#226

Merged
SvenVw merged 8 commits into
developmentfrom
FDM211
Aug 7, 2025
Merged

Update FDM app to use calendar-based dataset selection and new env variable#226
SvenVw merged 8 commits into
developmentfrom
FDM211

Conversation

@SvenVw
Copy link
Copy Markdown
Collaborator

@SvenVw SvenVw commented Aug 6, 2025

Summary by CodeRabbit

  • New Features

    • The Atlas view now displays datasets for available fields based on the selected calendar year.
  • Chores

    • Replaced previous dataset URL environment variables with a new unified variable for dataset access.
    • Updated configuration and environment files to include the new dataset URL variable.
    • Improved internal handling of dataset URLs by deriving them from the selected calendar year instead of passing URLs directly.

Closes #211

@SvenVw SvenVw self-assigned this Aug 6, 2025
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Aug 6, 2025

🦋 Changeset detected

Latest commit: 2e2a490

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

This PR includes changesets to release 1 package
Name Type
@svenvw/fdm-app Minor

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 Aug 6, 2025

Walkthrough

This change updates the FDM app to use a new environment variable (PUBLIC_FDM_DATASETS_URL) for dataset URLs, replacing the previous variable. The Atlas view now dynamically selects the dataset for available fields based on the selected calendar year. Supporting types, configuration, and loader logic have been updated to reflect this calendar-based dataset selection.

Changes

Cohort / File(s) Change Summary
Environment Variable Update
.changeset/blue-kiwis-dress.md, fdm-app/.env.example, fdm-app/app/root.tsx, fdm-app/app/types/public-env.d.ts
Introduced PUBLIC_FDM_DATASETS_URL environment variable, removed AVAILABLE_FIELDS_URL, and updated runtime/client config accordingly.
Atlas Calendar-based Dataset Selection
.changeset/silver-oranges-vanish.md, fdm-app/app/components/blocks/atlas/atlas-sources.tsx, fdm-app/app/components/blocks/atlas/atlas-url.ts, fdm-app/app/routes/farm.create.$b_id_farm.$calendar.atlas.tsx, fdm-app/app/routes/farm.$b_id_farm.$calendar.field.new.tsx
Refactored Atlas to derive available fields dataset URL from the selected calendar year using a new helper function; updated components and routes to pass calendar instead of URL.
Type and Interface Updates
fdm-app/app/types/config.d.ts, fdm-app/app/components/blocks/atlas/atlas.d.tsx
Added datasets_url to config interfaces; removed deprecated types relating to field URLs and props.
Server-side Dataset URL Refactor
fdm-app/app/routes/farm.$b_id_farm.$calendar.balance.nitrogen._index.tsx
Replaced direct environment variable usage with centralized server config for dataset URL.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant AtlasView
    participant FieldsSourceAvailable
    participant getAvailableFieldsUrl
    participant Config

    User->>AtlasView: Selects calendar year
    AtlasView->>FieldsSourceAvailable: Passes calendar year prop
    FieldsSourceAvailable->>getAvailableFieldsUrl: Requests URL for year
    getAvailableFieldsUrl->>Config: Reads PUBLIC_FDM_DATASETS_URL
    getAvailableFieldsUrl-->>FieldsSourceAvailable: Returns constructed dataset URL
    FieldsSourceAvailable-->>AtlasView: Loads and displays fields for selected year
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Assessment against linked issues

Objective Addressed Explanation
Show available fields per corresponding year in Atlas (use calendar to request fields) (#211)
Use calendar to specifically request available fields for that year (#211)
Upload fgb files for 2020, 2021, 2022, 2023, and 2025 (#211) Uploading files is not code-related and cannot be verified in this PR.

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Possibly related PRs

Suggested reviewers

  • gerardhros

Poem

The Atlas now knows which year you seek,
And fields appear—no longer bleak!
With datasets new, URLs in tow,
The calendar guides where data will flow.
A hop, a leap, a rabbit’s cheer—
For every field, and every year! 🐇🌱

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 6d5a9c4 and 2e2a490.

📒 Files selected for processing (1)
  • fdm-app/.env.example (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • fdm-app/.env.example
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch FDM211

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.
  • 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.

Support

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

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 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 Aug 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.02%. Comparing base (9e4168b) to head (2e2a490).
⚠️ Report is 9 commits behind head on development.

Additional details and impacted files
@@             Coverage Diff              @@
##           development     #226   +/-   ##
============================================
  Coverage        93.02%   93.02%           
============================================
  Files               85       85           
  Lines            12812    12812           
  Branches          1293     1293           
============================================
  Hits             11919    11919           
  Misses             891      891           
  Partials             2        2           
Flag Coverage Δ
fdm-calculator 95.00% <ø> (ø)
fdm-core 91.60% <ø> (ø)
fdm-data 94.21% <ø> (ø)

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 coderabbitai Bot changed the title @coderabbitai Update FDM app to use calendar-based dataset selection and new env variable Aug 6, 2025
@coderabbitai coderabbitai Bot added the fdm-app label Aug 6, 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

🔭 Outside diff range comments (1)
fdm-app/app/root.tsx (1)

48-54: Validate presence of the new env variable early.

PUBLIC_FDM_DATASETS_URL is now required by many Atlas components, but the loader silently passes through undefined.
Failing fast (e.g. throwing if the variable is missing in production) prevents hard-to-debug 404s later.

 const runtimeEnv = {
@@
-    PUBLIC_FDM_DATASETS_URL: process.env.PUBLIC_FDM_DATASETS_URL,
+    PUBLIC_FDM_DATASETS_URL: (() => {
+        if (process.env.PUBLIC_FDM_DATASETS_URL) return process.env.PUBLIC_FDM_DATASETS_URL
+        if (process.env.NODE_ENV === "development") return undefined
+        throw new Error("PUBLIC_FDM_DATASETS_URL is not set")
+    })(),
🧹 Nitpick comments (8)
.changeset/blue-kiwis-dress.md (1)

5-5: Wording nit – use “environment variable” instead of “environmental”.

environmental sounds like ecology‐related; the conventional phrasing in a changeset headline is “environment variable”.
Example:

-Replace environmental FDM_PUBLIC_DATA with PUBLIC_FDM_DATASETS_URL
+Replace environment variable FDM_PUBLIC_DATA with PUBLIC_FDM_DATASETS_URL
.changeset/silver-oranges-vanish.md (1)

5-5: Minor copy edit – clarify sentence structure.

Consider making the note active/imperative for consistency with other change-set messages:

-At Atlas show for the available fields the dataset for the selected calendar year
+Atlas: show the available-fields dataset for the selected calendar year
fdm-app/app/root.tsx (1)

70-78: Optional: drop the empty fallback object.

When the guarded assignment above is added, the catch-branch becomes redundant and can be removed, simplifying the loader.

fdm-app/app/types/config.d.ts (1)

62-63: Consistency – keep optionality in sync.

If ServerConfig.datasets_url remains required, ClientConfig.datasets_url should also be required (and vice-versa) to avoid accidental undefined on the client.

fdm-app/app/components/blocks/atlas/atlas-url.ts (3)

7-7: Fix typo in comment.

There's a spelling error in the comment.

-    // Set year accoriding to available at FDM public datasets
+    // Set year according to available at FDM public datasets

8-14: Consider input validation and error handling.

The Math.round(Number(calendar)) approach will handle non-numeric strings by returning NaN, which then gets clamped to 2020. Consider adding explicit validation for better error handling.

-    let year = Math.round(Number(calendar))
-    if (year < 2020) {
-        year = 2020
-    }
-    if (year > 2025) {
-        year = 2025
-    }
+    const parsedYear = parseInt(calendar, 10)
+    if (isNaN(parsedYear)) {
+        throw new Error(`Invalid calendar year: ${calendar}`)
+    }
+    let year = Math.max(2020, Math.min(2025, parsedYear))

23-23: Consider internationalization for hardcoded country code.

The hardcoded "nl" in the URL path may need consideration for future internationalization, though it's acceptable for the current Netherlands-focused implementation.

fdm-app/app/routes/farm.create.$b_id_farm.$calendar.atlas.tsx (1)

66-70: Update JSDoc comment to reflect current implementation.

The JSDoc comment mentions returning "the URL for available fields" but the loader now returns a calendar parameter instead.

- * This loader function extracts the farm ID from route parameters, validates its presence, and uses the current session to fetch the corresponding farm details. It then retrieves the Mapbox token and style configuration, and returns these along with the farm's display name and a URL for available fields. Any errors encountered during processing are transformed using {~link handleLoaderError}.
+ * This loader function extracts the farm ID and calendar from route parameters, validates their presence, and uses the current session to fetch the corresponding farm details. It then retrieves the Mapbox token and style configuration, and returns these along with the farm's display name and calendar parameter for dynamic field data loading. Any errors encountered during processing are transformed using {~link handleLoaderError}.
- * ~returns An object containing the farm name, Mapbox token, Mapbox style, and the URL for available fields.
+ * ~returns An object containing the farm name, Mapbox token, Mapbox style, and calendar parameter for field data selection.
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9e4168b and d5edaf0.

⛔ Files ignored due to path filters (2)
  • fdm-app/app/lib/config.server.ts is excluded by !fdm-app/app/lib/**
  • fdm-app/app/lib/config.ts is excluded by !fdm-app/app/lib/**
📒 Files selected for processing (11)
  • .changeset/blue-kiwis-dress.md (1 hunks)
  • .changeset/silver-oranges-vanish.md (1 hunks)
  • fdm-app/.env.example (1 hunks)
  • fdm-app/app/components/blocks/atlas/atlas-sources.tsx (4 hunks)
  • fdm-app/app/components/blocks/atlas/atlas-url.ts (1 hunks)
  • fdm-app/app/components/blocks/atlas/atlas.d.tsx (0 hunks)
  • fdm-app/app/root.tsx (1 hunks)
  • fdm-app/app/routes/farm.$b_id_farm.$calendar.balance.nitrogen._index.tsx (2 hunks)
  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.atlas.tsx (3 hunks)
  • fdm-app/app/types/config.d.ts (2 hunks)
  • fdm-app/app/types/public-env.d.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • fdm-app/app/components/blocks/atlas/atlas.d.tsx
🧰 Additional context used
🧠 Learnings (32)
📓 Common learnings
Learnt from: SvenVw
PR: SvenVw/fdm#156
File: fdm-calculator/src/norms/nl/2025/stikstofgebruiksnorm.ts:295-303
Timestamp: 2025-07-21T12:06:07.070Z
Learning: Functions in the fdm-calculator with "NL2025" in their names are specifically designed for Netherlands 2025 agricultural norms calculation and hardcoded 2025 dates are appropriate in this context, as different years would have separate calculation modules.
Learnt from: SvenVw
PR: SvenVw/fdm#88
File: fdm-core/src/cultivation.ts:246-246
Timestamp: 2025-03-04T11:09:08.169Z
Learning: In the FDM codebase, the `fdm` parameter should be documented as "The FDM instance providing the connection to the database. The instance can be created with {link createFdmServer}." in JSDoc comments.
📚 Learning: in the `fdm-app` project, svenvw is preparing for migration to remix v3 and may include type declara...
Learnt from: SvenVw
PR: SvenVw/fdm#6
File: fdm-app/vite.config.ts:5-9
Timestamp: 2024-11-25T12:42:32.783Z
Learning: In the `fdm-app` project, SvenVw is preparing for migration to Remix v3 and may include type declarations or configurations for v3 features in advance, such as in `vite.config.ts`.

Applied to files:

  • .changeset/blue-kiwis-dress.md
  • fdm-app/app/root.tsx
  • fdm-app/app/types/config.d.ts
  • fdm-app/app/types/public-env.d.ts
  • fdm-app/app/routes/farm.$b_id_farm.$calendar.balance.nitrogen._index.tsx
📚 Learning: in the fdm codebase, the `fdm` parameter should be documented as "the fdm instance providing the con...
Learnt from: SvenVw
PR: SvenVw/fdm#88
File: fdm-core/src/cultivation.ts:246-246
Timestamp: 2025-03-04T11:09:08.169Z
Learning: In the FDM codebase, the `fdm` parameter should be documented as "The FDM instance providing the connection to the database. The instance can be created with {link createFdmServer}." in JSDoc comments.

Applied to files:

  • .changeset/blue-kiwis-dress.md
  • fdm-app/app/root.tsx
  • fdm-app/app/types/config.d.ts
  • fdm-app/.env.example
📚 Learning: the `updatefield` function in fdm-core has optional parameters that don't need to be passed as undef...
Learnt from: SvenVw
PR: SvenVw/fdm#67
File: fdm-app/app/routes/farm.create.$b_id_farm.fields.$b_id.tsx:601-610
Timestamp: 2025-01-31T15:34:20.850Z
Learning: The `updateField` function in fdm-core has optional parameters that don't need to be passed as undefined. Only `fdm` and `b_id` are required.

Applied to files:

  • .changeset/blue-kiwis-dress.md
  • .changeset/silver-oranges-vanish.md
  • fdm-app/app/routes/farm.$b_id_farm.$calendar.balance.nitrogen._index.tsx
  • fdm-app/.env.example
  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.atlas.tsx
📚 Learning: sentry dsn being public in client-side code is not a security concern as per sentry documentation, b...
Learnt from: SvenVw
PR: SvenVw/fdm#82
File: fdm-app/app/entry.client.tsx:13-13
Timestamp: 2025-02-19T10:50:50.200Z
Learning: Sentry DSN being public in client-side code is not a security concern as per Sentry documentation, but it can be made configurable using Vite's environment variables system with the `VITE_` prefix.

Applied to files:

  • .changeset/blue-kiwis-dress.md
  • fdm-app/app/root.tsx
  • fdm-app/app/types/public-env.d.ts
📚 Learning: in the fdm project, `redirect` and other routing utilities should be imported from `react-router` in...
Learnt from: SvenVw
PR: SvenVw/fdm#45
File: fdm-app/app/routes/farm.$b_id_farm.settings._index.tsx:1-1
Timestamp: 2025-01-14T16:06:21.832Z
Learning: In the fdm project, `redirect` and other routing utilities should be imported from `react-router` instead of `react-router-dom`.

Applied to files:

  • .changeset/blue-kiwis-dress.md
  • fdm-app/app/root.tsx
📚 Learning: in the fdm-app codebase, the `redirect` function should be imported from `react-router`, not `react-...
Learnt from: SvenVw
PR: SvenVw/fdm#45
File: fdm-app/app/routes/farm.$b_id_farm._index.tsx:1-1
Timestamp: 2025-01-14T16:06:24.294Z
Learning: In the fdm-app codebase, the `redirect` function should be imported from `react-router`, not `react-router-dom`.

Applied to files:

  • .changeset/blue-kiwis-dress.md
  • fdm-app/app/root.tsx
  • fdm-app/app/routes/farm.$b_id_farm.$calendar.balance.nitrogen._index.tsx
📚 Learning: in the `fdm-app/tsconfig.json` file, the include path `.react-router/types/**/*` refers to a build-t...
Learnt from: SvenVw
PR: SvenVw/fdm#20
File: fdm-app/tsconfig.json:8-9
Timestamp: 2024-12-11T12:09:35.540Z
Learning: In the `fdm-app/tsconfig.json` file, the include path `.react-router/types/**/*` refers to a build-time generated directory which is intentionally not included in the repository.

Applied to files:

  • fdm-app/app/root.tsx
  • fdm-app/app/routes/farm.$b_id_farm.$calendar.balance.nitrogen._index.tsx
📚 Learning: the `updatefield` function in fdm-core has optional parameters after `fdm` and `b_id`. the typescrip...
Learnt from: SvenVw
PR: SvenVw/fdm#67
File: fdm-app/app/routes/farm.create.$b_id_farm.fields.$b_id.tsx:601-610
Timestamp: 2025-01-31T15:05:14.310Z
Learning: The `updateField` function in fdm-core has optional parameters after `fdm` and `b_id`. The TypeScript definitions might show 8 required parameters due to a potential version mismatch.

Applied to files:

  • .changeset/silver-oranges-vanish.md
  • fdm-app/app/routes/farm.$b_id_farm.$calendar.balance.nitrogen._index.tsx
  • fdm-app/app/components/blocks/atlas/atlas-url.ts
  • fdm-app/.env.example
  • fdm-app/app/components/blocks/atlas/atlas-sources.tsx
  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.atlas.tsx
📚 Learning: in fdm-app/app/routes/signin._index.tsx, the redirect destinations are intentionally inconsistent by...
Learnt from: SvenVw
PR: SvenVw/fdm#151
File: fdm-app/app/routes/signin._index.tsx:101-101
Timestamp: 2025-06-02T10:31:27.097Z
Learning: In fdm-app/app/routes/signin._index.tsx, the redirect destinations are intentionally inconsistent by design: the component defaults new sign-ins to "/welcome" (line 101) while the loader redirects authenticated users to "/farm" (line 80) and the action uses "/farm" as fallback (line 434). This creates appropriate user flows where new users complete their profile via the welcome page, while existing authenticated users bypass it and go directly to the main application.

Applied to files:

  • fdm-app/app/routes/farm.$b_id_farm.$calendar.balance.nitrogen._index.tsx
  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.atlas.tsx
📚 Learning: a shared layout component `farmlayoutbase` has been created in `components/custom/farm-layout-base.t...
Learnt from: SvenVw
PR: SvenVw/fdm#42
File: fdm-app/app/routes/farm/_b_id_farm/layout.tsx:46-95
Timestamp: 2025-01-09T16:03:37.764Z
Learning: A shared layout component `FarmLayoutBase` has been created in `components/custom/farm-layout-base.tsx` to maintain consistency across farm-related pages. The component handles farm selection dropdown, breadcrumb navigation, and provides a common layout structure.

Applied to files:

  • fdm-app/app/routes/farm.$b_id_farm.$calendar.balance.nitrogen._index.tsx
  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.atlas.tsx
📚 Learning: authentication for the “app.addfarm.new” route is already handled globally in “fdm-app/app/routes/ap...
Learnt from: SvenVw
PR: SvenVw/fdm#23
File: fdm-app/app/routes/app.addfarm.new.tsx:15-17
Timestamp: 2024-12-19T13:20:44.152Z
Learning: Authentication for the “app.addfarm.new” route is already handled globally in “fdm-app/app/routes/app.tsx,” automatically redirecting unauthenticated users to the SignIn page.

Applied to files:

  • fdm-app/app/routes/farm.$b_id_farm.$calendar.balance.nitrogen._index.tsx
  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.atlas.tsx
📚 Learning: in `fdm-data/src/cultivations/index.test.ts`, the `fdm` object created by `drizzle` does not have an...
Learnt from: SvenVw
PR: SvenVw/fdm#9
File: fdm-data/src/cultivations/index.test.ts:57-59
Timestamp: 2024-11-27T12:15:36.425Z
Learning: In `fdm-data/src/cultivations/index.test.ts`, the `fdm` object created by `drizzle` does not have an `.end()` method. Cleanup code should not attempt to call `fdm.end();`.

Applied to files:

  • fdm-app/app/routes/farm.$b_id_farm.$calendar.balance.nitrogen._index.tsx
📚 Learning: functions in the fdm-calculator with "nl2025" in their names are specifically designed for netherlan...
Learnt from: SvenVw
PR: SvenVw/fdm#156
File: fdm-calculator/src/norms/nl/2025/stikstofgebruiksnorm.ts:295-303
Timestamp: 2025-07-21T12:06:07.070Z
Learning: Functions in the fdm-calculator with "NL2025" in their names are specifically designed for Netherlands 2025 agricultural norms calculation and hardcoded 2025 dates are appropriate in this context, as different years would have separate calculation modules.

Applied to files:

  • fdm-app/app/routes/farm.$b_id_farm.$calendar.balance.nitrogen._index.tsx
📚 Learning: when adding multiple harvests in fdm-app, use promise.all instead of promise.allsettled to ensure at...
Learnt from: SvenVw
PR: SvenVw/fdm#71
File: fdm-app/app/routes/farm.create.$b_id_farm.cultivations.$b_lu_catalogue.crop.harvest._index.tsx:111-135
Timestamp: 2025-02-13T09:03:11.890Z
Learning: When adding multiple harvests in fdm-app, use Promise.all instead of Promise.allSettled to ensure atomic behavior - if one harvest addition fails, all should fail and rollback to maintain data consistency.

Applied to files:

  • fdm-app/app/routes/farm.$b_id_farm.$calendar.balance.nitrogen._index.tsx
📚 Learning: the `calculatedose` function in `@svenvw/fdm-calculator` is a synchronous function that includes bui...
Learnt from: SvenVw
PR: SvenVw/fdm#75
File: fdm-app/app/routes/farm.$b_id_farm.field.$b_id.fertilizer.tsx:68-71
Timestamp: 2025-02-14T09:56:37.606Z
Learning: The `calculateDose` function in `svenvw/fdm-calculator` is a synchronous function that includes built-in validation for negative application amounts and nutrient rates.

Applied to files:

  • fdm-app/app/routes/farm.$b_id_farm.$calendar.balance.nitrogen._index.tsx
📚 Learning: the `updatefield` function in fdm-core requires 8 parameters: fdm, b_id (required), and 6 optional p...
Learnt from: SvenVw
PR: SvenVw/fdm#67
File: fdm-app/app/routes/farm.create.$b_id_farm.fields.$b_id.tsx:601-610
Timestamp: 2025-01-31T15:05:14.310Z
Learning: The `updateField` function in fdm-core requires 8 parameters: fdm, b_id (required), and 6 optional parameters (b_name, b_id_source, b_geometry, b_acquiring_date, b_acquiring_method, b_discarding_date).

Applied to files:

  • fdm-app/app/routes/farm.$b_id_farm.$calendar.balance.nitrogen._index.tsx
  • fdm-app/.env.example
📚 Learning: the harvestform component in fdm-app expects undefined (not 0) for b_lu_yield when no yield informat...
Learnt from: SvenVw
PR: SvenVw/fdm#71
File: fdm-app/app/routes/farm.$b_id_farm.field.$b_id.cultivation.$b_lu.harvest.$b_id_harvesting.tsx:114-124
Timestamp: 2025-02-13T08:35:59.306Z
Learning: The HarvestForm component in fdm-app expects undefined (not 0) for b_lu_yield when no yield information is available, as 0 would incorrectly imply that yield data exists.

Applied to files:

  • fdm-app/app/routes/farm.$b_id_farm.$calendar.balance.nitrogen._index.tsx
  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.atlas.tsx
📚 Learning: when using `updatefield` from fdm-core, all 8 parameters must be provided in order: fdm, b_id, b_nam...
Learnt from: SvenVw
PR: SvenVw/fdm#67
File: fdm-app/app/routes/farm.create.$b_id_farm.fields.$b_id.tsx:601-610
Timestamp: 2025-01-31T15:05:14.310Z
Learning: When using `updateField` from fdm-core, all 8 parameters must be provided in order: fdm, b_id, b_name, b_geometry, b_area, b_id_source, b_id_farm, and b_id_farm_source.

Applied to files:

  • fdm-app/app/routes/farm.$b_id_farm.$calendar.balance.nitrogen._index.tsx
📚 Learning: the `addfield` function in fdm-core should use database transactions and field verification to ensur...
Learnt from: SvenVw
PR: SvenVw/fdm#49
File: fdm-app/app/routes/farm.create.$b_id_farm.atlas.tsx:208-208
Timestamp: 2025-01-23T15:17:23.028Z
Learning: The `addField` function in fdm-core should use database transactions and field verification to ensure field availability before resolving its promise, eliminating the need for sleep workarounds.

Applied to files:

  • fdm-app/app/routes/farm.$b_id_farm.$calendar.balance.nitrogen._index.tsx
📚 Learning: the `addfield` function in fdm-core should verify field creation within the same transaction by chec...
Learnt from: SvenVw
PR: SvenVw/fdm#49
File: fdm-app/app/routes/farm.create.$b_id_farm.atlas.tsx:208-208
Timestamp: 2025-01-23T15:17:23.027Z
Learning: The `addField` function in fdm-core should verify field creation within the same transaction by checking the existence of the field and all its required relations (field data, acquiring info, geometry) before resolving its promise.

Applied to files:

  • fdm-app/app/routes/farm.$b_id_farm.$calendar.balance.nitrogen._index.tsx
📚 Learning: in the atlas component's mapfieldsprops interface, mapstyle is intentionally restricted to "mapbox:/...
Learnt from: SvenVw
PR: SvenVw/fdm#67
File: fdm-app/app/components/custom/atlas/atlas.d.tsx:8-8
Timestamp: 2025-01-31T14:29:37.599Z
Learning: In the Atlas component's MapFieldsProps interface, mapStyle is intentionally restricted to "mapbox://styles/mapbox/satellite-streets-v12" as it's currently the only supported style option.

Applied to files:

  • fdm-app/app/components/blocks/atlas/atlas-sources.tsx
  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.atlas.tsx
📚 Learning: when facing prop name inconsistencies with react-map-gl (like mapboxaccesstoken vs mapboxapiaccessto...
Learnt from: SvenVw
PR: SvenVw/fdm#161
File: fdm-app/app/components/blocks/field-map.tsx:0-0
Timestamp: 2025-06-10T13:10:03.154Z
Learning: When facing prop name inconsistencies with react-map-gl (like mapboxAccessToken vs mapboxApiAccessToken), using different import statements can resolve the issue more elegantly than changing prop names across multiple files.

Applied to files:

  • fdm-app/app/components/blocks/atlas/atlas-sources.tsx
📚 Learning: in `fdm-app/app/components/blocks/field-map.tsx`, explicit cleanup of mapbox gl resources is not nec...
Learnt from: SvenVw
PR: SvenVw/fdm#6
File: fdm-app/app/components/blocks/field-map.tsx:0-0
Timestamp: 2024-11-25T14:42:26.660Z
Learning: In `fdm-app/app/components/blocks/field-map.tsx`, explicit cleanup of Mapbox GL resources is not necessary, as `react-map-gl` handles it automatically upon component unmount, and `MapRef` does not have a `remove` method.

Applied to files:

  • fdm-app/app/components/blocks/atlas/atlas-sources.tsx
📚 Learning: in react-map-gl components, when querying rendered features via map.queryrenderedfeatures(), the eff...
Learnt from: SvenVw
PR: SvenVw/fdm#67
File: fdm-app/app/components/custom/atlas/atlas-sources.tsx:21-66
Timestamp: 2025-01-31T15:06:35.764Z
Learning: In react-map-gl components, when querying rendered features via map.queryRenderedFeatures(), the effect's dependency array must include any props that affect the map's rendered state (like source data) to ensure features are queried against the current map state.

Applied to files:

  • fdm-app/app/components/blocks/atlas/atlas-sources.tsx
📚 Learning: when handling different map event types in react-map-gl v7.1.8, use maplayermouseevent for mouse eve...
Learnt from: SvenVw
PR: SvenVw/fdm#67
File: fdm-app/app/components/custom/atlas/atlas-panels.tsx:28-28
Timestamp: 2025-01-31T15:41:43.741Z
Learning: When handling different map event types in react-map-gl v7.1.8, use MapLayerMouseEvent for mouse events (which have the point property) and ViewStateChangeEvent for view state changes. Use a type guard like 'point' in evt to safely access event-specific properties.

Applied to files:

  • fdm-app/app/components/blocks/atlas/atlas-sources.tsx
📚 Learning: map configuration in the application should be modularized using the `usemapconfig` hook and `mapcon...
Learnt from: SvenVw
PR: SvenVw/fdm#67
File: fdm-app/app/routes/farm.create.$b_id_farm.atlas.tsx:164-212
Timestamp: 2025-01-31T16:06:33.810Z
Learning: Map configuration in the application should be modularized using the `useMapConfig` hook and `MapControls` component to maintain consistency across all MapGL instances.

Applied to files:

  • fdm-app/app/components/blocks/atlas/atlas-sources.tsx
📚 Learning: mapgl implementations should use the shared `usemapconfig` hook for configuration and `getlayerstyle...
Learnt from: SvenVw
PR: SvenVw/fdm#67
File: fdm-app/app/routes/farm.create.$b_id_farm.atlas.tsx:164-212
Timestamp: 2025-01-31T16:06:33.810Z
Learning: MapGL implementations should use the shared `useMapConfig` hook for configuration and `getLayerStyle` utility for consistent styling. The hook supports both interactive and non-interactive maps, handling bounds calculation and view state management.

Applied to files:

  • fdm-app/app/components/blocks/atlas/atlas-sources.tsx
📚 Learning: the `farmlayout` component in `components/custom/farm-layout.tsx` provides a reusable layout structu...
Learnt from: SvenVw
PR: SvenVw/fdm#42
File: fdm-app/app/routes/farm/_b_id_farm/layout.tsx:46-95
Timestamp: 2025-01-09T16:03:37.764Z
Learning: The `FarmLayout` component in `components/custom/farm-layout.tsx` provides a reusable layout structure for farm-related pages, with support for farm selection dropdown, customizable breadcrumb titles, and flexible content rendering through either children or Outlet components.

Applied to files:

  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.atlas.tsx
📚 Learning: in the fdm application, cultivation retrieval logic should be centralized in utility functions rathe...
Learnt from: SvenVw
PR: SvenVw/fdm#116
File: fdm-app/app/routes/farm.$b_id_farm.$calendar.field.new.tsx:111-154
Timestamp: 2025-04-04T14:27:39.518Z
Learning: In the FDM application, cultivation retrieval logic should be centralized in utility functions rather than duplicated across loader and action functions to improve maintainability and ensure consistent behavior.

Applied to files:

  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.atlas.tsx
📚 Learning: a comprehensive farm layout system has been created in `components/custom/farm-layouts/` with `basef...
Learnt from: SvenVw
PR: SvenVw/fdm#42
File: fdm-app/app/routes/farm/_b_id_farm/layout.tsx:46-95
Timestamp: 2025-01-09T16:03:37.764Z
Learning: A comprehensive farm layout system has been created in `components/custom/farm-layouts/` with `BaseFarmLayout` and `FarmSidebarLayout` components. The system supports both simple and sidebar-based layouts while maintaining consistent header and farm selection functionality across all farm routes.

Applied to files:

  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.atlas.tsx
📚 Learning: the farm layout system has been reorganized into separate components (`farmheader`, `contentlayout`,...
Learnt from: SvenVw
PR: SvenVw/fdm#42
File: fdm-app/app/routes/farm/_b_id_farm/layout.tsx:46-95
Timestamp: 2025-01-09T16:03:37.764Z
Learning: The farm layout system has been reorganized into separate components (`FarmHeader`, `ContentLayout`, `PaginationLayout`) to support different navigation patterns (sidebar, pagination) while maintaining consistent styling. Each layout component is designed to be used independently or combined as needed.

Applied to files:

  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.atlas.tsx
🧬 Code Graph Analysis (1)
fdm-app/app/components/blocks/atlas/atlas-sources.tsx (2)
fdm-app/app/components/blocks/atlas/atlas-functions.tsx (1)
  • generateFeatureClass (4-9)
fdm-app/app/components/blocks/atlas/atlas-url.ts (1)
  • getAvailableFieldsUrl (3-25)
🔇 Additional comments (12)
fdm-app/app/types/public-env.d.ts (1)

5-5: LGTM – type surface updated correctly.

fdm-app/app/types/config.d.ts (1)

5-6: Check existing config files for breakages.

The new datasets_url is mandatory (string). Any serverConfig.json / clientConfig.ts checked into other environments will now fail type-checking unless updated.
If backward compatibility is desirable, mark the field optional or supply a sensible default.

fdm-app/app/routes/farm.$b_id_farm.$calendar.balance.nitrogen._index.tsx (2)

39-39: LGTM! Centralized configuration import added.

The addition of serverConfig import supports the centralization of dataset URL configuration, replacing direct environment variable access.


83-89: LGTM! Improved configuration management.

The change from direct environment variable access to serverConfig.datasets_url centralizes configuration management and improves maintainability. This aligns well with the PR objective of supporting calendar-based dataset selection.

fdm-app/.env.example (1)

22-24: LGTM! New environment variable supports calendar-based dataset selection.

The addition of PUBLIC_FDM_DATASETS_URL replaces the previous static URL approach with a configurable base URL that supports dynamic calendar-based dataset construction. The documentation clearly indicates it's required.

fdm-app/app/components/blocks/atlas/atlas-url.ts (1)

3-25: LGTM! Well-structured URL generation function.

The function correctly implements calendar-based dataset URL construction with appropriate year clamping and version selection logic. This directly addresses the PR objective of showing available fields per corresponding year.

fdm-app/app/components/blocks/atlas/atlas-sources.tsx (4)

4-4: LGTM! Appropriate imports for new functionality.

The JSX type import and getAvailableFieldsUrl function import support the component's updated API and functionality.

Also applies to: 7-7


109-116: LGTM! Interface updated to support calendar-based URL generation.

The change from url prop to calendar prop with corresponding interface update correctly implements the shift to dynamic URL generation based on calendar year.


120-120: LGTM! Dynamic URL generation implemented.

The internal computation of availableFieldsUrl using getAvailableFieldsUrl(calendar) correctly implements the calendar-based dataset selection as required by the PR objectives.


176-176: LGTM! Effect dependency correctly updated.

The dependency array correctly includes availableFieldsUrl instead of the previous url prop, ensuring the effect re-runs when the computed URL changes.

fdm-app/app/routes/farm.create.$b_id_farm.$calendar.atlas.tsx (2)

85-85: LGTM! Calendar parameter extraction and usage implemented.

The extraction of calendar parameter and inclusion in loader data correctly supports the calendar-based dataset selection functionality.

Also applies to: 103-103


203-203: LGTM! Component prop updated to use calendar.

The change from passing a URL to passing the calendar parameter correctly aligns with the updated FieldsSourceAvailable component API.

@SvenVw SvenVw requested a review from BoraIneviNMI August 6, 2025 08:47
Copy link
Copy Markdown
Collaborator

@BoraIneviNMI BoraIneviNMI left a comment

Choose a reason for hiding this comment

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

This is a very important change to allow farmers select fields from the fdm public database for previous years. The implementation looks fine. I found a few issues though

  • farm.$b_id_farm.$calendar.field.new.tsx doesn't have the necessary changes.

@SvenVw
Copy link
Copy Markdown
Collaborator Author

SvenVw commented Aug 6, 2025

This is a very important change to allow farmers select fields from the fdm public database for previous years. The implementation looks fine. I found a few issues though

* farm.$b_id_farm.$calendar.field.new.tsx doesn't have the necessary changes.

Thanks! Resolved in 6d5a9c4

@SvenVw SvenVw requested a review from BoraIneviNMI August 6, 2025 11:07
Copy link
Copy Markdown
Collaborator

@BoraIneviNMI BoraIneviNMI left a comment

Choose a reason for hiding this comment

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

OK now it looks good to me.

Comment thread fdm-app/.env.example
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.

Atlas: Show available fields per corresponding year

2 participants