Skip to content

Remove the "Projects" repo tab when there are no projects - #411

Merged
sindresorhus merged 9 commits into
refined-github:masterfrom
lukaszklis:remove-projects-when-empty
May 11, 2017
Merged

sindresorhus merged 9 commits into
refined-github:masterfrom
lukaszklis:remove-projects-when-empty

Conversation

@lukaszklis

@lukaszklis lukaszklis commented May 9, 2017 •

Copy link
Copy Markdown
Contributor

Things done as part of this PR:

  • Remove ”Projects 0” tab when there are no projects
  • Add a ”Add a project” button under repo’s settings (see the attached screenshot)

refined-github-project-new-link

Closes #309.

@paulmolluzzo paulmolluzzo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A few comments, but this is on track!

Comment thread extension/content.js Outdated

function addProjectNewLink() {
const projectNewLink = `<a href="/${repoUrl}/projects/new" class="btn btn-sm" id="refined-github-project-new-link">Add a project</a>`;
$('#projects-feature').next('p.note').after(projectNewLink);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

$('#projects-feature').siblings('p.note').after(projectNewLink);

.next() only works on immediately following siblings.

Also, we need to check if the button was added and not add it again.

screen shot 2017-05-09 at 1 17 19 pm

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The ideal method for selecting would $.fn.nextAll():

$('#projects-feature').nextAll('p.note')

I've tested it on the Settings page and it finds the needed element. We could also use a CSS selector:

$('#projects-feature ~ p.note')

Comment thread extension/content.js Outdated

function removeProjectsTab() {
const projectsTab = $('.js-repo-nav').find('.reponav-item[data-selected-links^="repo_projects"]');
if (projectsTab.find('.Counter').text() === '0') {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should check that the projectsTab even exists. If not the find() is going to throw an error.

Comment thread extension/content.js Outdated
const projectNewLinkId = 'refined-github-project-new-link';
const projectNewLink = `<a href="/${repoUrl}/projects/new" class="btn btn-sm" id="${projectNewLinkId}">Add a project</a>`;
if ($(`#${projectNewLinkId}`).length === 0) {
$('#projects-feature').siblings('p.note').after(projectNewLink);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@lukaszklis @paulmolluzzo Please see my other comment: #411 (comment) I've posted it just after your commit.

Pasting it here:

The ideal method for selecting would $.fn.nextAll():

$('#projects-feature').nextAll('p.note')

I've tested it on the Settings page and it finds the needed element. We could also use a CSS selector:

$('#projects-feature ~ p.note')

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.

Okay, in this case I think it will be better to go with the CSS selector. Seems to be more consistent with other places where we try to achieve a similar effect.

Comment thread extension/content.js Outdated
function addProjectNewLink() {
const projectNewLinkId = 'refined-github-project-new-link';
const projectNewLink = `<a href="/${repoUrl}/projects/new" class="btn btn-sm" id="${projectNewLinkId}">Add a project</a>`;
if ($(`#${projectNewLinkId}`).length === 0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We'd need to add the button only if the Projects checkbox is checked. Otherwise, the link is pointing to a 404 when the Projects are not enabled. I guess we can skip adding it when you are just checking the checkbox. I don't think it's worth it.

@lukaszklis lukaszklis May 9, 2017 •

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.

Re: checkbox: true that, this can prevent an unnecessary UI element for a feature which a user can decide to disable anyway. In this case we should extend the condition we use in the statement.

Just one more thing that came to my mind: what about the case when a user has some projects already? Shall we still have the button shown in the Settings page?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just one more thing that came to my mind: what about the case when a user has some projects already? Shall we still have the button shown in the Settings page?

I don't see why not, it will be most handy to people using Projects already anyway.

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.

Alright, sounds good! Will apply the changes!

@lukaszklis

Copy link
Copy Markdown
Contributor Author

@hkdobrev I think it will make sense for me to squash the commits before merging to master (unless there is still something you think should be improved in this PR). ;)

@hkdobrev

hkdobrev commented May 9, 2017

Copy link
Copy Markdown
Contributor

@lukaszklis No need to squash, unless you want to do something special with interactive rebase about your commits as we're merging with the "Squash and merge" feature of GitHub.

@hkdobrev
hkdobrev dismissed paulmolluzzo’s stale review May 9, 2017 19:43

Dismissing as requested changes were implemented.

@hkdobrev
hkdobrev requested a review from sindresorhus May 9, 2017 19:43
@hkdobrev

Copy link
Copy Markdown
Contributor

@lukaszklis Could you please resolve the conflicts in CSS? Many thanks!

@paulmolluzzo @sindresorhus Any more comments on this?

@lukaszklis

lukaszklis commented May 10, 2017 •

Copy link
Copy Markdown
Contributor Author

@hkdobrev seems like GitHub’s UI managed allowed me to resolve conflicts quite nicely. ;)

@hkdobrev

hkdobrev commented May 10, 2017 •

Copy link
Copy Markdown
Contributor

seems like GitHub’s UI managed to resolve conflicts quite nicely

They are not using these settings to resolve automatically, unfortunately:
https://github.com/sindresorhus/refined-github/blob/db8cd5c/.gitattributes#L5

Comment thread extension/page-detect.js Outdated

const isNotifications = () => /\/notifications(\/participating)?/.test(location.pathname);

const isSettings = () => isRepo() && /^\/settings/.test(getRepoPath());

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.

isRepoSettings, as isSettings is too vague. It could be user account settings.

@sindresorhus

Copy link
Copy Markdown
Member

Can you add it to the https://github.com/sindresorhus/refined-github#highlights section? No screenshot needed.

@lukaszklis
lukaszklis force-pushed the remove-projects-when-empty branch from 39eb51f to 2aa68b0 Compare May 11, 2017 12:29
@lukaszklis

Copy link
Copy Markdown
Contributor Author

@sindresorhus thank you for fixing the readme 🙇

@sindresorhus sindresorhus changed the title Remove ”Projects” tab when there are no projects (#309) Remove the "Projects" repo tab when there are no projects May 11, 2017
@sindresorhus
sindresorhus merged commit be5631a into refined-github:master May 11, 2017
@lukaszklis
lukaszklis deleted the remove-projects-when-empty branch May 11, 2017 12:58
@sindresorhus

Copy link
Copy Markdown
Member

Looks great! Thanks for working this @lukaszklis 🍰✨

@lukaszklis

Copy link
Copy Markdown
Contributor Author

🎉 and sorry for the typos 🙈

@wlandau

wlandau commented Jan 13, 2019

Copy link
Copy Markdown

While this behavior does clean up the interface, it kept me from getting started with GitHub Projects. I wanted to create my first project and did not know why the tab was missing.

@fregante

fregante commented Jan 13, 2019 •

Copy link
Copy Markdown
Member

Open a new issue, we should not hide them when the current user is the owner of the repo. Or better yet, send a PR if you can

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.

6 participants