Skip to content

Commit ee3e83e

Browse files
authored
Don't reload timeline page when (un)resolving or replying conversation (#28654)
Fixes #15981
1 parent 4567a3a commit ee3e83e

File tree

4 files changed

+151
-150
lines changed

4 files changed

+151
-150
lines changed

routers/web/repo/pull_review.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ import (
2121
)
2222

2323
const (
24-
tplConversation base.TplName = "repo/diff/conversation"
25-
tplNewComment base.TplName = "repo/diff/new_comment"
24+
tplDiffConversation base.TplName = "repo/diff/conversation"
25+
tplTimelineConversation base.TplName = "repo/issue/view_content/conversation"
26+
tplNewComment base.TplName = "repo/diff/new_comment"
2627
)
2728

2829
// RenderNewCodeCommentForm will render the form for creating a new review comment
@@ -97,11 +98,7 @@ func CreateCodeComment(ctx *context.Context) {
9798

9899
log.Trace("Comment created: %-v #%d[%d] Comment[%d]", ctx.Repo.Repository, issue.Index, issue.ID, comment.ID)
99100

100-
if form.Origin == "diff" {
101-
renderConversation(ctx, comment)
102-
return
103-
}
104-
ctx.Redirect(comment.Link(ctx))
101+
renderConversation(ctx, comment, form.Origin)
105102
}
106103

107104
// UpdateResolveConversation add or remove an Conversation resolved mark
@@ -152,22 +149,21 @@ func UpdateResolveConversation(ctx *context.Context) {
152149
return
153150
}
154151

155-
if origin == "diff" {
156-
renderConversation(ctx, comment)
157-
return
158-
}
159-
ctx.JSONOK()
152+
renderConversation(ctx, comment, origin)
160153
}
161154

