Skip to content

Commit

Permalink
Add clean-sidebar feature (#2011)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed May 6, 2019
1 parent ad17f06 commit 4bc3f3a
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 5 deletions.
1 change: 1 addition & 0 deletions readme.md
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
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
@@ -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;
}
97 changes: 97 additions & 0 deletions source/features/clean-sidebar.tsx
@@ -0,0 +1,97 @@
/*
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>
);
assignees.closest('.discussion-sidebar-item')!.classList.add('rgh-clean-sidebar');
}
}

// 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')!;
const milestonesInfo = milestones.lastChild!.lastChild!;
if (milestonesInfo.textContent!.trim() === 'No milestone') {
if (canEditSidebar) {
milestonesInfo.remove();
milestones.classList.add('rgh-clean-sidebar');
} 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
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

0 comments on commit 4bc3f3a

Please sign in to comment.