Skip to content

fix: add error messages for max files uploaded, update uicore #843

Merged
smarcet merged 1 commit intomasterfrom
fix/pages-upload-input-v3-error
Apr 17, 2026
Merged

fix: add error messages for max files uploaded, update uicore #843
smarcet merged 1 commit intomasterfrom
fix/pages-upload-input-v3-error

Conversation

@tomrndom
Copy link
Copy Markdown

@tomrndom tomrndom commented Mar 26, 2026

ref: https://app.clickup.com/t/86b90ngzy

Signed-off-by: Tomás Castillo tcastilloboireau@gmail.com

Summary by CodeRabbit

Release Notes

  • New Features
    • Improved file upload validation with clear error messaging when the maximum file limit is exceeded.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 26, 2026

📝 Walkthrough

Walkthrough

The upload component was upgraded from UploadInputV2 to UploadInputV3, adding i18n support for maximum file limit errors. The component now computes the canAdd prop inline and conditionally passes an error message when the file limit is reached.

Changes

Cohort / File(s) Summary
Upload Component Upgrade
src/components/mui/formik-inputs/mui-formik-upload.js
Switched from UploadInputV2 to UploadInputV3, added i18n translator import, and enhanced props with inline canAddMore() computation for canAdd and conditional error prop using errors.maximum_files translation.
i18n Translations
src/i18n/en.json
Added new errors.maximum_files translation string ("Maximum number of files has been reached") and fixed JSON punctuation for errors.entity_not_found.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • smarcet

Poem

🐰 Upload flows smooth with version three,
Max file limits now let users see,
With i18n strings so neatly placed,
The rabbit hops through codespace!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately reflects the main changes: adding error messages for max files and updating to UploadInputV3, matching the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/pages-upload-input-v3-error

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

Copy link
Copy Markdown

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

Caution

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

⚠️ Outside diff range comments (1)
src/components/mui/formik-inputs/mui-formik-upload.js (1)

59-62: ⚠️ Potential issue | 🟠 Major

Removal matching uses the wrong filename field and can fail to remove uploaded items.

Line 61 checks i.filename, but newly uploaded entries are stored with file_name (Line 41). This can leave files in Formik state after removal and incorrectly keep max-files state locked.

💡 Proposed fix
 const handleRemove = (imageFile) => {
-  const updated = (field.value || []).filter(
-    (i) => i.filename !== imageFile.name
-  );
+  const targetId = imageFile?.id;
+  const targetName =
+    imageFile?.name ?? imageFile?.filename ?? imageFile?.file_name;
+  const updated = (field.value || []).filter((i) => {
+    if (targetId !== undefined && i.id !== undefined) return i.id !== targetId;
+    const currentName = i.file_name ?? i.filename ?? i.file_path ?? i.file_url;
+    return currentName !== targetName;
+  });
   helpers.setValue(updated);
   if (onDelete) {
     onDelete(imageFile.id);
   }
 };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/mui/formik-inputs/mui-formik-upload.js` around lines 59 - 62,
The removal predicate in handleRemove is comparing uploaded entries using the
wrong key; change the filter to compare the Formik entry's file_name field to
the incoming imageFile.name (i.e. replace i.filename with i.file_name) so
uploaded items are correctly removed from field.value and max-files state
unlocks; update any related comparisons in the component that assume filename to
instead use file_name (or normalize to a single key) to ensure consistency.
🧹 Nitpick comments (1)
src/components/mui/formik-inputs/mui-formik-upload.js (1)

86-87: Compute canAddMore() once and reuse it for both props.

This keeps canAdd and error perfectly aligned and avoids duplicate evaluation.

♻️ Suggested cleanup
+  const canAdd = canAddMore();
+
   return (
     <>
@@
         djsConfig={{ withCredentials: true }}
         maxFiles={maxFiles}
-        canAdd={canAddMore()}
-        error={!canAddMore() ? T.translate("errors.maximum_files") : undefined}
+        canAdd={canAdd}
+        error={!canAdd ? T.translate("errors.maximum_files") : undefined}
         parallelChunkUploads
       />
     </>
   );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/mui/formik-inputs/mui-formik-upload.js` around lines 86 - 87,
