From 0b7f788d2c8b557e8e83d76d86a6d5d93194bafa Mon Sep 17 00:00:00 2001 From: laixingyou Date: Thu, 22 Feb 2024 15:29:28 +0800 Subject: [PATCH] feat: add contributor avatar and fix Weekly Meeting date (#319) Signed-off-by: laixingyou --- .../ContributorTable/ContributorName.tsx | 60 +++++++++++++++++++ .../DomainPersona.tsx} | 16 ----- .../index.tsx} | 14 +++-- .../ContributorTable/tableDownload.ts | 48 +++++++++++++++ .../DataView/MetricDetail/MetricDashboard.tsx | 52 ++++++++++++++-- .../analyze/components/NavBar/LabelItems.tsx | 5 +- .../modules/home/LatestNews/DatePicker.tsx | 6 +- packages/graphql/src/generated.ts | 4 ++ packages/graphql/src/gql/query.graphql | 1 + 9 files changed, 175 insertions(+), 31 deletions(-) create mode 100644 apps/web/src/modules/analyze/DataView/MetricDetail/MetricContributor/ContributorTable/ContributorName.tsx rename apps/web/src/modules/analyze/DataView/MetricDetail/MetricContributor/{DomainPersona/index.tsx => ContributorTable/DomainPersona.tsx} (90%) rename apps/web/src/modules/analyze/DataView/MetricDetail/MetricContributor/{ContributorTable.tsx => ContributorTable/index.tsx} (96%) create mode 100644 apps/web/src/modules/analyze/DataView/MetricDetail/MetricContributor/ContributorTable/tableDownload.ts diff --git a/apps/web/src/modules/analyze/DataView/MetricDetail/MetricContributor/ContributorTable/ContributorName.tsx b/apps/web/src/modules/analyze/DataView/MetricDetail/MetricContributor/ContributorTable/ContributorName.tsx new file mode 100644 index 00000000..a4be48e0 --- /dev/null +++ b/apps/web/src/modules/analyze/DataView/MetricDetail/MetricContributor/ContributorTable/ContributorName.tsx @@ -0,0 +1,60 @@ +import React from 'react'; +import { IoPeopleCircle } from 'react-icons/io5'; +import Image from 'next/image'; + +const DomainPersona = ({ name, origin }) => { + let icon = getIcons(origin, name); + + return ( +
+
{icon}
+ {name} +
+ ); +}; + +const getIcons = (origin, name) => { + switch (origin) { + case 'github': + return ( +
+ (e.currentTarget.src = '/images/github.png')} + unoptimized + fill={true} + style={{ + objectFit: 'cover', + }} + alt="icon" + placeholder="blur" + blurDataURL="/images/github.png" + /> +
+ ); + case 'gitee': + return ( +
+ + (e.currentTarget.src = '/images/logos/gitee-red.svg') + } + unoptimized + fill={true} + style={{ + objectFit: 'cover', + }} + alt="icon" + placeholder="blur" + blurDataURL="/images/logos/gitee-red.svg" + /> +
+ ); + // return ; + default: + return ; + } +}; + +export default DomainPersona; diff --git a/apps/web/src/modules/analyze/DataView/MetricDetail/MetricContributor/DomainPersona/index.tsx b/apps/web/src/modules/analyze/DataView/MetricDetail/MetricContributor/ContributorTable/DomainPersona.tsx similarity index 90% rename from apps/web/src/modules/analyze/DataView/MetricDetail/MetricContributor/DomainPersona/index.tsx rename to apps/web/src/modules/analyze/DataView/MetricDetail/MetricContributor/ContributorTable/DomainPersona.tsx index b901cc61..2a2ff3f2 100644 --- a/apps/web/src/modules/analyze/DataView/MetricDetail/MetricContributor/DomainPersona/index.tsx +++ b/apps/web/src/modules/analyze/DataView/MetricDetail/MetricContributor/ContributorTable/DomainPersona.tsx @@ -5,7 +5,6 @@ import { getDomainData } from '../utils'; import { toFixed } from '@common/utils'; import classnames from 'classnames'; import Popper from '@mui/material/Popper'; -import { ClickAwayListener } from '@mui/base/ClickAwayListener'; const PopperContent = ({ dataList, name, active, setActive }) => { const { t } = useTranslation(); @@ -65,7 +64,6 @@ const PopperContent = ({ dataList, name, active, setActive }) => { }; const DomainPersona = ({ maxDomain, dataList, name }) => { - const { t } = useTranslation(); const contributionTypeMap = useGetContributionTypeI18n(); const domainData = useMemo(() => { return getDomainData(dataList, contributionTypeMap); @@ -80,12 +78,6 @@ const DomainPersona = ({ maxDomain, dataList, name }) => { }; return ( - // { - // setActive(''); - // popperOpen && togglePopperOpen(() => false); - // }} - // >
{ setActive(''); @@ -95,10 +87,6 @@ const DomainPersona = ({ maxDomain, dataList, name }) => {
{domainData.map(({ type, color, contribution }) => { const width = toFixed((contribution / maxDomain) * 100, 2); - const bg = { - backgroundColor: color, - width: `${width}%`, - }; return active === type ? (
{
) : (
{ - // handleClick(e, type); - // }} key={type} onMouseEnter={(e) => { handleClick(e, type); @@ -150,7 +135,6 @@ const DomainPersona = ({ maxDomain, dataList, name }) => { />
- // { + return ; + }, }, { title: t('analyze:metric_detail:role_persona'), @@ -229,7 +236,6 @@ const MetricTable: React.FC<{ defaultFilterOpts.find((i) => i.type === 'contribution_type')?.values || null, filterMode: 'tree', - // ellipsis: { showTitle: true }, align: 'left', width: '300px', }, diff --git a/apps/web/src/modules/analyze/DataView/MetricDetail/MetricContributor/ContributorTable/tableDownload.ts b/apps/web/src/modules/analyze/DataView/MetricDetail/MetricContributor/ContributorTable/tableDownload.ts new file mode 100644 index 00000000..bcd8cab6 --- /dev/null +++ b/apps/web/src/modules/analyze/DataView/MetricDetail/MetricContributor/ContributorTable/tableDownload.ts @@ -0,0 +1,48 @@ +import axios from 'axios'; + +export enum Status { + PENDING = 'pending', + PROGRESS = 'progress', + COMPLETE = 'complete', + UNKNOWN = 'unknown', +} +export const apiDownloadFiles = (path, fileName, onFinish) => { + let link = document.createElement('a'); + link.href = path; + link.download = fileName + '.csv'; + link.style.display = 'none'; + document.body.appendChild(link); + link.click(); + onFinish && onFinish(); + document.body.removeChild(link); +}; +export const getContributorPolling = (uuid) => { + return axios.get('/api/v1/contributor/export_state/' + uuid); +}; +export const getContributorExport = (query) => { + return axios.post('/api/v1/contributor/export', query, { + headers: { + accept: 'application/json', + }, + }); +}; +export const getIssuePolling = (uuid) => { + return axios.get('/api/v1/issue/export_state/' + uuid); +}; +export const getIssueExport = (query) => { + return axios.post('/api/v1/issue/export', query, { + headers: { + accept: 'application/json', + }, + }); +}; +export const getPrPolling = (uuid) => { + return axios.get('/api/v1/pull/export_state/' + uuid); +}; +export const getPrExport = (query) => { + return axios.post('/api/v1/pull/export', query, { + headers: { + accept: 'application/json', + }, + }); +}; diff --git a/apps/web/src/modules/analyze/DataView/MetricDetail/MetricDashboard.tsx b/apps/web/src/modules/analyze/DataView/MetricDetail/MetricDashboard.tsx index b5abf31a..dfb275ae 100644 --- a/apps/web/src/modules/analyze/DataView/MetricDetail/MetricDashboard.tsx +++ b/apps/web/src/modules/analyze/DataView/MetricDetail/MetricDashboard.tsx @@ -17,10 +17,10 @@ import { PullDetailOverview, } from '@oss-compass/graphql'; import client from '@common/gqlClient'; -import { AiFillGithub } from 'react-icons/ai'; -import { SiGitee } from 'react-icons/si'; +import { SiGitee, SiGithub } from 'react-icons/si'; import { toFixed } from '@common/utils'; import { useRouter } from 'next/router'; +import Image from 'next/image'; const MetricDashboard = () => { const { compareItems } = useCompareItems(); @@ -121,7 +121,10 @@ const MetricBoxContributors: React.FC<{
- + {getUserIcons( + data.highestContributionContributor.origin, + data.highestContributionContributor.name + )}
{data.highestContributionContributor.name || '/'} @@ -318,12 +321,51 @@ const Loading = () => ( const getIcons = (type: string) => { switch (type) { case 'github': - return ; + return ; case 'gitee': return ; default: return ; } }; - +const getUserIcons = (type, name) => { + switch (type) { + case 'github': + return ( +
+ (e.currentTarget.src = '/images/github.png')} + unoptimized + fill={true} + style={{ + objectFit: 'cover', + }} + alt="icon" + placeholder="blur" + blurDataURL="/images/github.png" + /> +
+ ); + case 'gitee': + return ( +
+ + (e.currentTarget.src = '/images/logos/gitee-red.svg') + } + unoptimized + fill={true} + alt="icon" + placeholder="blur" + blurDataURL="/images/logos/gitee-red.svg" + /> +
+ ); + // return ; + default: + return ; + } +}; export default MetricDashboard; diff --git a/apps/web/src/modules/analyze/components/NavBar/LabelItems.tsx b/apps/web/src/modules/analyze/components/NavBar/LabelItems.tsx index f5ff4236..3cbf3b20 100644 --- a/apps/web/src/modules/analyze/components/NavBar/LabelItems.tsx +++ b/apps/web/src/modules/analyze/components/NavBar/LabelItems.tsx @@ -12,9 +12,8 @@ const CommunityItem = ({ label, name }) => { const { data } = useCommunityReposQuery(client, { label, }); - const communityOrgUrl = - data?.communityOverview?.communityOrgUrl || 'https://gitee.com/mindspore'; - console.log(communityOrgUrl); + const communityOrgUrl = data?.communityOverview?.communityOrgUrl || ''; + return communityOrgUrl ? ( { const bookedDays = [ (date) => { - return date.getDay() === 2 || date.getDay() === 4; + return date.getDay() === 2; //每周二社区例会 }, new Date(2023, 7, 23), new Date(2023, 11, 13), @@ -60,7 +60,7 @@ const DatePicker = () => { }; const selectEvent = eventList.filter(({ key }, index) => { if (index === 0) { - return selected?.getDay() === 2 || selected?.getDay() === 4; + return selected?.getDay() === 2; } else { return selected && format(selected, 'yyyy-MM-dd') === key; } diff --git a/packages/graphql/src/generated.ts b/packages/graphql/src/generated.ts index f4ba88da..3b31a866 100644 --- a/packages/graphql/src/generated.ts +++ b/packages/graphql/src/generated.ts @@ -479,6 +479,8 @@ export type ContributorDetailPage = { __typename?: 'ContributorDetailPage'; count?: Maybe; items: Array; + /** contributors origin */ + origin: Scalars['String']; page?: Maybe; totalPage?: Maybe; }; @@ -4582,6 +4584,7 @@ export type ContributorsDetailListQuery = { contributorsDetailList: { __typename?: 'ContributorDetailPage'; count?: number | null; + origin: string; page?: number | null; totalPage?: number | null; items: Array<{ @@ -8369,6 +8372,7 @@ export const ContributorsDetailListDocument = /*#__PURE__*/ ` mileageType organization } + origin page totalPage } diff --git a/packages/graphql/src/gql/query.graphql b/packages/graphql/src/gql/query.graphql index 7b083568..698714f4 100644 --- a/packages/graphql/src/gql/query.graphql +++ b/packages/graphql/src/gql/query.graphql @@ -656,6 +656,7 @@ query contributorsDetailList( mileageType organization } + origin page totalPage }