Skip to content

Fix: global quantity bug#256

Merged
smarcet merged 6 commits into
mainfrom
fix/global-quantity-bug
May 27, 2026
Merged

Fix: global quantity bug#256
smarcet merged 6 commits into
mainfrom
fix/global-quantity-bug

Conversation

@santipalenque
Copy link
Copy Markdown
Contributor

@santipalenque santipalenque commented May 26, 2026

https://app.clickup.com/t/86ba4k6eq

Summary by CodeRabbit

  • Bug Fixes

    • Treat sponsor quantity limit of 0 as unlimited (no upper clamp).
    • Normalize quantity inputs: strip leading zeros and handle non-numeric input by falling back to the minimum/effective value.
  • Tests

    • Added/updated tests verifying quantity input normalization and submission behavior.
  • Chores

    • Version bumped to 5.0.27.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 26, 2026

Warning

Review limit reached

@santipalenque, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 48 minutes and 54 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: baa8d7e7-e3e3-4809-8806-85ff3fab03e6

📥 Commits

Reviewing files that changed from the base of the PR and between 05c1ca0 and 746436b.

📒 Files selected for processing (3)
  • package.json
  • src/components/mui/__tests__/mui-formik-quantity-field.test.js
  • src/components/mui/formik-inputs/mui-formik-quantity-field.js
📝 Walkthrough

Walkthrough

Normalize number inputs by writing cleaned values to the DOM and Formik, change max-clamp to only apply when max is truthy (so zero is treated as unlimited), update tests for leading-zero normalization and unlimited behavior, and bump package version to 5.0.27.

Changes

Quantity input normalization and release

Layer / File(s) Summary
Quantity input handling and clamping
src/components/mui/FormItemTable/components/GlobalQuantityField.js, src/components/mui/formik-inputs/mui-formik-quantity-field.js
Handlers now assign normalized numeric values back to the <input> on NaN/effective-min and before calling Formik helpers; clamping uses a truthy max check so falsy 0 no longer enforces an upper bound.
Tests: leading zeros and unlimited behavior
src/components/mui/FormItemTable/__tests__/GlobalQuantityField.test.js, src/components/mui/__tests__/mui-formik-quantity-field.test.js
Tests updated/added to expect leading-zero input normalization (e.g., "01" → displayed "1" and submitted 1) and to treat quantity_limit_per_sponsor: 0 as unlimited (entering 3 submits 3).
Package version bump
package.json
Bumped version from 5.0.26 to 5.0.27.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • smarcet

Poem

🐰 I nibble zeros off the end, so "01" becomes "1",
The input hums in orderly form, no odd NaN to shun,
A zero limit now means wide open skies,
Tests clap their paws and version bumps rise,
Hooray — a tidy field for every sponsor's run!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Fix: global quantity bug' is vague and lacks specific detail about the actual change—it does not clearly convey what the bug is or what aspect of quantity handling was fixed. Revise the title to be more specific, such as 'Fix: allow quantity_limit_per_sponsor to be set to 0' or 'Fix: global quantity field clamping when limit is zero'.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/global-quantity-bug

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.

@santipalenque santipalenque force-pushed the fix/global-quantity-bug branch from 4c4751b to 5ca51d9 Compare May 26, 2026 23:28
santipalenque and others added 3 commits May 26, 2026 20:35
React skips syncing controlled number inputs during typing, so leading
zeros persist unless e.target.value is set directly before reconciliation.
Applied to both GlobalQuantityField and MuiFormikQuantityField, with
tests covering the leading zero case.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/components/mui/FormItemTable/components/GlobalQuantityField.js (1)

43-43: ⚡ Quick win

Consider multi-line formatting for better readability.

The if-statement on line 43 contains multiple statements on a single line, which can make debugging and readability more difficult.