Compute canAddMore() once into a local constant (e.g., const canAdd =
canAddMore()) inside the MuiFormikUpload component and then pass that constant
to the canAdd prop and use it to derive error (error={!canAdd ?
T.translate("errors.maximum_files") : undefined}); update references to use that
constant so both props are consistent and the function is not evaluated twice.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/components/mui/formik-inputs/mui-formik-upload.js`:
- Around line 59-62: The removal predicate in handleRemove is comparing uploaded
entries using the wrong key; change the filter to compare the Formik entry's
file_name field to the incoming imageFile.name (i.e. replace i.filename with
i.file_name) so uploaded items are correctly removed from field.value and
max-files state unlocks; update any related comparisons in the component that
assume filename to instead use file_name (or normalize to a single key) to
ensure consistency.

---

Nitpick comments:
In `@src/components/mui/formik-inputs/mui-formik-upload.js`:
- Around line 86-87: Compute canAddMore() once into a local constant (e.g.,
const canAdd = canAddMore()) inside the MuiFormikUpload component and then pass
that constant to the canAdd prop and use it to derive error (error={!canAdd ?
T.translate("errors.maximum_files") : undefined}); update references to use that
constant so both props are consistent and the function is not evaluated twice.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c49f5cbd-5350-4dea-a691-8e3619c28050

📥 Commits

Reviewing files that changed from the base of the PR and between f80f175 and 5cb37fa.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (3)
  • package.json
  • src/components/mui/formik-inputs/mui-formik-upload.js
  • src/i18n/en.json

… UploadInputV3

Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
@tomrndom tomrndom force-pushed the fix/pages-upload-input-v3-error branch from 5cb37fa to 7d082db Compare April 17, 2026 19:09
Copy link
Copy Markdown

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

🧹 Nitpick comments (1)
src/components/mui/formik-inputs/mui-formik-upload.js (1)

86-87: Compute canAdd once to avoid duplicated evaluation.

This is minor, but deriving the boolean once improves readability and avoids repeating logic in adjacent props.

♻️ Suggested refactor
+      {(() => {
+        const canAdd = canAddMore();
+        return (
       <UploadInputV3
         id={id}
         name={name}
         onUploadComplete={handleUploadComplete}
         value={getInputValue()}
         mediaType={mediaType}
         onRemove={handleRemove}
         postUrl={`${window.FILE_UPLOAD_API_BASE_URL}/api/v1/files/upload`}
         djsConfig={{ withCredentials: true }}
         maxFiles={maxFiles}
-        canAdd={canAddMore()}
-        error={!canAddMore() ? T.translate("errors.maximum_files") : undefined}
+        canAdd={canAdd}
+        error={!canAdd ? T.translate("errors.maximum_files") : undefined}
         parallelChunkUploads
       />
+        );
+      })()}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/mui/formik-inputs/mui-formik-upload.js` around lines 86 - 87,
Compute the can-add boolean once and reuse it instead of calling canAddMore()
twice: call canAddMore() once (e.g., const canAdd = canAddMore()) near the
component render and replace the two uses with canAdd for the canAdd prop and
for the error conditional (error={!canAdd ? T.translate("errors.maximum_files")
: undefined}); update references in mui-formik-upload related to canAddMore(),
keeping function name canAddMore for clarity.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/components/mui/formik-inputs/mui-formik-upload.js`:
- Around line 86-87: Compute the can-add boolean once and reuse it instead of
calling canAddMore() twice: call canAddMore() once (e.g., const canAdd =
canAddMore()) near the component render and replace the two uses with canAdd for
the canAdd prop and for the error conditional (error={!canAdd ?
T.translate("errors.maximum_files") : undefined}); update references in
mui-formik-upload related to canAddMore(), keeping function name canAddMore for
clarity.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1eb9bf95-befc-4a1a-91b5-4c2b6437b9e5

📥 Commits

Reviewing files that changed from the base of the PR and between 5cb37fa and 7d082db.

📒 Files selected for processing (2)
  • src/components/mui/formik-inputs/mui-formik-upload.js
  • src/i18n/en.json
✅ Files skipped from review due to trivial changes (1)
  • src/i18n/en.json

Copy link
Copy Markdown

@smarcet smarcet left a comment

Choose a reason for hiding this comment

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

LGTM

@smarcet smarcet merged commit 33430a3 into master Apr 17, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants