diff --git a/src/lib/layout/usage.svelte b/src/lib/layout/usage.svelte index e34799528b..f469136089 100644 --- a/src/lib/layout/usage.svelte +++ b/src/lib/layout/usage.svelte @@ -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; } diff --git a/src/routes/console/project-[project]/overview/+layout.svelte b/src/routes/console/project-[project]/overview/+layout.svelte index fbed69cfbd..3f7485aa0f 100644 --- a/src/routes/console/project-[project]/overview/+layout.svelte +++ b/src/routes/console/project-[project]/overview/+layout.svelte @@ -5,11 +5,13 @@ // TODO: metric type is wrong export function last(set: Array): 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): number { + if (!set) return 0; return (set as Models.Metric[]).reduce((prev, curr) => prev + curr.value, 0); } @@ -65,7 +67,7 @@ {:else} {#if $usage} - {@const storage = humanFileSize(last($usage.storage).value)} + {@const storage = humanFileSize(last($usage.storage)?.value ?? 0)}
@@ -89,14 +91,14 @@
- {format(last($usage.documents).value)} + {format(last($usage.documents)?.value ?? 0)}
Documents
- Databases: {format(last($usage.databases).value)} + Databases: {format(last($usage.databases)?.value ?? 0)}
@@ -124,7 +126,7 @@
- Buckets: {format(last($usage.buckets).value)} + Buckets: {format(last($usage.buckets)?.value ?? 0)}
@@ -144,7 +146,7 @@
- {format(last($usage.users).value)} + {format(last($usage.users)?.value ?? 0)}
Users
@@ -165,7 +167,7 @@
- {format(last($usage.executions).value)} + {format(last($usage.executions)?.value ?? 0)}
Executions