Skip to content

Fix file drop functionality in the farm creation wizard shapefile upload#319

Merged
SvenVw merged 10 commits into
developmentfrom
FDM312
Nov 3, 2025
Merged

Fix file drop functionality in the farm creation wizard shapefile upload#319
SvenVw merged 10 commits into
developmentfrom
FDM312

Conversation

@BoraIneviNMI
Copy link
Copy Markdown
Collaborator

@BoraIneviNMI BoraIneviNMI commented Oct 31, 2025

Enhancements

  • The Shapefile upload area's borders didn't use to match where the user is able to drop the files, leading the browser to handle the file drop wrong if the files are dropped close to the border of the area. This is fixed by moving the label role to a different HTML element.
  • Dropping files now lets the form validate properly.

Summary by CodeRabbit

  • New Features
    • Files can be dropped anywhere on the shapefile upload area during farm creation.
    • Soil Analysis PDF upload also accepts drops across the whole upload area.
    • Entire upload areas (click or keyboard Enter/Space) open the file picker.
    • Visual status indicators for idle, uploading, success, and error states.
    • Clear/dismiss control to remove uploaded files and reset the area.
    • File picker and dropped files stay synchronized; required-file status is shown.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Oct 31, 2025

🦋 Changeset detected

Latest commit: b0fb323

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 Oct 31, 2025

Walkthrough

Replaces label-wrapped file inputs with hidden input[type="file"] + interactive dropzone labels for shapefile and soil PDF uploads; consolidates drag/drop/click/keyboard flows, synchronizes input.files via a constructed DataTransfer, and adds status-driven visuals and dismiss controls.

Changes

Cohort / File(s) Summary
Changelog entries
.changeset/new-hornets-hope.md, .changeset/free-donkeys-greet.md
Added changelog entries describing expanded dropzone upload support and a minor package bump for @svenvw/fdm-app.
Shapefile upload (Mijn Percelen)
fdm-app/app/components/blocks/mijnpercelen/form-upload.tsx
Reworked upload UI to a hidden file input + interactive label dropzone; unified click/keyboard/drag handlers; added handleFileChange, dragOver/onDrop, status-driven states (idle/success/error), dismiss/clear, and synchronization of input.files via DataTransfer.
Soil analysis PDF upload
fdm-app/app/components/blocks/soil/form-upload.tsx
Mirrored refactor to hidden input + label dropzone: adjusted drag/drop handler element types, unified onChange flow to update form state and visible filename, reset upload status on drop, and synchronize the hidden input by building a DataTransfer.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Dropzone as Dropzone (label)
  participant HiddenInput as Hidden input[type="file"]
  participant Component as Upload component logic

  Note over User,Dropzone: User clicks, presses Enter/Space, or drops files
  User->>Dropzone: click / key / drop
  Dropzone->>Component: onClick / onKeyDown / onDrop
  Component->>Component: validate/process files, update internal file list & UI status
  Component->>HiddenInput: build DataTransfer & set input.files
  HiddenInput->>Component: input.onchange (file picker) → handleFileChange
  Component->>Dropzone: render updated status (idle → uploading → success/error)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Pay special attention to drag/drop event prevention and propagation across label vs. div elements.
  • Verify keyboard activation, ARIA attributes, and focus management for accessibility.
  • Inspect DataTransfer-based input.files synchronization for add/remove flows and cross-browser edge cases.

Possibly related PRs

Suggested reviewers

  • gerardhros

Poem

🐇 I hopped through code to catch each falling file,
A hidden input listens while a label wears the smile.
Click, press, or tumble — I gather every part,
I stitch them with DataTransfer into the app's heart,
Now lights show idle, success, or a gentle wile. ✨

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'Fix file drop functionality in the farm creation wizard shapefile upload' directly addresses the main objective of the PR, which is to fix the misalignment between the visible drop target boundaries and the actual browser drop target in the shapefile upload area. The title clearly identifies the component (farm creation wizard shapefile upload) and the change (fixing file drop functionality), making it specific and relevant to the changeset.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch FDM312

📜 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 42ddf7b and b0fb323.

📒 Files selected for processing (2)
  • .changeset/free-donkeys-greet.md (1 hunks)
  • fdm-app/app/components/blocks/soil/form-upload.tsx (2 hunks)

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@BoraIneviNMI BoraIneviNMI linked an issue Oct 31, 2025 that may be closed by this pull request
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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
fdm-app/app/components/blocks/mijnpercelen/form-upload.tsx (1)

206-237: Refactor to use the field's onChange callback for consistency.

handleDrop uses form.setValue directly (line 233), while handleFileChange uses the field's onChange callback (line 201 in handleFileChange). This inconsistency may cause issues if the field's onChange has side effects that should execute.

Refactor handleDrop to accept the onChange callback as a parameter:

