Skip to content

Conversation

@lovasoa
Copy link
Owner

@lovasoa lovasoa commented Dec 30, 2025

Summary

Fixes the issue where fields would move to the end of the properties list when their names were edited.

Root Cause

When renaming a field, the old property was being deleted and re-added with the new name, causing it to move to the end of the object.

Solution

  • Extracted field rename logic into a new utility function: renameObjectProperty() in src/lib/schemaEditor.ts
  • This function iterates through properties in order and replaces the old key with the new key, preserving position
  • Simplified handleEditField in SchemaVisualEditor to use the new utility

Changes

  • src/lib/schemaEditor.ts: Added renameObjectProperty() utility function
  • src/components/SchemaEditor/SchemaVisualEditor.tsx: Refactored to use renameObjectProperty()
  • test/lib/schemaEditor.test.ts: Single focused unit test of the actual rename function

Test Coverage

  • ✅ 50 total tests pass (49 existing + 1 new)
  • ✅ Build succeeds without errors
  • ✅ 4-line test that directly tests renameObjectProperty() function

Closes #11

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Dec 30, 2025

Deploying jsonjoy-builder with  Cloudflare Pages  Cloudflare Pages

Latest commit: 39b42d7
Status: ✅  Deploy successful!
Preview URL: https://5025a684.jsonjoy-builder.pages.dev
Branch Preview URL: https://fix-field-rename-position.jsonjoy-builder.pages.dev

View logs

@lovasoa lovasoa force-pushed the fix/field-rename-position branch 2 times, most recently from 55421ee to 86e8aed Compare December 30, 2025 22:10
When editing a field's name, the field was being moved to the end of the properties list because the old property was deleted and re-added with the new name.

Fixed by iterating through properties in order and replacing the old key with the new key while maintaining the original position. Also updated the required array to use the new field name.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@lovasoa lovasoa force-pushed the fix/field-rename-position branch from 86e8aed to 39b42d7 Compare December 30, 2025 22:15
@lovasoa lovasoa merged commit fbb6566 into main Dec 30, 2025
3 checks passed
@lovasoa lovasoa deleted the fix/field-rename-position branch December 30, 2025 22:16
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.

Field is placed at end of list after edit of Field Name

2 participants