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

Fix review excerpt #18502

Merged
merged 9 commits into from
Feb 1, 2022
Merged

Fix review excerpt #18502

merged 9 commits into from
Feb 1, 2022

Conversation

confusedsushi
Copy link
Contributor

@confusedsushi confusedsushi commented Jan 31, 2022

Currently the "File Changed" tab of a PR is somehow broken. This is also true for the current release 1.16.0.

When you are on the "File Changed" tab, and want to look at code excerpt before or after the code changes, the layout breaks. You can test this on try.gitea.io here: https://try.gitea.io/testnotexisting/magic_enum/pulls/2/files

The problem occurs for the unified view and for the split view.

Kind of the same problem was there for commenting a line of code, this was fixed in #18321 and #18403.

For consistency, I changed the solution of #18321, I removed the colspan and instead added a <td>. The goal was to have code similarly with the split view.

Also the separator line in the split view was in the wrong column, this was fixed too.

@lunny
Copy link
Member

lunny commented Feb 1, 2022

Fix #18516 and #18517?

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 1, 2022
@silverwind
Copy link
Member

@zeripath could you verify this is the correct fix?

@confusedsushi
Copy link
Contributor Author

Yes, this is fixing #18516.

#18517 is something different.

Copy link
Contributor

@zeripath zeripath left a comment

Choose a reason for hiding this comment

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

Sorry for another bug here. The diff code is remarkably complex and fiddly.

I've fixed this so that the escaped warning triangle appears on the excerpted lines too.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Feb 1, 2022
@zeripath
Copy link
Contributor

zeripath commented Feb 1, 2022

@silverwind I think this is now fixed.

I don't understand why the colspan in the js has been switched to three separate columns in the js - because that is not related to these code changes but I guess it might just help with keeping the same rendering so I've left it.

@silverwind
Copy link
Member

JS should probably not create DOM elements from scratch but clone existing ones and alter them. That way, a whole class of possible errors is eliminated :)

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Feb 1, 2022
@confusedsushi
Copy link
Contributor Author

@silverwind I think this is now fixed.

I don't understand why the colspan in the js has been switched to three separate columns in the js - because that is not related to these code changes but I guess it might just help with keeping the same rendering so I've left it.

I wanted to have the similarity to the table layout of other rows. There you have line-number-old | line-number-new it was before collapsed with the colspan.

With your changes now, there is again one line number column missing.

@zeripath
Copy link
Contributor

zeripath commented Feb 1, 2022

Show me I can't see how that could be happening.

This is the patch between my changes and c090808

diff --git a/templates/repo/diff/blob_excerpt.tmpl b/templates/repo/diff/blob_excerpt.tmpl
index c20e2c8b6..9bf0a7f99 100644
--- a/templates/repo/diff/blob_excerpt.tmpl
+++ b/templates/repo/diff/blob_excerpt.tmpl
@@ -21,25 +21,18 @@
 			</td>
 			<td colspan="5" class="lines-code lines-code-old ">{{$inlineDiff := $.section.GetComputedInlineDiffFor $line}}<code {{if $inlineDiff.EscapeStatus.Escaped}}class="code-inner has-escaped" title="{{$.i18n.Tr "repo.line_unicode"}}"{{else}}class="code-inner"{{end}}>{{$inlineDiff.Content}}</code></td>
 		{{else}}
+			{{$inlineDiff := $.section.GetComputedInlineDiffFor $line}}
 			<td class="lines-num lines-num-old" data-line-num="{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}"><span rel="{{if $line.LeftIdx}}diff-{{Sha1 $.fileName}}L{{$line.LeftIdx}}{{end}}"></span></td>
-			<td class="blob-excerpt lines-escape lines-escape-old"></td>
+			<td class="blob-excerpt lines-escape lines-escape-old">{{if and $line.LeftIdx $inlineDiff.EscapeStatus.Escaped}}<a href="" class="toggle-escape-button" title="{{$.i18n.Tr "repo.line_unicode"}}"></a>{{end}}</td>
 			<td class="blob-excerpt lines-type-marker lines-type-marker-old">{{if $line.LeftIdx}}<span class="mono" data-type-marker=""></span>{{end}}</td>
 			<td class="blob-excerpt lines-code lines-code-old halfwidth">{{/*
-				*/}}{{if $line.LeftIdx}}{{/*
-						*/}}{{$inlineDiff := $.section.GetComputedInlineDiffFor $line}}<code {{if $inlineDiff.EscapeStatus.Escaped}}class="code-inner has-escaped" title="{{$.i18n.Tr "repo.line_unicode"}}"{{else}}class="code-inner"{{end}}>{{$inlineDiff.Content}}</code>{{/*
-					*/}}{{else}}{{/*
-						*/}}<code class="code-inner"></code>{{/*
-					*/}}{{end}}{{/*
-				*/}}</td>
+				*/}}<code {{if and $line.LeftIdx $inlineDiff.EscapeStatus.Escaped}}class="code-inner has-escaped" title="{{$.i18n.Tr "repo.line_unicode"}}"{{else}}class="code-inner"{{end}}>{{if $line.LeftIdx}}{{$inlineDiff.Content}}{{end}}</code>{{/*
+			*/}}</td>
 			<td class="lines-num lines-num-new" data-line-num="{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}"><span rel="{{if $line.RightIdx}}diff-{{Sha1 $.fileName}}R{{$line.RightIdx}}{{end}}"></span></td>
