Skip to content

feat: add new formik input for file size, update page media module#791

Merged
smarcet merged 5 commits intomasterfrom
feature/mui-formik-file-size-input
Feb 18, 2026
Merged

feat: add new formik input for file size, update page media module#791
smarcet merged 5 commits intomasterfrom
feature/mui-formik-file-size-input

Conversation

@tomrndom
Copy link

@tomrndom tomrndom commented Feb 13, 2026

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

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

Summary by CodeRabbit

  • New Features

    • Added a file-size input that displays/accepts integer megabytes with an "MB" unit, converts MB↔bytes for storage, and is now used in media request forms with validation enforcing a positive, MB-aligned value for file-type modules.
  • Tests

    • Added tests for MB↔bytes conversion, display of stored bytes as MB, empty-value handling, input restrictions, and form submission behavior.
  • Chores

    • Introduced a BYTES_PER_MB constant and added a new i18n validation message.

…media

Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
@coderabbitai
Copy link

coderabbitai bot commented Feb 13, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a Formik-bound file-size input component that displays megabytes and stores bytes, a BYTES_PER_MB constant, tests for MB↔bytes behavior, replaces a numeric text field with the new component in the media request module, and enforces MB-aligned validation for FILE type max_file_size.

Changes

Cohort / File(s) Summary
New Component & Tests
src/components/mui/formik-inputs/mui-formik-file-size-field.js, src/components/mui/__tests__/mui-formik-file-size-field.test.js
Adds MuiFormikFilesizeField (default export) with PropTypes; displays MB (floored), stores bytes, blocks non-integer keys, supports empty/null; tests validate MB→bytes conversion, bytes→MB display, and submit behavior.
Integration Update
src/pages/sponsors-global/page-templates/page-template-popup/modules/page-template-media-request-module.js
Replaces MuiFormikTextField for max_file_size with MuiFormikFilesizeField, adjusts imports and removed type="number" prop.
Validation Schema
src/pages/sponsors-global/page-templates/page-template-popup/index.js
Adds conditional validation: when media type === FILE, max_file_size is required, >= 1 MB and aligned to multiples of BYTES_PER_MB; otherwise nullable.
Constants
src/utils/constants.js
Introduces exported BYTES_PER_MB = 1_048_576 and minor formatting tweak.
i18n
src/i18n/en.json
Adds validation.boolean.mib_aligned translation key and adjusts JSON formatting.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Field as MuiFormikFilesizeField
    participant Formik
    participant Module as MediaRequestModule
    participant API

    User->>Field: types "10"
    Field->>Formik: setFieldValue("max_file_size", 10 * BYTES_PER_MB)
    Note right of Formik: value stored as bytes
    User->>Formik: submit form
    Formik->>Module: onSubmit(payload with bytes)
    Module->>API: send payload
    API-->>Module: response
    Module-->>User: result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • smarcet
  • romanetar

Poem

🐇 I nibble bytes and count each MB,

I hop from field to Formik with glee,
From fifteen million down to fifteen,
I convert and validate behind the screen,
Hooray — the payload's neat and free.

🚥 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 title accurately describes the primary changes: adding a new Formik file size input component and integrating it into the page media module.
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
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/mui-formik-file-size-input

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

Copy link

@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: 2

🤖 Fix all issues with AI agents
In `@src/components/mui/formik-inputs/mui-formik-file-size-field.js`:
- Line 19: initialValues[name] is incorrect for nested/formik paths like
"modules[0].max_file_size"; use Formik's getIn to read nested values. Replace
the emptyValue computation to use getIn(initialValues, name) (from
useFormikContext) so emptyValue becomes null when the nested initial value is
null and "" otherwise; update any references in mui-formik-file-size-field.js
(the emptyValue variable and its usage) accordingly.
- Around line 14-17: displayValue computation does not guard against undefined
leading to NaN; update the conditional used to compute displayValue in
mui-formik-file-size-field.js (the expression using field.value, BYTES_PER_MB
and Math.floor) to explicitly check for undefined (e.g., ensure field.value is
not null, not undefined, and not an empty string) before performing
Math.floor(field.value / BYTES_PER_MB) so that when field.value is undefined you
return "" instead of computing and producing NaN.
🧹 Nitpick comments (2)
src/components/mui/formik-inputs/mui-formik-file-size-field.js (2)

48-52: Prefer e.preventDefault() over e.nativeEvent.preventDefault().

Using e.nativeEvent is unconventional. React's synthetic event methods (e.preventDefault(), e.stopPropagation()) are sufficient and more idiomatic.

Proposed fix
      onKeyDown={(e) => {
        if (BLOCKED_KEYS.includes(e.key)) {
-         e.nativeEvent.preventDefault();
-         e.nativeEvent.stopImmediatePropagation();
+         e.preventDefault();
+         e.stopPropagation();
        }
      }}

33-61: Consider adding required prop support for consistency.

Looking at MuiFormikTextField in the relevant snippets, it supports a required prop that appends * to the label. This component doesn't forward that behavior explicitly, though it may work via ...props spread.

Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
@tomrndom tomrndom requested a review from smarcet February 13, 2026 16:16
Copy link

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

