-
Notifications
You must be signed in to change notification settings - Fork 99
(feat) O3-4321: Show ObsGroup question's sub questions with functional drag and drop #398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Hi @NethmiRodrigo, @denniskigen, |
Currently working on styling the |
Done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Twiineenock! This is a really cool feature and very well done!
One minor caveat, could we make it so that users can only drag sub-questions only within the parent question. i.e, make it so that you can't drag a sub question out of the main question.
This is because I could drag a sub question out of the obsGroup question into a different question which wasn't an obsGroup question. It changed the target question into an obsGroup
(very well thought out, kudos), but this could lead to unstable behavior because the non-obsGroup question could have properties not meant for obsGroup questions and we'd have to clean it up. This could also happen accidentally, which would be annoying when working on large forms, so we'd have to support reversing the question back.
TLDR: can we restrict the dragging of sub questions to be only within its respectful obsGroup question?
border-top: 1px solid colors.$gray-20; | ||
border-bottom: 1px solid colors.$gray-20; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const draggableId = `question-${pageIndex}-${sectionIndex}-${questionIndex}`; | ||
const [isCollapsed, setIsCollapsed] = useState(true); | ||
const toggleCollapse = () => { | ||
if (question.questions) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question object could be received as null as well. Better to add optional chaining like this :
question?.questions
Requirements
Summary
Currently, questions within the
questions
array of anobsGroup
type question are not rendered in the interactive builder.This PR addresses:
Sub-question Display Functionality
Sub-question Drag-and-Drop Functionality
obsGroup
questionobsGroup
questionNote: Sub-questions cannot be used as drop targets.
Approach
<SortableContext/>
component because we need to handle sorting for both parent questions (across different pages and sections) and sub-questions, both within and outside their parent questions.useSortable
hook, as shown below:handleDragEnd
function since we already know the exact path to a question within the schema.<Droppable/>
component, asuseSortable
already handles both dragging and dropping, eliminating the need for separate handling.Screenshots
Related Issue
https://openmrs.atlassian.net/browse/O3-4321
Screancasts
Duplicate, Edit, delete
dup-edi-del.webm
Drag and Drop
styled-dnd.webm