FE: Add JSON formatting for produce message fields #1484
+333
−26
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What changes did you make?
Implemented JSON formatting functionality for the produce message modal as requested in issue #1244. This enhancement addresses the need for formatted JSON display when working with Schema Registry examples and manual JSON input.
Core Implementation:
Format Toggle Buttons: Added format buttons adjacent to Key, Value, and Headers field labels. These buttons trigger JSON formatting on-demand using JSON.stringify with 2-space indentation.
JSON Formatting Utility: Implemented a safe formatting function that parses and stringifies JSON with proper error handling. If parsing fails, the original content is preserved and an error message is displayed to the user.
Optional Validation: Added a validation checkbox that allows users to enable JSON syntax validation before form submission. This is opt-in and does not interrupt existing workflows.
Enhanced Editor Configuration: Modified ACE editor to conditionally use JSON mode when formatting is active, providing syntax highlighting for better readability.
Resizable Headers Field: Implemented CSS-based resize functionality for the headers textarea, addressing the usability issue with multi-line JSON headers.
Accessibility Features: Added comprehensive ARIA labels, keyboard navigation support (Tab, Enter, Space), screen reader announcements, and proper focus management.
Technical Details:
State management using React hooks:
Event-driven architecture:
Error handling:
Integration approach:
Files Modified:
frontend/src/components/Topics/Topic/SendMessage/SendMessage.tsx: Core formatting logic, state management, event handlers (189 additions, 26 deletions)frontend/src/components/Topics/Topic/SendMessage/SendMessage.styled.tsx: UI components and accessibility styles (144 additions)Is there anything you'd like reviewers to focus on?
How Has This Been Tested?
Manually (please, describe, if necessary)
Manual Testing Performed:
Edge Cases Tested:
Unit checks
Integration checks
Covered by existing automation
Checklist
Check out Contributing and Code of Conduct
Closes #1244
Additional Context
Alignment with Maintainer Feedback:
This implementation directly addresses all points from the maintainer discussion:
Design Rationale:
Button Placement: Format buttons positioned next to field labels for discoverability while maintaining clean layout hierarchy
Validation Approach: Checkbox-based opt-in validation respects existing user workflows while providing safety net for users who want it
Event-Driven Formatting: Button-triggered formatting (versus on-type) provides explicit user control and avoids performance overhead during rapid input
State Reset on Edit: Format state automatically clears when users manually modify content, preventing confusion about current formatting state
Error Preservation: Failed formatting operations preserve original content to prevent accidental data loss
Performance Characteristics:
Security Considerations:
Browser Compatibility:
Future Enhancement Opportunities:
Thank you for reviewing this contribution. I am happy to make any adjustments based on code review feedback or maintainer preferences.