Fix supressing leading zeros in Collection Object's Catalog Number in data entry#8027
Fix supressing leading zeros in Collection Object's Catalog Number in data entry#8027
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughRefines the numeric zero-trimming logic in Changes
🚥 Pre-merge checks | ✅ 4 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Review rate limit: 9/10 reviews remaining, refill in 6 minutes. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
specifyweb/frontend/js_src/lib/components/Formatters/formatters.ts (1)
199-202: Add tests fortrimZeros: trueedge cases introduced by this change.This branch now treats whitespace-only values differently, but current
formatFieldtests (seespecifyweb/frontend/js_src/lib/components/Formatters/__tests__/formatters.test.ts:79-150) only covertrimZeros: false. Please add cases fortrimZeros: true(whitespace-only, normal zero-padded numeric strings, and long numeric strings).🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@specifyweb/frontend/js_src/lib/components/Formatters/formatters.ts` around lines 199 - 202, Add unit tests in specifyweb/frontend/js_src/lib/components/Formatters/__tests__/formatters.test.ts that exercise the new trimZeros:true behavior in formatField/formatters (cover whitespace-only, zero-padded numeric strings, and very long numeric strings). Specifically, create tests calling formatField (or the exported formatter that uses the trimZeros branch) with trimZeros: true and assert that: a) a whitespace-only input (e.g., " ") is returned unchanged, b) a zero-padded numeric string (e.g., "000123.4500") is normalized to Number(...).toString() (e.g., "123.45"), and c) a very long numeric string is converted to the same value produced by Number(longString).toString() (assert using Number(longString).toString() to avoid precision assumptions). Use the existing test file structure and naming pattern to add these three cases.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@specifyweb/frontend/js_src/lib/components/Formatters/formatters.ts`:
- Around line 199-202: The code uses Number(formatted).toString() when trimZeros
is true which can lose precision for long numeric IDs; switch to string-based
trimming: treat formatted as a string (String(formatted)), and if it contains a
decimal point remove only trailing fractional zeros and a trailing dot (e.g.
formatted = String(formatted).replace(/(\.\d*?[1-9])0+$|\.0+$/,'$1')), leaving
integer strings untouched so large integers are preserved; update the logic
around the trimZeros branch (the variable formatted and its handling) and add
unit tests covering trimZeros: true for integer-like long IDs and decimal cases
to ensure no precision loss and correct zero trimming.
---
Nitpick comments:
In `@specifyweb/frontend/js_src/lib/components/Formatters/formatters.ts`:
- Around line 199-202: Add unit tests in
specifyweb/frontend/js_src/lib/components/Formatters/__tests__/formatters.test.ts
that exercise the new trimZeros:true behavior in formatField/formatters (cover
whitespace-only, zero-padded numeric strings, and very long numeric strings).
Specifically, create tests calling formatField (or the exported formatter that
uses the trimZeros branch) with trimZeros: true and assert that: a) a
whitespace-only input (e.g., " ") is returned unchanged, b) a zero-padded
numeric string (e.g., "000123.4500") is normalized to Number(...).toString()
(e.g., "123.45"), and c) a very long numeric string is converted to the same
value produced by Number(longString).toString() (assert using
Number(longString).toString() to avoid precision assumptions). Use the existing
test file structure and naming pattern to add these three cases.
🪄 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: CHILL
Plan: Pro Plus
Run ID: 0b121e1f-c917-4242-b761-2e5ad6f83bc0
📒 Files selected for processing (1)
specifyweb/frontend/js_src/lib/components/Formatters/formatters.ts
emenslin
left a comment
There was a problem hiding this comment.
- On data entry, the title of the unsaved CO should read "Collection Object"
- On data entry, the title of the saved CO should read something like "Collection Object: 1"
- On data entry, the title of the unsaved CO should read "Collection Object"
- On data entry, the title of the saved CO should read something like "Collection Object: 000000001"
- Generally test table formatters in the preview to make sure they are okay. You don't need to test formatters in query results.
Looks good!
bhumikaguptaa
left a comment
There was a problem hiding this comment.
- On data entry, the title of the unsaved CO should read "Collection Object"
- On data entry, the title of the saved CO should read something like "Collection Object: 1"
- On data entry, the title of the unsaved CO should read "Collection Object"
- On data entry, the title of the saved CO should read something like "Collection Object: 000000001"
- Generally test table formatters in the preview to make sure they are okay. You don't need to test formatters in query results.
Works as expected!
Fixes #1707
Checklist
self-explanatory (or properly documented)
Testing instructions
Summary by CodeRabbit