Skip to content

Commit ca63a9d

Browse files
authored
Add edit, delete and reaction support to code review comments on issue page (#14339)
1 parent acb1ceb commit ca63a9d

File tree

5 files changed

+101
-20
lines changed

5 files changed

+101
-20
lines changed

routers/repo/issue.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,7 +1377,26 @@ func ViewIssue(ctx *context.Context) {
13771377
ctx.ServerError("Review.LoadCodeComments", err)
13781378
return
13791379
}
1380+
for _, codeComments := range comment.Review.CodeComments {
1381+
for _, lineComments := range codeComments {
1382+
for _, c := range lineComments {
1383+
// Check tag.
1384+
tag, ok = marked[c.PosterID]
1385+
if ok {
1386+
c.ShowTag = tag
1387+
continue
1388+
}
13801389

1390+
c.ShowTag, err = commentTag(repo, c.Poster, issue)
1391+
if err != nil {
1392+
ctx.ServerError("commentTag", err)
1393+
return
1394+
}
1395+
marked[c.PosterID] = c.ShowTag
1396+
participants = addParticipant(c.Poster, participants)
1397+
}
1398+
}
1399+
}
13811400
if err = comment.LoadResolveDoer(); err != nil {
13821401
ctx.ServerError("LoadResolveDoer", err)
13831402
return

templates/repo/diff/comments.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
{{end}}
4848
{{end}}
4949
{{template "repo/issue/view_content/add_reaction" Dict "ctx" $.root "ActionURL" (Printf "%s/comments/%d/reactions" $.root.RepoLink .ID) }}
50-
{{template "repo/issue/view_content/context_menu" Dict "ctx" $.root "item" . "delete" true "diff" true "IsCommentPoster" (and $.root.IsSigned (eq $.root.SignedUserID .PosterID))}}
50+
{{template "repo/issue/view_content/context_menu" Dict "ctx" $.root "item" . "delete" true "issue" false "diff" true "IsCommentPoster" (and $.root.IsSigned (eq $.root.SignedUserID .PosterID))}}
5151
</div>
5252
</div>
5353
<div class="ui attached segment comment-body">

templates/repo/issue/view_content/comments.tmpl

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
</div>
5959
{{end}}
6060
{{template "repo/issue/view_content/add_reaction" Dict "ctx" $ "ActionURL" (Printf "%s/comments/%d/reactions" $.RepoLink .ID)}}
61-
{{template "repo/issue/view_content/context_menu" Dict "ctx" $ "item" . "delete" true "diff" false "IsCommentPoster" (and $.IsSigned (eq $.SignedUserID .PosterID))}}
61+
{{template "repo/issue/view_content/context_menu" Dict "ctx" $ "item" . "delete" true "issue" true "diff" false "IsCommentPoster" (and $.IsSigned (eq $.SignedUserID .PosterID))}}
6262
{{end}}
6363
</div>
6464
</div>
@@ -494,25 +494,49 @@
494494
</div>
495495
</div>
496496
{{end}}
497-
<div id="code-comments-{{(index $comms 0).ID}}" class="ui segment{{if $resolved}} hide{{end}} py-3">
497+
<div id="code-comments-{{(index $comms 0).ID}}" class="comment-code-cloud ui segment{{if $resolved}} hide{{end}} py-3">
498498
<div class="ui comments mb-0">
499499
{{range $comms}}
500500
{{ $createdSubStr:= TimeSinceUnix .CreatedUnix $.Lang }}
501501
<div class="comment code-comment" id="{{.HashTag}}">
502-
{{if not .OriginalAuthor }}
503-
<a class="avatar">
504-
{{avatar .Poster}}
505-
</a>
506-
{{end}}
507502
<div class="content">
508-
<span class="text grey">
509-
{{if .OriginalAuthor }}
510-
<span class="text black"><i class="fa {{MigrationIcon $.Repository.GetOriginalURLHostname}}" aria-hidden="true"></i> {{ .OriginalAuthor }}</span><span class="text grey"> {{if $.Repository.OriginalURL}}</span><span class="text migrate">({{$.i18n.Tr "repo.migrated_from" $.Repository.OriginalURL $.Repository.GetOriginalURLHostname | Safe }}){{end}}</span>
511-
{{else}}
512-
<a class="author"{{if gt .Poster.ID 0}} href="{{.Poster.HomeLink}}"{{end}}>{{.Poster.GetDisplayName}}</a>
513-
{{end}}
514-
{{$.i18n.Tr "repo.issues.commented_at" .HashTag $createdSubStr | Safe}}
515-
</span>
503+
<div class="header comment-header">
504+
<div class="comment-header-left df ac">
505+
{{if not .OriginalAuthor }}
506+
<a class="avatar">
507+
{{avatar .Poster}}
508+
</a>
509+
{{end}}
510+
<span class="text grey">
511+
{{if .OriginalAuthor }}
512+
<span class="text black"><i class="fa {{MigrationIcon $.Repository.GetOriginalURLHostname}}" aria-hidden="true"></i> {{ .OriginalAuthor }}</span><span class="text grey"> {{if $.Repository.OriginalURL}}</span><span class="text migrate">({{$.i18n.Tr "repo.migrated_from" $.Repository.OriginalURL $.Repository.GetOriginalURLHostname | Safe }}){{end}}</span>
513+
{{else}}
514+
<a class="author"{{if gt .Poster.ID 0}} href="{{.Poster.HomeLink}}"{{end}}>{{.Poster.GetDisplayName}}</a>
515+
{{end}}
516+
{{$.i18n.Tr "repo.issues.commented_at" .HashTag $createdSubStr | Safe}}
517+
</span>
518+
</div>
519+
<div class="comment-header-right actions df ac">
520+
{{if not $.Repository.IsArchived}}
521+
{{if or (and (eq .PosterID $.Issue.PosterID) (eq $.Issue.OriginalAuthorID 0)) (eq $.Issue.OriginalAuthorID .OriginalAuthorID) }}
522+
<div class="ui basic label">
523+
{{$.i18n.Tr "repo.issues.poster"}}
524+
</div>
525+
{{end}}
526+
{{if gt .ShowTag 0}}
527+
<div class="ui basic label">
528+
{{if eq .ShowTag 2}}
529+
{{$.i18n.Tr "repo.issues.collaborator"}}
530+
{{else if eq .ShowTag 3}}
531+
{{$.i18n.Tr "repo.issues.owner"}}
532+
{{end}}
533+
</div>
534+
{{end}}
535+
{{template "repo/issue/view_content/add_reaction" Dict "ctx" $ "ActionURL" (Printf "%s/comments/%d/reactions" $.RepoLink .ID)}}
536+
{{template "repo/issue/view_content/context_menu" Dict "ctx" $ "item" . "delete" true "issue" true "diff" true "IsCommentPoster" (and $.IsSigned (eq $.SignedUserID .PosterID))}}
537+
{{end}}
538+
</div>
539+
</div>
516540
<div class="text comment-content">
517541
<div class="render-content markdown">
518542
{{if .RenderedContent}}
@@ -521,8 +545,15 @@
521545
<span class="no-content">{{$.i18n.Tr "repo.issues.no_content"}}</span>
522546
{{end}}
523547
</div>
524-
<div class="raw-content hide">{{.Content}}</div>
548+
<div id="comment-{{.ID}}" class="raw-content hide">{{.Content}}</div>
549+
<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>
525550
</div>
551+
{{$reactions := .Reactions.GroupByType}}
552+
{{if $reactions}}
553+
<div class="ui attached segment reactions">
554+
{{template "repo/issue/view_content/reactions" Dict "ctx" $ "ActionURL" (Printf "%s/comments/%d/reactions" $.RepoLink .ID) "Reactions" $reactions}}
555+
</div>
556+
{{end}}
526557
</div>
527558
</div>
528559
{{end}}

templates/repo/issue/view_content/context_menu.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
{{svg "octicon-kebab-horizontal"}}
55
</a>
66
<div class="menu">
7-
{{if .diff}}
8-
<div class="item context clipboard" data-clipboard-text="{{Printf "%s%s/pulls/%d/files#%s" AppUrl .ctx.Repository.FullName .ctx.Issue.Index .item.HashTag}}">{{.ctx.i18n.Tr "repo.issues.context.copy_link"}}</div>
9-
{{else}}
7+
{{if .issue}}
108
<div class="item context clipboard" data-clipboard-text="{{Printf "%s%s/issues/%d#%s" AppUrl .ctx.Repository.FullName .ctx.Issue.Index .item.HashTag}}">{{.ctx.i18n.Tr "repo.issues.context.copy_link"}}</div>
9+
{{else}}
10+
<div class="item context clipboard" data-clipboard-text="{{Printf "%s%s/pulls/%d/files#%s" AppUrl .ctx.Repository.FullName .ctx.Issue.Index .item.HashTag}}">{{.ctx.i18n.Tr "repo.issues.context.copy_link"}}</div>
1111
{{end}}
1212
<div class="item context quote-reply {{if .diff}}quote-reply-diff{{end}}" data-target="{{.item.ID}}">{{.ctx.i18n.Tr "repo.issues.context.quote_reply"}}</div>
1313
{{if or .ctx.Permission.IsAdmin .IsCommentPoster .ctx.HasIssuesOrPullsWritePermission}}

web_src/less/_repository.less

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,10 @@
939939
}
940940
}
941941

942+
.ui.comments {
943+
max-width: 100%;
944+
}
945+
942946
.comment {
943947
> .content {
944948
> div:first-child {
@@ -1048,12 +1052,39 @@
10481052
border: none !important;
10491053
}
10501054

1055+
.comment-header {
1056+
background: transparent;
1057+
border-bottom: 0 !important;
1058+
padding: 0 !important;
1059+
1060+
&::after,
1061+
&::before {
1062+
display: none;
1063+
}
1064+
}
1065+
10511066
.avatar.image {
10521067
width: 28px;
10531068
height: 28px;
10541069
}
10551070
}
10561071

1072+
.comment-code-cloud {
1073+
.segment.reactions {
1074+
border-top: none !important;
1075+
1076+
.ui.label {
1077+
border: 1px solid;
1078+
padding: 6px !important;
1079+
border-radius: var(--border-radius);
1080+
}
1081+
}
1082+
1083+
button.comment-form-reply {
1084+
margin-left: 0;
1085+
}
1086+
}
1087+
10571088
.event {
10581089
padding-left: 15px;
10591090

0 commit comments

Comments
 (0)