Skip to content

Commit

Permalink
fix(analytics): fix analytics if empty
Browse files Browse the repository at this point in the history
  • Loading branch information
gregberge committed Dec 28, 2024
1 parent 316173f commit 78a85a1
Showing 1 changed file with 44 additions and 14 deletions.
58 changes: 44 additions & 14 deletions apps/frontend/src/pages/Account/Analytics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ function Charts(props: { accountSlug: string; period: Period }) {
},
{},
),
total: Math.round(screenshots.total / builds.total),
total: builds.total
? Math.round(screenshots.total / builds.total)
: 0,
ts: serie.ts,
});
return acc;
Expand Down Expand Up @@ -209,10 +211,7 @@ function Charts(props: { accountSlug: string; period: Period }) {
<ChartCardBody>
{metrics?.builds ? (
metrics.builds.all.total === 0 ? (
<EmptyState
title="No builds"
description="You haven't created any builds for this period."
/>
<EmptyStateBuilds />
) : (
<EvolutionChart
metric={metrics.builds}
Expand All @@ -232,10 +231,7 @@ function Charts(props: { accountSlug: string; period: Period }) {
<ChartCardBody>
{metrics ? (
metrics.screenshots.all.total === 0 ? (
<EmptyState
title="No screenshots"
description="You haven't uploaded any screenshots for this period."
/>
<EmptyStateScreenshots />
) : (
<EvolutionChart
metric={metrics.screenshots}
Expand All @@ -252,7 +248,13 @@ function Charts(props: { accountSlug: string; period: Period }) {
<ChartCardHeading>Screenshots by Project</ChartCardHeading>
</ChartCardHeader>
<ChartCardBody>
{metrics ? <ProjectPieChart metric={metrics.screenshots} /> : null}
{metrics ? (
metrics.screenshots.all.total > 0 ? (
<ProjectPieChart metric={metrics.screenshots} />
) : (
<EmptyStateScreenshots />
)
) : null}
</ChartCardBody>
</Card>
<div className="col-span-12 flex flex-col gap-[inherit] lg:col-span-3">
Expand Down Expand Up @@ -294,14 +296,23 @@ function Charts(props: { accountSlug: string; period: Period }) {
<ChartCardHeading className="mb-4">
Screenshots by Build
</ChartCardHeading>
<ChartCardDescription>Screenshots</ChartCardDescription>
<Count
count={
metrics
? metrics.screenshots.all.total
? Math.round(
metrics.screenshots.all.total / metrics.builds.all.total,
)
: 0
: null
}
/>
</ChartCardHeader>
<ChartCardBody>
{screenshotByBuildSeries ? (
screenshotByBuildSeries.all.total === 0 ? (
<EmptyState
title="No screenshots"
description="You haven't uploaded any screenshots for this period."
/>
<EmptyStateScreenshots />
) : (
<EvolutionChart
metric={screenshotByBuildSeries}
Expand All @@ -317,6 +328,24 @@ function Charts(props: { accountSlug: string; period: Period }) {
);
}

function EmptyStateScreenshots() {
return (
<EmptyState
title="No screenshots"
description="You haven't uploaded any screenshots for this period."
/>
);
}

function EmptyStateBuilds() {
return (
<EmptyState
title="No builds"
description="You haven't created any builds for this period."
/>
);
}

type Metric = {
all: {
total: number;
Expand All @@ -342,6 +371,7 @@ function Count(props: { count: number | null }) {
value={props.count ?? 0}
className={isLoading ? "invisible" : undefined}
/>

{isLoading && (
<div className="bg-subtle absolute left-0 top-2 h-[1em] w-32 rounded" />
)}
Expand Down

0 comments on commit 78a85a1

Please sign in to comment.