refactor: usage

This commit is contained in:
Arman committed 2023-06-23 17:15:42 +02:00
1 parent 248e4a44eb
commit cf4b25c942
5 files changed
+131 -49

No files matched your search

+1
View File
@@ -56,4 +56,5 @@ export { default as ClickableList } from './clickableList.svelte';
export { default as ClickableListItem } from './clickableListItem.svelte';
export { default as Id } from './id.svelte';
export { default as ProgressBar } from './progressBar.svelte';
export { default as ProgressBarBig } from './progressBarBig.svelte';
export { default as ProjectUsage } from './projectUsage.svelte';
+31
View File
@@ -0,0 +1,31 @@
<script lang="ts">
export let unit: string;
export let used: number;
export let max: number;
export let status: null | 'warning' | 'error' = null;
$: progress = Math.round((used / max) * 100);
//TODO: depending on the data received, we could set the status
</script>
<section class="progress-bar">
<div class="u-flex u-flex-vertical">
<div class="u-flex u-main-space-between">
<p>
<span class="heading-level-4">{used}</span>
<span class="body-text-1 u-bold">{unit}</span>
</p>
<p class="heading-level-4">{progress}%</p>
</div>
<p class="body-text-2">
{max}
{unit}
</p>
</div>
<div
class="progress-bar-container u-margin-block-start-16"
class:is-warning={status === 'warning'}
class:is-danger={status === 'error'}
style:--graph-size={progress + '%'} />
</section>
@@ -1,5 +1,12 @@
<script lang="ts">
import { DropList, DropListItem, Heading } from '$lib/components';
import {
DropList,
DropListItem,
DropListLink,
EmptySearch,
Heading,
PaginationInline
} from '$lib/components';
import { Pill } from '$lib/elements';
import {
TableBody,
@@ -12,7 +19,9 @@
} from '$lib/elements/table';
import { Container } from '$lib/layout';
export let invoices = [];
export let data;
export let offset = 0;
let showDropdown = [];
</script>
@@ -20,50 +29,58 @@
<div class="common-section">
<Heading tag="h2" size="5">Invoices</Heading>
</div>
<TableScroll>
<TableHeader>
<TableCellHead width={100}>Date</TableCellHead>
<TableCellHead width={100}>Status</TableCellHead>
<TableCellHead width={80}>Amount Due</TableCellHead>
<TableCellHead width={90}>Invoce #</TableCellHead>
<TableCellHead width={40} />
</TableHeader>
<TableBody>
{#each invoices as invoice, i}
<TableRow>
<TableCellText title="date">test</TableCellText>
<TableCell title="status">
<Pill>test</Pill>
</TableCell>
<TableCellText title="due">$1BILLION</TableCellText>
<TableCellText title="invoice number">test</TableCellText>
<TableCell showOverflow>
<DropList bind:show={showDropdown[i]} placement="bottom-start" noArrow>
<button
class="button is-only-icon is-text"
aria-label="More options"
on:click|preventDefault={() => {
showDropdown[i] = !showDropdown[i];
}}>
<span class="icon-dots-horizontal" aria-hidden="true" />
</button>
<svelte:fragment slot="list">
<DropListItem
icon="external-link"
on:click={() => {
console.log('test');
}}>View invoice</DropListItem>
<DropListItem
icon="download"
on:click={() => {
console.log('test');
}}>Download PDF</DropListItem>
</svelte:fragment>
</DropList>
</TableCell>
</TableRow>
{/each}
</TableBody>
</TableScroll>
{#if data.invoices?.total}
<TableScroll>
<TableHeader>
<TableCellHead width={100}>Date</TableCellHead>
<TableCellHead width={100}>Status</TableCellHead>
<TableCellHead width={80}>Amount Due</TableCellHead>
<TableCellHead width={90}>Invoce #</TableCellHead>
<TableCellHead width={40} />
</TableHeader>
<TableBody>
<!-- {#each data.invoices?.invoices as invoice, i} -->
{#each [] as invoice, i}
<TableRow>
<TableCellText title="date">test</TableCellText>
<TableCell title="status">
<Pill>test</Pill>
</TableCell>
<TableCellText title="due">$1BILLION</TableCellText>
<TableCellText title="invoice number">test</TableCellText>
<TableCell showOverflow>
<DropList bind:show={showDropdown[i]} placement="bottom-start" noArrow>
<button
class="button is-only-icon is-text"
aria-label="More options"
on:click|preventDefault={() => {
showDropdown[i] = !showDropdown[i];
}}>
<span class="icon-dots-horizontal" aria-hidden="true" />
</button>
<svelte:fragment slot="list">
<DropListLink icon="external-link" href="#/">
View invoice
</DropListLink>
<DropListItem
icon="download"
on:click={() => {
console.log('test');
}}>Download PDF</DropListItem>
</svelte:fragment>
</DropList>
</TableCell>
</TableRow>
{/each}
</TableBody>
</TableScroll>
<div class="u-flex u-margin-block-start-32 u-main-space-between">
<p class="text">Total results: {data.invoices?.total}</p>
<PaginationInline limit={5} bind:offset sum={data.invoices?.total} />
</div>
{:else}
<EmptySearch>
You have no payment history. After you receive your first invoice, you'll see it here.
</EmptySearch>
{/if}
</Container>
@@ -0,0 +1,21 @@
import { Query } from '@appwrite.io/console';
import { sdk } from '$lib/stores/sdk';
import { getPage, pageToOffset } from '$lib/helpers/load';
import { PAGE_LIMIT } from '$lib/constants';
import type { PageLoad } from './$types';
export const load: PageLoad = async ({ params, url }) => {
const page = getPage(url);
// const limit = getLimit(url, route, CARD_LIMIT);
const offset = pageToOffset(page, PAGE_LIMIT);
return {
offset,
invoices: await sdk.forConsole.projects.list([
Query.offset(offset),
Query.limit(PAGE_LIMIT),
Query.equal('teamId', params.organization),
Query.orderDesc('$createdAt')
])
};
};
@@ -1,6 +1,6 @@
<script lang="ts">
import { Container } from '$lib/layout';
import { Heading, ProjectUsage } from '$lib/components';
import { CardGrid, Heading, ProgressBarBig, ProjectUsage } from '$lib/components';
import type { PageData } from './$types';
export let data: PageData;
@@ -26,4 +26,16 @@
<ProjectUsage title={project?.name} data={project?.projectUsage} />
{/each}
</ul>
<CardGrid>
<Heading tag="h6" size="7">Function executions</Heading>
<p class="text">
Calculated for all functions that are executed in all projects in your organization.
</p>
<svelte:fragment slot="aside">
<ProgressBarBig unit="executions" max={750000} used={125000} />
</svelte:fragment>
</CardGrid>
</Container>