Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
6694029
Upgrade pnpm
SvenVw Nov 26, 2024
e1764c6
Add cultivations to database
SvenVw Nov 26, 2024
b67815f
Add functions for cultivations
SvenVw Nov 26, 2024
3628a25
Improve documentation
SvenVw Nov 26, 2024
41cb1d1
Fix migration
SvenVw Nov 26, 2024
5516df3
Add unit tests for cultivations
SvenVw Nov 26, 2024
3f02cb5
Add export of cultivation functions
SvenVw Nov 26, 2024
49aa60c
Add to changeset
SvenVw Nov 26, 2024
869b2fd
Add cultivations for fdm-data
SvenVw Nov 26, 2024
973e097
Small TS fixes
SvenVw Nov 27, 2024
35c55e1
Add example configuration file as `.env.example`
SvenVw Nov 27, 2024
e1aa0ee
Rename to Nutriëntenbalans
SvenVw Nov 27, 2024
bfa7927
Increase width of sidebar on desktop to `18rem`
SvenVw Nov 27, 2024
b1dea77
Export type `FdmServerType`
SvenVw Nov 27, 2024
709f431
Update and fix tests
SvenVw Nov 27, 2024
d39b097
Add `brp` catalogue
SvenVw Nov 27, 2024
b8e33be
Fix incorrect type reference
SvenVw Nov 27, 2024
ad11dec
Remove unsafe type assertion and improve type safety
SvenVw Nov 27, 2024
986a121
Add environment variable validation.
SvenVw Nov 27, 2024
225767f
Add environment variable validation and error handling.
SvenVw Nov 27, 2024
c8c6b8e
Replace unsafe isNaN with Number.isNaN
SvenVw Nov 27, 2024
2f70bcc
Replace unsafe isNaN with Number.isNaN
SvenVw Nov 27, 2024
d8cf2b3
Merge branch 'add-cultivations' of https://github.com/SvenVw/fdm into…
SvenVw Nov 27, 2024
4d4d807
Inconsistent documentation and behavior in getCultivation function
SvenVw Nov 27, 2024
d2bcc04
Add error handling
SvenVw Nov 27, 2024
0a6b66e
Fix naming
SvenVw Nov 27, 2024
23c38a7
Fix
SvenVw Nov 27, 2024
4165904
Fix cleanup of tests
SvenVw Nov 27, 2024
3f6c7ca
Handle potential errors during deletion gracefully
SvenVw Nov 27, 2024
3bd6879
fix some nitpicks
SvenVw Nov 27, 2024
114a9c8
Add error handling for database connection and migrations.
SvenVw Nov 27, 2024
da272eb
Small improvement
SvenVw Nov 27, 2024
1dd8d6a
Add select for soiltype
SvenVw Nov 27, 2024
7188eed
Improve layout of pages
SvenVw Nov 27, 2024
e449ae1
Add selection of cultivations
SvenVw Nov 27, 2024
8aabffe
Update fdm-app/app/components/blocks/fields.tsx
SvenVw Nov 27, 2024
29e990e
Consider adding error handling and optimizing catalogue extensions
SvenVw Nov 28, 2024
06cf156
Add error handling for cultivation fetching
SvenVw Nov 28, 2024
3bbf38b
Define proper TypeScript interface for cultivationOptions
SvenVw Nov 28, 2024
0b5d2e6
Remove not needed imports
SvenVw Nov 28, 2024
362a168
Add form integration attributes to soil type selector
SvenVw Nov 28, 2024
460889e
Add validation for required fields
SvenVw Nov 28, 2024
63d3ea8
Merge branch 'add-cultivations' of https://github.com/SvenVw/fdm into…
SvenVw Nov 28, 2024
2352e62
Use string for date format
SvenVw Nov 28, 2024
60dba71
Add cultivation from map
SvenVw Nov 28, 2024
b6b04d2
Shown the cultivation on fields page
SvenVw Nov 28, 2024
4379d6d
Add error handling for database operations
SvenVw Nov 28, 2024
07e6838
Improve date handling and validation
SvenVw Nov 28, 2024
80db2e7
Fix async/await usage in Array.map
SvenVw Nov 28, 2024
d1a5b68
Check if sowing date is after manage start date
SvenVw Nov 28, 2024
4637fee
Add getCultivationPlan to get the plan of cultivations for a farm
SvenVw Nov 28, 2024
007545d
Enhance the changeset description with implementation details and kno…
SvenVw Nov 28, 2024
d6b8294
Add duplicate check before insertion
SvenVw Nov 28, 2024
1b9722d
Fix return type mismatch
SvenVw Nov 28, 2024
050e682
Merge branch 'add-cultivations' of https://github.com/SvenVw/fdm into…
SvenVw Nov 28, 2024
8f86ed4
Simplify the calculation of b_id_name by utilizing the map's index
SvenVw Nov 28, 2024
3a6d90f
Remove obsolete rollbacks as it is already handled by the drizzle tra…
SvenVw Nov 28, 2024
f28882e
Extend tests and validation for edge cases
SvenVw Nov 28, 2024
3d90cfd
Merge branch 'add-cultivations' of https://github.com/SvenVw/fdm into…
SvenVw Nov 28, 2024
988fa5c
Add error handling and input validation.
SvenVw Nov 28, 2024
c316d5c
Add `b_area` with the are of the field in hectares to the output of `…
SvenVw Nov 28, 2024
44dab14
Consolidate duplicate cultivation validation.
SvenVw Nov 28, 2024
3bd450f
Fix typo and enhance error handling
SvenVw Nov 28, 2024
efc0761
Wrap database operations in a transaction.
SvenVw Nov 28, 2024
1ab985e
Fix nitpicks
SvenVw Nov 28, 2024
f338f73
Fix merge conflicts
SvenVw Nov 28, 2024
77c31bf
Fix typo in the description
SvenVw Nov 28, 2024
cbc9cfe
Export getCultivationPlan
SvenVw Nov 29, 2024
090c411
Fix import of or
SvenVw Nov 29, 2024
6a97469
Add field name to output of getCultivationPlan
SvenVw Nov 29, 2024
d4c7fbe
Fix type
SvenVw Nov 29, 2024
94ba874
Show farm name above in breadcrumb
SvenVw Nov 29, 2024
069e5da
Add first part of cultivations
SvenVw Nov 29, 2024
5eae0b4
Fix showing name of farm
SvenVw Nov 29, 2024
a4abff2
Use term bouwplan
SvenVw Nov 29, 2024
a3a2fc8
Create a combobox and extend it for fertilizers
SvenVw Nov 29, 2024
ab2f5b9
Add fertilizers to bouwplan
SvenVw Nov 29, 2024
a6c19de
Prevent too wide box
SvenVw Nov 29, 2024
975d959
Add combobox for cover crops
SvenVw Nov 29, 2024
e9bb078
Add a nice header on top of the page
SvenVw Nov 29, 2024
273e151
Add header to map
SvenVw Nov 29, 2024
e4a4f38
Fix various monorepo issues
SvenVw Dec 2, 2024
f587a6f
Enhance component props and state management.
SvenVw Dec 3, 2024
84ba48a
Add validation for b_lu_catalogue parameter.
SvenVw Dec 3, 2024
52e6966
Validate b_id_farm in action function
SvenVw Dec 3, 2024
9cdb4d5
Handle case where getFarm returns null
SvenVw Dec 3, 2024
d22471c
Add essential props for component control and event handling
SvenVw Dec 3, 2024
32e8b40
Add error handling for getFarm operation
SvenVw Dec 3, 2024
bd1f10b
Add error handling for cultivation retrieval.
SvenVw Dec 3, 2024
3b359f6
Remove duplicate
SvenVw Dec 3, 2024
a860f6c
Merge branch 'add-cultivations' of https://github.com/SvenVw/fdm into…
SvenVw Dec 3, 2024
dddc435
Fixes
SvenVw Dec 3, 2024
f98175a
Split it into tabs
SvenVw Dec 3, 2024
b5d3e23
Improve error message
SvenVw Dec 3, 2024
f8500b7
Remove not used code
SvenVw Dec 5, 2024
e1aadf5
The ESLint configuration needs to be updated to match the actual proj…
SvenVw Dec 5, 2024
6e9e94d
Bump version number and update changelog
SvenVw Dec 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions fdm-app/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# NodeJS Configuration
# Sets the environment for the application (development, production).
# Example: development, production
NODE_ENV=

# Secret key used to sign session cookies.
# Must be a strong, randomly generated string. Do not hardcode or commit this value to version control. Use a secure secret management system.
# Rotate this key periodically. Compromising this secret can allow attackers to hijack user sessions.
FDM_SESSION_SECRET=

# DB configuration
# The hostname or IP address of the PostgreSQL database server.
POSTGRES_HOST=

# The port number on which the PostgreSQL database server is listening. Defaults to 5432 if not specified.
POSTGRES_PORT=

# The name of the PostgreSQL database to connect to.
POSTGRES_DB=

# The username used to authenticate with the PostgreSQL database server.
POSTGRES_USER=

# The password used to authenticate with the PostgreSQL database server. Ensure this is stored securely and not exposed in version control.
POSTGRES_PASSWORD=

# Mapbox configuration
# API token for Mapbox services. Required to use Mapbox features.
# Obtain your token from the Mapbox website. Keep this token secure and do not expose it in version control.
MAPBOX_TOKEN=

90 changes: 0 additions & 90 deletions fdm-app/.eslintrc.cjs

This file was deleted.

24 changes: 22 additions & 2 deletions fdm-app/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Changelog fdm-app

## v.0.1.0
## 0.2.0

A first prototype of an application for fdm with minimal functions
### Minor Changes

- e1aa0ee: Rename an app to `Nutriëntenbalans`

### Patch Changes

- bfa7927: Increase width of sidebar on desktop to `18rem`
- 35c55e1: Add example configuration file as `.env.example`
- Updated dependencies [d39b097]
- Updated dependencies [35c55e1]
- Updated dependencies [6694029]
- Updated dependencies [c316d5c]
- Updated dependencies [b1dea77]
- Updated dependencies [d39b097]
- Updated dependencies [49aa60c]
- @svenvw/fdm-data@1.0.0
- @svenvw/fdm-core@0.6.0

## 0.1.0

A first prototype of an application for fdm with minimal functions
2 changes: 1 addition & 1 deletion fdm-app/app/components/app-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export function AppSidebar(props: SideBarType) {
<SidebarMenuButton asChild>
<a href="#">
<ArrowRightLeft />
<span>MINAS2</span>
<span>Nutriëntenbalans</span>
</a>
</SidebarMenuButton>
<SidebarMenuBadge>
Expand Down
107 changes: 107 additions & 0 deletions fdm-app/app/components/blocks/cultivation-plan.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { useState } from "react";
import { Form, useLocation, useNavigation } from "@remix-run/react";

import { cn } from "@/lib/utils"
import { Label } from "@/components/ui/label";
import { Input } from "@/components/ui/input";
import { buttonVariants } from "@/components/ui/button"
import { Calendar } from "@/components/ui/calendar"
// import { nl } from "react-day-picker/locale" // Could not be found somehow
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Resolve the locale import issue

The commented import for the Dutch locale suggests there's an unresolved installation or configuration issue that needs attention. This could affect the calendar's localization.

Consider these solutions:

  1. Install the missing locale: npm install date-fns/locale/nl
  2. Use the locale from date-fns directly: import { nl } from 'date-fns/locale'


interface SidebarNavProps extends React.HTMLAttributes<HTMLElement> {
items: {
href: string
title: string
}[]
}

export function SidebarNav({ className, items, ...props }: SidebarNavProps) {
const { pathname } = useLocation();

return (
<nav
className={cn(
"flex space-x-2 lg:flex-col lg:space-x-0 lg:space-y-1 truncate",
className
)}
{...props}
>
{items.map((item) => (
<a
key={item.href}
href={item.href}
className={cn(
buttonVariants({ variant: "ghost" }),
pathname === item.href
? "bg-muted hover:bg-muted"
: "hover:bg-transparent hover:underline",
"justify-start"
)}
>
{item.title}
</a>
))}
Comment on lines +30 to +43
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use Remix's Link component instead of anchor tags

Replace the anchor tags with Remix's Link component to leverage client-side routing and prevent full page reloads.

-import { Form, useLocation, useNavigation } from "@remix-run/react";
+import { Form, useLocation, useNavigation, Link } from "@remix-run/react";

 // ... in the map function ...
-<a
+<Link
     key={item.href}
-    href={item.href}
+    to={item.href}
     className={cn(
         buttonVariants({ variant: "ghost" }),
         pathname === item.href
             ? "bg-muted hover:bg-muted"
             : "hover:bg-transparent hover:underline",
         "justify-start"
     )}
 >
     {item.title}
-</a>
+</Link>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<a
key={item.href}
href={item.href}
className={cn(
buttonVariants({ variant: "ghost" }),
pathname === item.href
? "bg-muted hover:bg-muted"
: "hover:bg-transparent hover:underline",
"justify-start"
)}
>
{item.title}
</a>
))}
<Link
key={item.href}
to={item.href}
className={cn(
buttonVariants({ variant: "ghost" }),
pathname === item.href
? "bg-muted hover:bg-muted"
: "hover:bg-transparent hover:underline",
"justify-start"
)}
>
{item.title}
</Link>
))}

</nav>
)
}

export default function Cultivation(props: { action: string | undefined; }) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add comprehensive props interface for the Cultivation component

The component needs a proper TypeScript interface for its props to improve type safety and documentation.

interface CultivationProps {
  action?: string;
  initialSowingDate?: Date;
  initialHarvestingDate?: Date;
  onSubmit?: (data: {
    yield: number;
    nitrogenContent: number;
    sowingDate?: Date;
    harvestingDate?: Date;
  }) => void;
}

export default function Cultivation({
  action,
  initialSowingDate,
  initialHarvestingDate,
  onSubmit,
}: CultivationProps) {
  // ... rest of the component
}

const navigation = useNavigation();

// Get sowing and harvesting dates
const [dateSowing, setDateSowing] = useState<Date | undefined>(new Date('2024-03-01'))
const [dateHarvesting, setDateHarvesting] = useState<Date | undefined>(new Date('2024-10-01'))
Comment on lines +52 to +53
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Avoid hardcoded dates in state initialization

The component initializes dates with hardcoded values, which might not be appropriate for all use cases.

-const [dateSowing, setDateSowing] = useState<Date | undefined>(new Date('2024-03-01'))
-const [dateHarvesting, setDateHarvesting] = useState<Date | undefined>(new Date('2024-10-01'))
+const [dateSowing, setDateSowing] = useState<Date | undefined>(props.defaultSowingDate || undefined)
+const [dateHarvesting, setDateHarvesting] = useState<Date | undefined>(props.defaultHarvestingDate || undefined)

Committable suggestion skipped: line range outside the PR's diff.



return (
<div className="space-y-6">
<div>
<p className="text-sm text-muted-foreground">
Werk de opbrengst, stikstofgehalte en zaai- en oogstdatum bij voor dit gewas.
</p>
</div>
<Form method="post" action={props.action}>
<fieldset
disabled={navigation.state === "submitting"}
>
</fieldset>
Comment on lines +63 to +67
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix fieldset structure and enhance form validation

The fieldset is not properly enclosing the form fields, and the form lacks proper validation.

 <Form method="post" action={props.action}>
     <fieldset
         disabled={navigation.state === "submitting"}
+        className="grid w-full items-center gap-4"
     >
-    </fieldset>
-    <div className="grid w-full items-center gap-4">
         {/* Move all form fields here */}
-    </div>
+    </fieldset>
 </Form>

Also, consider adding form validation:

const [errors, setErrors] = useState<Record<string, string>>({});

const validateForm = () => {
  const newErrors: Record<string, string> = {};
  if (!yield) newErrors.yield = "Yield is required";
  if (!nitrogenContent) newErrors.nitrogenContent = "Nitrogen content is required";
  setErrors(newErrors);
  return Object.keys(newErrors).length === 0;
};

Also applies to: 85-136

<div className="grid w-full items-center gap-4">
<div className="flex flex-col space-y-1.5">
<Label htmlFor="b_name_farm">Opbrengst (ton ds/ ha) <span className="text-red-500">*</span></Label>
<Input id="b_name_farm" type="number" name="b_name_farm" placeholder="37 ton ds / ha" aria-required="true" />
</div>
<div className="flex flex-col space-y-1.5">
<Label htmlFor="b_name_farm">Stikstofgehalte gewas (kg N / ton DS) <span className="text-red-500">*</span></Label>
<Input id="b_name_farm" type="number" name="b_name_farm" placeholder="4 kg N / ton DS" aria-required="true" />
Comment on lines +71 to +75
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix duplicate form field IDs

The input fields are using the same ID b_name_farm, which violates HTML uniqueness requirements and affects accessibility.

-<Input id="b_name_farm" type="number" name="b_name_farm" placeholder="37 ton ds / ha" aria-required="true" />
+<Input id="yield" type="number" name="yield" placeholder="37 ton ds / ha" aria-required="true" />

-<Input id="b_name_farm" type="number" name="b_name_farm" placeholder="4 kg N / ton DS" aria-required="true" />
+<Input id="nitrogen_content" type="number" name="nitrogen_content" placeholder="4 kg N / ton DS" aria-required="true" />
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<Input id="b_name_farm" type="number" name="b_name_farm" placeholder="37 ton ds / ha" aria-required="true" />
</div>
<div className="flex flex-col space-y-1.5">
<Label htmlFor="b_name_farm">Stikstofgehalte gewas (kg N / ton DS) <span className="text-red-500">*</span></Label>
<Input id="b_name_farm" type="number" name="b_name_farm" placeholder="4 kg N / ton DS" aria-required="true" />
<Input id="yield" type="number" name="yield" placeholder="37 ton ds / ha" aria-required="true" />
</div>
<div className="flex flex-col space-y-1.5">
<Label htmlFor="b_name_farm">Stikstofgehalte gewas (kg N / ton DS) <span className="text-red-500">*</span></Label>
<Input id="nitrogen_content" type="number" name="nitrogen_content" placeholder="4 kg N / ton DS" aria-required="true" />

</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div className="flex flex-col space-y-1.5">
<Label htmlFor="b_name_farm">Zaaidatum</Label>
<Calendar
// locale={nl} TODO: library has installation issues somehow
mode="single"
selected={dateSowing}
onSelect={setDateSowing}
className="rounded-md border"
weekStartsOn={1}
month={dateSowing}
/>
</div>
<div className="flex flex-col space-y-1.5">
<Label htmlFor="b_name_farm">Oogstdatum</Label>
<Calendar
// locale={nl} TODO: library has installation issues somehow
mode="single"
selected={dateHarvesting}
onSelect={setDateHarvesting}
className="rounded-md border"
weekStartsOn={1}
month={dateHarvesting}
/>
</div>
</div>
</div>
</Form>
</div>
)
}
2 changes: 1 addition & 1 deletion fdm-app/app/components/blocks/fields-map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export function FieldsMap(props: FieldsMapType) {
latitude: 52,
zoom: 10,
}}
style={{ height: "calc(100vh - 64px)" }}
style={{ height: "calc(100vh - 64px - 123px)" }}
mapStyle="mapbox://styles/mapbox/satellite-streets-v12"
mapboxAccessToken={mapboxToken}
onZoomEnd={async evt => await loadBrpFields(evt)}
Expand Down
Loading