feat: add new formik input for file size, update page media module#791
feat: add new formik input for file size, update page media module#791
Conversation
…media Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
📝 WalkthroughWalkthroughAdds a new Formik-bound file-size input component that displays megabytes and stores bytes, a constant for bytes-per-MB, tests for conversions and display, and replaces the previous numeric text field with the new component in the media request module. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Field as MuiFormikFilesizeField
participant Formik
participant Module as PageTemplateMediaRequestModule
participant API
User->>Field: enters "10" (MB)
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 (max_file_size: bytes)
Module->>API: send payload
API-->>Module: response
Module-->>User: submit result
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts (beta)
No actionable comments were generated in the recent review. 🎉 Comment |
There was a problem hiding this comment.
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: Prefere.preventDefault()overe.nativeEvent.preventDefault().Using
e.nativeEventis 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 addingrequiredprop support for consistency.Looking at
MuiFormikTextFieldin the relevant snippets, it supports arequiredprop that appends*to the label. This component doesn't forward that behavior explicitly, though it may work via...propsspread.
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
src/components/mui/__tests__/mui-formik-file-size-field.test.js
Outdated
Show resolved
Hide resolved
| name={name} | ||
| label={label} | ||
| type="number" | ||
| value={displayValue} |
There was a problem hiding this comment.
do we need this? formik will pick up the value with the name
There was a problem hiding this comment.
this is required to display a simpler value to the user (MB) instead of the value sent and received from the API (bytes)
…constant and tests Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
ref: https://app.clickup.com/t/86b8gnk8b
Signed-off-by: Tomás Castillo tcastilloboireau@gmail.com
Summary by CodeRabbit
New Features
Tests