diff --git a/apps/web/src/common/components/CollectionTag.tsx b/apps/web/src/common/components/CollectionTag.tsx new file mode 100644 index 00000000..93475a8e --- /dev/null +++ b/apps/web/src/common/components/CollectionTag.tsx @@ -0,0 +1,62 @@ +import React from 'react'; +import { useTranslation } from 'next-i18next'; +import { useRouter } from 'next/navigation'; +import Tooltip from '@common/components/Tooltip'; +import { getSecondIdentName } from '@common/collectionsI18n'; +import cls from 'classnames'; + +const CollectionTag = ({ + collections, + className, +}: { + collections: string[]; + className: string; +}) => { + const { t, i18n } = useTranslation(); + const router = useRouter(); + const first = collections?.[0]; + + let restCollections: string[] = []; + if (collections?.length > 1) { + restCollections = collections?.slice(1).map((item) => { + return getSecondIdentName(item, i18n.language); + }); + } + + return ( +
+ {first ? ( + <> +
{ + e.preventDefault(); + e.stopPropagation(); + router.push(`/collection/${first}`); + }} + > + {getSecondIdentName(first, i18n.language)} +
+ {collections?.length > 1 ? ( + + {restCollections?.join(', ')} +
+ } + > +
+{collections.length - 1}
+ + ) : null} + + ) : null} + + ); +}; + +export default CollectionTag; diff --git a/apps/web/src/modules/analyze/components/NavBar/LabelItems.tsx b/apps/web/src/modules/analyze/components/NavBar/LabelItems.tsx index bc610b62..593aee0f 100644 --- a/apps/web/src/modules/analyze/components/NavBar/LabelItems.tsx +++ b/apps/web/src/modules/analyze/components/NavBar/LabelItems.tsx @@ -1,65 +1,22 @@ -import React, { useCallback, useEffect, useState, useRef } from 'react'; +import React from 'react'; import { useTranslation } from 'next-i18next'; import useCompareItems from '@modules/analyze/hooks/useCompareItems'; import { getProvider } from '@common/utils'; -import ColorSwitcher from '@modules/analyze/components/CompareBar/ColorSwitcher'; import { Level } from '@modules/analyze/constant'; -import { useClickAway } from 'react-use'; -import { useResizeDetector } from 'react-resize-detector'; import classnames from 'classnames'; -import Popper from '@mui/material/Popper'; import ProviderIcon from '../ProviderIcon'; +import CollectionTag from '@common/components/CollectionTag'; const LabelItems = () => { const { t } = useTranslation(); const { compareItems } = useCompareItems(); - const [hiddenIndex, setHiddenIndex] = useState(-1); - const [hiddenVisible, setHiddenVisible] = useState(false); - const [anchorEl, setAnchorEl] = React.useState(null); - const hiddenRef = useRef(null); + const item = compareItems.length > 0 ? [compareItems[0]] : []; - const computeWidth = () => { - if (ref) { - const parentsWidth = ref.current.offsetWidth; - let childrenWidth = 0; - const index = [...ref.current.children].findIndex((item, index) => { - if (item.id !== 'more') { - childrenWidth += item.offsetWidth; - if (parentsWidth < childrenWidth) { - return index; - } - } - }); - setHiddenIndex(index); - } - }; - const onResize = useCallback(computeWidth, [hiddenIndex, compareItems]); - useEffect(computeWidth, [compareItems]); - useClickAway(hiddenRef, () => { - setTimeout(() => { - setHiddenVisible(false); - }, 200); - }); - - const { ref } = useResizeDetector({ - handleHeight: false, - refreshMode: 'debounce', - refreshRate: 200, - onResize, - }); - - const style = { - background: 'linear-gradient(270deg, #FFFFFF 0%, rgba(255,255,255,0) 100%)', - }; return ( <> -
- {compareItems.map(({ name, label, level }, index) => { +
+ {item.map(({ name, label, level, collections }) => { const host = getProvider(label); - let labelNode = ( {name} ); @@ -78,92 +35,21 @@ const LabelItems = () => { } return ( -
= hiddenIndex, - })} - > +
{labelNode} - {compareItems.length > 1 && } {level === Level.COMMUNITY && (
{t('home:community')}
)} - {index < compareItems.length - 1 ? ( - vs - ) : null} +
); })} - {hiddenIndex !== -1 && ( -
-
{ - setAnchorEl(event.currentTarget); - setHiddenVisible(true); - }} - > - +{compareItems.length - hiddenIndex} -
-
- )} - -
- {compareItems - .filter((item, index) => index >= hiddenIndex) - .map(({ name, label, level }) => { - const host = getProvider(label); - - let labelNode = ( - {name} - ); - - if (level === Level.REPO) { - labelNode = ( - - {name} - - ); - } - - return ( -
- - {labelNode} - {compareItems.length > 1 && } - {level === Level.COMMUNITY && ( -
- {t('home:community')} -
- )} -
- ); - })} -
-
{/* todo show compare items in mobile */} diff --git a/apps/web/src/modules/analyze/context/ChartsDataProvider.tsx b/apps/web/src/modules/analyze/context/ChartsDataProvider.tsx index 5b77832f..ee1a270c 100644 --- a/apps/web/src/modules/analyze/context/ChartsDataProvider.tsx +++ b/apps/web/src/modules/analyze/context/ChartsDataProvider.tsx @@ -54,7 +54,7 @@ const ChartsDataProvider: React.FC = ({ children }) => { level, start: timeStart, end: timeEnd, - repoType: repoType, + repoType: level === Level.COMMUNITY ? repoType : '', }; return { queryKey: useMetricQuery.getKey(variables), @@ -80,7 +80,7 @@ const ChartsDataProvider: React.FC = ({ children }) => { level, start: timeStart, end: timeEnd, - repoType: repoType, + repoType: level === Level.COMMUNITY ? repoType : '', }; const key = useMetricQuery.getKey(variables); return { diff --git a/apps/web/src/modules/analyze/context/StatusContext.tsx b/apps/web/src/modules/analyze/context/StatusContext.tsx index 24b95165..00ba5f4b 100644 --- a/apps/web/src/modules/analyze/context/StatusContext.tsx +++ b/apps/web/src/modules/analyze/context/StatusContext.tsx @@ -4,7 +4,7 @@ import { Level } from '../constant'; type Item = Pick< StatusVerifyQuery['analysisStatusVerify'], - 'label' | 'status' | 'shortCode' + 'label' | 'status' | 'shortCode' | 'collections' >; export type VerifiedLabelItem = { diff --git a/apps/web/src/modules/analyze/hooks/useCompareItems.ts b/apps/web/src/modules/analyze/hooks/useCompareItems.ts index 99cc3d1f..0b9e402c 100644 --- a/apps/web/src/modules/analyze/hooks/useCompareItems.ts +++ b/apps/web/src/modules/analyze/hooks/useCompareItems.ts @@ -5,10 +5,12 @@ import { Level } from '@modules/analyze/constant'; const useCompareItems = () => { const { verifiedItems } = useStatusContext(); - const items = verifiedItems.map(({ label, level, shortCode }) => { - const name = level === Level.REPO ? getPathname(label) : label; - return { label, level, shortCode, name }; - }); + const items = verifiedItems.map( + ({ label, level, shortCode, collections }) => { + const name = level === Level.REPO ? getPathname(label) : label; + return { label, level, shortCode, name, collections }; + } + ); const ids = items.map((i) => i.shortCode); diff --git a/apps/web/src/modules/home/Trending/ListPanel.tsx b/apps/web/src/modules/home/Trending/ListPanel.tsx index d6a12411..467b279d 100644 --- a/apps/web/src/modules/home/Trending/ListPanel.tsx +++ b/apps/web/src/modules/home/Trending/ListPanel.tsx @@ -1,18 +1,15 @@ import React from 'react'; import Link from 'next/link'; -import { useRouter } from 'next/navigation'; -import cls from 'classnames'; import { useTranslation } from 'next-i18next'; import { BsCodeSquare } from 'react-icons/bs'; import { TrendingQuery } from '@oss-compass/graphql'; import { formatLabel } from '@common/utils/format'; -import Tooltip from '@common/components/Tooltip'; import { getShortAnalyzeLink } from '@common/utils/links'; import ProviderIcon from '@common/components/ProviderIcon'; import ImageFallback from '@common/components/ImageFallback'; import transHundredMarkSystem from '@common/transform/transHundredMarkSystem'; import { Level } from '@modules/analyze/constant'; -import { getSecondIdentName } from '@common/collectionsI18n'; +import CollectionTag from '@common/components/CollectionTag'; const ListPanel = (props: { loading: boolean; @@ -104,55 +101,6 @@ const Avatar = ({ item }: { item: TrendingQuery['trending'][number] }) => { ); }; -const CollectionTag = ({ - collections, - className, -}: { - collections: string[]; - className: string; -}) => { - const { t, i18n } = useTranslation(); - const router = useRouter(); - const first = collections?.[0]; - - let restCollections: string[] = []; - if (collections?.length > 1) { - restCollections = collections?.slice(1).map((item) => { - return getSecondIdentName(item, i18n.language); - }); - } - - return ( -
- {first ? ( - <> -
{ - e.preventDefault(); - e.stopPropagation(); - router.push(`/collection/${first}`); - }} - > - {getSecondIdentName(first, i18n.language)} -
- {collections?.length > 1 ? ( - - {restCollections?.join(', ')} -
- } - > -
+{collections.length - 1}
- - ) : null} - - ) : null} -
- ); -}; - const Loading = () => (
diff --git a/packages/graphql/src/generated.ts b/packages/graphql/src/generated.ts index 9cf72a36..e72aa965 100644 --- a/packages/graphql/src/generated.ts +++ b/packages/graphql/src/generated.ts @@ -1167,6 +1167,8 @@ export type Permission = { export type ProjectCompletionRow = { __typename?: 'ProjectCompletionRow'; + /** second collections of this label */ + collections?: Maybe>; /** metric model object identification */ label?: Maybe; /** metric model object level (project or repo) */ @@ -3349,6 +3351,7 @@ export type StatusVerifyQuery = { level?: string | null; shortCode?: string | null; status?: string | null; + collections?: Array | null; }; }; @@ -3365,6 +3368,7 @@ export type SearchQuery = { label?: string | null; status?: string | null; shortCode?: string | null; + collections?: Array | null; }>; }; @@ -6268,6 +6272,7 @@ export const StatusVerifyDocument = /*#__PURE__*/ ` level shortCode status + collections } } `; @@ -6311,6 +6316,7 @@ export const SearchDocument = /*#__PURE__*/ ` label status shortCode + collections } } `; diff --git a/packages/graphql/src/gql/query.graphql b/packages/graphql/src/gql/query.graphql index 24944f44..6efdb154 100644 --- a/packages/graphql/src/gql/query.graphql +++ b/packages/graphql/src/gql/query.graphql @@ -51,6 +51,7 @@ query statusVerify($label: String, $shortCode: String) { level shortCode status + collections } } @@ -60,6 +61,7 @@ query search($keyword: String!, $level: String) { label status shortCode + collections } }