From 5130dc5f3123f7a7ac38fac21ae9b10d4e7e86c9 Mon Sep 17 00:00:00 2001 From: Ephraim Atta-Duncan Date: Tue, 15 Aug 2023 09:43:24 +0000 Subject: [PATCH] chore: refactor github charts into a single component --- .../app/(marketing)/open/gh-merged-prs.tsx | 44 ------------------- .../open/{gh-forks.tsx => gh-metrics.tsx} | 28 +++++++++--- .../app/(marketing)/open/gh-open-issues.tsx | 44 ------------------- .../src/app/(marketing)/open/gh-stars.tsx | 44 ------------------- .../src/app/(marketing)/open/page.tsx | 41 +++++++++++++---- 5 files changed, 54 insertions(+), 147 deletions(-) delete mode 100644 apps/marketing/src/app/(marketing)/open/gh-merged-prs.tsx rename apps/marketing/src/app/(marketing)/open/{gh-forks.tsx => gh-metrics.tsx} (62%) delete mode 100644 apps/marketing/src/app/(marketing)/open/gh-open-issues.tsx delete mode 100644 apps/marketing/src/app/(marketing)/open/gh-stars.tsx diff --git a/apps/marketing/src/app/(marketing)/open/gh-merged-prs.tsx b/apps/marketing/src/app/(marketing)/open/gh-merged-prs.tsx deleted file mode 100644 index 8f32458d8..000000000 --- a/apps/marketing/src/app/(marketing)/open/gh-merged-prs.tsx +++ /dev/null @@ -1,44 +0,0 @@ -'use client'; - -import { HTMLAttributes } from 'react'; - -import { Bar, BarChart, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts'; - -import { formatMonth } from '@documenso/lib/client-only/format-month'; -import { cn } from '@documenso/ui/lib/utils'; - -import { StargazersType } from './page'; - -export type GithubMergedPrsProps = HTMLAttributes & { data: StargazersType }; - -export const GithubMergedPrs = ({ className, data, ...props }: GithubMergedPrsProps) => { - const formattedData = Object.keys(data) - .map((key) => ({ - month: formatMonth(key), - mergedPRs: data[key].mergedPRs, - })) - .reverse(); - - return ( -
-

Github: Merged PRs

- -
- - - - - [Number(value), 'Merged PRs']} - cursor={{ fill: 'hsl(var(--primary) / 10%)' }} - /> - - - -
-
- ); -}; diff --git a/apps/marketing/src/app/(marketing)/open/gh-forks.tsx b/apps/marketing/src/app/(marketing)/open/gh-metrics.tsx similarity index 62% rename from apps/marketing/src/app/(marketing)/open/gh-forks.tsx rename to apps/marketing/src/app/(marketing)/open/gh-metrics.tsx index 6e2c7e8c6..552edf167 100644 --- a/apps/marketing/src/app/(marketing)/open/gh-forks.tsx +++ b/apps/marketing/src/app/(marketing)/open/gh-metrics.tsx @@ -9,22 +9,36 @@ import { cn } from '@documenso/ui/lib/utils'; import { StargazersType } from './page'; -export type GithubForksProps = HTMLAttributes & { data: StargazersType }; +export type GithubMetricProps = HTMLAttributes & { + data: StargazersType; + metricKey: keyof StargazersType; + title: string; + label: string; + chartHeight?: number; +}; -export const GithubForks = ({ className, data, ...props }: GithubForksProps) => { +export const GithubMetric = ({ + className, + data, + metricKey, + title, + label, + chartHeight = 400, + ...props +}: GithubMetricProps) => { const formattedData = Object.keys(data) .map((key) => ({ month: formatMonth(key), - forks: data[key].forks, + [metricKey]: data[key][metricKey], })) .reverse(); return (
-

Github: Forks

+

{title}

- + @@ -32,10 +46,10 @@ export const GithubForks = ({ className, data, ...props }: GithubForksProps) => itemStyle={{ color: 'hsl(var(--primary-foreground))', }} - formatter={(value) => [Number(value), 'Forks']} + formatter={(value) => [Number(value), label]} cursor={{ fill: 'hsl(var(--primary) / 10%)' }} /> - +
diff --git a/apps/marketing/src/app/(marketing)/open/gh-open-issues.tsx b/apps/marketing/src/app/(marketing)/open/gh-open-issues.tsx deleted file mode 100644 index 7f761ddb1..000000000 --- a/apps/marketing/src/app/(marketing)/open/gh-open-issues.tsx +++ /dev/null @@ -1,44 +0,0 @@ -'use client'; - -import { HTMLAttributes } from 'react'; - -import { Bar, BarChart, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts'; - -import { formatMonth } from '@documenso/lib/client-only/format-month'; -import { cn } from '@documenso/ui/lib/utils'; - -import { StargazersType } from './page'; - -export type GithubOpenIssuesProps = HTMLAttributes & { data: StargazersType }; - -export const GithubOpenIssues = ({ className, data, ...props }: GithubOpenIssuesProps) => { - const formattedData = Object.keys(data) - .map((key) => ({ - month: formatMonth(key), - openIssues: data[key].openIssues, - })) - .reverse(); - - return ( -
-

Github: Open Issues

- -
- - - - - [Number(value), 'Open Issues']} - cursor={{ fill: 'hsl(var(--primary) / 10%)' }} - /> - - - -
-
- ); -}; diff --git a/apps/marketing/src/app/(marketing)/open/gh-stars.tsx b/apps/marketing/src/app/(marketing)/open/gh-stars.tsx deleted file mode 100644 index 8d696a358..000000000 --- a/apps/marketing/src/app/(marketing)/open/gh-stars.tsx +++ /dev/null @@ -1,44 +0,0 @@ -'use client'; - -import { HTMLAttributes } from 'react'; - -import { Bar, BarChart, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts'; - -import { formatMonth } from '@documenso/lib/client-only/format-month'; -import { cn } from '@documenso/ui/lib/utils'; - -import { StargazersType } from './page'; - -export type GithubStarsProps = HTMLAttributes & { data: StargazersType }; - -export const GithubStars = ({ className, data, ...props }: GithubStarsProps) => { - const formattedData = Object.keys(data) - .map((key) => ({ - month: formatMonth(key), - stars: data[key].stars, - })) - .reverse(); - - return ( -
-

Github: Stars

- -
- - - - - [Number(value), 'Stars']} - cursor={{ fill: 'hsl(var(--primary) / 10%)' }} - /> - - - -
-
- ); -}; diff --git a/apps/marketing/src/app/(marketing)/open/page.tsx b/apps/marketing/src/app/(marketing)/open/page.tsx index 202b58f41..e52d01734 100644 --- a/apps/marketing/src/app/(marketing)/open/page.tsx +++ b/apps/marketing/src/app/(marketing)/open/page.tsx @@ -5,10 +5,7 @@ import { SalaryBands } from '~/app/(marketing)/open/salary-bands'; import { CapTable } from './cap-table'; import { FundingRaised } from './funding-raised'; -import { GithubForks } from './gh-forks'; -import { GithubMergedPrs } from './gh-merged-prs'; -import { GithubOpenIssues } from './gh-open-issues'; -import { GithubStars } from './gh-stars'; +import { GithubMetric } from './gh-metrics'; import { TeamMembers } from './team-members'; export const revalidate = 86400; @@ -110,10 +107,38 @@ export default async function OpenPage() { - - - - + + + + +

Where's the rest?