-
Notifications
You must be signed in to change notification settings - Fork 0
I499 edit questions #512
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
I499 edit questions #512
Conversation
Split into separate UI component to separate logic and presentation.
This commit updates the QuestionFormUI component to ensure that it renders the appropriate form based on the question type when a user is editing a question. The component checks the question from the database and maps it to the correct question type. Ref: - #499
This commit adds the functionality to display the question image on the edit modal if the question has an associated image. Ref: - #499
This commit updates the fetch function to support PUT requests for creating new questions and PATCH requests for updating existing questions. Ref: - #499
This commit ensures the correct format for the matching questions is rendered in the edit form. The correct answer is stored as an array ['match1'], but the form component expects it as a string 'match1'. Ref: - #499
This commit ensures the typeahead functionality works correctly for the subject field in the edit questions form. Ref: - #499
This commit adds an update route and controller action for questions to be modified. Ref: - #499
This commit ensures the question create and edit forms maintain a two two column layout even when many subjects are added to the question. Ref: - #499
This commit removes the footer that contained a close button from the edit question modal. There is a close button available in the header. This ensures a more visually clean UI and reduces confusion between close button and update button. Ref: - #499
This commit sets dynamic text on the button to display "Submit" when creating a new question and "Update" when editing an existing question. Ref: - #499
1724e04 to
848d2f6
Compare
This commit will let the user edit the existing image, which is only the alt text currently, and also let them delete the image.
848d2f6 to
308e489
Compare
A WYSIWYG editor would make it much easier for users to edit html.
d9093d8 to
9b2928f
Compare
This commit removes the edit button from the stimulus case study type questions until we can refactor the question structure to make editing more accessible. As a workaround, users can still export the stimulus case study questions, edit the CSV, and re-import. They would need to manually delete the existing question. Ref: - #539 - #499
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.
Pull request overview
This pull request adds edit functionality for questions, allowing users to edit their own questions and admins to edit all questions (excluding Stimulus Case Study type). The implementation includes a modal-based editing interface that reuses the existing question creation form, with modifications to support pre-populating data from existing questions.
Changes:
- Added
react-quillpackage for WYSIWYG editing of Essay and File Upload question types - Implemented update route and controller action for questions API
- Created modal-based edit interface using the existing CreateQuestionForm component
- Enhanced form components to support both create and edit modes with data pre-population
- Added image management for existing images (update alt text, mark for deletion)
Reviewed changes
Copilot reviewed 23 out of 25 changed files in this pull request and generated 16 comments.
Show a summary per file
| File | Description |
|---|---|
| package.json | Added react-quill dependency for rich text editing |
| config/routes.rb | Added update route to questions API |
| app/models/question.rb | Enhanced images_as_json to include image IDs for edit functionality |
| app/javascript/components/ui/Question/QuestionWrapper.jsx | Passed subjects prop for edit modal |
| app/javascript/components/ui/Question/QuestionMetadata.jsx | Added edit button with permission checks and edit modal integration |
| app/javascript/components/ui/Question/QuestionEditModal.jsx | New modal component for editing questions |
| app/javascript/components/ui/CreateQuestionForm/index.jsx | Refactored to support both create and edit modes with data initialization |
| app/javascript/components/ui/CreateQuestionForm/QuestionFormUI.jsx | Extracted UI component to support modal rendering |
| app/javascript/components/ui/CreateQuestionForm/Essay.jsx | Added ReactQuill for rich text editing and data prop support |
| app/javascript/components/ui/CreateQuestionForm/Upload.jsx | Added ReactQuill for rich text editing and data prop support |
| app/javascript/components/ui/CreateQuestionForm/Subject.jsx | Enhanced to support pre-populated subjects |
| app/javascript/components/ui/CreateQuestionForm/LevelDropdown.jsx | Enhanced to support pre-selected level |
| app/javascript/components/ui/CreateQuestionForm/ImageUploader.jsx | Added support for existing images with deletion marking |
| app/javascript/components/ui/CreateQuestionForm/AnswerSet.jsx | Added initialData prop for pre-populating answers |
| app/javascript/components/ui/CreateQuestionForm/Bowtie.jsx | Added data prop for pre-populating bowtie answers |
| app/javascript/components/ui/CreateQuestionForm/Categorization.jsx | Added data prop for pre-populating categories |
| app/javascript/components/ui/CreateQuestionForm/DragAndDrop.jsx | Added data prop for pre-populating drag and drop items |
| app/javascript/components/ui/CreateQuestionForm/Matching.jsx | Added data prop for pre-populating matching pairs |
| app/javascript/components/ui/CreateQuestionForm/MultipleChoice.jsx | Added data prop for pre-populating choices |
| app/javascript/components/ui/CreateQuestionForm/SelectAllThatApply.jsx | Added data prop for pre-populating answer options |
| app/javascript/components/ui/CreateQuestionForm/StimulusCaseStudy.jsx | Enhanced to support editing with data pre-population |
| app/javascript/components/pages/Search/index.jsx | Code formatting changes and subjects prop passing |
| app/controllers/api/questions_controller.rb | Added update action with image handling and permission validation |
Comments suppressed due to low confidence (1)
app/javascript/components/ui/CreateQuestionForm/index.jsx:111
- For Essay and File Upload question types, the handler converts data by splitting on newlines and wrapping in paragraph tags (lines 95-98, 107-110). However, when editing an existing Essay/Upload question, the data is already HTML from ReactQuill (as set in line 43). Calling .split('\n') on HTML content will break the formatting. This handler should check if the data is already HTML or use the data as-is when it's already in HTML format.
Essay: () =>
appendData({
html: data
.split('\n')
.map((line, index) => `<p key=${index}>${line}</p>`)
.join('')
}),
'Drag and Drop': () => appendData(filterValidData(data)),
'Bow Tie': () => data && appendData(data),
'Multiple Choice': () => appendData(filterValidData(data)),
'Select All That Apply': () => appendData(filterValidData(data)),
'Stimulus Case Study': () => appendData(data),
'File Upload': () =>
appendData({
html: data
.split('\n')
.map((line, index) => `<p key=${index}>${line}</p>`)
.join('')
})
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Story: [i499] Edit Functionality for Questions
This implementation does not include stimulus case study questions at this time.
Ref:
Expected Behavior Before Changes
Users had no way to edit questions once they were created.
Expected Behavior After Changes
Users can see an edit button on their own questions and admins can see an edit button on all questions (expect stimulus case study).
Users can see the data of their question populated into a modal form.
Users can edit and update their question.
Screenshots / Video
Edit functionality
Screen.Recording.2026-01-20.at.3.10.38.PM.mov
User can only edit their own questions
Screen.Recording.2026-01-20.at.3.16.48.PM.mov
Wysiwyg for essay questions
Notes
This implementation does not include stimulus case study questions at this time. Users can perform an edit-like action on stimulus case study questions by exporting the question to a CSV, editing the CSV, importing the question, and deleting the old version.