162-
func renderConversation(ctx *context.Context, comment *issues_model.Comment) {
155+
func renderConversation(ctx *context.Context, comment *issues_model.Comment, origin string) {
163156
comments, err := issues_model.FetchCodeCommentsByLine(ctx, comment.Issue, ctx.Doer, comment.TreePath, comment.Line, ctx.Data["ShowOutdatedComments"].(bool))
164157
if err != nil {
165158
ctx.ServerError("FetchCodeCommentsByLine", err)
166159
return
167160
}
168-
ctx.Data["PageIsPullFiles"] = true
161+
ctx.Data["PageIsPullFiles"] = (origin == "diff")
169162
ctx.Data["comments"] = comments
170-
ctx.Data["CanMarkConversation"] = true
163+
if ctx.Data["CanMarkConversation"], err = issues_model.CanMarkConversation(ctx, comment.Issue, ctx.Doer); err != nil {
164+
ctx.ServerError("CanMarkConversation", err)
165+
return
166+
}
171167
ctx.Data["Issue"] = comment.Issue
172168
if err = comment.Issue.LoadPullRequest(ctx); err != nil {
173169
ctx.ServerError("comment.Issue.LoadPullRequest", err)
@@ -179,7 +175,11 @@ func renderConversation(ctx *context.Context, comment *issues_model.Comment) {
179175
return
180176
}
181177
ctx.Data["AfterCommitID"] = pullHeadCommitID
182-
ctx.HTML(http.StatusOK, tplConversation)
178+
if origin == "diff" {
179+
ctx.HTML(http.StatusOK, tplDiffConversation)
180+
} else if origin == "timeline" {
181+
ctx.HTML(http.StatusOK, tplTimelineConversation)
182+
}
183183
}
184184

185185
// SubmitReview creates a review out of the existing pending review or creates a new one if no pending review exist

templates/repo/issue/view_content/comments.tmpl

+1-133
Original file line numberDiff line numberDiff line change
@@ -460,139 +460,7 @@
460460
<div class="timeline-item event">
461461
{{range $filename, $lines := .Review.CodeComments}}
462462
{{range $line, $comms := $lines}}
463-
<div class="ui segments">
464-
<div class="ui segment collapsible-comment-box gt-py-3 gt-df gt-ac gt-sb">
465-
{{$invalid := (index $comms 0).Invalidated}}
466-
{{$resolved := (index $comms 0).IsResolved}}
467-
{{$resolveDoer := (index $comms 0).ResolveDoer}}
468-
{{$isNotPending := (not (eq (index $comms 0).Review.Type 0))}}
469-
<div class="gt-df gt-ac">
470-
<a href="{{(index $comms 0).CodeCommentLink ctx}}" class="file-comment gt-ml-3 gt-word-break">{{$filename}}</a>
471-
{{if $invalid}}
472-
<span class="ui label basic small gt-ml-3" data-tooltip-content="{{ctx.Locale.Tr "repo.issues.review.outdated_description"}}">
473-
{{ctx.Locale.Tr "repo.issues.review.outdated"}}
474-
</span>
475-
{{end}}
476-
</div>
477-
<div>
478-
{{if or $invalid $resolved}}
479-
<button id="show-outdated-{{(index $comms 0).ID}}" data-comment="{{(index $comms 0).ID}}" class="{{if not $resolved}}gt-hidden {{end}}ui compact labeled button show-outdated gt-df gt-ac">
480-
{{svg "octicon-unfold" 16 "gt-mr-3"}}
481-
{{if $resolved}}
482-
{{ctx.Locale.Tr "repo.issues.review.show_resolved"}}
483-
{{else}}
484-
{{ctx.Locale.Tr "repo.issues.review.show_outdated"}}
485-
{{end}}
486-
</button>
487-
<button id="hide-outdated-{{(index $comms 0).ID}}" data-comment="{{(index $comms 0).ID}}" class="{{if $resolved}}gt-hidden {{end}}ui compact labeled button hide-outdated gt-df gt-ac">
488-
{{svg "octicon-fold" 16 "gt-mr-3"}}
489-
{{if $resolved}}
490-
{{ctx.Locale.Tr "repo.issues.review.hide_resolved"}}
491-
{{else}}
492-
{{ctx.Locale.Tr "repo.issues.review.hide_outdated"}}
493-
{{end}}
494-
</button>
495-
{{end}}
496-
</div>
497-
</div>
498-
{{$diff := (CommentMustAsDiff ctx (index $comms 0))}}
499-
{{if $diff}}
500-
{{$file := (index $diff.Files 0)}}
501-
<div id="code-preview-{{(index $comms 0).ID}}" class="ui table segment{{if $resolved}} gt-hidden{{end}}">
502-
<div class="diff-file-box diff-box file-content {{TabSizeClass $.Editorconfig $file.Name}}">
503-
<div class="file-body file-code code-view code-diff code-diff-unified unicode-escaped">
504-
<table>
505-
<tbody>
506-
{{template "repo/diff/section_unified" dict "file" $file "root" $}}
507-
</tbody>
508-
</table>
509-
</div>
510-
</div>
511-
</div>
512-
{{end}}
513-
<div id="code-comments-{{(index $comms 0).ID}}" class="comment-code-cloud ui segment{{if $resolved}} gt-hidden{{end}}">
514-
<div class="ui comments gt-mb-0">
515-
{{range $comms}}
516-
{{$createdSubStr:= TimeSinceUnix .CreatedUnix ctx.Locale}}
517-
<div class="comment code-comment gt-pb-4" id="{{.HashTag}}">
518-
<div class="content">
519-
<div class="header comment-header">
520-
<div class="comment-header-left gt-df gt-ac">
521-
{{if not .OriginalAuthor}}
522-
<a class="avatar">
523-
{{ctx.AvatarUtils.Avatar .Poster 20}}
524-
</a>
525-
{{end}}
526-
<span class="text grey muted-links">
527-
{{if .OriginalAuthor}}
528-
<span class="text black gt-font-semibold">
529-
{{svg (MigrationIcon $.Repository.GetOriginalURLHostname)}}
530-
{{.OriginalAuthor}}
531-
</span>
532-
<span class="text grey muted-links"> {{if $.Repository.OriginalURL}}</span>
533-
<span class="text migrate">({{ctx.Locale.Tr "repo.migrated_from" ($.Repository.OriginalURL|Escape) ($.Repository.GetOriginalURLHostname|Escape) | Safe}}){{end}}</span>
534-
{{else}}
535-
{{template "shared/user/authorlink" .Poster}}
536-
{{end}}
537-
{{ctx.Locale.Tr "repo.issues.commented_at" (.HashTag|Escape) $createdSubStr | Safe}}
538-
</span>
539-
</div>
540-
<div class="comment-header-right actions gt-df gt-ac">
541-
{{template "repo/issue/view_content/show_role" dict "ShowRole" .ShowRole}}
542-
{{if not $.Repository.IsArchived}}
543-
{{template "repo/issue/view_content/add_reaction" dict "ctxData" $ "ActionURL" (printf "%s/comments/%d/reactions" $.RepoLink .ID)}}
544-
{{template "repo/issue/view_content/context_menu" dict "ctxData" $ "item" . "delete" true "issue" true "diff" true "IsCommentPoster" (and $.IsSigned (eq $.SignedUserID .PosterID))}}
545-
{{end}}
546-
</div>
547-
</div>
548-
<div class="text comment-content">
549-
<div class="render-content markup" {{if or $.Permission.IsAdmin $.HasIssuesOrPullsWritePermission (and $.IsSigned (eq $.SignedUserID .PosterID))}}data-can-edit="true"{{end}}>
550-
{{if .RenderedContent}}
551-
{{.RenderedContent|Str2html}}
552-
{{else}}
553-
<span class="no-content">{{ctx.Locale.Tr "repo.issues.no_content"}}</span>
554-
{{end}}
555-
</div>
556-
<div id="issuecomment-{{.ID}}-raw" class="raw-content gt-hidden">{{.Content}}</div>
557-
<div class="edit-content-zone gt-hidden" data-update-url="{{$.RepoLink}}/comments/{{.ID}}" data-context="{{$.RepoLink}}" data-attachment-url="{{$.RepoLink}}/comments/{{.ID}}/attachments"></div>
558-
</div>
559-
{{$reactions := .Reactions.GroupByType}}
560-
{{if $reactions}}
561-
{{template "repo/issue/view_content/reactions" dict "ctxData" $ "ActionURL" (printf "%s/comments/%d/reactions" $.RepoLink .ID) "Reactions" $reactions}}
562-
{{end}}
563-
</div>
564-
</div>
565-
{{end}}
566-
</div>
567-
<div class="code-comment-buttons gt-df gt-ac gt-fw gt-mt-3 gt-mb-2 gt-mx-3">
568-
<div class="gt-f1">
569-
{{if $resolved}}
570-
<div class="ui grey text">
571-
{{svg "octicon-check" 16 "gt-mr-2"}}
572-
<b>{{$resolveDoer.Name}}</b> {{ctx.Locale.Tr "repo.issues.review.resolved_by"}}
573-
</div>
574-
{{end}}
575-
</div>
576-
<div class="code-comment-buttons-buttons">
577-
{{if and $.CanMarkConversation $isNotPending}}
578-
<button class="ui tiny basic button resolve-conversation" data-origin="timeline" data-action="{{if not $resolved}}Resolve{{else}}UnResolve{{end}}" data-comment-id="{{(index $comms 0).ID}}" data-update-url="{{$.RepoLink}}/issues/resolve_conversation">
579-
{{if $resolved}}
580-
{{ctx.Locale.Tr "repo.issues.review.un_resolve_conversation"}}
581-
{{else}}
582-
{{ctx.Locale.Tr "repo.issues.review.resolve_conversation"}}
583-
{{end}}
584-
</button>
585-
{{end}}
586-
{{if and $.SignedUserID (not $.Repository.IsArchived)}}
587-
<button class="comment-form-reply ui primary tiny labeled icon button gt-ml-2 gt-mr-0">
588-
{{svg "octicon-reply" 16 "reply icon gt-mr-2"}}{{ctx.Locale.Tr "repo.diff.comment.reply"}}
589-
</button>
590-
{{end}}
591-
</div>
592-
</div>
593-
{{template "repo/diff/comment_form_datahandler" dict "hidden" true "reply" (index $comms 0).ReviewID "root" $ "comment" (index $comms 0)}}
594-
</div>
595-
</div>
463+
{{template "repo/issue/view_content/conversation" dict "." $ "comments" $comms}}
596464
{{end}}
597465
{{end}}
598466
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
{{$invalid := (index .comments 0).Invalidated}}
2+
{{$resolved := (index .comments 0).IsResolved}}
3+
{{$resolveDoer := (index .comments 0).ResolveDoer}}
4+
{{$isNotPending := (not (eq (index .comments 0).Review.Type 0))}}
5+
<div class="ui segments conversation-holder">
6+
<div class="ui segment collapsible-comment-box gt-py-3 gt-df gt-ac gt-sb">
7+
<div class="gt-df gt-ac">
8+
<a href="{{(index .comments 0).CodeCommentLink ctx}}" class="file-comment gt-ml-3 gt-word-break">{{(index .comments 0).TreePath}}</a>
9+
{{if $invalid}}
10+
<span class="ui label basic small gt-ml-3" data-tooltip-content="{{ctx.Locale.Tr "repo.issues.review.outdated_description"}}">
11+
{{ctx.Locale.Tr "repo.issues.review.outdated"}}
12+
</span>
13+
{{end}}
14+
</div>
15+
<div>
16+
{{if or $invalid $resolved}}
17+
<button id="show-outdated-{{(index .comments 0).ID}}" data-comment="{{(index .comments 0).ID}}" class="{{if not $resolved}}gt-hidden {{end}}ui compact labeled button show-outdated gt-df gt-ac">
18+
{{svg "octicon-unfold" 16 "gt-mr-3"}}
19+
{{if $resolved}}
20+
{{ctx.Locale.Tr "repo.issues.review.show_resolved"}}
21+
{{else}}
22+
{{ctx.Locale.Tr "repo.issues.review.show_outdated"}}
23+
{{end}}
24+
</button>
25+
<button id="hide-outdated-{{(index .comments 0).ID}}" data-comment="{{(index .comments 0).ID}}" class="{{if $resolved}}gt-hidden {{end}}ui compact labeled button hide-outdated gt-df gt-ac">
26+
{{svg "octicon-fold" 16 "gt-mr-3"}}
27+
{{if $resolved}}
28+
{{ctx.Locale.Tr "repo.issues.review.hide_resolved"}}
29+
{{else}}
30+
{{ctx.Locale.Tr "repo.issues.review.hide_outdated"}}
31+
{{end}}
32+
</button>
33+
{{end}}
34+
</div>
35+
</div>
36+
{{$diff := (CommentMustAsDiff ctx (index .comments 0))}}
37+
{{if $diff}}
38+
{{$file := (index $diff.Files 0)}}
39+
<div id="code-preview-{{(index .comments 0).ID}}" class="ui table segment{{if $resolved}} gt-hidden{{end}}">
40+
<div class="diff-file-box diff-box file-content {{TabSizeClass $.Editorconfig $file.Name}}">
41+
<div class="file-body file-code code-view code-diff code-diff-unified unicode-escaped">
42+
<table>
43+
<tbody>
44+
{{template "repo/diff/section_unified" dict "file" $file "root" $}}
45+
</tbody>
46+
</table>
47+
</div>
48+
</div>
49+
</div>
50+
{{end}}
51+
<div id="code-comments-{{(index .comments 0).ID}}" class="comment-code-cloud ui segment{{if $resolved}} gt-hidden{{end}}">
52+
<div class="ui comments gt-mb-0">
53+
{{range .comments}}
54+
{{$createdSubStr:= TimeSinceUnix .CreatedUnix ctx.Locale}}
55+
<div class="comment code-comment gt-pb-4" id="{{.HashTag}}">
56+
<div class="content">
57+
<div class="header comment-header">
58+
<div class="comment-header-left gt-df gt-ac">
59+
{{if not .OriginalAuthor}}
60+
<a class="avatar">
61+
{{ctx.AvatarUtils.Avatar .Poster 20}}
62+
</a>
63+
{{end}}
64+
<span class="text grey muted-links">
65+
{{if .OriginalAuthor}}
66+
<span class="text black gt-font-semibold">
67+
{{svg (MigrationIcon $.Repository.GetOriginalURLHostname)}}
68+
{{.OriginalAuthor}}
69+
</span>
70+
<span class="text grey muted-links"> {{if $.Repository.OriginalURL}}</span>
71+
<span class="text migrate">({{ctx.Locale.Tr "repo.migrated_from" ($.Repository.OriginalURL|Escape) ($.Repository.GetOriginalURLHostname|Escape) | Safe}}){{end}}</span>
72+
{{else}}
73+
{{template "shared/user/authorlink" .Poster}}
74+
{{end}}
75+
{{ctx.Locale.Tr "repo.issues.commented_at" (.HashTag|Escape) $createdSubStr | Safe}}
76+
</span>
77+
</div>
78+
<div class="comment-header-right actions gt-df gt-ac">
79+
{{template "repo/issue/view_content/show_role" dict "ShowRole" .ShowRole}}
80+
{{if not $.Repository.IsArchived}}
81+
{{template "repo/issue/view_content/add_reaction" dict "ctxData" $ "ActionURL" (printf "%s/comments/%d/reactions" $.RepoLink .ID)}}
82+
{{template "repo/issue/view_content/context_menu" dict "ctxData" $ "item" . "delete" true "issue" true "diff" true "IsCommentPoster" (and $.IsSigned (eq $.SignedUserID .PosterID))}}
83+
{{end}}
84+
</div>
85+
</div>
86+
<div class="text comment-content">
87+
<div class="render-content markup" {{if or $.Permission.IsAdmin $.HasIssuesOrPullsWritePermission (and $.IsSigned (eq $.SignedUserID .PosterID))}}data-can-edit="true"{{end}}>
88+
{{if .RenderedContent}}
89+
{{.RenderedContent|Str2html}}
90+
{{else}}
91+
<span class="no-content">{{ctx.Locale.Tr "repo.issues.no_content"}}</span>
92+
{{end}}
93+
</div>
94+
<div id="issuecomment-{{.ID}}-raw" class="raw-content gt-hidden">{{.Content}}</div>
95+
<div class="edit-content-zone gt-hidden" data-update-url="{{$.RepoLink}}/comments/{{.ID}}" data-context="{{$.RepoLink}}" data-attachment-url="{{$.RepoLink}}/comments/{{.ID}}/attachments"></div>
96+
</div>
97+
{{$reactions := .Reactions.GroupByType}}
98+
{{if $reactions}}
99+
{{template "repo/issue/view_content/reactions" dict "ctxData" $ "ActionURL" (printf "%s/comments/%d/reactions" $.RepoLink .ID) "Reactions" $reactions}}
100+
{{end}}
101+
</div>
102+
</div>
103+
{{end}}
104+
</div>
105+
<div class="code-comment-buttons gt-df gt-ac gt-fw gt-mt-3 gt-mb-2 gt-mx-3">
106+
<div class="gt-f1">
107+
{{if $resolved}}
108+
<div class="ui grey text">
109+
{{svg "octicon-check" 16 "gt-mr-2"}}
110+
<b>{{$resolveDoer.Name}}</b> {{ctx.Locale.Tr "repo.issues.review.resolved_by"}}
111+
</div>
112+
{{end}}
113+
</div>
114+
<div class="code-comment-buttons-buttons">
115+
{{if and $.CanMarkConversation $isNotPending}}
116+
<button class="ui tiny basic button resolve-conversation" data-origin="timeline" data-action="{{if not $resolved}}Resolve{{else}}UnResolve{{end}}" data-comment-id="{{(index .comments 0).ID}}" data-update-url="{{$.RepoLink}}/issues/resolve_conversation">
117+
{{if $resolved}}
118+
{{ctx.Locale.Tr "repo.issues.review.un_resolve_conversation"}}
119+
{{else}}
120+
{{ctx.Locale.Tr "repo.issues.review.resolve_conversation"}}
121+
{{end}}
122+
</button>
123+
{{end}}
124+
{{if and $.SignedUserID (not $.Repository.IsArchived)}}
125+
<button class="comment-form-reply ui primary tiny labeled icon button gt-ml-2 gt-mr-0">
126+
{{svg "octicon-reply" 16 "reply icon gt-mr-2"}}{{ctx.Locale.Tr "repo.diff.comment.reply"}}
127+
</button>
128+
{{end}}
129+
</div>
130+
</div>
131+
{{template "repo/diff/comment_form_datahandler" dict "hidden" true "reply" (index .comments 0).ReviewID "root" $ "comment" (index .comments 0)}}
132+
</div>
133+
</div>

web_src/css/review.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
position: relative;
6868
}
6969

70-
.conversation-holder .comment-code-cloud {
70+
.code-diff .conversation-holder .comment-code-cloud {
7171
max-width: 820px;
7272
}
7373

0 commit comments

Comments
 (0)