Skip to content

Commit

Permalink
Merge pull request #237 from appwrite/fix-undefined-values-breaking-u…
Browse files Browse the repository at this point in the history
…sage

Fix: undefined values breaking usage section
  • Loading branch information
TorstenDittmann authored Jan 27, 2023
2 parents 6fca232 + f877674 commit ea0c66d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/lib/layout/usage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
export type UsagePeriods = '24h' | '30d' | '90d';
export function last(set: Models.Metric[]): Models.Metric | null {
if (!set) return null;
return set.slice(-1)[0] ?? null;
}
Expand Down
14 changes: 8 additions & 6 deletions src/routes/console/project-[project]/overview/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
// TODO: metric type is wrong
export function last(set: Array<unknown>): Models.Metric | null {
if (!set) return null;
return (set as Models.Metric[]).slice(-1)[0] ?? null;
}
// TODO: metric type is wrong
export function total(set: Array<unknown>): number {
if (!set) return 0;
return (set as Models.Metric[]).reduce((prev, curr) => prev + curr.value, 0);
}
Expand Down Expand Up @@ -65,7 +67,7 @@
<Onboard {projectId} />
{:else}
{#if $usage}
{@const storage = humanFileSize(last($usage.storage).value)}
{@const storage = humanFileSize(last($usage.storage)?.value ?? 0)}
<section class="common-section">
<div class="grid-dashboard-1s-2m-6l">
<div class="card is-2-columns-medium-screen is-3-columns-large-screen">
Expand All @@ -89,14 +91,14 @@

<div class="grid-item-1-end-start">
<div class="heading-level-4">
{format(last($usage.documents).value)}
{format(last($usage.documents)?.value ?? 0)}
</div>
<div>Documents</div>
</div>

<div class="grid-item-1-end-end">
<div class="text">
Databases: {format(last($usage.databases).value)}
Databases: {format(last($usage.databases)?.value ?? 0)}
</div>
</div>
</div>
Expand Down Expand Up @@ -124,7 +126,7 @@

<div class="grid-item-1-end-end">
<div class="text">
Buckets: {format(last($usage.buckets).value)}
Buckets: {format(last($usage.buckets)?.value ?? 0)}
</div>
</div>
</div>
Expand All @@ -144,7 +146,7 @@

<div class="grid-item-1-end-start">
<div class="heading-level-4">
{format(last($usage.users).value)}
{format(last($usage.users)?.value ?? 0)}
</div>
<div>Users</div>
</div>
Expand All @@ -165,7 +167,7 @@

<div class="grid-item-1-end-start">
<div class="heading-level-4">
{format(last($usage.executions).value)}
{format(last($usage.executions)?.value ?? 0)}
</div>
<div>Executions</div>
</div>
Expand Down

1 comment on commit ea0c66d

@vercel
Copy link

@vercel vercel bot commented on ea0c66d Jan 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.