@tomrndom please review

name={name}
label={label}
type="number"
value={displayValue}

Choose a reason for hiding this comment

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

do we need this? formik will pick up the value with the name

Copy link
Author

Choose a reason for hiding this comment

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

this is required to display a simpler value to the user (MB) instead of the value sent and received from the API (bytes)

Copy link

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

@tomrndom please review

…constant and tests

Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
Copy link

@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/pages/sponsors-global/page-templates/page-template-popup/index.js (1)

91-103: ⚠️ Potential issue | 🔴 Critical

Fix Biome lint error by using Yup's functional when signature.

The code triggers Biome's noThenProperty rule, which flags objects with a then property to prevent accidental "thenable" behavior. Refactor to use Yup v1.4.0's functional when(key, (values, schema) => schema) signature. Note: values are passed as an array, so use destructuring ([type], schema) not (type, schema).

🛠️ Corrected refactor (functional when with array destructuring)
-    max_file_size: yup.number().when("type", {
-      is: PAGE_MODULES_MEDIA_TYPES.FILE,
-      then: (schema) =>
-        schema
-          .min(1, T.translate("validation.number_positive"))
-          .required(T.translate("validation.required")),
-      otherwise: (schema) => schema.nullable()
-    }),
-    file_type_id: yup.object().when("type", {
-      is: PAGE_MODULES_MEDIA_TYPES.FILE,
-      then: (schema) => schema.required(T.translate("validation.required")),
-      otherwise: (schema) => schema.nullable()
-    })
+    max_file_size: yup.number().when("type", ([type], schema) =>
+      type === PAGE_MODULES_MEDIA_TYPES.FILE
+        ? schema
+            .min(1, T.translate("validation.number_positive"))
+            .required(T.translate("validation.required"))
+        : schema.nullable()
+    ),
+    file_type_id: yup.object().when("type", ([type], schema) =>
+      type === PAGE_MODULES_MEDIA_TYPES.FILE
+        ? schema.required(T.translate("validation.required"))
+        : schema.nullable()
+    )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/pages/sponsors-global/page-templates/page-template-popup/index.js` around
lines 91 - 103, Refactor the Yup .when calls for max_file_size and file_type_id
to use the functional signature when("type", ([type], schema) => ...) instead of
the object form to satisfy Biome's noThenProperty rule: inside the handler check
if [type] === PAGE_MODULES_MEDIA_TYPES.FILE and return
schema.min(1).required(...) for max_file_size or schema.required(...) for
file_type_id, otherwise return schema.nullable(); keep the same validation
messages via T.translate and preserve the symbols max_file_size, file_type_id,
PAGE_MODULES_MEDIA_TYPES.FILE and the existing schema methods.
🤖 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/pages/sponsors-global/page-templates/page-template-popup/index.js`:
- Around line 91-103: Refactor the Yup .when calls for max_file_size and
file_type_id to use the functional signature when("type", ([type], schema) =>
...) instead of the object form to satisfy Biome's noThenProperty rule: inside
the handler check if [type] === PAGE_MODULES_MEDIA_TYPES.FILE and return
schema.min(1).required(...) for max_file_size or schema.required(...) for
file_type_id, otherwise return schema.nullable(); keep the same validation
messages via T.translate and preserve the symbols max_file_size, file_type_id,
PAGE_MODULES_MEDIA_TYPES.FILE and the existing schema methods.

Copy link

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

@tomrndom please review comments

Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
Copy link

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/i18n/en.json`:
- Around line 97-98: The validation message key "mib_aligned" uses "MiB" while
the UI label uses "MB"; update the "mib_aligned" value to match the UI
terminology (e.g., change the string to "Must be an MB aligned value") so labels
and validation are consistent, and scan for any other i18n keys using "MiB" to
align them with the UI term if present.

Comment on lines +97 to +98
"boolean": "Must be a boolean.",
"mib_aligned": "Must be a MiB aligned value"
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Align MB/MiB wording with the UI label.

Line 98 says “MiB” while the UI label says “MB” (Line 3976). This mixed terminology can confuse users—please pick one term across label + validation.

📝 Suggested wording fix (if you keep “MB” in the label)
-    "mib_aligned": "Must be a MiB aligned value"
+    "mib_aligned": "Must be an MB-aligned value."
📝 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
"boolean": "Must be a boolean.",
"mib_aligned": "Must be a MiB aligned value"
"boolean": "Must be a boolean.",
"mib_aligned": "Must be an MB-aligned value."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/i18n/en.json` around lines 97 - 98, The validation message key
"mib_aligned" uses "MiB" while the UI label uses "MB"; update the "mib_aligned"
value to match the UI terminology (e.g., change the string to "Must be an MB
aligned value") so labels and validation are consistent, and scan for any other
i18n keys using "MiB" to align them with the UI term if present.

Copy link

@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 8bbc259 into master Feb 18, 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.

3 participants

Comments