From 0e9e6c58733127563af2491c2d1d386d17cd7cd5 Mon Sep 17 00:00:00 2001 From: laixingyou Date: Mon, 26 Feb 2024 19:25:43 +0800 Subject: [PATCH] fix:delete unnecessary url query Signed-off-by: laixingyou --- .../ContributorTable/index.tsx | 8 +- .../DataView/MetricDetail/MetricDashboard.tsx | 119 +++++++++++------- .../analyze/hooks/useHandleQueryParams.ts | 8 ++ 3 files changed, 84 insertions(+), 51 deletions(-) diff --git a/apps/web/src/modules/analyze/DataView/MetricDetail/MetricContributor/ContributorTable/index.tsx b/apps/web/src/modules/analyze/DataView/MetricDetail/MetricContributor/ContributorTable/index.tsx index 192e6403..c1779462 100644 --- a/apps/web/src/modules/analyze/DataView/MetricDetail/MetricContributor/ContributorTable/index.tsx +++ b/apps/web/src/modules/analyze/DataView/MetricDetail/MetricContributor/ContributorTable/index.tsx @@ -157,7 +157,7 @@ const MetricTable: React.FC<{ } } if (filterOpts.find((i) => i.type === 'contribution_type')) { - sortOpts = sorter.field && { + sortOpts = sorter.order && { type: sorter.field === 'contribution' ? 'contribution_filterd' @@ -165,14 +165,14 @@ const MetricTable: React.FC<{ direction: sorter.order === 'ascend' ? 'asc' : 'desc', }; } else { - sortOpts = sorter.field && { + sortOpts = sorter.order && { type: sorter.field, direction: sorter.order === 'ascend' ? 'asc' : 'desc', }; } handleQueryParams({ - filterOpts: JSON.stringify(filterOpts), - sortOpts: JSON.stringify(sortOpts), + filterOpts: filterOpts.length > 0 ? JSON.stringify(filterOpts) : null, + sortOpts: sortOpts && JSON.stringify(sortOpts), }); setFilterOpts(filterOpts); setTableParams({ diff --git a/apps/web/src/modules/analyze/DataView/MetricDetail/MetricDashboard.tsx b/apps/web/src/modules/analyze/DataView/MetricDetail/MetricDashboard.tsx index dfb275ae..e877f7e8 100644 --- a/apps/web/src/modules/analyze/DataView/MetricDetail/MetricDashboard.tsx +++ b/apps/web/src/modules/analyze/DataView/MetricDetail/MetricDashboard.tsx @@ -120,15 +120,10 @@ const MetricBoxContributors: React.FC<{
-
- {getUserIcons( - data.highestContributionContributor.origin, - data.highestContributionContributor.name - )} -
-
- {data.highestContributionContributor.name || '/'} -
+ {getTopUser( + data.highestContributionContributor.origin, + data.highestContributionContributor.name + )}
{t('analyze:metric_detail:top_contributor')} @@ -328,44 +323,74 @@ const getIcons = (type: string) => { 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 ; +const getTopUser = (type, name) => { + let url = null; + let userIcon = null; + if (!name) { + userIcon = ; + } else { + switch (type) { + case 'github': + url = 'https://github.com/' + name; + userIcon = ( +
+ (e.currentTarget.src = '/images/github.png')} + unoptimized + fill={true} + style={{ + objectFit: 'cover', + }} + alt="icon" + placeholder="blur" + blurDataURL="/images/github.png" + /> +
+ ); + break; + case 'gitee': + url = 'https://gitee.com/' + name; + userIcon = ( +
+ + (e.currentTarget.src = '/images/logos/gitee-red.svg') + } + unoptimized + fill={true} + alt="icon" + placeholder="blur" + blurDataURL="/images/logos/gitee-red.svg" + /> +
+ ); + break; + default: + userIcon = ; + break; + } } + + return ( + <> +
{userIcon}
+
+ {url ? ( + + {name} + + ) : ( + name || '/' + )} +
+ + ); }; export default MetricDashboard; diff --git a/apps/web/src/modules/analyze/hooks/useHandleQueryParams.ts b/apps/web/src/modules/analyze/hooks/useHandleQueryParams.ts index 537bc0e5..bab4560d 100644 --- a/apps/web/src/modules/analyze/hooks/useHandleQueryParams.ts +++ b/apps/web/src/modules/analyze/hooks/useHandleQueryParams.ts @@ -1,11 +1,19 @@ import { useRouter } from 'next/router'; // 修改或新增查询参数 +const clearEmptyProperties = (obj) => { + Object.keys(obj).forEach(function (key) { + if (obj[key] === null || obj[key] === undefined || obj[key] === '') { + delete obj[key]; + } + }); +}; export const useHandleQueryParams = () => { const router = useRouter(); const handleQueryParams = (newParams) => { const { pathname, query } = router; const newQueryParams = { ...query, ...newParams }; + clearEmptyProperties(newQueryParams); router.push({ pathname, query: newQueryParams,