fix: put toggle sidebar button and sidebar over GHE stat bar

fix #220
This commit is contained in:
EnixCoda 2022-04-06 17:30:27 +08:00
parent b908d7d29c
commit fc3e19650d
3 changed files with 26 additions and 0 deletions

View file

@ -264,3 +264,7 @@ export function getPath() {
export function isNativePRFileTreeShown() {
return $('file-tree[data-target="diff-layout.fileTree"]')
}
export function selectEnterpriseStatHeader() {
return $('.stats-ui-enabled .server-stats')
}

View file

@ -0,0 +1,20 @@
import { useEffect } from 'react'
import { $ } from 'utils/DOMHelper'
import * as DOMHelper from '../DOMHelper'
import { GitHub } from '../index'
// A dirty fix for putting Gitako components over GHE stat bar.
// In normal cases the styles should be set via react render function return value,
// but adding the logic for such uncommon case is not worth the maintenance cost.
export function useEnterpriseStatBarStyleFix() {
useEffect(() => {
if (GitHub.isEnterprise()) {
const enterpriseStatHeaderElement = DOMHelper.selectEnterpriseStatHeader()
const zIndex = parseInt(enterpriseStatHeaderElement?.style.zIndex || '0', 10)
if (!isNaN(zIndex) && zIndex) {
$('.gitako-toggle-show-button-wrapper', e => (e.style.zIndex = `${zIndex + 1}`))
$('.gitako-side-bar-body-wrapper', e => (e.style.zIndex = `${zIndex + 1}`))
}
}
}, [])
}

View file

@ -6,6 +6,7 @@ import { resolveGitModules } from 'utils/gitSubmodule'
import { sortFoldersToFront } from 'utils/treeParser'
import * as API from './API'
import * as DOMHelper from './DOMHelper'
import { useEnterpriseStatBarStyleFix } from './hooks/useEnterpriseStatBarStyleFix'
import { useGitHubAttachCopyFileButton } from './hooks/useGitHubAttachCopyFileButton'
import { useGitHubAttachCopySnippetButton } from './hooks/useGitHubAttachCopySnippetButton'
import { useGitHubCodeFold } from './hooks/useGitHubCodeFold'
@ -202,6 +203,7 @@ export const GitHub: Platform = {
useGitHubAttachCopyFileButton(copyFileButton)
useGitHubAttachCopySnippetButton(copySnippetButton)
useGitHubCodeFold(codeFolding)
useEnterpriseStatBarStyleFix()
},
delegatePJAXProps(options) {
if (!options?.node || options.node.type === 'blob')