(feat) O3-3980: synchronize schema editor and interactive builder selection#1083
Open
Twiineenock wants to merge 13 commits intoopenmrs:mainfrom
Open
(feat) O3-3980: synchronize schema editor and interactive builder selection#1083Twiineenock wants to merge 13 commits intoopenmrs:mainfrom
Twiineenock wants to merge 13 commits intoopenmrs:mainfrom
Conversation
Contributor
Author
|
Hi @denniskigen , @VeronicaMuthee , @NethmiRodrigo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Requirements
Summary
This PR implements robust two-way synchronization between the JSON Schema Editor and the Interactive Builder. It ensures that selecting an element in one view instantly highlights and scrolls to the corresponding element in the other view.
In addition to the synchronization logic, this PR significantly refactors the
InteractiveBuildercomponent to be more modular, maintainable, and loosely coupled from the UI implementation.Technical Approach & Design
To achieve a clean separation of concerns and enable easy future UI redesigns, we implemented the following architectural changes:
1. "Headless" Selection Logic (
useInteractiveElement)We extracted the complex logic for ID generation, selection state, and event handling into a custom hook:
useInteractiveElement.2. Composition with
InteractiveElementWrapperWe introduced a
InteractiveElementWrappercomponent that acts as a contract between the system and the UI.PageElement,SectionElement,QuestionElement).3. AST-Aware Selection (
schema-navigation.ts)We refined the JSON traversal algorithms in
src/utils/schema-navigation.ts."sections": [...]) and its first child. Clicking a container property now correctly selects the parent object rather than defaulting to the first item in the array.Changes
InteractiveElementWrapperuseInteractiveElement,useBuilderScrollInteractiveBuildernow uses hoisted function declarations for sub-components to prevent hoisting errors and improve readability.schema.namebefore loading completed.SelectionProviderto tests to fix failures ininteractive-builder.test.tsx.Screenshots
The page UI is synced to its json object
The section UI is synced to its json object
The question UI is synced to its json object
Screanshcast
Here is a short video showing the schema editor in sync with the interactive builder
sync.webm
Related Issue
Other
https://openmrs.atlassian.net/browse/O3-3980