Repository navigation
Add delete button to files in a PR - #1398
Conversation
Append button to file-actions container
Add delete anchor tag to all headers
Add func to find file name to delete
There is a hidden div with class BtnGroup which was causing the wrong link to be appended
|
Thanks for the PR! Are you open to making changes to the code? I'm asking because this feels like homework for a GitHub course. |
| const branchName = findBranch.includes(':') ? findBranch.split(':')[1] : findBranch; | ||
|
|
||
| const filesInfo = select.all('.file-info'); | ||
| const generateURL = filesInfo.map(file => 'https://github.com/' + repoURL + '/delete/' + branchName + '/' + file.children[1].title); |
There was a problem hiding this comment.
This will not work with GHE. Please apply the logic we use other places to account for different base URLs.
Indent anchor properties
|
Thank you for your feedback! We would be happy to make changes to this pull request. Is this an example of the logic you would like applied to account for the different base URLs: |
|
Yes, that example doesn't include the domain at all. :) |
|
Pushed updates to reflect requested changes to remove hard coded domain name. Please review and let us know if there's anything else we can do. |
| @@ -0,0 +1,21 @@ | |||
| import select from 'select-dom'; | |||
| import {h} from 'dom-chef'; | |||
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| const repoURL = pageDetect.getRepoURL(); | ||
|
|
||
| export default function () { | ||
| const findBranch = select('.head-ref').innerText; |
|
|
||
| export default function () { | ||
| const findBranch = select('.head-ref').innerText; | ||
| const branchName = findBranch.includes(':') ? findBranch.split(':')[1] : findBranch; |
There was a problem hiding this comment.
Just use
const branchName = findBranch.split(':').pop();Or merge the lines:
const branchName = select('.head-ref').textContent.split(':').pop();| href={generateURL[index]} | ||
| className="btn btn-sm tooltipped tooltipped-s BtnGroup-item" | ||
| aria-label="Delete this file from the pull request">Delete</a>); | ||
| }); |
There was a problem hiding this comment.
Each "file info" is connected to a "file action container", so no need to select them separately and use indexes.
Find a container and then query both, something like:
for (const file of select.all('.file-header')) {
const fileName = select('.file-info a', file).title;
const url = `/${repoURL}/delete/${branchName}/${fileName}`
select('.BtnGroup', file).prepend(
<a
href={url}
...>
Delete
</a>
);
}Also those extra [1] and .slice(1) were a code smell because the first one depended on the exact position of an element and the second one was the consequence of a selector that included unrelated BtnGroups
|
Great feedback! Your requested changes have been made. |
fregante
left a comment
There was a problem hiding this comment.
I haven’t tested it yet but it looks good 🙂
| import select from 'select-dom'; | ||
| import * as pageDetect from '../libs/page-detect'; | ||
|
|
||
| const repoURL = pageDetect.getRepoURL(); |
There was a problem hiding this comment.
I’d move this inside the function while we’re at it
|
Just inside the function, not in the loop 😅 |
|
Sorry! Shouldn't have made those changes so late. |
Like we do elsewhere for the delete button
It should point to the source repo, not the current one. Conveniently, the edit button has a nearly-identical URL
|
Looks good! 🎉 |
|
|
Gotta specify where you saw that |
|
@bfred-it sorry was in a rush |
* master: Copy Prev/Next buttons to bottom of commit page (refined-github#1389) Hide Releases tab if there are no releases (refined-github#1339) Add delete button to files in a PR (refined-github#1398)

This PR fixes #1127. The issue was to add a delete button for individual files in a PR. We implemented this functionality by adding
add-delete-to-pr-files.jsto the features directory, importing that file intocontent.jsand added line 287 tocontent.jsto add the delete button functionality to the extension. The delete button appears to the left of the "Copy path" button on the toolbar of each file. When clicked, the button takes you to the correct page to delete that specific file from the PR. No tests were affected and we removed all linter errors.Contributors: @JackLaird0, @EricMellow, @meloncatty