Skip to content

fix: clear values array on additional input type change#248

Open
tomrndom wants to merge 1 commit into
mainfrom
fix/additional-input-type-change
Open

fix: clear values array on additional input type change#248
tomrndom wants to merge 1 commit into
mainfrom
fix/additional-input-type-change

Conversation

@tomrndom
Copy link
Copy Markdown
Contributor

@tomrndom tomrndom commented May 21, 2026

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

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

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Form now properly manages field options based on selected type: options are automatically cleared when switching to non-options-compatible types and preserved when switching between compatible types.
  • Tests

    • Added comprehensive test coverage for field type changes and form option handling behavior.

Review Change Stack

Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
@tomrndom tomrndom requested a review from smarcet May 21, 2026 14:09
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

📝 Walkthrough

Walkthrough

The PR adds type-change handling to the AdditionalInput form component. When a field type switches from an options-capable type (e.g., CheckBoxList) to a non-options type, the component now clears the associated values array. Tests verify both the clearing behavior and value preservation when switching between options-based types.

Changes

Type-change handler and validation

Layer / File(s) Summary
handleTypeChange handler implementation and wiring
src/components/mui/formik-inputs/additional-input/additional-input.js
Component extracts setFieldValue from Formik context and adds handleTypeChange logic that clears the values array when type switches to a non-options-capable type. The MuiFormikSelect for type is wired to invoke this handler on user selection.
Type-change handler tests
src/components/mui/__tests__/additional-input.test.js
Test imports updated to include waitFor. New handleTypeChange test suite with two async tests: one verifies values are cleared when switching from CheckBoxList to TextInput (non-options type), another verifies values are preserved when switching between options-based types (CheckBoxList to ComboBox).

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • smarcet

Poem

🐰 When types shift like autumn leaves,
Our values dance with gentle eases,
Clear when needed, keep when wise,
A form that knows what's unwise!
—Code Rabbit 🌾

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: clearing values when the additional input type changes, which is the core functionality added in both the implementation and test files.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/additional-input-type-change

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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.

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/__tests__/additional-input.test.js (1)

219-305: 💤 Low value

Reduce duplication between the two handleTypeChange tests.

The two test cases share an identical TestWrapper, itemWithValues, and render setup; only the option clicked and expected count differ. Consider hoisting TestWrapper and a small helper (e.g., renderWithValuesCount(initialItem)) to the describe scope to cut ~40 lines and make the behavioral diff between cases obvious.

🤖 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/__tests__/additional-input.test.js` around lines 219 -
305, Hoist the duplicated setup inside the describe("handleTypeChange") by
extracting the repeated itemWithValues object, the TestWrapper component (which
uses useFormikContext and renders AdditionalInput plus the values-count div),
and the Formik render logic into shared helpers—e.g., define const
itemWithValues = ... once, create a renderWithValuesCount(initialItem) helper
that mounts <Formik><Form><TestWrapper/></Form></Formik>, and reuse those in
each test; keep each test only performing the specific userEvent clicks and
final expect (referencing TestWrapper, itemWithValues, renderWithValuesCount,
and AdditionalInput to locate the code).
🤖 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.

Nitpick comments:
In `@src/components/mui/__tests__/additional-input.test.js`:
- Around line 219-305: Hoist the duplicated setup inside the
describe("handleTypeChange") by extracting the repeated itemWithValues object,
the TestWrapper component (which uses useFormikContext and renders
AdditionalInput plus the values-count div), and the Formik render logic into
shared helpers—e.g., define const itemWithValues = ... once, create a
renderWithValuesCount(initialItem) helper that mounts
<Formik><Form><TestWrapper/></Form></Formik>, and reuse those in each test; keep
each test only performing the specific userEvent clicks and final expect
(referencing TestWrapper, itemWithValues, renderWithValuesCount, and
AdditionalInput to locate the code).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 932d88da-54fb-43ec-98b9-f1aedd2920ee

📥 Commits

Reviewing files that changed from the base of the PR and between 1ea9d93 and 5212796.

📒 Files selected for processing (2)
  • src/components/mui/__tests__/additional-input.test.js
  • src/components/mui/formik-inputs/additional-input/additional-input.js

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.

1 participant