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} 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"]',
);
}
async function init(): Promise {
await elementReady('.pagehead + *'); // Wait for the tab bar to be loaded
if (!select.exists('.reponav-dropdown')) {
createDropdown();
}
select('.reponav-dropdown .dropdown-menu')!.append(
{icons.darkCompare()} Compare
,
isEnterprise() ? '' :
{icons.dependency()} Dependencies
,
{icons.graph()} Insights
,
{icons.history()} Commits
,
{icons.branch()} Branches
,
);
// Remove native Insights tab
const insightsTab = select('[data-selected-links~="pulse"]');
if (insightsTab) {
insightsTab.remove();
}
}
features.add({
id: 'more-dropdown',
description: 'Access the `Commits`, `Branches`, `Dependencies`, and `Compare` pages from anywhere in a repository',
include: [
features.isRepo
],
load: features.onAjaxedPages,
init
});