♻️ Suggested formatting
-    if (isNaN(val)) { e.target.value = 0; helpers.setValue(0); return; }
+    if (isNaN(val)) {
+      e.target.value = 0;
+      helpers.setValue(0);
+      return;
+    }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/mui/FormItemTable/components/GlobalQuantityField.js` at line
43, The single-line if in GlobalQuantityField.js currently packs multiple
statements into one line (if (isNaN(val)) { e.target.value = 0;
helpers.setValue(0); return; }), hurting readability; refactor it into a
multi-line if block with braces and each operation on its own line (check
isNaN(val), set e.target.value = 0, call helpers.setValue(0), then return) so
the flow is clearer and easier to debug.
src/components/mui/formik-inputs/mui-formik-quantity-field.js (1)

31-31: ⚡ Quick win

Consider multi-line formatting for better readability.

The if-statement on line 31 contains multiple statements on a single line, which can make debugging and readability more difficult.

♻️ Suggested formatting
-    if (isNaN(val)) { e.target.value = effectiveMin; helpers.setValue(effectiveMin); return; }
+    if (isNaN(val)) {
+      e.target.value = effectiveMin;
+      helpers.setValue(effectiveMin);
+      return;
+    }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/mui/formik-inputs/mui-formik-quantity-field.js` at line 31,
The single-line if in the mui-formik-quantity-field component (the if
(isNaN(val)) { e.target.value = effectiveMin; helpers.setValue(effectiveMin);
return; }) should be expanded into a multi-line block for readability: open an
if block checking isNaN(val), set e.target.value = effectiveMin on its own line,
call helpers.setValue(effectiveMin) on its own line, then return on its own
line; keep the same logic and placement in the event handler so behavior is
unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/components/mui/FormItemTable/components/GlobalQuantityField.js`:
- Line 45: The bug is inconsistent handling of a zero max between
GlobalQuantityField and MuiFormikQuantityField: GlobalQuantityField treats falsy
0 as "no limit" while MuiFormikQuantityField treats 0 as a real limit. Normalize
the boundary by choosing "null/undefined = unlimited" and update the code paths
that compute clamped values (the clamped expression in GlobalQuantityField and
the max handling in MuiFormikQuantityField) to treat 0 as unlimited (e.g.,
convert quantity_limit_per_sponsor or max to null when === 0, or use a nullish
check max != null) and add an inline comment by the normalization explaining "0
is treated as unlimited; use null/undefined for no limit" so both components and
tests align.

---

Nitpick comments:
In `@src/components/mui/formik-inputs/mui-formik-quantity-field.js`:
- Line 31: The single-line if in the mui-formik-quantity-field component (the if
(isNaN(val)) { e.target.value = effectiveMin; helpers.setValue(effectiveMin);
return; }) should be expanded into a multi-line block for readability: open an
if block checking isNaN(val), set e.target.value = effectiveMin on its own line,
call helpers.setValue(effectiveMin) on its own line, then return on its own
line; keep the same logic and placement in the event handler so behavior is
unchanged.

In `@src/components/mui/FormItemTable/components/GlobalQuantityField.js`:
- Line 43: The single-line if in GlobalQuantityField.js currently packs multiple
statements into one line (if (isNaN(val)) { e.target.value = 0;
helpers.setValue(0); return; }), hurting readability; refactor it into a
multi-line if block with braces and each operation on its own line (check
isNaN(val), set e.target.value = 0, call helpers.setValue(0), then return) so
the flow is clearer and easier to debug.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 83703ff4-1247-481b-800a-7f5dc6a13030

📥 Commits

Reviewing files that changed from the base of the PR and between 4c4751b and 05c1ca0.

📒 Files selected for processing (5)
  • package.json
  • src/components/mui/FormItemTable/__tests__/GlobalQuantityField.test.js
  • src/components/mui/FormItemTable/components/GlobalQuantityField.js
  • src/components/mui/__tests__/mui-formik-quantity-field.test.js
  • src/components/mui/formik-inputs/mui-formik-quantity-field.js
🚧 Files skipped from review as they are similar to previous changes (2)
  • package.json
  • src/components/mui/FormItemTable/tests/GlobalQuantityField.test.js

Comment thread src/components/mui/FormItemTable/components/GlobalQuantityField.js
Copy link
Copy Markdown
Collaborator

@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 b287ea2 into main May 27, 2026
5 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