-			<td class="blob-excerpt lines-escape lines-escape-new"></td>
+			<td class="blob-excerpt lines-escape lines-escape-new">{{if and $line.RightIdx $inlineDiff.EscapeStatus.Escaped}}<a href="" class="toggle-escape-button" title="{{$.i18n.Tr "repo.line_unicode"}}"></a>{{end}}</td>
 			<td class="blob-excerpt lines-type-marker lines-type-marker-new">{{if $line.RightIdx}}<span class="mono" data-type-marker=""></span>{{end}}</td>
 			<td class="blob-excerpt lines-code lines-code-new halfwidth">{{/*
-				*/}}{{if $line.RightIdx}}{{/*
-					*/}}{{$inlineDiff := $.section.GetComputedInlineDiffFor $line}}<code {{if $inlineDiff.EscapeStatus.Escaped}}class="code-inner has-escaped" title="{{$.i18n.Tr "repo.line_unicode"}}"{{else}}class="code-inner"{{end}}>{{$inlineDiff.Content}}</code>{{/*
-				*/}}{{else}}{{/*
-					*/}}<code class="code-inner"></code>{{/*
-				*/}}{{end}}{{/*
+				*/}}<code {{if and $line.RightIdx $inlineDiff.EscapeStatus.Escaped}}class="code-inner has-escaped" title="{{$.i18n.Tr "repo.line_unicode"}}"{{else}}class="code-inner"{{end}}>{{if $line.RightIdx}}{{$inlineDiff.Content}}{{end}}</code>{{/*
 			*/}}</td>
 		{{end}}
 	</tr>
@@ -69,9 +62,10 @@
 			<td class="lines-num lines-num-old" data-line-num="{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}"><span rel="{{if $line.LeftIdx}}diff-{{Sha1 $.fileName}}L{{$line.LeftIdx}}{{end}}"></span></td>
 			<td class="lines-num lines-num-new" data-line-num="{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}"><span rel="{{if $line.RightIdx}}diff-{{Sha1 $.fileName}}R{{$line.RightIdx}}{{end}}"></span></td>
 		{{end}}
-		<td class="blob-excerpt lines-escape"></td>
+		{{$inlineDiff := $.section.GetComputedInlineDiffFor $line}}
+		<td class="blob-excerpt lines-escape">{{if $inlineDiff.EscapeStatus.Escaped}}<a href="" class="toggle-escape-button" title="{{$.i18n.Tr "repo.line_unicode"}}"></a>{{end}}</td>
 		<td class="blob-excerpt lines-type-marker"><span class="mono" data-type-marker="{{$line.GetLineTypeMarker}}"></span></td>
-		<td class="blob-excerpt lines-code{{if (not $line.RightIdx)}} lines-code-old{{end}}">{{$inlineDiff := $.section.GetComputedInlineDiffFor $line}}<code {{if $inlineDiff.EscapeStatus.Escaped}}class="code-inner has-escaped" title="{{$.i18n.Tr "repo.line_unicode"}}"{{else}}class="code-inner"{{end}}>{{$inlineDiff.Content}}</code></td>
+		<td class="blob-excerpt lines-code{{if (not $line.RightIdx)}} lines-code-old{{end}}"><code {{if $inlineDiff.EscapeStatus.Escaped}}class="code-inner has-escaped" title="{{$.i18n.Tr "repo.line_unicode"}}"{{else}}class="code-inner"{{end}}>{{$inlineDiff.Content}}</code></td>
 	</tr>
 	{{end}}
 {{end}}

@codecov-commenter
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (main@6f6b849). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #18502   +/-   ##
=======================================
  Coverage        ?   46.24%           
=======================================
  Files           ?      842           
  Lines           ?   121192           
  Branches        ?        0           
=======================================
  Hits            ?    56049           
  Misses          ?    58333           
  Partials        ?     6810           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6f6b849...f63df6a. Read the comment docs.

