diff --git a/src/lib/layout/usageMultiple.svelte b/src/lib/layout/usageMultiple.svelte index 85f5091ca4..ff1789c49a 100644 --- a/src/lib/layout/usageMultiple.svelte +++ b/src/lib/layout/usageMultiple.svelte @@ -1,19 +1,47 @@
@@ -41,19 +69,12 @@ {#if count} - {@const totalCount = clampMin(total.reduce((a, b) => a + b, 0))} - {formatNumberWithCommas(totalCount)} Total {title.toLocaleLowerCase()}
- ({ - name: legendData[index].name, - data: accumulateFromEndingTotal(c, total[index]) - }))} /> + {#if legendData} + import { base } from '$app/paths'; + import { page } from '$app/state'; + import { clampMin } from '$lib/helpers/numbers'; + import { formatNum } from '$lib/helpers/string'; import { Container, UsageMultiple } from '$lib/layout'; + import type { PageProps } from './$types'; - export let data; + let { data }: PageProps = $props(); - $: reads = data.databaseReads; - $: readsTotal = data.databaseReadsTotal; + const reads = $derived(data.databaseReads ?? []); + const readsTotal = $derived(clampMin(reads.reduce((sum, item) => sum + item.value, 0))); - $: writes = data.databaseWrites; - $: writesTotal = data.databaseWritesTotal; + const writes = $derived(data.databaseWrites ?? []); + const writesTotal = $derived(clampMin(writes.reduce((sum, item) => sum + item.value, 0))); + + const usagePath = $derived( + `${base}/project-${page.params.region}-${page.params.project}/databases/database-${page.params.database}/usage` + ); + import { goto } from '$app/navigation'; + import { base } from '$app/paths'; + import { page } from '$app/state'; import { Container, UsageMultiple } from '$lib/layout'; + import { InputSelect } from '$lib/elements/forms'; + import { clampMin } from '$lib/helpers/numbers'; + import { formatNum } from '$lib/helpers/string'; import { Layout } from '@appwrite.io/pink-svelte'; - import type { PageData } from './$types'; + import type { PageProps } from './$types'; - export let data: PageData; + let { data }: PageProps = $props(); - $: reads = data.databasesReads; - $: readsTotal = data.databasesReadsTotal; + const reads = $derived(data.databasesReads ?? []); + const readsTotal = $derived(clampMin(reads.reduce((sum, item) => sum + item.value, 0))); - $: writes = data.databasesWrites; - $: writesTotal = data.databasesWritesTotal; + const writes = $derived(data.databasesWrites ?? []); + const writesTotal = $derived(clampMin(writes.reduce((sum, item) => sum + item.value, 0))); + + const usagePath = $derived( + `${base}/project-${page.params.region}-${page.params.project}/databases/usage` + ); +
+ goto(`${usagePath}/${e.detail}`)} + id="period" + options={[ + { + label: '24 hours', + value: '24h' + }, + { + label: '30 days', + value: '30d' + }, + { + label: '90 days', + value: '90d' + } + ]} + value={page.params.period ?? '30d'} /> +
+ - import { Container, Usage } from '$lib/layout'; - import { page } from '$app/state'; import { base } from '$app/paths'; + import { page } from '$app/state'; + import { clampMin } from '$lib/helpers/numbers'; + import { Container, Usage } from '$lib/layout'; import { Layout } from '@appwrite.io/pink-svelte'; + import type { PageProps } from './$types'; + + let { data }: PageProps = $props(); + + const count = $derived(data.executions ?? []); + const total = $derived(clampMin(count.reduce((sum, metric) => sum + metric.value, 0))); - export let data; - $: total = data.executionsTotal; - $: count = data.executions; - $: gbHoursTotal = data.executionsMbSecondsTotal / 1000 / 3600; - $: mbSecondsCount = data.executionsMbSeconds; - $: gbHoursCount = data.executionsMbSeconds - ?.map((metric) => ({ - ...metric, - value: metric.value / 1000 / 3600 - })) - .filter(({ value }) => value); + // Function compute time is returned as MB-seconds and displayed as GB-hours. + const executionsTime = $derived(data.executionsTime ?? []); + const gbHoursCount = $derived( + executionsTime + .map((metric) => ({ + ...metric, + value: metric.value / 1000 / 3600 + })) + .filter(({ value }) => value) + ); + const gbHoursTotal = $derived( + clampMin(gbHoursCount.reduce((sum, metric) => sum + metric.value, 0)) + ); - {#if count} + {#if count.length} {/if} - {#if mbSecondsCount} + {#if executionsTime.length} {/if}