Skip to content
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

Improve reviewing PR UX #19612

Merged
merged 13 commits into from
May 7, 2022
21 changes: 20 additions & 1 deletion routers/web/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,11 +752,30 @@ func ViewPullFiles(ctx *context.Context) {
if ctx.Written() {
return
}
ctx.Data["CurrentReview"], err = models.GetCurrentReview(ctx.Doer, issue)

currentReview, err := models.GetCurrentReview(ctx.Doer, issue)
if err != nil && !models.IsErrReviewNotExist(err) {
ctx.ServerError("GetCurrentReview", err)
return
}
numPendingCodeComments := int64(0)
if currentReview != nil {
numPendingCodeComments, err = models.CountComments(&models.FindCommentsOptions{
Type: models.CommentTypeCode,
ReviewID: currentReview.ID,
IssueID: issue.ID,
})
if err != nil {
ctx.ServerError("CountComments", err)
return
}
}
ctx.Data["CurrentReview"] = currentReview
ctx.Data["PendingCodeComments"] = numPendingCodeComments
Gusted marked this conversation as resolved.
Show resolved Hide resolved
ctx.PageData["prReview"] = map[string]interface{}{
"pendingCodeComments": numPendingCodeComments,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm ... it's duplicated. I think we can use data-xxx to pass the template data to JS in this case.


getBranchData(ctx, issue)
ctx.Data["IsIssuePoster"] = ctx.IsSigned && issue.IsPoster(ctx.Doer.ID)
ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/diff/comments.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<div class="comment-header-right actions df ac">
{{if and .Review}}
{{if eq .Review.Type 0}}
<div class="ui label basic small yellow">
<div class="ui label basic small yellow pending-label">
{{$.root.i18n.Tr "repo.issues.review.pending"}}
</div>
{{else}}
Expand Down
1 change: 1 addition & 0 deletions templates/repo/diff/new_review.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<div class="ui top right pointing dropdown custom" id="review-box">
<div class="ui tiny green button btn-review">
{{.i18n.Tr "repo.diff.review"}}
<span class="ui small label review-comments-counter" {{if eq .PendingCodeComments 0}}style="display: none"{{end}}>{{if gt .PendingCodeComments 0}}{{.PendingCodeComments}}{{end}}</span>
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
</div>
<div class="menu review-box">
Expand Down
27 changes: 26 additions & 1 deletion web_src/js/features/repo-diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,36 @@ import {initCompReactionSelector} from './comp/ReactionSelector.js';
import {initRepoIssueContentHistory} from './repo-issue-content.js';
import {validateTextareaNonEmpty} from './comp/EasyMDE.js';

const {csrfToken} = window.config;
const {csrfToken, pageData} = window.config;
const prReview = pageData.prReview || {};

export function initRepoDiffReviewButton() {
const reviewBox = document.querySelector('#review-box');
$(document).on('click', 'button[name="is_review"]', (e) => {
$(e.target).closest('form').append('<input type="hidden" name="is_review" value="true">');

// Watch for the form's submit event.
e.target.closest('form').addEventListener('submit', () => {
// Set a zero-timeout, so this would be executed after the network request has finished.
setTimeout(() => {
const commentCounter = document.querySelector('#review-box .review-comments-counter');
// Remove the display: none.
commentCounter.style.display = '';
// Increase counter by one, in case it's the first review, `pendingCodeComments` will
// return undefined so it will default to '1'.
prReview.pendingCodeComments = prReview.pendingCodeComments + 1 || 1;
commentCounter.textContent = String(prReview.pendingCodeComments);

// Make the review-box to do a little pulse.
reviewBox.classList.remove('pulse');
// Force the browser to reflow the DOM. This is to ensure that the browser.
// Actually removes the 'pulse' class from the DOM. Otherwise the browser
// is smart enough to de-duplicate these two requests.
const _ = reviewBox.offsetWidth;
// Add the class again.
reviewBox.classList.add('pulse');
});
});
});
}

Expand Down
17 changes: 16 additions & 1 deletion web_src/js/features/repo-issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {createCommentEasyMDE, getAttachedEasyMDE} from './comp/EasyMDE.js';
import {initCompImagePaste} from './comp/ImagePaste.js';
import {initCompMarkupContentPreviewTab} from './comp/MarkupContentPreview.js';

const {appSubUrl, csrfToken} = window.config;
const {appSubUrl, csrfToken, pageData} = window.config;
const prReview = pageData.prReview || {};

export function initRepoIssueTimeTracking() {
$(document).on('click', '.issue-add-time', () => {
Expand Down Expand Up @@ -160,6 +161,20 @@ export function initRepoIssueCommentDelete() {
_csrf: csrfToken,
}).done(() => {
const $conversationHolder = $this.closest('.conversation-holder');

// Check if this was a pending comment.
if ($conversationHolder.find('.pending-label').length) {
// This is a pending comment.
const commentCounter = document.querySelector('#review-box .review-comments-counter');
// Decrease the counter by one.
prReview.pendingCodeComments -= 1;
commentCounter.textContent = String(prReview.pendingCodeComments);
// If no pending comments remains, don't show the counter.
if (commentCounter.textContent === '0') {
commentCounter.style.display = 'none';
}
}

$(`#${$this.data('comment-id')}`).remove();
if ($conversationHolder.length && !$conversationHolder.find('.comment').length) {
const path = $conversationHolder.data('path');
Expand Down
9 changes: 9 additions & 0 deletions web_src/less/_review.less
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,15 @@ a.blob-excerpt:hover {
border: none !important;
}

#review-box .review-comments-counter {
background-color: var(--color-primary-light-4);
color: #fff;
}

#review-box:hover .review-comments-counter {
background-color: var(--color-primary-light-5);
}

.pull.files.diff [id] {
scroll-margin-top: 99px;

Expand Down
16 changes: 16 additions & 0 deletions web_src/less/animations.less
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,19 @@
opacity: 0;
}
}

@keyframes pulse {
0% {
transform: scale(1);
}
50% {
transform: scale(1.8);
}
100% {
transform: scale(1);
}
}

.pulse {
animation: pulse 2s linear;
}