Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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={16}
height={16}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

The tag height of Gitee is slightly smaller than that of GitHub. It feels better to make this picture smaller.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

/>
{label.name}
</div>
</a>
);
};

export default OpenDiggerLabel;
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('a');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be changed to span.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

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,
});
1 change: 1 addition & 0 deletions src/pages/ContentScripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ import './features/repo-activity-racing-bar';
import './features/repo-activity-racing-bar/gitee-index';
import './features/developer-hovercard-info';
import './features/repo-sidebar-labels';
import './features/repo-sidebar-labels/gitee-index';
import './features/fast-pr';
Loading