Skip to content

Commit 2b5d6ea

Browse files
committed
chore: updated usage to project level
1 parent 586a51e commit 2b5d6ea

File tree

4 files changed

+60
-15
lines changed

4 files changed

+60
-15
lines changed

src/lib/sdk/billing.ts

+1
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ export type OrganizationUsage = {
237237
users: number;
238238
authPhoneTotal: number;
239239
authPhoneEstimate: number;
240+
imageTransformations: number;
240241
}>;
241242
authPhoneTotal: number;
242243
authPhoneEstimate: number;

src/lib/sdk/usage.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,12 @@ export type UsageProject = {
319319
authPhoneEstimate: number;
320320

321321
/**
322-
* Aggregated statistics of total number SMS by country
322+
* Aggregated statistics of total number SMS by country.
323323
*/
324324
authPhoneCountriesBreakdown: Models.MetricBreakdown[];
325+
326+
/**
327+
* Aggregated statistics of total number of image transformations.
328+
*/
329+
imageTransformations: number;
325330
};

src/routes/(console)/organization-[organization]/usage/[[invoice]]/ProjectBreakdown.svelte

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
}
9595
9696
switch (metric) {
97+
case 'imageTransformations':
9798
case 'authPhoneTotal':
9899
return formatNumberWithCommas(value);
99100
case 'executions':
@@ -106,6 +107,7 @@
106107
}
107108
108109
onMount(() => {
110+
console.log(JSON.stringify(projects, null, 2));
109111
if (metric === undefined && databaseOperationMetric === undefined) {
110112
throw new Error(`metric or database operations must be defined`);
111113
}

src/routes/(console)/project-[project]/settings/usage/[[invoice]]/+page.svelte

+51-14
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
<script lang="ts">
2-
import { Container } from '$lib/layout';
3-
import { CardGrid, Heading, Card, ProgressBarBig } from '$lib/components';
2+
import { base } from '$app/paths';
3+
import { BarChart, Legend } from '$lib/charts';
4+
import { Card, CardGrid, Heading, ProgressBarBig } from '$lib/components';
5+
import Collapsible from '$lib/components/collapsible.svelte';
6+
import CollapsibleItem from '$lib/components/collapsibleItem.svelte';
7+
import { BillingPlan } from '$lib/constants.js';
8+
import { Button } from '$lib/elements/forms';
49
import {
5-
TableRow,
10+
Table,
611
TableBody,
712
TableCell,
813
TableCellHead,
914
TableHeader,
10-
Table,
15+
TableRow,
1116
TableRowLink
1217
} from '$lib/elements/table';
13-
import { showUsageRatesModal, tierToPlan, upgradeURL } from '$lib/stores/billing';
14-
import { organization } from '$lib/stores/organization';
15-
import { Button } from '$lib/elements/forms';
18+
import { getCountryName } from '$lib/helpers/diallingCodes.js';
19+
import { formatCurrency, formatNumberWithCommas } from '$lib/helpers/numbers';
1620
import { bytesToSize, humanFileSize, mbSecondsToGBHours } from '$lib/helpers/sizeConvertion';
17-
import { BarChart, Legend } from '$lib/charts';
1821
import { formatNum } from '$lib/helpers/string';
22+
import { Container } from '$lib/layout';
1923
import { total } from '$lib/layout/usage.svelte';
20-
import { BillingPlan } from '$lib/constants.js';
21-
import { base } from '$app/paths';
22-
import { formatCurrency, formatNumberWithCommas } from '$lib/helpers/numbers';
23-
import Collapsible from '$lib/components/collapsible.svelte';
24-
import CollapsibleItem from '$lib/components/collapsibleItem.svelte';
25-
import { getCountryName } from '$lib/helpers/diallingCodes.js';
24+
import { showUsageRatesModal, tierToPlan, upgradeURL } from '$lib/stores/billing';
25+
import { organization } from '$lib/stores/organization';
2626
2727
export let data;
2828
@@ -39,6 +39,7 @@
3939
4040
$: dbReads = data.usage.databasesReads;
4141
$: dbWrites = data.usage.databasesWrites;
42+
$: imageTransformations = data.usage.imageTransformations;
4243
4344
$: legendData = [
4445
{ name: 'Reads', value: data.usage.databasesReadsTotal },
@@ -246,6 +247,42 @@
246247
{/if}
247248
</svelte:fragment>
248249
</CardGrid>
250+
<CardGrid>
251+
<Heading tag="h6" size="7">Image transformations</Heading>
252+
253+
<p class="text">Total image transformations in your project.</p>
254+
255+
<svelte:fragment slot="aside">
256+
{#if imageTransformations}
257+
<div style:margin-top="-1.5em" style:margin-bottom="-1em">
258+
<BarChart
259+
options={{
260+
yAxis: {
261+
axisLabel: {
262+
formatter: formatNum
263+
}
264+
}
265+
}}
266+
series={[
267+
{
268+
name: 'Image transformations',
269+
data: [...imageTransformations.map((e) => [e.date, e.value])]
270+
}
271+
]} />
272+
</div>
273+
{:else}
274+
<Card isDashed>
275+
<div class="u-flex u-cross-center u-flex-vertical u-main-center u-flex">
276+
<span
277+
class="icon-chart-square-bar text-large"
278+
aria-hidden="true"
279+
style="font-size: 32px;" />
280+
<p class="u-bold">No data to show</p>
281+
</div>
282+
</Card>
283+
{/if}
284+
</svelte:fragment>
285+
</CardGrid>
249286
<CardGrid>
250287
<Heading tag="h6" size="7">Executions</Heading>
251288

0 commit comments

Comments
 (0)