From 850f552a672f33d4fb799cca6f6dd7ded62e0a1c Mon Sep 17 00:00:00 2001 From: "Dusan Mijatovic (PC2020)" Date: Mon, 11 Nov 2024 17:07:16 +0100 Subject: [PATCH] show archived repo status, start and forks count --- .../charts/d3LineChart/drawLineChart.tsx | 2 +- .../charts/d3LineChart/formatData.ts | 4 +- frontend/components/software/CommitsChart.tsx | 51 +++++++++++++++++-- .../components/software/GetStartedSection.tsx | 15 +++--- frontend/pages/software/[slug]/index.tsx | 4 +- frontend/types/SoftwareTypes.ts | 5 ++ 6 files changed, 65 insertions(+), 16 deletions(-) diff --git a/frontend/components/charts/d3LineChart/drawLineChart.tsx b/frontend/components/charts/d3LineChart/drawLineChart.tsx index d290bef5f..82f7695d5 100644 --- a/frontend/components/charts/d3LineChart/drawLineChart.tsx +++ b/frontend/components/charts/d3LineChart/drawLineChart.tsx @@ -24,7 +24,7 @@ type LineChartConfig = { const margin = { // minimal margins to host first/last year label 'overflow' left: 12, right: 12, - top: 4, bottom: 16 + top: 4, bottom: 24 } function findMax(data:LineData[]) { diff --git a/frontend/components/charts/d3LineChart/formatData.ts b/frontend/components/charts/d3LineChart/formatData.ts index 54b115e69..095b8797f 100644 --- a/frontend/components/charts/d3LineChart/formatData.ts +++ b/frontend/components/charts/d3LineChart/formatData.ts @@ -1,5 +1,7 @@ // SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all) // SPDX-FileCopyrightText: 2022 dv4all +// SPDX-FileCopyrightText: 2024 Dusan Mijatovic (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2024 Netherlands eScience Center // // SPDX-License-Identifier: Apache-2.0 @@ -40,7 +42,7 @@ export function prepareDataForSoftwarePage(data: Data) { // format unix time in seconds to ms for js const {lineData,lastUpdateInMs} = formatUnixDateData(data) // calculate total number of commits - const totalCountY = lineData.reduce((acc: any, point) => { + const totalCountY:number = lineData.reduce((acc: any, point) => { return acc+=point.y }, 0) // extract last commit date diff --git a/frontend/components/software/CommitsChart.tsx b/frontend/components/software/CommitsChart.tsx index d3f8f9681..64e77c395 100644 --- a/frontend/components/software/CommitsChart.tsx +++ b/frontend/components/software/CommitsChart.tsx @@ -3,6 +3,8 @@ // SPDX-FileCopyrightText: 2022 Christian Meeßen (GFZ) // SPDX-FileCopyrightText: 2022 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences // SPDX-FileCopyrightText: 2023 Dusan Mijatovic (dv4all) (dv4all) +// SPDX-FileCopyrightText: 2024 Dusan Mijatovic (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2024 Netherlands eScience Center // // SPDX-License-Identifier: Apache-2.0 @@ -14,12 +16,50 @@ import SingleLineChart from '~/components/charts/d3LineChart/SingleLineChart' export type CommitsChartProps = { repository_url: string | null, + archived: boolean | null, + star_count: number | null, + fork_count: number | null, commit_history?: CommitHistory commit_history_scraped_at?: string className?: string } -export default function CommitsChart({repository_url, commit_history, commit_history_scraped_at, className}: CommitsChartProps) { +function ArchivedRepo({archived}:{archived:boolean|null}){ + if (!archived) return null + return ( + archived repository + ) +} + +function StarCount({star_count}:{star_count:number|null}){ + if (!star_count) return null + return ( + {star_count===1 ? `${star_count} star`:`${star_count} stars`} + ) +} + +function ForkCount({fork_count}:{fork_count:number|null}){ + if (!fork_count) return null + return ( + {fork_count===1 ? `${fork_count} fork` : `${fork_count} forks`} + ) +} + +function Commits({commits,lastCommitDate}:{commits:number|null,lastCommitDate?:Date}){ + return ( + <> + {commits===1 ? `${commits} commit` : `${commits} commits`} + Last commit ≈ { + getTimeAgoSince(new Date(), lastCommitDate?.toISOString() ?? null) + } + + ) +} + +export default function CommitsChart({ + repository_url, commit_history, commit_history_scraped_at, + archived, star_count, fork_count, className +}: CommitsChartProps) { // if there is commit_history if (commit_history && Object.keys(commit_history).length > 0) { // format commits data for chart and calculate other stats @@ -28,10 +68,11 @@ export default function CommitsChart({repository_url, commit_history, commit_his return (
-
- {totalCountY} commits | Last commit ≈ { - getTimeAgoSince(new Date(), lastCommitDate?.toISOString() ?? null) - } +
+ + + +
) diff --git a/frontend/components/software/GetStartedSection.tsx b/frontend/components/software/GetStartedSection.tsx index a09e1b3df..500c1ed7c 100644 --- a/frontend/components/software/GetStartedSection.tsx +++ b/frontend/components/software/GetStartedSection.tsx @@ -2,22 +2,22 @@ // SPDX-FileCopyrightText: 2021 - 2022 dv4all // SPDX-FileCopyrightText: 2022 Christian Meeßen (GFZ) // SPDX-FileCopyrightText: 2022 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences +// SPDX-FileCopyrightText: 2024 Dusan Mijatovic (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2024 Netherlands eScience Center // // SPDX-License-Identifier: Apache-2.0 import LinkIcon from '@mui/icons-material/Link' import CommitsChart from './CommitsChart' -import {CommitHistory} from '../../types/SoftwareTypes' +import {RepositoryInfo} from '../../types/SoftwareTypes' type GetStartedSectionProps = { get_started_url: string | null, - repository_url: string | null, - commit_history: CommitHistory, - commit_history_scraped_at: string + repositoryInfo: RepositoryInfo } -export default function GetStartedSection(props:GetStartedSectionProps) { - const {repository_url, get_started_url, commit_history, commit_history_scraped_at} = props +export default function GetStartedSection({get_started_url,repositoryInfo}:GetStartedSectionProps) { + const {url:repository_url, commit_history, commit_history_scraped_at, archived, star_count,fork_count} = repositoryInfo // if no get_started_url and repository_url we do not render this section if (!get_started_url && !repository_url) return null @@ -48,6 +48,9 @@ export default function GetStartedSection(props:GetStartedSectionProps) { repository_url={repository_url} commit_history={commit_history} commit_history_scraped_at={commit_history_scraped_at} + archived={archived} + star_count={star_count} + fork_count={fork_count} /> ) } diff --git a/frontend/pages/software/[slug]/index.tsx b/frontend/pages/software/[slug]/index.tsx index 3e13d70fb..500817ede 100644 --- a/frontend/pages/software/[slug]/index.tsx +++ b/frontend/pages/software/[slug]/index.tsx @@ -166,9 +166,7 @@ export default function SoftwareIndexPage(props:SoftwareIndexData) { />