import './more-dropdown.css';
import React from 'dom-chef';
import select from 'select-dom';
import elementReady from 'element-ready';
import features from '../libs/features';
import * as icons from '../libs/icons';
import {getRepoURL, getRef} from '../libs/utils';
import {isEnterprise} from '../libs/page-detect';
import {appendBefore} from '../libs/dom-utils';
const repoUrl = getRepoURL();
function createDropdown(): void {
// Markup copied from native GHE dropdown
appendBefore('.reponav', '[href$="settings"]',
{'More '}
);
}
async function init(): Promise {
await elementReady('.pagehead + *'); // Wait for the tab bar to be loaded
if (!select.exists('.reponav-dropdown')) {
createDropdown();
}
let compareUrl = `/${repoUrl}/compare`;
let commitsUrl = `/${repoUrl}/commits`;
const ref = getRef();
if (ref) {
compareUrl += `/${ref}`;
commitsUrl += `/${ref}`;
}
const menu = select('.reponav-dropdown .dropdown-menu')!;
menu.append(
{icons.darkCompare()} Compare
,
isEnterprise() ? '' :
{icons.dependency()} Dependencies
,
{icons.history()} Commits
,
{icons.branch()} Branches
,
);
// Selector only affects desktop navigation
for (const tab of select.all(`
.hx_reponav [data-selected-links~="pulse"],
.hx_reponav [data-selected-links~="security"]
`)) {
tab.remove();
menu.append(
{[...tab.childNodes]}
);
}
}
features.add({
id: __featureName__,
description: 'Adds links to `Commits`, `Branches`, `Dependencies`, and `Compare` in a new `More` dropdown.',
screenshot: 'https://user-images.githubusercontent.com/1402241/55089736-d94f5300-50e8-11e9-9095-329ac74c1e9f.png',
include: [
features.isRepo
],
load: features.onAjaxedPages,
init
});