-const handleDrop = async (e: React.DragEvent<HTMLLabelElement>) => {
+const handleDrop = async (
+    e: React.DragEvent<HTMLLabelElement>,
+    onChange: (files: File[]) => void,
+) => {
     e.preventDefault()
     if (e.dataTransfer.files && e.dataTransfer.files.length > 0) {
         const newFiles = Array.from(e.dataTransfer.files)
         // ... validation logic ...
         
         const currentFiles = form.getValues("shapefile") || []
         const updatedFiles = mergeShapefileParts(
             currentFiles,
             validNewFiles,
             requiredExtensions,
         )
 
-        form.setValue("shapefile", updatedFiles, { shouldValidate: true })
+        onChange(updatedFiles)
         await handleFilesSet(updatedFiles)
         e.dataTransfer.clearData()
     }
 }

Then update the label's onDrop prop to pass the onChange callback:

-    onDrop={handleDrop}
+    onDrop={async (e) => await handleDrop(e, onChange)}
🧹 Nitpick comments (1)
fdm-app/app/components/blocks/mijnpercelen/form-upload.tsx (1)

461-464: Remove commented-out code.

The commented-out file extensions should be removed if they're no longer needed, or uncommented if they should be displayed.

-    <div className="text-xs text-muted-foreground mt-1">
-        {/* .shp,
-        .shx,
-        .dbf,
-        .prj */}
-    </div>
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 73609a1 and d756cf4.

📒 Files selected for processing (2)
  • .changeset/new-hornets-hope.md (1 hunks)
  • fdm-app/app/components/blocks/mijnpercelen/form-upload.tsx (3 hunks)
🔇 Additional comments (1)
.changeset/new-hornets-hope.md (1)

1-5: LGTM!

The changelog entry is clear and properly formatted. It accurately describes the UI improvement that allows users to drop files onto the entire shapefile upload area.

@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.31%. Comparing base (d815edc) to head (b0fb323).
⚠️ Report is 11 commits behind head on development.

Additional details and impacted files
@@             Coverage Diff              @@
##           development     #319   +/-   ##
============================================
  Coverage        93.31%   93.31%           
============================================
  Files               96       96           
  Lines            15325    15325           
  Branches          1557     1557           
============================================
  Hits             14301    14301           
  Misses            1022     1022           
  Partials             2        2           
Flag Coverage Δ
fdm-calculator 95.48% <ø> (ø)
fdm-core 91.66% <ø> (ø)
fdm-data 94.04% <ø> (ø)

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 added enhancement New feature or request fdm-app labels Oct 31, 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: 1

♻️ Duplicate comments (1)
fdm-app/app/components/blocks/mijnpercelen/form-upload.tsx (1)

391-414: Add tabIndex={0} and role="button" for keyboard accessibility.

The label is not keyboard-focusable because the associated file input is hidden. This was flagged in a previous review but hasn't been addressed yet. Without tabIndex={0}, keyboard users cannot tab to this element, and without role="button", screen readers won't identify it as an interactive control.

Apply this diff to make the label keyboard-accessible:

 <label
-    className="relative block"
+    className="relative block focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary"
     htmlFor="file-upload"
+    tabIndex={0}
+    role="button"
     aria-label="Upload shapefile files by clicking or dragging and dropping"
     onKeyDown={(e) => {
🧹 Nitpick comments (1)
fdm-app/app/components/blocks/mijnpercelen/form-upload.tsx (1)

450-450: Consider moving cursor-pointer to the label.

The cursor-pointer class on the inner div is somewhat redundant since the label itself is the interactive element. Consider moving it to the label's className (line 392) for clarity, or rely on the browser's default cursor behavior for labels.

Apply this diff if you prefer to make it explicit on the label:

 <label
-    className="relative block"
+    className="relative block cursor-pointer"
     htmlFor="file-upload"

Then remove from the inner div:

-<div className="flex flex-col items-center justify-center w-full h-full cursor-pointer">
+<div className="flex flex-col items-center justify-center w-full h-full">
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d756cf4 and 06314a5.

📒 Files selected for processing (2)
  • .changeset/free-donkeys-greet.md (1 hunks)
  • fdm-app/app/components/blocks/mijnpercelen/form-upload.tsx (4 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .changeset/free-donkeys-greet.md
🧰 Additional context used
🧬 Code graph analysis (1)
fdm-app/app/components/blocks/mijnpercelen/form-upload.tsx (1)
fdm-app/app/components/ui/input.tsx (1)
  • Input (25-25)

Comment thread fdm-app/app/components/blocks/mijnpercelen/form-upload.tsx Outdated
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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 06314a5 and ae56457.

📒 Files selected for processing (1)
  • fdm-app/app/components/blocks/mijnpercelen/form-upload.tsx (4 hunks)
🧰 Additional context used
🪛 Biome (2.1.2)
fdm-app/app/components/blocks/mijnpercelen/form-upload.tsx

[error] 402-402: The elements with this role can be changed to the following elements:

For examples and more information, see WAI-ARIA Roles

(lint/a11y/useSemanticElements)


[error] 402-402: The HTML element label is non-interactive and should not have an interactive role.

Replace label with a div or a span.
Unsafe fix: Remove the role attribute.

(lint/a11y/noNoninteractiveElementToInteractiveRole)

🔇 Additional comments (1)
fdm-app/app/components/blocks/mijnpercelen/form-upload.tsx (1)

234-244: LGTM! Type safety issue resolved.

The code now properly types the file input element and includes a null check before accessing its properties, addressing the previous review concern.

Comment thread fdm-app/app/components/blocks/mijnpercelen/form-upload.tsx
@BoraIneviNMI BoraIneviNMI changed the title Allow dropping the shapefiles onto the entire visual area in farm creation Fix file drop functionality in the farm creation wizard shapefile upload Oct 31, 2025
@coderabbitai coderabbitai Bot added the branch:development Issue only affecting development, not the main branch (yet) label Nov 3, 2025
@SvenVw SvenVw merged commit b1c842f into development Nov 3, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

branch:development Issue only affecting development, not the main branch (yet) enhancement New feature or request fdm-app

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dragging files into dropzone does not enable upload

2 participants