-
Notifications
You must be signed in to change notification settings - Fork 4
Add default cultivation dates: schema fields, core util, app routes #293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
c3c96e3
refactor: use correct loop
SvenVw a226f7e
feat: adds b_lu_start_default and b_date_harvest_default
SvenVw 97083dd
feat: adds `b_lu_start_default` and `b_date_harvest_default` to brp c…
SvenVw 2f7b281
feat: adds getDefaultDatesOfCultivation as helper function to determi…
SvenVw 250987e
tests: fixes
SvenVw d279d08
feat: for cultivations default dates based on the cultivation catalog…
SvenVw afc85b7
fix: winter crops should be sown previous year instead of harvest nex…
SvenVw 945f752
refactor: combine changesets
SvenVw c3c8e41
fix: typo
SvenVw a4268f7
refactor: validate date format
SvenVw c35663a
refactor: use fixed default dates if not provided
SvenVw 95309db
fix: add validation for year
SvenVw b90c1d2
refactor: add check to db for format of default dates
SvenVw cc91da2
nitpicks
SvenVw 45c245d
Merge branch 'development' into FDM290
SvenVw a38d207
chore: remove migration to merge dev branch
SvenVw d2c501d
Merge remote-tracking branch 'origin/development' into FDM290
SvenVw d30a616
chore: add db migration
SvenVw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@svenvw/fdm-data": minor | ||
| --- | ||
|
|
||
| Adds `b_lu_start_default` and `b_date_harvest_default` to brp catalogue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@svenvw/fdm-core": minor | ||
| --- | ||
|
|
||
| Adds `b_lu_start_default` and `b_date_harvest_default` to cultivations catalogue as the default start and harvest dates of a cultivation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@svenvw/fdm-core": minor | ||
| --- | ||
|
|
||
| Adds getDefaultDatesOfCultivation as helper function to determine default dates for cultivations |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@svenvw/fdm-app": minor | ||
| --- | ||
|
|
||
| For cultivations default dates based on the cultivation catalogue date are used for b_lu_start and b_lu_end if available when adding a field with a cultivation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Add guards for calendar year and invalid default dates
Apply this diff:
📝 Committable suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? The function
getCalendarshould return a calendar year andgetDefaultDatesOfCultivationwill return date objectsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Length of output: 5433
🏁 Script executed:
Length of output: 2258
🏁 Script executed:
Length of output: 4152
🏁 Script executed:
Length of output: 447
@SvenVw, I understand your point. Let me clarify what I found by examining the actual implementations:
getCalendarcurrently just returns the route parameter as-is:It performs no validation that the value is actually a valid year. So
Number(calendar)could theoretically produceNaNor a non-integer if the route param is malformed.getDefaultDatesOfCultivationdoes constructDateobjects:However, it doesn't validate that the resulting Date is valid. JavaScript's
new Date()with invalid input (like"2025-13-32") creates an Invalid Date object wheregetTime()returnsNaN.So while your assumptions about what these functions should do are reasonable, the current implementations don't actually enforce those guarantees. The validation catches:
That said, if you're confident the route params and catalogue data are always well-formed in practice, you can skip these checks. The decision is yours!
🧬 Code Graph Analysis Results
fdm-app/app/lib/calendar.ts
Snippet: getCalendar
Snippet: getTimeframe
fdm-app/app/routes/farm.$b_id_farm.$calendar.field.new.tsx
Snippet: usage of calendar value as current year
Snippet: getDefaultDatesOfCultivation usage
fdm-core/src/cultivation.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved in c35663a and 95309db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SvenVw, thank you for addressing this! I appreciate you taking the time to implement the validation guards. 🎉
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!