diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-03-04 15:13:37 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-04 02:13:37 -0500 |
commit | 188c8c12c290e131fb342e3203634828652b0af5 (patch) | |
tree | 228bd46aa0aed2f059e7bd5a71ab42e7ceebe52e /web_src/js | |
parent | 47b912cd526207f831bff759b29a734049d1c8f2 (diff) | |
download | gitea-188c8c12c290e131fb342e3203634828652b0af5.tar.gz gitea-188c8c12c290e131fb342e3203634828652b0af5.zip |
Make Ctrl+Enter submit a pending comment (starting review) instead of submitting a single comment (#23245)
Close #23241
Before: press Ctrl+Enter in the Code Review Form, a single comment will
be added.
After: press Ctrl+Enter in the Code Review Form, start the review with
pending comments.
The old name `is_review` is not clear, so the new code use
`pending_review` as the new name.
Co-authored-by: delvh <leon@kske.dev>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'web_src/js')
-rw-r--r-- | web_src/js/features/repo-diff.js | 14 | ||||
-rw-r--r-- | web_src/js/features/repo-issue.js | 2 |
2 files changed, 11 insertions, 5 deletions
diff --git a/web_src/js/features/repo-diff.js b/web_src/js/features/repo-diff.js index d2559b1237..56ebe4fc99 100644 --- a/web_src/js/features/repo-diff.js +++ b/web_src/js/features/repo-diff.js @@ -11,10 +11,8 @@ export function initRepoDiffReviewButton() { const $reviewBox = $('#review-box'); const $counter = $reviewBox.find('.review-comments-counter'); - $(document).on('click', 'button[name="is_review"]', (e) => { + $(document).on('click', 'button[name="pending_review"]', (e) => { const $form = $(e.target).closest('form'); - $form.append('<input type="hidden" name="is_review" value="true">'); - // Watch for the form's submit event. $form.on('submit', () => { const num = parseInt($counter.attr('data-pending-comment-number')) + 1 || 1; @@ -50,7 +48,15 @@ export function initRepoDiffConversationForm() { return; } - const formDataString = String(new URLSearchParams(new FormData($form[0]))); + const formData = new FormData($form[0]); + + // if the form is submitted by a button, append the button's name and value to the form data + const submitter = e.originalEvent?.submitter; + const isSubmittedByButton = (submitter?.nodeName === 'BUTTON') || (submitter?.nodeName === 'INPUT' && submitter.type === 'submit'); + if (isSubmittedByButton && submitter.name) { + formData.append(submitter.name, submitter.value); + } + const formDataString = String(new URLSearchParams(formData)); const $newConversationHolder = $(await $.post($form.attr('action'), formDataString)); const {path, side, idx} = $newConversationHolder.data(); diff --git a/web_src/js/features/repo-issue.js b/web_src/js/features/repo-issue.js index 4163fb120e..41c9dd118f 100644 --- a/web_src/js/features/repo-issue.js +++ b/web_src/js/features/repo-issue.js @@ -535,7 +535,7 @@ export function initRepoPullRequestReview() { const td = ntr.find(`.add-comment-${side}`); let commentCloud = td.find('.comment-code-cloud'); - if (commentCloud.length === 0 && !ntr.find('button[name="is_review"]').length) { + if (commentCloud.length === 0 && !ntr.find('button[name="pending_review"]').length) { const data = await $.get($(this).closest('[data-new-comment-url]').data('new-comment-url')); td.html(data); commentCloud = td.find('.comment-code-cloud'); |