Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tree links to issue timestamps #741

Merged
merged 31 commits into from
Nov 6, 2017

Conversation

jgierer12
Copy link
Contributor

@jgierer12 jgierer12 commented Oct 18, 2017

Fixes #732

I often find myself browsing through old issues, and sometimes when reading a discussion I think to myself, "I wonder what that part of the code looked like while that was being discussed". Right now it's super tedious to find out, because you have to remember the comment date, then page through the commits until you find something roughly at that date, and then find the "view files at" button, etc.

It would be super awesome if there was an extra little icon button next to comments that let you "jump to the repo at this point on time"!

@ianstormtaylor @sindresorhus is this what you had in mind functionality-wise?


This still needs a lot of work:

  • I don't really know how to fit this into there styling-wise. Currently making a few concepts See Add tree links to issue timestamps #741 (comment), Add tree links to issue timestamps #741 (comment)
  • Currently, the button is added to every timestamp link on issue/PR pages (including timestamps for activities etc.). This might be useful but only works if it's really small and non-intrusive
  • Since the target commit is loaded dynamically after clicking the button, it's not actually a link. This means that things like middle-clicking/ctrl-clicking to open in a new tab don't work. Should we open in a new tab by default?
  • Still need to figure out GitHub Enterprise support (cc @busches) and private repo support
  • Messy code needs to be cleaned up

@tanmayrajani
Copy link
Contributor

@jgierer12 Oh shoot, I didn't notice you assigned it to yourself and worked on it. I worked on this too 😬. What should I do now?

@tanmayrajani
Copy link
Contributor

I thought a lot and sent duplicate pull anyway mentioning the same. You can have a look. 😄

@jgierer12
Copy link
Contributor Author

Thanks, sorry again!

@jgierer12
Copy link
Contributor Author

Design concepts I have so far:

  • A 'browse files' button like on single commit pages (this is probably the closest thing in native GitHub to these timestamp links)
    image
    Pros: unambiguous, consistent with GH's native design, easy to add loading/error styles
    Cons: big, intrusive and attention-grabbing

  • Leave it as a link button (maybe make it grey instead)
    image
    Pros: Similar to button but a bit smaller
    Cons: Still pretty large

  • An icon button. Maybe the eye icon?
    image
    Pros: small, unintrusive
    Cons: hard to guess what it does, bit harder to do loading/error styles

@yakov116
Copy link
Member

I like option 3.

Can you show it with more detail on how it would show on the page

@ianstormtaylor
Copy link

ianstormtaylor commented Oct 18, 2017

I think it was the Option 3 icon button, but with this icon and tooltip it would be discoverable enough: (GitHub uses this icon already for this behavior it seems, so it would match.)

image

Ideally in the same "style" as this icon:

image

@jgierer12
Copy link
Contributor Author

Ok, I updated the PR with icon buttons for now:

Idle Loading Error
image image image

@jgierer12 jgierer12 changed the title [WIP] Add tree links to issue timestamps (#732) [WIP] Add tree links to issue timestamps Oct 18, 2017
src/content.js Outdated
@@ -645,6 +646,7 @@ async function onDomReady() {
if (pageDetect.isPR() || pageDetect.isIssue()) {
safely(linkifyIssuesInTitles);
observeEl('.new-discussion-timeline', addOPLabels, {childList: true, subtree: true});
observeEl('.new-discussion-timeline', addTimestampTreeLinks, {childList: true, subtree: true});
Copy link
Member

Choose a reason for hiding this comment

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

Since these are identical, can you merge them?

return;
}

location.href = `https://github.com/${ownerName}/${repoName}/tree/${sha}`;
Copy link
Member

Choose a reason for hiding this comment

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

Drop protocol and hostname to support GHEnterprise

const timestampValue = select('relative-time', timestampLink).attributes.datetime.value;

const openTree = async ({target}) => {
target.replaceChild(icons.clock(), target.firstChild);
Copy link
Member

Choose a reason for hiding this comment

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

All replaceChild instances can be replaced by firstChild.replaceWith

export default async () => {
const newTimestamps = select.all(`.new-discussion-timeline .timestamp:not(.refined-github-comment-browse-files)`);

newTimestamps.forEach(async timestampLink => {
Copy link
Member

Choose a reason for hiding this comment

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

async is not needed here, this loop can be replaced with for of

const {ownerName, repoName} = getOwnerAndRepo();

const getSHABeforeTimestamp = async timestamp => {
const url = `https://api.github.com/repos/${ownerName}/${repoName}/commits?until=${timestamp}&per_page=1`;
Copy link
Member

Choose a reason for hiding this comment

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

If we’re positive we can’t do this without the API, we still need to support /api instead of the subdomain, for GHE. You might want to pack it up as a getApiUrl function because we’ll probably need the same logic again in the future.

@fregante fregante force-pushed the timestamp-tree-links branch 2 times, most recently from 8c005f5 to 580e563 Compare October 19, 2017 08:46
@fregante
Copy link
Member

fregante commented Oct 19, 2017

Note: if we settle for the commits page, we can forgo the API call and just load this page:

https://github.com/sindresorhus/refined-github/commits/master?until=2017-08-09T22:24:21Z

"Timestamp tree link" didn't sound right.
"Time Machine" here should remind of macOS' Time Machine or just "going back in time"
Name suggestions welcome
@fregante
Copy link
Member

fregante commented Nov 1, 2017

This is the tooltip (updated to show above the icon for consistency):

screen shot 2017-11-02 at 12 34 24

@sindresorhus
Copy link
Member

@bfred-it Can you fix the merge conflict? Is this PR done?

@fregante
Copy link
Member

fregante commented Nov 6, 2017

Yep it's done

@sindresorhus sindresorhus changed the title [WIP] Add tree links to issue timestamps Add tree links to issue timestamps Nov 6, 2017
export default endpoint => {
const api = location.hostname === 'github.com' ? 'https://api.github.com/' : `${location.origin}/api/`;
return fetch(api + endpoint).then(res => res.json());
};
Copy link
Member

Choose a reason for hiding this comment

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

This file looks unused?

Copy link
Member

Choose a reason for hiding this comment

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

Currently, yes, but it's not being included at the moment. I feel it's a start for whenever the API materializes.

padding: 0;
}
:root .rgh-timestamp-button .octicon {
vertical-align: sub;
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be sub => middle. It looks slightly vertically unaligned now.

Copy link
Member

Choose a reason for hiding this comment

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

Actually for some reason this isn't being applied at all so it defaults to middle (which isn't aligned)

Copy link
Member

Choose a reason for hiding this comment

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

baseline is the default, not middle.

Copy link
Member

Choose a reason for hiding this comment

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

When I manually applied middle in devtools it looked ok.

@sindresorhus sindresorhus merged commit 235f528 into refined-github:master Nov 6, 2017
sindresorhus pushed a commit that referenced this pull request Nov 6, 2017
@sindresorhus
Copy link
Member

Great work @jgierer12 and @bfred-it. This is a very useful feature. And thanks for suggesting it @ianstormtaylor 👌

@DrewML
Copy link
Contributor

DrewML commented Nov 6, 2017

Just noticed this feature while looking through a giant PR at work, and was so excited when I saw it. Thanks for doing this!

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.

None yet

8 participants