Skip to content

Add delete button to files in a PR - #1398

Merged
sindresorhus merged 25 commits into
refined-github:masterfrom
meloncatty:add-delete-pr-files
Jul 10, 2018
Merged

sindresorhus merged 25 commits into
refined-github:masterfrom
meloncatty:add-delete-pr-files

Conversation

@meloncatty

@meloncatty meloncatty commented Jul 5, 2018 •

Copy link
Copy Markdown
Contributor

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.js to the features directory, importing that file into content.js and added line 287 to content.js to 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

after

meloncatty added 10 commits July 2, 2018 15:32
Append button to file-actions container
Add delete anchor tag to all headers
Add func to find file name to delete
Add styling for link
There is a hidden div with class BtnGroup which was causing the wrong link to be appended
@fregante

fregante commented Jul 6, 2018

Copy link
Copy Markdown
Member

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.

busches
busches previously requested changes Jul 6, 2018
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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This will not work with GHE. Please apply the logic we use other places to account for different base URLs.

Indent anchor properties
@meloncatty

Copy link
Copy Markdown
Contributor Author

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:
https://github.com/sindresorhus/refined-github/blob/3f5fc489e417d4f4a14da5ea423775e9ca9246fd/source/features/add-releases-tab.js#L31-L37

@fregante
fregante self-requested a review July 7, 2018 23:04
@busches

busches commented Jul 8, 2018

Copy link
Copy Markdown
Member

Yes, that example doesn't include the domain at all. :)

@meloncatty

Copy link
Copy Markdown
Contributor Author

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.

const repoURL = pageDetect.getRepoURL();

export default function () {
const findBranch = select('.head-ref').innerText;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Best to use .textContent


export default function () {
const findBranch = select('.head-ref').innerText;
const branchName = findBranch.includes(':') ? findBranch.split(':')[1] : findBranch;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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>);
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

@meloncatty

Copy link
Copy Markdown
Contributor Author

Great feedback! Your requested changes have been made.

@fregante fregante left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I’d move this inside the function while we’re at it

@fregante

Copy link
Copy Markdown
Member

Just inside the function, not in the loop 😅

@meloncatty

Copy link
Copy Markdown
Contributor Author

Sorry! Shouldn't have made those changes so late.

@fregante

Copy link
Copy Markdown
Member

How about an icon like it appears in the regular files view?

Screenshot from my commits:

button

@fregante
fregante dismissed busches’s stale review July 10, 2018 18:27

Changes made

fregante added 2 commits July 10, 2018 20:40
It should point to the source repo, not the current one.

Conveniently, the edit button has a nearly-identical URL
@sindresorhus
sindresorhus merged commit e2d35e5 into refined-github:master Jul 10, 2018
@sindresorhus

Copy link
Copy Markdown
Member

Looks good! 🎉

@yakov116

Copy link
Copy Markdown
Member
 add-delete-to-pr-files
content.js:1228 TypeError: Cannot read property 'replace' of undefined
    at add_delete_to_pr_files (content.js:1097)
    at enableFeature (content.js:1224)

@fregante

Copy link
Copy Markdown
Member

Gotta specify where you saw that

fregante added a commit that referenced this pull request Jul 12, 2018
@yakov116

Copy link
Copy Markdown
Member

@bfred-it sorry was in a rush

ahmadassaf added a commit to ahmadassaf/refined-github that referenced this pull request Jul 16, 2018
* 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)
@just-be-dev just-be-dev mentioned this pull request Apr 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Add delete button to files in a PR

5 participants