Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/pages/ContentScripts/features/repo-pr-tooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@ let PRDetail: PRDetail = {
};
let meta: RepoMeta;
let platform: string;
const pullRequestTabSelectors = [
'a[data-tab-item="pull-requests"]',
'#pull-requests-tab',
'a[href$="/pulls"][data-selected-links*="repo_pulls"]',
'a[href$="/pulls"]',
];
const pullRequestTabSelector = 'a[data-tab-item="pull-requests"]';
const pullRequestFallbackSelectors = ['#pull-requests-tab', 'a[href$="/pulls"][data-selected-links*="repo_pulls"]'];

const getData = async () => {
PRDetail.PROpened = await getPROpened(platform, repoName);
Expand All @@ -45,7 +41,13 @@ const getData = async () => {
meta = (await metaStore.get(platform, repoName)) as RepoMeta;
};
const getPullRequestTab = () => {
const $tabs = $(pullRequestTabSelectors.join(',')).filter((_, element) => !element.closest('template'));
const $primaryTabs = $(pullRequestTabSelector).filter((_, element) => !element.closest('template'));
const $visiblePrimaryTabs = $primaryTabs.filter(':visible');
if ($visiblePrimaryTabs.length > 0 || $primaryTabs.length > 0) {
return ($visiblePrimaryTabs.length > 0 ? $visiblePrimaryTabs : $primaryTabs).first();
}

const $tabs = $(pullRequestFallbackSelectors.join(',')).filter((_, element) => !element.closest('template'));
const $visibleTabs = $tabs.filter(':visible');

return ($visibleTabs.length > 0 ? $visibleTabs : $tabs).first();
Expand All @@ -55,8 +57,11 @@ const init = async (): Promise<void> => {
platform = getPlatform();
repoName = getRepoName();
await getData();
await elementReady(pullRequestTabSelectors.join(','));
await elementReady([pullRequestTabSelector, ...pullRequestFallbackSelectors].join(','));
const $prTab = getPullRequestTab();
if ($prTab.length === 0) {
return;
}
const placeholderElement = $('<div class="NativePopover" />').appendTo('body')[0];
createRoot(placeholderElement).render(
<NativePopover anchor={$prTab} width={340} arrowPosition="top-middle">
Expand Down
Loading