Skip to content

Add raw-file-link feature - #1924

Merged
fregante merged 14 commits into
refined-github:masterfrom
idasbiste:view-raw-file
Apr 24, 2019
Merged

fregante merged 14 commits into
refined-github:masterfrom
idasbiste:view-raw-file

Conversation

@idasbiste

Copy link
Copy Markdown
Contributor

This PR closes #1595
It adds a "View raw" button next to the usual "View file" one.

Without rich diff:
Screenshot 2019-04-13 at 01 22 20

With rich diff:
Screenshot 2019-04-13 at 01 22 14

Comment thread source/content.ts Resolved
Comment thread source/features/view-raw-file.tsx Resolved
Comment thread source/features/view-raw-file.tsx Resolved
Comment thread source/features/view-raw-file.tsx Resolved
Comment thread source/features/view-raw-file.tsx Resolved
Comment thread source/features/view-raw-file.tsx Resolved
Comment thread source/features/view-raw-file.tsx Resolved
@idasbiste

Copy link
Copy Markdown
Contributor Author

@bfred-it I think I've addressed all your comments! Please have a look.
To deal with the asynchronous files load and the respective DOM updates, I've used the MutationObserver. I had to recursively look for elements with a specific class and observe it because the files are added in "cascade" mode inside the second <div class="js-diff-progressive-container">. If the PR is large enough you can get 3 or 4 levels of this div. Something like:

<div class="js-diff-progressive-container">
  ...
  <div class="js-diff-progressive-container">
    ...
    <div class="js-diff-progressive-container">
     ...
    </div>
  </div>
</div>

@sindresorhus

Copy link
Copy Markdown
Member

@idasbiste Can you rebase from master (we enabled TS strict mode) and fix any issues?

@sindresorhus

Copy link
Copy Markdown
Member

Seems to work fine for me otherwise.

Eduardo Fernandes added 7 commits April 17, 2019 15:29
* This feature adds a "View raw" button in the file actions section of each file modified in a commit next to "View file"
* This initial commit is WIP as we're not able to directly access the raw content of files from private repositories by simply prepending the raw.githubusercontent.com domain
* Replace 'blob' with 'raw' to allow redirect with token on private repositories
* Change feature/file name
* Fix blob-to-raw url function
* Fix add 'Raw' button function by selecting the link element directly and use .after() function
* Use MutationObserver to check for DOM changes when new PR changed files are added into the page
Comment thread source/features/raw-view-link.tsx Resolved
Comment thread source/features/raw-view-link.tsx Outdated

function init() {
addRawBtn(select('.js-diff-progressive-container:first-child'));
observer.observe(select('.js-diff-progressive-container:last-child'), childList);

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.

Do you mean last child or the last in the dom?

Where did you get this logic from? At some point we’ll want to standardize it

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.

It is the last child. Please see my comment above #1924 (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.

It is the last child

In the HTML you posted I see two :last-child, and I think querySelector will match the first one (level 2), not the one you expect (level 3)

See a6a6e15 for an alternative implementation that avoids this altogether

Also do you know a PR that has more than one level? Because in the biggest PR I can think of (#1783) I'm seeing only one deferred level, not nested:

<div class="js-diff-progressive-container">already here</div>
<div class="js-diff-progressive-container">(content deferred)</div>

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.

I like your approach on the other PR 👍
In the HTML I've posted I was specifically talking about the container that gets updated -- which is the :last-child in the beginning (the one with deferred content). I.e. the HTML will, in the end, have a format of:

<div class="js-diff-progressive-container">already here</div>
<div class="js-diff-progressive-container">
  (nested containers)
</div>

Comment thread source/features/raw-view-link.tsx Outdated
addRawBtn(select('.js-diff-progressive-container:first-child'));
const lastProgressiveContainer = select('.js-diff-progressive-container:last-child');
if (lastProgressiveContainer) {
observer.observe(lastProgressiveContainer, {childList: true});

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.

Maybe we should turn this into a utility function, like on-new-pr-files.ts

Comment thread source/features/raw-view-link.tsx Resolved
Comment thread source/features/raw-view-link.tsx Resolved
Comment thread source/features/raw-view-link.tsx Resolved
@fregante fregante changed the title Add "View raw" button on file actions Add raw-file-link feature Apr 18, 2019
@fregante

fregante commented Apr 22, 2019 •

Copy link
Copy Markdown
Member

I want to merge this but I'm seeing a couple of unrelated RGH bugs on this (show-names and co-authors), I want to use this PR as testing ground. I'll merge soon

@notlmn

notlmn commented Apr 22, 2019

Copy link
Copy Markdown
Contributor

I want to merge this but I'm seeing a couple of unrelated RGH bugs on this (show-names and co-authors), I want to use this PR as testing ground. I'll merge soon

show-names is broken as the author of this PR has used an email to make commits that do not match with a GitHub account, in that case GH would display only the name used to create that commit. Querying the v4 API with this name (and especially which contain spaces) would fail, hence the broken feature.

Non-referencing commit

image

GraphQL exception

image


Didn't want to go off topic but an it is an interesting bug that sometimes bites the GH team too, add-co-authored-by is probably broken for the same reason as above (didn't test that though).

fregante added a commit that referenced this pull request Apr 24, 2019
- `show-names`
- `add-co-authored-by`

Context: #1924 (comment)
@fregante
fregante merged commit 1d4fd6a into refined-github:master Apr 24, 2019
@fregante

Copy link
Copy Markdown
Member

Thanks Eduardo! 🎯

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.

Add "View Raw" button next to all View buttons for files

4 participants