feat: validate numeric custom fields during import#2152
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- Remove unhelpful heavily-mocked integration test that didn't test real behavior - Reject thousand separators in AMOUNT/NUMBER fields (e.g., 1,234 or 1,234.56) with specific error messages - Add smart heuristic to detect thousand separators: reject if exactly 3 digits follow a single separator - Restructure error messages for clarity: show specific reason first, then actionable guidance - Update error guidance to accurately reflect that currency symbols are automatically removed, not forbidden - Add comprehensive test coverage for edge cases: plain numbers, decimals, negatives, zeros, and all rejection scenarios - Preserve original error context when adding asset information during import
There was a problem hiding this comment.
Pull Request Overview
This PR adds validation and sanitization for numeric custom fields (AMOUNT and NUMBER types) during asset import to prevent invalid data and provide clear error messages to users.
Key Changes:
- Implements
sanitizeNumericInputfunction to validate and normalize numeric values with support for various formats (decimals, negatives, currency symbols) while rejecting invalid formats (thousand separators, scientific notation) - Enhances error handling in
createAssetsFromContentImportto catch validation errors and provide asset-specific context in error messages - Adds comprehensive test coverage for numeric validation logic
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| test/utils/custom-fields.test.ts | New test file with 196 lines covering numeric sanitization edge cases including valid formats, invalid formats, and error scenarios |
| app/utils/custom-fields.ts | Adds sanitizeNumericInput function with detailed validation logic and updates buildCustomFieldValue to use it for AMOUNT/NUMBER fields |
| app/modules/asset/service.server.ts | Refactors custom field processing in createAssetsFromContentImport with enhanced error handling for numeric fields and database constraint failures |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Address code review feedback: - Replace fragile string-based check (includes "(asset: '")) with robust additionalData check for assetKey presence - Use regex with capture group instead of simple replace() to precisely insert asset context after field name, avoiding issues with multiple occurrences - Simplify test type definition to avoid Omit<> complexity This makes the error context injection more maintainable and less coupled to message format.
- Forward generic type parameter T to underlying useFetcher call - Update import-content to use useFetcherWithReset with SerializeFrom - Add reset functionality to AlertDialog onOpenChange to clear form state when dialog is closed This ensures proper TypeScript inference when using the hook with typed actions.
Summary
buildCustomFieldValueand surface descriptive validation errorscreateAssetsFromContentImport, adding actionable error handling for bad data and DB constraint fallbacksTesting
https://chatgpt.com/codex/tasks/task_b_68efb543f8bc8320a3a3443ee24449ac