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 clean-sidebar feature #2011

Merged
merged 10 commits into from
May 6, 2019
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ GitHub Enterprise is also supported. More info in the options.
- [Forks and watchers counters are hidden.](https://user-images.githubusercontent.com/1402241/53681077-f3328b80-3d1e-11e9-9e29-2cb017141769.png)
- [Diff signs are hidden.](https://user-images.githubusercontent.com/1402241/54807718-149cec80-4cb9-11e9-869c-e265863211e3.png)
- [Hide milestone sorter UI if you don’t have permission to use it.](https://user-images.githubusercontent.com/7753001/56913933-738a2880-6ae5-11e9-9d13-1973cbbf5df0.png)
- [Empty sections in the issue/PRs sidebar are hidden.](https://user-images.githubusercontent.com/1402241/57199809-20691780-6fb6-11e9-9672-1ad3f9e1b827.png)


### UI improvements
Expand Down
1 change: 1 addition & 0 deletions source/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ import './features/filter-pr-by-build-status';
import './features/edit-files-faster';
import './features/hide-disabled-milestone-sorter';
import './features/link-to-file-in-file-history';
import './features/clean-sidebar';

import './features/scrollable-code-and-blockquote.css';
import './features/center-reactions-popup.css';
Expand Down
9 changes: 9 additions & 0 deletions source/features/clean-sidebar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* Adjust spacing of empty sections */
.discussion-sidebar-item.rgh-clean-sidebar {
margin-bottom: -5px;
}

/* Remove message under the `Unsubscribe` button */
.sidebar-notifications .reason {
display: none !important;
}
100 changes: 100 additions & 0 deletions source/features/clean-sidebar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
Hide all empty sections (or just their "empty" label) in discussion sidebar
*/

import './clean-sidebar.css';
import React from 'dom-chef';
import select from 'select-dom';
import features from '../libs/features';
import observeEl from '../libs/simplified-element-observer';
import {isPR} from '../libs/page-detect';

let canEditSidebar = false;

// Selector points to element containing list of elements or "No labels" text
function cleanSection(selector: string): boolean {
const list = select(selector)!;
if (list.children.length === 0) {
const section = list.closest('.discussion-sidebar-item')!;
if (canEditSidebar) {
list.remove();
section.classList.add('rgh-clean-sidebar');
} else {
section.remove();
}

return true;
}

return false;
}

function clean(): void {
if (select.exists('.rgh-clean-sidebar')) {
return;
}

select('#partial-discussion-sidebar')!.classList.add('rgh-clean-sidebar');

// Assignees
const assignees = select('.js-issue-assignees')!;
if (assignees.children.length === 0) {
assignees.closest('.discussion-sidebar-item')!.remove();
} else {
const assignYourself = select('.js-issue-assign-self');
if (assignYourself) {
(assignYourself.previousSibling as ChildNode).remove(); // Drop "No one β€” "
select('[aria-label="Select assignees"] summary')!.append(
<span style={{fontWeight: 'normal'}}> – {assignYourself}</span>
);
}
}

// Reviewers
if (isPR()) {
cleanSection('[aria-label="Select reviewers"] > .css-truncate');
}

// Labels
if (!cleanSection('.js-issue-labels') && !canEditSidebar) {
select('.sidebar-labels div.discussion-sidebar-heading')!.remove();
}

// Projects
cleanSection('.sidebar-projects');

// Milestones
const milestones = select('.sidebar-milestone')!;
if (!select.exists('.milestone-name', milestones)) {
if (canEditSidebar) {
const lastTextNode = milestones.lastChild!.lastChild!;
if (lastTextNode.textContent!.trim() === 'No milestone') {
lastTextNode.remove();
milestones.classList.add('rgh-clean-sidebar');
} else {
throw new Error('Refined GitHub: milestones in sidebar could not be hidden');
}
} else {
milestones.remove();
}
}

// Notifications
select('.sidebar-notifications .discussion-sidebar-heading')!.remove();
}

function init(): void {
canEditSidebar = select.exists('.sidebar-labels .octicon-gear');
clean();
observeEl('.discussion-sidebar', clean);
}

features.add({
id: 'link-to-file-in-file-history',
include: [
features.isIssue,
features.isPRConversation
],
load: features.onAjaxedPages,
init
});
5 changes: 0 additions & 5 deletions source/features/hide-tips.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ a.tabnav-extra[href$='mastering-markdown/'] {
display: none !important;
}

/* Remove message under the `Unsubscribe` button */
.sidebar-notifications .reason {
display: none !important;
}

/* Remove Marketplace marketing box on PRs */
.js-marketplace-callout-container {
display: none !important;
Expand Down