Display errors in UI correctly when creating notes
What does this MR do and why?
- Resolves sub-task 1 of https://gitlab.com/gitlab-org/gitlab/-/issues/411329
- Fixes the way that UI handles validation errors when adding a note or when replying to a discussion
- It displays the error message above the problematic note and returns the input back to the
note-form
- This is a pre-condition to the epic (https://gitlab.com/groups/gitlab-org/-/epics/10118) where we would add a validation error to the note when it gets detected as spam.
Screenshots or screen recordings
Context | Before | After |
---|---|---|
adding a note | adding-note-before | adding-note-after |
adding a note (snippet i.e. deprecated_notes.js ) |
adding-deprecated-note-before | adding-deprecated-note-after |
replying to discussion | replying-to-discussion-before | replying-to-discussion-after |
How to set up and validate locally
- Add a validator to the
app/models/note.rb
model since we don't have an easy validation we can test against in the Note model.
validate :test_ui_validation, on: [:create, :update]
def test_ui_validation
if note.include? 'TEST_VALIDATION'
self.errors.add(:base, _('it failed validation'))
end
end
- Navigate to any issue / merge request / snippet / commit and add a note with
TEST_VALIDATION
.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #411329
Edited by Hinam Mehra