MCPcopy
hub / github.com/refined-github/refined-github / addBugsTab

Function addBugsTab

source/features/bugs-tab.tsx:67–131  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

65}
66
67async function addBugsTab(): Promise<void | false> {
68 // Query API as early as possible, even if it's not necessary on archived repos
69 const bugsPromise = bugs.get();
70
71 // On a label:bug listing:
72 // - always show the tab, as soon as possible
73 // - update the count later
74 // On other pages:
75 // - only show the tab if needed
76 if (!(await isBugsListing())) {
77 const {count} = await bugsPromise;
78 if (count === 0) {
79 return false;
80 }
81 }
82
83 const issuesTab = await elementReady('a.UnderlineNav-item[data-hotkey="g i"]', {waitForChildren: false});
84 if (!issuesTab) {
85 // Issues are disabled
86 return false;
87 }
88
89 // Copy Issues tab
90 const bugsTab = issuesTab.cloneNode(true);
91 bugsTab.classList.add('rgh-bugs-tab');
92 unhighlightTab(bugsTab);
93
94 // Disable unwanted behavior #3001
95 delete bugsTab.dataset.hotkey;
96 delete bugsTab.dataset.selectedLinks;
97 bugsTab.removeAttribute('id');
98
99 // Update its appearance
100 const bugsTabTitle = $('[data-content]', bugsTab);
101 bugsTabTitle.dataset.content = 'Bugs';
102 bugsTabTitle.textContent = 'Bugs';
103 $('.octicon', bugsTab).replaceWith(<BugIcon className="UnderlineNav-octicon d-none d-sm-inline" />);
104
105 // Set temporary counter
106 const bugsCounter = $('.Counter', bugsTab);
107 bugsCounter.textContent = '0';
108 bugsCounter.title = '';
109
110 // Update Bugs’ link
111 bugsTab.href = SearchQuery.from(bugsTab).append(await getSearchQueryBugLabel()).href;
112
113 // In case GitHub changes its layout again #4166
114 if (issuesTab.parentElement instanceof HTMLLIElement) {
115 issuesTab.parentElement.after(<li className="d-inline-flex">{bugsTab}</li>);
116 } else {
117 issuesTab.after(bugsTab);
118 }
119
120 triggerRepoNavOverflow();
121
122 // Update bugs count
123 try {
124 const {count: bugCount} = await bugsPromise;

Callers 1

initFunction · 0.85

Calls 10

isBugsListingFunction · 0.85
unhighlightTabFunction · 0.85
getSearchQueryBugLabelFunction · 0.85
triggerRepoNavOverflowFunction · 0.85
abbreviateNumberFunction · 0.85
getMethod · 0.80
cloneNodeMethod · 0.80
fromMethod · 0.80
removeMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected