Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 84f8ef3

Browse files
authoredJan 18, 2022
Fix PR comments UI (#18323)
Closes: * Review comment cannot be edited #17768 * Changing PR Comment Resolved State Disables Further Changes #18315
1 parent 11b4827 commit 84f8ef3

File tree

7 files changed

+64
-27
lines changed

7 files changed

+64
-27
lines changed
 

‎models/issue_comment.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ func (c *Comment) LoadPoster() error {
519519
return c.loadPoster(db.GetEngine(db.DefaultContext))
520520
}
521521

522-
// LoadAttachments loads attachments
522+
// LoadAttachments loads attachments (it never returns error, the error during `GetAttachmentsByCommentIDCtx` is ignored)
523523
func (c *Comment) LoadAttachments() error {
524524
if len(c.Attachments) > 0 {
525525
return nil

‎routers/api/v1/repo/issue_comment.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,9 @@ func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption)
537537
if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.IsAdmin()) {
538538
ctx.Status(http.StatusForbidden)
539539
return
540-
} else if comment.Type != models.CommentTypeComment {
540+
}
541+
542+
if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeReview && comment.Type != models.CommentTypeCode {
541543
ctx.Status(http.StatusNoContent)
542544
return
543545
}

‎routers/web/repo/issue.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ func ViewIssue(ctx *context.Context) {
13331333
return
13341334
}
13351335

1336-
if comment.Type == models.CommentTypeComment {
1336+
if comment.Type == models.CommentTypeComment || comment.Type == models.CommentTypeReview {
13371337
if err := comment.LoadAttachments(); err != nil {
13381338
ctx.ServerError("LoadAttachments", err)
13391339
return
@@ -2194,7 +2194,9 @@ func UpdateCommentContent(ctx *context.Context) {
21942194
if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.CanWriteIssuesOrPulls(comment.Issue.IsPull)) {
21952195
ctx.Error(http.StatusForbidden)
21962196
return
2197-
} else if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeCode {
2197+
}
2198+
2199+
if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeReview && comment.Type != models.CommentTypeCode {
21982200
ctx.Error(http.StatusNoContent)
21992201
return
22002202
}
@@ -2212,11 +2214,9 @@ func UpdateCommentContent(ctx *context.Context) {
22122214
return
22132215
}
22142216

2215-
if comment.Type == models.CommentTypeComment {
2216-
if err := comment.LoadAttachments(); err != nil {
2217-
ctx.ServerError("LoadAttachments", err)
2218-
return
2219-
}
2217+
if err := comment.LoadAttachments(); err != nil {
2218+
ctx.ServerError("LoadAttachments", err)
2219+
return
22202220
}
22212221

22222222
// when the update request doesn't intend to update attachments (eg: change checkbox state), ignore attachment updates
@@ -2404,7 +2404,9 @@ func ChangeCommentReaction(ctx *context.Context) {
24042404

24052405
ctx.Error(http.StatusForbidden)
24062406
return
2407-
} else if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeCode {
2407+
}
2408+
2409+
if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeCode && comment.Type != models.CommentTypeReview {
24082410
ctx.Error(http.StatusNoContent)
24092411
return
24102412
}

‎templates/repo/issue/view_content/comments.tmpl

+46-15
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@
399399
</div>
400400
{{else if eq .Type 22}}
401401
<div class="timeline-item-group">
402-
<div class="timeline-item event" id="{{.HashTag}}">
402+
<div class="timeline-item event">
403403
{{if .OriginalAuthor }}
404404
{{else}}
405405
<a class="timeline-avatar"{{if gt .Poster.ID 0}} href="{{.Poster.HomeLink}}"{{end}}>
@@ -434,23 +434,46 @@
434434
</span>
435435
</div>
436436
{{if .Content}}
437-
<div class="timeline-item comment">
437+
<div class="timeline-item comment" id="{{.HashTag}}">
438438
<div class="content comment-container">
439439
<div class="ui top attached header comment-header df ac sb">
440-
<span class="text grey">
441-
{{if .OriginalAuthor }}
442-
<span class="text black">
443-
{{svg (MigrationIcon $.Repository.GetOriginalURLHostname)}}
444-
{{ .OriginalAuthor }}
445-
</span>
446-
<span class="text grey"> {{if $.Repository.OriginalURL}}</span>
447-
<span class="text migrate">({{$.i18n.Tr "repo.migrated_from" ($.Repository.OriginalURL|Escape) ($.Repository.GetOriginalURLHostname|Escape) | Safe }}){{end}}</span>
448-
{{else}}
449-
<a class="author"{{if gt .Poster.ID 0}} href="{{.Poster.HomeLink}}"{{end}}>{{.Poster.GetDisplayName}}</a>
450-
{{end}}
440+
<div class="comment-header-left df ac">
441+
<span class="text grey">
442+
{{if .OriginalAuthor }}
443+
<span class="text black">
444+
{{svg (MigrationIcon $.Repository.GetOriginalURLHostname)}}
445+
{{ .OriginalAuthor }}
446+
</span>
447+
<span class="text grey"> {{if $.Repository.OriginalURL}}</span>
448+
<span class="text migrate">({{$.i18n.Tr "repo.migrated_from" ($.Repository.OriginalURL|Escape) ($.Repository.GetOriginalURLHostname|Escape) | Safe }}){{end}}</span>
449+
{{else}}
450+
<a class="author"{{if gt .Poster.ID 0}} href="{{.Poster.HomeLink}}"{{end}}>{{.Poster.GetDisplayName}}</a>
451+
{{end}}
451452

452-
{{$.i18n.Tr "repo.issues.review.left_comment" | Safe}}
453-
</span>
453+
{{$.i18n.Tr "repo.issues.review.left_comment" | Safe}}
454+
</span>
455+
</div>
456+
<div class="comment-header-right actions df ac">
457+
{{if (.ShowRole.HasRole "Poster")}}
458+
<div class="ui basic label">
459+
{{$.i18n.Tr "repo.issues.poster"}}
460+
</div>
461+
{{end}}
462+
{{if (.ShowRole.HasRole "Writer")}}
463+
<div class="ui basic label">
464+
{{$.i18n.Tr "repo.issues.collaborator"}}
465+
</div>
466+
{{end}}
467+
{{if (.ShowRole.HasRole "Owner")}}
468+
<div class="ui basic label">
469+
{{$.i18n.Tr "repo.issues.owner"}}
470+
</div>
471+
{{end}}
472+
{{if not $.Repository.IsArchived}}
473+
{{template "repo/issue/view_content/add_reaction" Dict "ctx" $ "ActionURL" (Printf "%s/comments/%d/reactions" $.RepoLink .ID)}}
474+
{{template "repo/issue/view_content/context_menu" Dict "ctx" $ "item" . "delete" true "issue" true "diff" false "IsCommentPoster" (and $.IsSigned (eq $.SignedUserID .PosterID))}}
475+
{{end}}
476+
</div>
454477
</div>
455478
<div class="ui attached segment comment-body">
456479
<div class="render-content markup">
@@ -460,10 +483,18 @@
460483
<span class="no-content">{{$.i18n.Tr "repo.issues.no_content"}}</span>
461484
{{end}}
462485
</div>
486+
<div id="comment-{{.ID}}" class="raw-content hide">{{.Content}}</div>
487+
<div class="edit-content-zone hide" data-write="issuecomment-{{.ID}}-write" data-preview="issuecomment-{{.ID}}-preview" data-update-url="{{$.RepoLink}}/comments/{{.ID}}" data-context="{{$.RepoLink}}" data-attachment-url="{{$.RepoLink}}/comments/{{.ID}}/attachments"></div>
463488
{{if .Attachments}}
464489
{{template "repo/issue/view_content/attachments" Dict "ctx" $ "Attachments" .Attachments "Content" .RenderedContent}}
465490
{{end}}
466491
</div>
492+
{{$reactions := .Reactions.GroupByType}}
493+
{{if $reactions}}
494+
<div class="ui attached segment reactions">
495+
{{template "repo/issue/view_content/reactions" Dict "ctx" $ "ActionURL" (Printf "%s/comments/%d/reactions" $.RepoLink .ID) "Reactions" $reactions}}
496+
</div>
497+
{{end}}
467498
</div>
468499
</div>
469500
{{end}}

‎web_src/js/features/repo-diff.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function initRepoDiffConversationForm() {
4545
});
4646

4747

48-
$('.resolve-conversation').on('click', async function (e) {
48+
$(document).on('click', '.resolve-conversation', async function (e) {
4949
e.preventDefault();
5050
const comment_id = $(this).data('comment-id');
5151
const origin = $(this).data('origin');

‎web_src/js/features/repo-issue-content.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export function initRepoIssueContentHistory() {
109109
if (!issueIndex) return;
110110

111111
const $itemIssue = $('.repository.issue .timeline-item.comment.first'); // issue(PR) main content
112-
const $comments = $('.repository.issue .comment-list .comment'); // includes: issue(PR) comments, code rerview comments
112+
const $comments = $('.repository.issue .comment-list .comment'); // includes: issue(PR) comments, review comments, code comments
113113
if (!$itemIssue.length && !$comments.length) return;
114114

115115
const repoLink = $('#repolink').val();

‎web_src/less/_repository.less

+2
Original file line numberDiff line numberDiff line change
@@ -2673,10 +2673,12 @@
26732673

26742674
a {
26752675
color: var(--color-text);
2676+
text-decoration: none;
26762677
}
26772678

26782679
a:hover {
26792680
color: var(--color-primary);
2681+
text-decoration: none;
26802682
}
26812683
}
26822684

0 commit comments

Comments
 (0)
Please sign in to comment.