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

Restore clean-conversation-sidebar feature #4445

Merged
merged 4 commits into from
Jun 8, 2021
Merged
Changes from 2 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
18 changes: 9 additions & 9 deletions source/features/clean-conversation-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,25 @@ Expected DOM:
"No issues"
```

@param containerSelector Element that contains `details` or `.discussion-sidebar-heading`
@param selector Element that contains `details` or `.discussion-sidebar-heading` or distinctive element inside it
*/
function cleanSection(containerSelector: string): boolean {
const container = select(containerSelector);
function cleanSection(selector: string): boolean {
const container = select(selector)?.closest('form, .discussion-sidebar-item');
if (!container) {
return false;
}

const header = select(':scope > details, :scope > .discussion-sidebar-heading', container)!;
const heading = select(':scope > details, :scope > .discussion-sidebar-heading', container)!;

// Magic. Do not touch.
// Section is empty if: no sibling element OR empty sibling element
if (header.nextElementSibling?.firstElementChild) {
if (heading.nextElementSibling?.firstElementChild) {
return false;
}

const section = container.closest('.discussion-sidebar-item')!;
if (canEditSidebar()) {
getNodesAfter(header).deleteContents();
getNodesAfter(heading).deleteContents();
section.classList.add('rgh-clean-sidebar');
} else {
section.remove();
Expand Down Expand Up @@ -93,9 +93,9 @@ async function clean(): Promise<void> {
}

// Labels
if (!cleanSection('.sidebar-labels') && !canEditSidebar()) {
// Hide header in any case except `canEditSidebar`
select('.sidebar-labels div.discussion-sidebar-heading')!.remove();
if (!cleanSection('.js-issue-labels') && !canEditSidebar()) {
// Hide heading in any case except `canEditSidebar`
select('.discussion-sidebar-item [data-hotkey="l"]')!.remove();
}

// Linked issues/PRs
Expand Down