[NAE-2435] Enumeration field with no choices does not properly handle validation#328
Conversation
… validation - refactore checkKey function in enumeration-field.ts
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThe ChangesEnumeration Field Validator Logic
🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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
`@projects/netgrif-components-core/src/lib/data-fields/enumeration-field/models/enumeration-field.ts`:
- Line 84: There is a missing semicolon after the "return null" statement in the
EnumerationField source; open the EnumerationField class in
enumeration-field.ts, locate the method that returns null (the return null
statement shown at line 84) and add a trailing semicolon so the statement
becomes "return null;". Ensure the change is limited to that return statement to
satisfy TS/JS syntax.
- Around line 83-89: The validator treats null inconsistently: update the
initial empty-value check to include null (change the condition controlling the
early-return to: control.value === '' || control.value === undefined ||
control.value === null) so null is considered valid like '' and undefined, and
remove the short-circuit `|| control.value === null` from the find predicate
(leave the find as choice => choice.key === control.value) so matching relies
only on actual choice keys; keep existing behavior for the no-choices branch
using this._choices to return {wrongValue: true} when a non-empty/non-null value
is present.
🪄 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: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 857f86f7-a2a4-474c-babe-6b9f8c2e5261
📒 Files selected for processing (1)
projects/netgrif-components-core/src/lib/data-fields/enumeration-field/models/enumeration-field.ts
… validation Ensure that null values are correctly handled in the validation logic of enumeration fields. This prevents unnecessary errors when null is passed as a control value.
Replaced `find` with `some` to improve code clarity and intent. The updated method now directly checks for the existence of a matching key, simplifying the logic while maintaining functionality.
969a6cd
|



Description
Fixes NAE-2435
Dependencies
No new dependencies were introduced
Third party dependencies
No new dependencies were introduced
Blocking Pull requests
There are no dependencies on other PR
How Has Been This Tested?
This was tested manually and with unit tests.
Test Configuration
Checklist:
Summary by CodeRabbit