From 9db3a1f310090a75f87a3011e579b18b65f3459f Mon Sep 17 00:00:00 2001 From: Darshan Date: Wed, 29 Jan 2025 19:57:58 +0530 Subject: [PATCH] update: hide project breakdown if the metric doesn't exist for it. --- src/lib/sdk/billing.ts | 2 + .../usage/[[invoice]]/+page.svelte | 32 ++-- .../usage/[[invoice]]/ProjectBreakdown.svelte | 166 +++++++++--------- 3 files changed, 103 insertions(+), 97 deletions(-) diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index 32e65b6a1..9428f3032 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -198,6 +198,8 @@ export type OrganizationUsage = { storage: number; executions: number; bandwidth: number; + databasesReads: number; + databasesWrites: number; users: number; authPhoneTotal: number; authPhoneEstimate: number; diff --git a/src/routes/(console)/organization-[organization]/usage/[[invoice]]/+page.svelte b/src/routes/(console)/organization-[organization]/usage/[[invoice]]/+page.svelte index d4b23112a..27a59f68e 100644 --- a/src/routes/(console)/organization-[organization]/usage/[[invoice]]/+page.svelte +++ b/src/routes/(console)/organization-[organization]/usage/[[invoice]]/+page.svelte @@ -28,7 +28,7 @@ : (data?.currentInvoice?.plan ?? $organization?.billingPlan); const plan = data?.plan ?? undefined; - $: project = (data.organizationUsage as OrganizationUsage).projects; + $: projects = (data.organizationUsage as OrganizationUsage).projects; $: legendData = [ { name: 'Reads', value: data.organizationUsage.databasesReadsTotal }, @@ -129,8 +129,8 @@ } ]} /> - {#if project?.length > 0} - + {#if projects?.length > 0} + {/if} {:else} @@ -181,8 +181,8 @@ } ]} /> - {#if project?.length > 0} - + {#if projects?.length > 0} + {/if} {:else} @@ -239,10 +239,10 @@ - {#if project?.length > 0} + {#if projects?.length > 0} {/if} {:else} @@ -298,9 +298,10 @@ } ]} /> - {#if project?.length > 0} - - {/if} + {#if projects?.length > 0}{/if} {:else}
@@ -368,9 +369,10 @@ progressValue={bytesToSize(current, 'GB')} progressMax={max} progressBarData={progressBarStorageDate} /> - {#if project?.length > 0} - - {/if} + {#if projects?.length > 0}{/if} {:else}
@@ -478,9 +480,9 @@

- {#if project?.length > 0} + {#if projects?.length > 0} diff --git a/src/routes/(console)/organization-[organization]/usage/[[invoice]]/ProjectBreakdown.svelte b/src/routes/(console)/organization-[organization]/usage/[[invoice]]/ProjectBreakdown.svelte index 7bd50227c..ca31412f4 100644 --- a/src/routes/(console)/organization-[organization]/usage/[[invoice]]/ProjectBreakdown.svelte +++ b/src/routes/(console)/organization-[organization]/usage/[[invoice]]/ProjectBreakdown.svelte @@ -111,90 +111,92 @@ }); - - - Project breakdown - - - Project - {#if databaseOperationMetric} - Reads - Writes - {:else} - {getMetricTitle(metric)} - {/if} - - {#if estimate} - Estimated cost - {/if} - {#if $canSeeProjects} - - {/if} - - - {#each groupByProject(metric, estimate, databaseOperationMetric).sort((a, b) => { - const aValue = a.usage ?? a.databasesReads ?? 0; - const bValue = b.usage ?? b.databasesReads ?? 0; - return bValue - aValue; - }) as project} - {#if !$canSeeProjects} - - - {data.projectNames[project.projectId]?.name ?? 'Unknown'} - - {#if databaseOperationMetric} - - {format(project.databasesReads ?? 0)} - - - {format(project.databasesWrites ?? 0)} - - {:else} - - {format(project.usage)} - - {/if} - - {#if project.estimate} - - {formatCurrency(project.estimate)} - - {/if} - +{#if projects.some((project) => project[metric]) || projects.some( (project) => databaseOperationMetric?.some((metric) => project[metric]) )} + + + Project breakdown + + + Project + {#if databaseOperationMetric} + Reads + Writes {:else} - - - {data.projectNames[project.projectId]?.name ?? 'Unknown'} - - {#if databaseOperationMetric} - - {format(project.databasesReads ?? 0)} - - - {format(project.databasesWrites ?? 0)} - - {:else} - - {format(project.usage)} - - {/if} - - {#if project.estimate} - - {formatCurrency(project.estimate)} - - {/if} - - - - + {getMetricTitle(metric)} {/if} - {/each} - - - - + + {#if estimate} + Estimated cost + {/if} + {#if $canSeeProjects} + + {/if} + + + {#each groupByProject(metric, estimate, databaseOperationMetric).sort( (a, b) => { + const aValue = a.usage ?? a.databasesReads ?? 0; + const bValue = b.usage ?? b.databasesReads ?? 0; + return bValue - aValue; + } ) as project} + {#if !$canSeeProjects} + + + {data.projectNames[project.projectId]?.name ?? 'Unknown'} + + {#if databaseOperationMetric} + + {format(project.databasesReads ?? 0)} + + + {format(project.databasesWrites ?? 0)} + + {:else} + + {format(project.usage)} + + {/if} + + {#if project.estimate} + + {formatCurrency(project.estimate)} + + {/if} + + {:else} + + + {data.projectNames[project.projectId]?.name ?? 'Unknown'} + + {#if databaseOperationMetric} + + {format(project.databasesReads ?? 0)} + + + {format(project.databasesWrites ?? 0)} + + {:else} + + {format(project.usage)} + + {/if} + + {#if project.estimate} + + {formatCurrency(project.estimate)} + + {/if} + + + + + {/if} + {/each} + + + + +{/if}