-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Migrate repo labels to Gitee (#969)
* feat: Migrate repo labels to Gitee * fix: The warning problem is solved and the problem of excessive image size is optimized
- Loading branch information
Showing
3 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
src/pages/ContentScripts/features/repo-sidebar-labels/gitee-OpenDiggerLabel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React from 'react'; | ||
import { Label } from '../../../../api/common'; | ||
|
||
interface OpenDiggerLabelProps { | ||
label: Label; | ||
} | ||
|
||
const OpenDiggerLabel: React.FC<OpenDiggerLabelProps> = ({ label }) => { | ||
return ( | ||
<a | ||
id={`opendigger-label-${label.id}`} | ||
className="project-label-item-box" | ||
href="https://open-digger.cn" | ||
target="_blank" | ||
> | ||
<div | ||
className="project-label-item " | ||
style={{ | ||
whiteSpace: 'normal', | ||
maxWidth: '100%', | ||
}} | ||
> | ||
<img | ||
style={{ | ||
marginLeft: '-4px', | ||
marginRight: '2px', | ||
borderRadius: '50%', | ||
verticalAlign: 'middle', | ||
transform: 'translateY(-1px)', | ||
}} | ||
src={chrome.runtime.getURL('openDiggerLogo.png')} | ||
width={14} | ||
height={14} | ||
/> | ||
{label.name} | ||
</div> | ||
</a> | ||
); | ||
}; | ||
|
||
export default OpenDiggerLabel; |
54 changes: 54 additions & 0 deletions
54
src/pages/ContentScripts/features/repo-sidebar-labels/gitee-index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import features from '../../../../feature-manager'; | ||
import { getRepoName, hasRepoContainerHeader, isPublicRepoWithMeta } from '../../../../helpers/get-gitee-repo-info'; | ||
import { Label, RepoMeta, metaStore } from '../../../../api/common'; | ||
import { createRoot } from 'react-dom/client'; | ||
import OpenDiggerLabel from './gitee-OpenDiggerLabel'; | ||
|
||
import React from 'react'; | ||
import $ from 'jquery'; | ||
import isGitee from '../../../../helpers/is-gitee'; | ||
import { getPlatform } from '../../../../helpers/get-platform'; | ||
const featureId = features.getFeatureID(import.meta.url); | ||
let platform: string; | ||
const getLabels = async (repoName: string) => { | ||
const meta = (await metaStore.get(platform, repoName)) as RepoMeta; | ||
return meta.labels?.filter((label) => { | ||
return !(label.type.includes('-') && parseInt(label.type.split('-')[1]) > 0); | ||
}); | ||
}; | ||
|
||
const renderTags = (labels: Label[]) => { | ||
const defaultDiv = document.querySelector('.intro-list .default') as HTMLElement; | ||
if (defaultDiv) { | ||
defaultDiv.style.display = 'none'; | ||
$('.mixed-label').css('display', 'block'); | ||
} | ||
|
||
let giteeTagContainer = $('.mixed-label'); | ||
for (const label of labels) { | ||
const id = `opendigger-label-${label.id}`; | ||
// if the tag already exists, skip | ||
if (document.getElementById(id)) { | ||
continue; | ||
} | ||
const labelElement = document.createElement('span'); | ||
createRoot(labelElement).render(<OpenDiggerLabel label={label} />); | ||
giteeTagContainer.append(labelElement); | ||
} | ||
}; | ||
|
||
const init = async (): Promise<void> => { | ||
platform = getPlatform(); | ||
const repoName = getRepoName(); | ||
const labels = await getLabels(repoName); | ||
|
||
if (labels && labels.length > 0) { | ||
renderTags(labels); | ||
} | ||
}; | ||
|
||
features.add(featureId, { | ||
asLongAs: [isGitee, isPublicRepoWithMeta, hasRepoContainerHeader], | ||
awaitDomReady: true, | ||
init, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters