Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add pr-easy-toggle-files feature - #3750

Merged
fregante merged 6 commits into
refined-github:masterfrom
MrChocolatine:easy-toggle-files-in-pr
Nov 24, 2020
Merged

Add pr-easy-toggle-files feature#3750
fregante merged 6 commits into
refined-github:masterfrom
MrChocolatine:easy-toggle-files-in-pr

Conversation

@MrChocolatine

@MrChocolatine MrChocolatine commented Nov 20, 2020

Copy link
Copy Markdown
Contributor

@MrChocolatine
MrChocolatine marked this pull request as ready for review November 20, 2020 22:28
@fregante fregante changed the title feat: add pr-easy-toggle-files feature add pr-easy-toggle-files feature Nov 21, 2020

@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.

Thanks for the PR! Here's a few suggestions

Comment thread source/features/pr-easy-toggle-files.tsx Outdated
Comment thread source/features/pr-easy-toggle-files.tsx Outdated
Comment thread source/features/pr-easy-toggle-files.tsx Outdated
@MrChocolatine
MrChocolatine marked this pull request as draft November 21, 2020 13:41
@MrChocolatine

Copy link
Copy Markdown
Contributor Author

Updated according to your suggestions @fregante.

@MrChocolatine
MrChocolatine marked this pull request as ready for review November 21, 2020 14:34
@fregante

Copy link
Copy Markdown
Member

Thanks! Generally here force pushing is not necessary and it makes reviewing only the changes harder

Comment thread source/features/pr-easy-toggle-files.tsx
@MrChocolatine

Copy link
Copy Markdown
Contributor Author

Thanks! Generally here force pushing is not necessary and it makes reviewing only the changes harder

You are welcome! Your extension is great and brings a lot of convenience.

@fregante no offense at all but for the "it makes reviewing only the changes harder" when I see some commits simply titled "shorten" and "lint" 😅 ...

@fregante fregante changed the title add pr-easy-toggle-files feature Add pr-easy-toggle-files feature Nov 21, 2020
@fregante

Copy link
Copy Markdown
Member

when I see some commits simply titled "shorten" and "lint" 😅 ...

I use "lint" generously to describe "obvious" changes that are only meant to make the build, types or linter pass.

As for the "shorter" I just followed what my previous review suggested + I left a comment there explaining why === is enough.

We squash commits in the end, so my comment was more about being able to tell the difference between a review and the next, so that I don't need to review the same piece of code twice.


// The clicked element is either the bar itself or one of its 2 children
if (elementClicked === headerBar || elementClicked.parentElement === headerBar) {
select('.file-info > button', headerBar)!.click();

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.

Suggested change
select('.file-info > button', headerBar)!.click();
select('[aria-label="Toggle diff contents"]', headerBar)!.click();

@MrChocolatine MrChocolatine Nov 21, 2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Are you sure? I thought relying on an attribute so "unstable"/volatile (I mean his value could change more easily and more quickly than the others) would not be a good idea.

I also thought about using [aria-expanded] to discriminate the button, as in the left part of the bar only this element would have this attribute.

I think using [aria-label="Toggle diff contents"] would require us/you to keep this selector up-to-date more often.

@fregante fregante Nov 21, 2020

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.

Are you sure? I thought relying on an attribute so "unstable"/volatile (I mean his value could change more easily and more quickly than the others) would not be a good idea.

heheh welcome to the world of "hacking on content you don't own."

Anything we use can change with any frequency, so it's best to use the most unique identifiers rather than loose selectors, because GitHub might change the order of elements and suddenly .file-info > button does something you don't expect at all.

If [aria-label="Toggle diff contents"] changes, the click will do nothing (with a console error) and that's still preferable to "doing the unexpected."

GitHub has been removing many unique classes so we're left with fickle position-based selectors. Where possible, even if it requires more code, it's best to still select the most unique part of the page and then traverse the DOM from there, for example:

https://github.com/sindresorhus/refined-github/blob/38fb7b001222421c6e3d3e17bfddb3d373a37739/source/features/deprioritize-marketplace-link.tsx#L22-L24

data-ga-click and aria-label are the attributes that are less likely to change, whereas even .file-info could be gone one day and replaced with .box.position-relative.px-2

Either way, it's best to keep our code readable, and with the suggested selector you know exactly what we're looking for.

@MrChocolatine MrChocolatine Nov 21, 2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

And I completely understand. In this direction I still think [aria-expanded] would be a better choice, but I will update the selector like your suggestion then.

@fregante
fregante merged commit 97679ac into refined-github:master Nov 24, 2020
@fregante

Copy link
Copy Markdown
Member

Thanks Mr Pan au Chocolate

@MrChocolatine

MrChocolatine commented Nov 24, 2020

Copy link
Copy Markdown
Contributor Author

Thanks Mr Pan au Chocolate

Noooo, damn it! How is that possible 😄 ?!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Pull request / Tab Files - Toggle files by clicking on their header bar

3 participants