@zeripath zeripath merged commit f6f4e1d into go-gitea:main Feb 1, 2022
@zeripath
Copy link
Contributor

zeripath commented Feb 1, 2022

Please send backport

zeripath added a commit to zeripath/gitea that referenced this pull request Feb 1, 2022
Backport go-gitea#18502

Currently the "File Changed" tab of a PR is somehow broken. This is also true for the current release 1.16.0.

When you are on the "File Changed" tab, and want to look at code excerpt before or after the code changes, the layout breaks. You can test this on try.gitea.io here: https://try.gitea.io/testnotexisting/magic_enum/pulls/2/files

The problem occurs for the unified view and for the split view.

Kind of the same problem was there for commenting a line of code, this was fixed in go-gitea#18321 and go-gitea#18403.

For consistency, I changed the solution of go-gitea#18321, I removed the ``colspan`` and instead added a ``<td>``. The goal was to have code similarly with the split view.

Also the separator line in the split view was in the wrong column, this was fixed too.* more consistent unified review comment

Fix go-gitea#18516

Co-authored-by: Andrew Thornton <[email protected]>
@zeripath zeripath added this to the 1.17.0 milestone Feb 1, 2022
@zeripath zeripath added the backport/done All backports for this PR have been created label Feb 1, 2022
zeripath added a commit that referenced this pull request Feb 2, 2022
Backport #18502

Currently the "File Changed" tab of a PR is somehow broken. This is also true for the current release 1.16.0.

When you are on the "File Changed" tab, and want to look at code excerpt before or after the code changes, the layout breaks. You can test this on try.gitea.io here: https://try.gitea.io/testnotexisting/magic_enum/pulls/2/files

The problem occurs for the unified view and for the split view.

Kind of the same problem was there for commenting a line of code, this was fixed in #18321 and #18403.

For consistency, I changed the solution of #18321, I removed the ``colspan`` and instead added a ``<td>``. The goal was to have code similarly with the split view.

Also the separator line in the split view was in the wrong column, this was fixed too.* more consistent unified review comment

Fix #18516

Co-authored-by: Andrew Thornton <[email protected]>
Co-authored-by: confusedsushi <[email protected]>
zjjhot added a commit to zjjhot/gitea that referenced this pull request Feb 2, 2022
* giteaofficial/main: (37 commits)
  Collaborator trust model should trust collaborators (go-gitea#18539)
  Detect conflicts with 3way merge (go-gitea#18536)
  [skip ci] Updated translations via Crowdin
  Update 1.16.0 changelog to set go-gitea#17846 as breaking (go-gitea#18533)
  In docker rootless use $GITEA_APP_INI if provided (go-gitea#18524)
  revert to node14 for snapcraft
  Add `GetUserTeams` (go-gitea#18499)
  Fix review excerpt (go-gitea#18502)
  Update JS dependencies, fix lint (go-gitea#18389)
  add test coverage for original author conversion during migrations (go-gitea#18506)
  add gitea-fmt back (go-gitea#18526)
  Fix non-ASCII search on database  (go-gitea#18437)
  Use "read" value for General Access (go-gitea#18496)
  Fix for AvatarURL database type (go-gitea#18487)
  Remove go 1.15 support (go-gitea#18511)
  [skip ci] Updated translations via Crowdin
  Use `ImagedProvider` for gplus oauth2 provider (go-gitea#18504)
  build with node16 in snap (go-gitea#18508)
  point to s3 endpoint directly (go-gitea#18497)
  Fix OAuth Source Edit Page (go-gitea#18495)
  ...
Chianina pushed a commit to Chianina/gitea that referenced this pull request Mar 28, 2022
Currently the "File Changed" tab of a PR is somehow broken. This is also true for the current release 1.16.0.

When you are on the "File Changed" tab, and want to look at code excerpt before or after the code changes, the layout breaks. You can test this on try.gitea.io here: https://try.gitea.io/testnotexisting/magic_enum/pulls/2/files

The problem occurs for the unified view and for the split view.

Kind of the same problem was there for commenting a line of code, this was fixed in go-gitea#18321 and go-gitea#18403.

For consistency, I changed the solution of go-gitea#18321, I removed the ``colspan`` and instead added a ``<td>``. The goal was to have code similarly with the split view.

Also the separator line in the split view was in the wrong column, this was fixed too.* more consistent unified review comment

Fix go-gitea#18516

Co-authored-by: Andrew Thornton <[email protected]>
@go-gitea go-gitea locked and limited conversation to collaborators Apr 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/done All backports for this PR have been created lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants