Skip to content

fix: add type error handling for numeric fields in validation schemas#1073

Merged
achour94 merged 2 commits intomainfrom
fix-yup-number-translation
Mar 26, 2026
Merged

fix: add type error handling for numeric fields in validation schemas#1073
achour94 merged 2 commits intomainfrom
fix-yup-number-translation

Conversation

@achour94
Copy link
Copy Markdown
Contributor

PR Summary

Problem: When consuming commons-ui as a library, the yup.setLocale() config in yupConfig.ts may not be loaded, causing number() type validation errors to lose their translation key YupNotTypeNumber.

Fix — same pattern as required(YUP_REQUIRED):

  1. [translationKeys.ts] — Added YUP_NOT_TYPE_NUMBER = 'YupNotTypeNumber' constant
  2. [[networkModificationsEn.ts] / [networkModificationsFr.ts] — Added YupNotTypeNumber translation (EN/FR)
  3. Added .typeError(YUP_NOT_TYPE_NUMBER) to every number() schema in network-modifications:
  • [loadCreation.utils.ts]— 2 fields
  • [voltageLevelCreation.utils.ts] — 7 fields
  • [voltageLevelModification.utils.ts] — 5 fields
  • [connectivityForm.utils.ts] — 1 field
  • [setPoints.utils.ts] — 2 fields
  • [powerWithValidity.utils.ts] — 1 field

This ensures the translation key is explicitly passed at the schema level, making it independent of yup.setLocale() being loaded.

Signed-off-by: achour94 <berrahmaachour@gmail.com>
@achour94 achour94 self-assigned this Mar 26, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 866a5693-cc30-42c0-bef6-49503c2eaf9e

📥 Commits

Reviewing files that changed from the base of the PR and between 523fb61 and 42a092b.

📒 Files selected for processing (2)
  • src/translations/en/networkModificationsEn.ts
  • src/translations/fr/networkModificationsFr.ts
✅ Files skipped from review due to trivial changes (2)
  • src/translations/fr/networkModificationsFr.ts
  • src/translations/en/networkModificationsEn.ts

📝 Walkthrough

Walkthrough

Adds a new validation translation key YUP_NOT_TYPE_NUMBER and applies .typeError(YUP_NOT_TYPE_NUMBER) to numeric Yup validators across network-modification forms, plus English and French translations and the new constant export.

Changes

Cohort / File(s) Summary
Translation Files
src/translations/en/networkModificationsEn.ts, src/translations/fr/networkModificationsFr.ts
Added translation key YupNotTypeNumber with English and French messages.
Constants Definition
src/utils/constants/translationKeys.ts
Exported new constant YUP_NOT_TYPE_NUMBER = 'YupNotTypeNumber'.
Connectivity & Measurements Validation
src/components/network-modifications/common/connectivity/connectivityForm.utils.ts, src/components/network-modifications/common/measurements/powerWithValidity.utils.ts
Added .typeError(YUP_NOT_TYPE_NUMBER) to numeric field validators to surface type-mismatch errors.
Setpoints & Load Creation Validation
src/components/network-modifications/common/setpoints/setPoints.utils.ts, src/components/network-modifications/load/creation/loadCreation.utils.ts
Applied .typeError(YUP_NOT_TYPE_NUMBER) to active/reactive power setpoint validators.
Voltage Level Validation
src/components/network-modifications/voltage-level/creation/voltageLevelCreation.utils.ts, src/components/network-modifications/voltage-level/modification/voltageLevelModification.utils.ts
Added .typeError(YUP_NOT_TYPE_NUMBER) to multiple numeric voltage-related fields (nominal, limits, short-circuit currents, counts).

Suggested reviewers

  • KoloMenek
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: add type error handling for numeric fields in validation schemas' accurately and clearly describes the main change: adding type error handling for numeric fields across validation schemas.
Description check ✅ Passed The description is directly related to the changeset, providing a clear problem statement, the fix applied, and a detailed list of files modified with specific counts of affected fields.

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


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/translations/fr/networkModificationsFr.ts (1)

134-134: Prefer the shared constant key in locale objects.

Using the literal key here can drift from schema constants later. Use [YUP_NOT_TYPE_NUMBER] like other shared validation keys.

Proposed patch
-import { DUPLICATED_PROPS_ERROR, YUP_REQUIRED } from '../../utils';
+import { DUPLICATED_PROPS_ERROR, YUP_NOT_TYPE_NUMBER, YUP_REQUIRED } from '../../utils';
@@
-    YupNotTypeNumber: "Ce champ n'accepte que des valeurs numériques",
+    [YUP_NOT_TYPE_NUMBER]: "Ce champ n'accepte que des valeurs numériques",
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/translations/fr/networkModificationsFr.ts` at line 134, Replace the
literal translation key "YupNotTypeNumber" with the shared constant key
YUP_NOT_TYPE_NUMBER (i.e., use [YUP_NOT_TYPE_NUMBER] as the object property) to
match other locale entries; update the entry in
src/translations/fr/networkModificationsFr.ts so the translations object uses
the imported/shared constant YUP_NOT_TYPE_NUMBER rather than the hard-coded
string, ensuring the constant is imported if not already.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/translations/fr/networkModificationsFr.ts`:
- Line 134: Replace the literal translation key "YupNotTypeNumber" with the
shared constant key YUP_NOT_TYPE_NUMBER (i.e., use [YUP_NOT_TYPE_NUMBER] as the
object property) to match other locale entries; update the entry in
src/translations/fr/networkModificationsFr.ts so the translations object uses
the imported/shared constant YUP_NOT_TYPE_NUMBER rather than the hard-coded
string, ensuring the constant is imported if not already.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a57e5164-dbc2-47b0-95fb-74062cb531a3

📥 Commits

Reviewing files that changed from the base of the PR and between a1bad06 and 523fb61.

📒 Files selected for processing (9)
  • src/components/network-modifications/common/connectivity/connectivityForm.utils.ts
  • src/components/network-modifications/common/measurements/powerWithValidity.utils.ts
  • src/components/network-modifications/common/setpoints/setPoints.utils.ts
  • src/components/network-modifications/load/creation/loadCreation.utils.ts
  • src/components/network-modifications/voltage-level/creation/voltageLevelCreation.utils.ts
  • src/components/network-modifications/voltage-level/modification/voltageLevelModification.utils.ts
  • src/translations/en/networkModificationsEn.ts
  • src/translations/fr/networkModificationsFr.ts
  • src/utils/constants/translationKeys.ts

@sonarqubecloud
Copy link
Copy Markdown

@achour94 achour94 merged commit c6700d6 into main Mar 26, 2026
6 checks passed
@achour94 achour94 deleted the fix-yup-number-translation branch March 26, 2026 14:12
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