Make "Edit/delete file" clickable on compare page #2704
jack1142 posted onGitHub
Example URL: https://github.com/Cog-Creators/Red-DiscordBot/compare/V3/develop...jack1142:pr/ghactions?expand=1
"Edit/delete file" links are already there, but they're not active, IMO it would be useful to be able to quickly edit files from there if you notice some error in files:
Of course that link should only be active when you can edit the head branch.
Edit: I also noticed that "View file" link there doesn't link you to branch but to commit so that makes it take even longer to edit a file.
Where would the file be edited? This could be kind of confusing
@fregante What do you mean by where? Cause I just meant for it to be a link to:
https://github.com/[ORG_OR_USER]/[REPO_NAME]/edit/[BRANCH]/[FILE_PATH]
Same as it works when you're on the PR page:
Or on file page:
I meant “which of the 2 branches will receive the edit?”
But yeah this is comparable to a PR view so the right-hand branch will be edited.
This feature is similar to one we recently added so perhaps that one can be extended, it could become enable-file-links-in-compare-view
https://github.com/sindresorhus/refined-github/pull/2529
I remember trying to also “fix” the edit link in that view but it didn’t make sense (I don’t remember why)
@fregante and @jack1142
Have this done in https://github.com/yakov116/refined-github/tree/enable-file-links-in-compare-view
But I need to wait for #3138 to be merged first.
I remember trying to also “fix” the edit link in that view but it didn’t make sense (I don’t remember why)
I think I remember now. The link only makes sense if you don't compare permalinks (commit, tag), and this information might not be available on compare views. Example: https://github.com/sindresorhus/refined-github/compare/a@b...20.5.27
If you compare 2 commits, the edit and delete links don’t make sense.
@yakov116 can you reliably detect whether the compared reference (right) points to a permalink? If not, this feature should probably be scrapped.
Yes I can except for one case. (I wish I had a fork of your's I can give you a link to test on) https://github.com/yakov116/refined-github/compare/upstream...FloEdelmann:faster-reviews In this case I am comparing a fork to my own repo and I don't have rights to edit the forked repo. Clicking edit/delete will not lead to a 404 rather to the page offering me to fork the repo.
Github gives us an easy detection for permalink's, since it will not give you an option to create a PR if you are comparing a permalink. In that case I only enabled the feature for the view and not the edit/delete. (Link to the branch/tag instead of a commit)
I wish I had a fork of your's I can give you a link to test on
I just made this: https://github.com/fregante/refined-github
This is the one case https://github.com/fregante/refined-github/compare/a@b...FloEdelmann:faster-reviews Permalink https://github.com/fregante/refined-github/compare/20.5.27...FloEdelmann:faster-reviews
Where you should be able to edit https://github.com/fregante/refined-github/compare/a@b...sindresorhus:incremental-tag-changelog-link
A suggestion: the button text could be changed to "Edit latest file" to make it clear that it edits the latest file on that branch.
Or to make it clearer which branch it would edit on:
The above screenshot requires the <details-menu ... style="width: 185px; ...">
to be changed to <details-menu ... style="width: initial; ...">
, otherwise the menu will be too thin:
Good point. I wonder if that can be displayed any other way since it applies to all of the 3 links.
https://primer.style/css/components/dropdown#headers
<img width="227" alt="" src="https://user-images.githubusercontent.com/1402241/83401479-23c31280-a405-11ea-87d0-22e7dacdaa14.png">
<div class="dropdown-header">Dropdown header</div>
Not a great default style though
I like that idea.
What about the "View file" button? i.e. in the case of https://github.com/fregante/refined-github/compare/a@b...FloEdelmann:faster-reviews, "View file" always views at point of 1ab3f6f and not the latest.
Maybe something like this?
(The first "View file" button is GitHub's original button.)
If branch name was shown in the dropdown, this is another edge case to consider: a user might be confused about whether it shows the latest file the left branch vs. the right branch.
i.e. this case, where the base
branch name matches the compare
branch name.
I suppose in that case you could show this (if repo names are different)
(if repo names are the same)
p.s. the width: initial
thing is applied here, but it seems that only the buttons themselves can widen the dropdown, and not the headers. Can't figure out the CSS fix here.
Definitely interesting, but I wonder if it’s useful to ever link to the commit from that dropdown. If you can open the branch link, why would you ever open the commit link?