Add card for project usage

This commit is contained in:
ernstmul committed 2024-09-24 15:31:36 +02:00
1 parent b24eea7777
commit d9dabb3baf
1 file changed
+60 -1
@@ -13,7 +13,7 @@
import { showUsageRatesModal, tierToPlan, upgradeURL } from '$lib/stores/billing';
import { organization } from '$lib/stores/organization';
import { Button } from '$lib/elements/forms';
import { bytesToSize, humanFileSize } from '$lib/helpers/sizeConvertion';
import { bytesToSize, humanFileSize, mbSecondsToGBHours } from '$lib/helpers/sizeConvertion';
import { BarChart } from '$lib/charts';
import { formatNum } from '$lib/helpers/string';
import { total } from '$lib/layout/usage.svelte';
@@ -273,6 +273,7 @@
<svelte:fragment slot="aside">
{#if storage}
{console.log(data.usage)}
{@const humanized = humanFileSize(storage)}
{@const progressBarStorageDate = [
{
@@ -325,6 +326,64 @@
{/if}
</svelte:fragment>
</CardGrid>
<CardGrid>
<Heading tag="h6" size="7">GB hours</Heading>
<p class="text">
GB hours represent the memory usage (in gigabytes) of your function executions and
builds, multiplied by the total execution time (in hours).
</p>
<svelte:fragment slot="aside">
{#if data.usage.executionsMbSecondsTotal}
{@const totalGbHours = mbSecondsToGBHours(
data.usage.executionsMbSecondsTotal +
data.usage.buildsMbSecondsTotal
)}
{@const progressBarStorageDate = [
{
size: mbSecondsToGBHours(data.usage.executionsMbSecondsTotal),
color: '#85DBD8',
tooltip: {
title: 'Executions',
label: `${(Math.round(mbSecondsToGBHours(data.usage.executionsMbSecondsTotal) * 100) / 100).toLocaleString('en-US')} GB hours`
}
},
{
size: mbSecondsToGBHours(data.usage.buildsMbSecondsTotal),
color: '#FE9567',
tooltip: {
title: 'Deployments',
label: `${(Math.round(mbSecondsToGBHours(data.usage.buildsMbSecondsTotal) * 100) / 100).toLocaleString('en-US')} GB hours`
}
}
]}
<div class="u-flex u-flex-vertical">
<div class="u-flex u-main-space-between">
<p>
<span class="heading-level-4"
>{(Math.ceil(totalGbHours * 100) / 100).toLocaleString('en-US')}</span>
<span class="body-text-1 u-bold">{`GB hours`}</span>
</p>
</div>
</div>
<ProgressBarBig
progressMax={totalGbHours}
progressValue={totalGbHours}
progressBarData={progressBarStorageDate} />
{:else}
<Card isDashed>
<div class="u-flex u-cross-center u-flex-vertical u-main-center u-flex">
<span
class="icon-chart-square-bar text-large"
aria-hidden="true"
style="font-size: 32px;" />
<p class="u-bold">No data to show</p>
</div>
</Card>
{/if}
</svelte:fragment>
</CardGrid>
<p class="text u-text-color-gray u-margin-block-start-16">
Metrics are estimates updated every 24 hours and may not accurately reflect your invoice.
</p>