feat: sites usage

This commit is contained in:
Arman
2025-03-05 15:21:07 +01:00
parent 4f7fce859f
commit d63e24bc31
8 changed files with 94 additions and 27 deletions
@@ -19,11 +19,6 @@
title: 'Deployments',
event: 'deployments'
},
// {
// href: `${path}/analytics`,
// title: 'Analytics',
// event: 'analytics'
// },
{
href: `${path}/logs`,
title: 'Logs',
@@ -34,6 +29,11 @@
title: 'Domains',
event: 'domains'
},
{
href: `${path}/usage`,
title: 'Usage',
event: 'usage'
},
{
href: `${path}/settings`,
title: 'Settings',
@@ -79,7 +79,8 @@
buildCommand === site?.buildCommand &&
outputDirectory === site?.outputDirectory &&
selectedFramework?.key === site?.framework &&
fallback === site?.fallbackFile
fallback === site?.fallbackFile &&
adapter === site?.adapter
) {
isButtonDisabled = true;
} else {
@@ -0,0 +1,34 @@
<script lang="ts">
import { base } from '$app/paths';
import { page } from '$app/stores';
import { Usage } from '$lib/layout';
export let data;
$: total = data.deploymentsTotal;
$: count = data.deployments;
// $: totalBuilds = data.buildsTotal;
// $: countBuilds = data.builds;
$: console.log(data);
</script>
<Usage
title="Deployments"
path={`${base}/project-${$page.params.project}/sites/site-${$page.params.site}/usage`}
countMetadata={{
legend: 'Deployments',
title: 'Total deployments'
}}
{total}
{count} />
<!-- <Usage
title="Builds"
path={`${base}/project-${$page.params.project}/sites/site-${$page.params.site}/usage`}
countMetadata={{
legend: 'Builds',
title: 'Total builds'
}}
total={totalBuilds}
count={countBuilds} /> -->
@@ -0,0 +1,16 @@
import { isValueOfStringEnum } from '$lib/helpers/types';
import { sdk } from '$lib/stores/sdk';
import { SiteUsageRange } from '@appwrite.io/console';
import type { PageLoad } from './$types';
import { error } from '@sveltejs/kit';
export const load: PageLoad = async ({ params }) => {
const period = isValueOfStringEnum(SiteUsageRange, params.period)
? params.period
: SiteUsageRange.ThirtyDays;
try {
return sdk.forProject.sites.getUsage(params.site, period);
} catch (e) {
error(e.code, e.message);
}
};
@@ -1,9 +0,0 @@
<script lang="ts">
import { Container } from '$lib/layout';
export let data;
$: console.log(data.usage);
</script>
<Container>Coming soon</Container>
@@ -1,12 +0,0 @@
import { sdk } from '$lib/stores/sdk';
import { Dependencies } from '$lib/constants';
export const load = async ({ depends }) => {
depends(Dependencies.SITES);
const usage = await sdk.forProject.sites.listUsage();
return {
usage
};
};
@@ -0,0 +1,21 @@
<script lang="ts">
import { base } from '$app/paths';
import { page } from '$app/stores';
import { Usage } from '$lib/layout';
export let data;
$: total = data.deploymentsTotal;
$: count = data.deployments;
$: console.log(data);
</script>
<Usage
title="Sites"
path={`${base}/project-${$page.params.project}/sites/usage`}
countMetadata={{
legend: 'Sites',
title: 'Total sites'
}}
{total}
{count} />
@@ -0,0 +1,16 @@
import { isValueOfStringEnum } from '$lib/helpers/types';
import { sdk } from '$lib/stores/sdk';
import { SiteUsageRange } from '@appwrite.io/console';
import type { PageLoad } from './$types';
import { error } from '@sveltejs/kit';
export const load: PageLoad = async ({ params }) => {
const period = isValueOfStringEnum(SiteUsageRange, params.period)
? params.period
: SiteUsageRange.ThirtyDays;
try {
return sdk.forProject.sites.listUsage(period);
} catch (e) {
error(e.code, e.message);
}
};