-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Expandable commit bodies #2980
Expandable commit bodies #2980
Conversation
You should add function that checks if message contains newlines and returns true if it does and false otherwise. This way you can add:
|
Okay, I've fixed all the commit having the box for showing the commit body, now I've just gotta figure out how to properly render it in HTML. |
2388c31
to
67fde4d
Compare
modules/templates/helper.go
Outdated
} | ||
|
||
func IsMultilineCommitMessage(msg string) bool { | ||
msgLines := strings.Split(strings.TrimSpace(msg), "\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just do
return strings.Count(strings.TrimSpace(msg), "\n") > 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet, I was looking for a better way to do that.
Use <pre> instead of <p>, this is so we can use \n instead of having to manually place <br> into the HTML. Makes it easier to display commit bodies.
Add comments to public functions |
I've managed to make it place the commit bodies somewhat properly into the HTML now, my biggest hurdle now is getting the cells to stop moving when you expand the commit bodies. The image below shows what happens, when you press the [...] button it moves the commit time, avatar, username and SHA-code into the middle of the cell, which makes the whole layout jump around when you press it. How would I stop that from happening? Also, where do we display the commit messages in Gitea? I need to update all the places where we show the commit message to this new format. @lafriks yeah, I haven't added them yet. I'll do it once I'm happy with them. |
To stop jumping you need to add |
modules/templates/helper.go
Outdated
if len(body) == 0 { | ||
return template.HTML("") | ||
} | ||
return template.HTML(strings.Join(body[1:], "\n")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should differentiate between single and double new-lines, since a single newline may just be wrapping a long line, but a double newline typically indicates the start of a new paragraph. In fact, I think the best solution is just to render newlines as they appear in the commit message (this is what Github does).
Also, note that newlines in a (the crossed-out part is incorrect, ignore it)template.HTML
will not be rendered as newlines. The somewhat hacky way to fix this problem is to replace newlines with <br>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I initially tried joining on <br>
but then I looked at Github and saw that they wrapped their commit messages in <pre>
. However, if that's the case I think the method needs to work differently because it already splits on \n
and then I discard the first element and join the others. It seems to render correctly, but I'll see what I can figure out.
public/js/index.js
Outdated
@@ -2016,3 +2016,7 @@ function initFilterBranchTagDropdown(selector) { | |||
}); | |||
}); | |||
} | |||
|
|||
$(".commit-button").click(function() { | |||
$(this).next().toggle(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a JS expert, but this seems fragile. What if we add a DOM element between the commit button and the commit body? Perhaps it would be better to select for the commit-body
class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried doing
$(".commit-button").click(function() {
$("commit-body").toggle();
But that opens and closes all of the commit messages, not just the one selected. All the documentation I could find from both JQuery themselves and online used this method, otherwise I think we'd have to use one of those JQuery-Toggle libraries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try:
$(".commit-button").on('click', function() {
$(this).parent().find('.commit-body').toggle();
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I'll give it a go later today.
templates/repo/view_list.tmpl
Outdated
@@ -28,6 +28,10 @@ | |||
{{end}} | |||
</a> | |||
<span class="grey has-emoji">{{RenderCommitMessage .LatestCommit.Summary .RepoLink $.Repository.ComposeMetas}} | |||
{{if IsMultilineCommitMessage .LatestCommit.Message}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please indent with tabs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll fix it, Golands for some reason doesn't want to respect the settings.
templates/repo/view_list.tmpl
Outdated
@@ -28,6 +28,10 @@ | |||
{{end}} | |||
</a> | |||
<span class="grey has-emoji">{{RenderCommitMessage .LatestCommit.Summary .RepoLink $.Repository.ComposeMetas}} | |||
{{if IsMultilineCommitMessage .LatestCommit.Message}} | |||
<button class="basic compact mini ui icon button commit-button"><i class="ellipsis horizontal icon"></i></button> | |||
<p class="commit-body" style="display: none;">{{RenderCommitBody .LatestCommit.Message $.RepoLink $.Repository.ComposeMetas}}</span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be inside a paragraph, but instead inside a <pre>
like in the other template (in order for newlines to be rendered properly).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I forgot to change this one once I updated the other.
modules/templates/helper.go
Outdated
}) | ||
} | ||
|
||
func RenderCommitBodyLink(msg, urlPrefix string, urlDefault string, metas map[string]string) template.HTML { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function does not seems to be used anywhere, so should be dropped
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good! I just copied the RenderCommit
functions and changed them a tiny bit.
I've updated the code with the suggestions from you guys, but I also changed the edit: I'm not sure what the error is now, it suggests adding a newline to the CSS as far as I can see but that didn't work. |
I've fixed a few other issues, however there are some things I want to change but I'm not sure whether they are out of the scope of this request, namely properly listing commits in issues and pull requests, nor whether I'll have time. |
04c2818
to
f55878c
Compare
Codecov Report
@@ Coverage Diff @@
## master #2980 +/- ##
==========================================
- Coverage 33.03% 32.98% -0.06%
==========================================
Files 270 270
Lines 39534 39549 +15
==========================================
- Hits 13061 13044 -17
- Misses 24617 24650 +33
+ Partials 1856 1855 -1
Continue to review full report at Codecov.
|
Alright, the tests are passing. I had to force push the latest commit again for it to properly test it for some reason, but hey. If anybody wants to give this a go I'd appreciate it! Should I squash the commits together? |
LGTM |
LGTM |
@ethantkoenig needs your approval. |
public/less/_repository.less
Outdated
@@ -1606,3 +1606,11 @@ | |||
} | |||
} | |||
} | |||
|
|||
.commit-list { | |||
vertical-align: baseline; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please indent with tabs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix.
@@ -61,6 +61,10 @@ | |||
</td> | |||
<td class="message collapsing"> | |||
<span class="has-emoji{{if gt .ParentCount 1}} grey text{{end}}">{{RenderCommitMessage .Summary $.RepoLink $.Repository.ComposeMetas}}</span> | |||
{{if IsMultilineCommitMessage .Message}} | |||
<button class="basic compact mini ui icon button commit-button"><i class="ellipsis horizontal icon"></i></button> | |||
<pre class="commit-body" style="display: none;">{{RenderCommitBody .Message $.RepoLink $.Repository.ComposeMetas}}</pre> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is inline CSS here, could you change it out with a CSS class?
Also this requires JS which means if someone has JS disabled then they won't be able to see the long commit message (perhaps default to open when JS is disabled?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or perhaps hide the button if the user doesn't have JS is another option
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@techknowlogick I think for this inline style is ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree it's not the prettiest, but the toggle
function changes the style inline so I thought it was a decent compromise. Regarding what to do when JS is disabled, I'll leave that to the Gitea maintainers, I think Gitea depends on JS enough that if you disable it you're on your own.
@@ -28,6 +28,10 @@ | |||
{{end}} | |||
</a> | |||
<span class="grey has-emoji">{{RenderCommitMessage .LatestCommit.Summary .RepoLink $.Repository.ComposeMetas}} | |||
{{if IsMultilineCommitMessage .LatestCommit.Message}} | |||
<button class="basic compact mini ui icon button commit-button"><i class="ellipsis horizontal icon"></i></button> | |||
<pre class="commit-body" style="display: none;">{{RenderCommitBody .LatestCommit.Message $.RepoLink $.Repository.ComposeMetas}}</pre> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above regarding inline CSS
Alright, fixed the spaces not being tabs. Given that this pull request contains some 20 commits, should I squash them together or just keep them as is? |
@sondr3 just keep them as is. We will merge with squash. |
LGTM |
UPDATE: Here is how it looks right now:
Original post
I've taken some time to try to work on some kind of solution to the expandable commit message bodies that was talked about in #2939 and #2944, but trying to make it work like it does on GitHub and GitLab. It is however a very rough work in progress as I've never programmed in Go before nor have I much experience with JQuery.
There are several issues with this right now:
It shows the expand button for every commit, even if it's not required.The commit bodies doesn't expand properly, the text get squished together in one line and I'm not sure how to display it over several linesThere's quite a bit of code duplication going on with the commit bodiesI'd like a helping hand with this to figure out how to best solve it, as I'm not a Go programmer.