mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
fix: remove orphaned shared usage components and breadcrumb entry
Removing every remaining usage/[[period]] route in this branch left the shared Usage/UsageMultiple components (src/lib/layout) with no consumers, which also broke type-checking since no route defines a `period` param anymore. Extracted the still-used helper functions (periodToDates, total, etc.) to a plain usageHelpers.ts and deleted the dead components. Also removed a leftover "Usage" sub-navigation entry in the database store.
This commit is contained in:
1 parent
a8a7bb8257
commit
a0ee4324ef
8 files changed
+73
-251
No files matched your search
@@ -10,8 +10,7 @@ export { default as WizardWithSteps } from './wizardWithSteps.svelte';
|
||||
export { default as WizardStep } from './wizardStep.svelte';
|
||||
export { default as Breadcrumbs } from './breadcrumbs.svelte';
|
||||
export { default as Unauthenticated } from './unauthenticated.svelte';
|
||||
export { default as Usage, type UsagePeriods } from './usage.svelte';
|
||||
export { default as UsageMultiple } from './usageMultiple.svelte';
|
||||
export type { UsagePeriods } from './usageHelpers';
|
||||
export { default as Progress } from './progress.svelte';
|
||||
export { default as GridHeader } from './gridHeader.svelte';
|
||||
export { default as ContainerHeader } from './containerHeader.svelte';
|
||||
|
||||
@@ -1,145 +0,0 @@
|
||||
<script context="module" lang="ts">
|
||||
import { ProjectUsageRange, type Models } from '@appwrite.io/console';
|
||||
export type UsagePeriods = '24h' | '30d' | '90d';
|
||||
|
||||
export function periodToDates(period: UsagePeriods): {
|
||||
start: string;
|
||||
end: string;
|
||||
period: ProjectUsageRange;
|
||||
} {
|
||||
const start = new Date();
|
||||
switch (period) {
|
||||
case '24h':
|
||||
start.setUTCHours(start.getHours() - 24);
|
||||
break;
|
||||
case '30d':
|
||||
start.setUTCHours(0, 0, 0, 0);
|
||||
start.setUTCDate(start.getDate() - 30);
|
||||
break;
|
||||
case '90d':
|
||||
start.setUTCHours(0, 0, 0, 0);
|
||||
start.setUTCDate(start.getDate() - 90);
|
||||
break;
|
||||
}
|
||||
const end = new Date();
|
||||
end.setUTCDate(end.getUTCDate() + 1);
|
||||
end.setUTCHours(0, 0, 0, 0);
|
||||
return {
|
||||
start: start.toISOString(),
|
||||
end: end.toISOString(),
|
||||
period: period === '24h' ? ProjectUsageRange.OneHour : ProjectUsageRange.OneDay
|
||||
};
|
||||
}
|
||||
|
||||
export function last(set: Models.Metric[]): Models.Metric | null {
|
||||
if (!set) return null;
|
||||
return set.slice(-1)[0] ?? null;
|
||||
}
|
||||
|
||||
export function total(set: Models.Metric[]): number {
|
||||
return set?.reduce((prev, curr) => prev + curr.value, 0) ?? 0;
|
||||
}
|
||||
|
||||
export function accumulateFromEndingTotal(
|
||||
metrics: Models.Metric[],
|
||||
endingTotal: number,
|
||||
startingDayToFillZero: Date = null
|
||||
): Array<[string, number]> {
|
||||
return (metrics ?? []).reduceRight(
|
||||
(acc, curr) => {
|
||||
if (startingDayToFillZero !== null && startingDayToFillZero instanceof Date) {
|
||||
const date = new Date(curr.date);
|
||||
if (date > startingDayToFillZero) {
|
||||
acc.data.unshift([date.toISOString(), 0]);
|
||||
acc.total -= 0;
|
||||
|
||||
return acc;
|
||||
}
|
||||
}
|
||||
acc.data.unshift([curr.date, acc.total]);
|
||||
acc.total -= curr.value;
|
||||
return acc;
|
||||
},
|
||||
{
|
||||
total: endingTotal,
|
||||
data: []
|
||||
}
|
||||
).data;
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { page } from '$app/state';
|
||||
import { goto } from '$app/navigation';
|
||||
|
||||
import { BarChart } from '$lib/charts';
|
||||
import { Card } from '$lib/components';
|
||||
import { InputSelect } from '$lib/elements/forms';
|
||||
import { formatNumberWithCommas } from '$lib/helpers/numbers';
|
||||
import { Layout, Typography } from '@appwrite.io/pink-svelte';
|
||||
|
||||
type MetricMetadata = {
|
||||
title: string;
|
||||
legend: string;
|
||||
};
|
||||
|
||||
export let total: number;
|
||||
export let count: Models.Metric[];
|
||||
export let countMetadata: MetricMetadata;
|
||||
export let path: string = null;
|
||||
export let hidePeriodSelect = false;
|
||||
export let isCumulative: boolean = false;
|
||||
</script>
|
||||
|
||||
<Layout.Stack gap="s">
|
||||
{#if !hidePeriodSelect}
|
||||
<div
|
||||
style:max-width="250px"
|
||||
style:--input-background-color="var(--bgcolor-neutral-primary)">
|
||||
<InputSelect
|
||||
on:change={(e) => goto(`${path}/${e.detail}`)}
|
||||
id="period"
|
||||
options={[
|
||||
{
|
||||
label: '24 hours',
|
||||
value: '24h'
|
||||
},
|
||||
{
|
||||
label: '30 days',
|
||||
value: '30d'
|
||||
},
|
||||
{
|
||||
label: '90 days',
|
||||
value: '90d'
|
||||
}
|
||||
]}
|
||||
value={page.params.period ?? '30d'} />
|
||||
</div>
|
||||
{/if}
|
||||
<Card>
|
||||
{#if count}
|
||||
<Layout.Stack gap="xs">
|
||||
<Typography.Title>{formatNumberWithCommas(total)}</Typography.Title>
|
||||
<Typography.Text>{countMetadata.title}</Typography.Text>
|
||||
</Layout.Stack>
|
||||
<div class="chart-container">
|
||||
<BarChart
|
||||
formatted={page.params.period === '24h' ? 'hours' : 'days'}
|
||||
series={[
|
||||
{
|
||||
name: countMetadata.legend,
|
||||
data: isCumulative
|
||||
? count.map((m) => [m.date, m.value])
|
||||
: accumulateFromEndingTotal(count, total)
|
||||
}
|
||||
]} />
|
||||
</div>
|
||||
{/if}
|
||||
</Card>
|
||||
</Layout.Stack>
|
||||
|
||||
<style lang="scss">
|
||||
.chart-container {
|
||||
height: 12rem;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,68 @@
|
||||
import { ProjectUsageRange, type Models } from '@appwrite.io/console';
|
||||
|
||||
export type UsagePeriods = '24h' | '30d' | '90d';
|
||||
|
||||
export function periodToDates(period: UsagePeriods): {
|
||||
start: string;
|
||||
end: string;
|
||||
period: ProjectUsageRange;
|
||||
} {
|
||||
const start = new Date();
|
||||
switch (period) {
|
||||
case '24h':
|
||||
start.setUTCHours(start.getHours() - 24);
|
||||
break;
|
||||
case '30d':
|
||||
start.setUTCHours(0, 0, 0, 0);
|
||||
start.setUTCDate(start.getDate() - 30);
|
||||
break;
|
||||
case '90d':
|
||||
start.setUTCHours(0, 0, 0, 0);
|
||||
start.setUTCDate(start.getDate() - 90);
|
||||
break;
|
||||
}
|
||||
const end = new Date();
|
||||
end.setUTCDate(end.getUTCDate() + 1);
|
||||
end.setUTCHours(0, 0, 0, 0);
|
||||
return {
|
||||
start: start.toISOString(),
|
||||
end: end.toISOString(),
|
||||
period: period === '24h' ? ProjectUsageRange.OneHour : ProjectUsageRange.OneDay
|
||||
};
|
||||
}
|
||||
|
||||
export function last(set: Models.Metric[]): Models.Metric | null {
|
||||
if (!set) return null;
|
||||
return set.slice(-1)[0] ?? null;
|
||||
}
|
||||
|
||||
export function total(set: Models.Metric[]): number {
|
||||
return set?.reduce((prev, curr) => prev + curr.value, 0) ?? 0;
|
||||
}
|
||||
|
||||
export function accumulateFromEndingTotal(
|
||||
metrics: Models.Metric[],
|
||||
endingTotal: number,
|
||||
startingDayToFillZero: Date = null
|
||||
): Array<[string, number]> {
|
||||
return (metrics ?? []).reduceRight(
|
||||
(acc, curr) => {
|
||||
if (startingDayToFillZero !== null && startingDayToFillZero instanceof Date) {
|
||||
const date = new Date(curr.date);
|
||||
if (date > startingDayToFillZero) {
|
||||
acc.data.unshift([date.toISOString(), 0]);
|
||||
acc.total -= 0;
|
||||
|
||||
return acc;
|
||||
}
|
||||
}
|
||||
acc.data.unshift([curr.date, acc.total]);
|
||||
acc.total -= curr.value;
|
||||
return acc;
|
||||
},
|
||||
{
|
||||
total: endingTotal,
|
||||
data: []
|
||||
}
|
||||
).data;
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/state';
|
||||
import { BarChart, Legend, type LegendData } from '$lib/charts';
|
||||
import { Card, SecondaryTabs, SecondaryTabsItem } from '$lib/components';
|
||||
import { clampMin, formatNumberWithCommas } from '$lib/helpers/numbers';
|
||||
import { accumulateFromEndingTotal } from '$lib/layout/usage.svelte';
|
||||
import { type Models } from '@appwrite.io/console';
|
||||
import { Layout, Typography } from '@appwrite.io/pink-svelte';
|
||||
import type { EChartsOption } from 'echarts';
|
||||
|
||||
type Props = {
|
||||
title: string;
|
||||
total: number[];
|
||||
path?: string | null;
|
||||
count: Models.Metric[][];
|
||||
legendData: LegendData[];
|
||||
showHeader?: boolean;
|
||||
legendNumberFormat?: 'comma' | 'abbreviate';
|
||||
isCumulative?: boolean;
|
||||
options?: EChartsOption | null;
|
||||
};
|
||||
|
||||
let {
|
||||
title,
|
||||
total,
|
||||
path = null,
|
||||
count,
|
||||
legendData,
|
||||
showHeader = true,
|
||||
legendNumberFormat = 'comma',
|
||||
isCumulative = true,
|
||||
options = null
|
||||
}: Props = $props();
|
||||
|
||||
const formatted = $derived(page.params.period === '24h' ? 'hours' : 'days');
|
||||
const totalCount = $derived(clampMin(total.reduce((a, b) => a + b, 0)));
|
||||
const series = $derived(
|
||||
count.map((metrics, index) => ({
|
||||
name: legendData[index].name,
|
||||
data: isCumulative
|
||||
? accumulateFromEndingTotal(metrics, total[index])
|
||||
: metrics.map((metric) => [metric.date, metric.value])
|
||||
}))
|
||||
);
|
||||
</script>
|
||||
|
||||
<div>
|
||||
{#if showHeader}
|
||||
<div class="u-flex u-main-space-between common-section">
|
||||
<Typography.Title>{title}</Typography.Title>
|
||||
|
||||
{#if path}
|
||||
<SecondaryTabs>
|
||||
<SecondaryTabsItem href={`${path}/24h`} disabled={page.params.period === '24h'}>
|
||||
24h
|
||||
</SecondaryTabsItem>
|
||||
<SecondaryTabsItem
|
||||
href={`${path}/30d`}
|
||||
disabled={!page.params.period || page.params.period === '30d'}>
|
||||
30d
|
||||
</SecondaryTabsItem>
|
||||
<SecondaryTabsItem href={`${path}/90d`} disabled={page.params.period === '90d'}>
|
||||
90d
|
||||
</SecondaryTabsItem>
|
||||
</SecondaryTabs>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<Card>
|
||||
{#if count}
|
||||
<Layout.Stack gap="xs">
|
||||
<Typography.Title>{formatNumberWithCommas(totalCount)}</Typography.Title>
|
||||
<Typography.Text>Total {title.toLocaleLowerCase()}</Typography.Text>
|
||||
</Layout.Stack>
|
||||
<div class="multiple-chart-container u-flex-vertical u-gap-16">
|
||||
<BarChart {formatted} {options} {series} />
|
||||
|
||||
{#if legendData}
|
||||
<Legend
|
||||
{legendData}
|
||||
decimalsForAbbreviate={2}
|
||||
numberFormat={legendNumberFormat} />
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
<style lang="scss">
|
||||
.multiple-chart-container {
|
||||
height: 12rem;
|
||||
}
|
||||
|
||||
:global(.multiple-chart-container .echart) {
|
||||
margin-top: -1em;
|
||||
margin-bottom: -1em;
|
||||
}
|
||||
</style>
|
||||
@@ -15,7 +15,7 @@
|
||||
import { organization } from '$lib/stores/organization';
|
||||
import ProjectBreakdown from './ProjectBreakdown.svelte';
|
||||
import { formatNum } from '$lib/helpers/string';
|
||||
import { accumulateFromEndingTotal, total } from '$lib/layout/usage.svelte';
|
||||
import { accumulateFromEndingTotal, total } from '$lib/layout/usageHelpers';
|
||||
import { Click, trackEvent } from '$lib/actions/analytics';
|
||||
import TotalMembers from './totalMembers.svelte';
|
||||
import { formatCurrency, formatNumberWithCommas } from '$lib/helpers/numbers';
|
||||
|
||||
+1
-2
@@ -1,6 +1,6 @@
|
||||
import { writable } from 'svelte/store';
|
||||
import type { Column } from '$lib/helpers/types';
|
||||
import { IconChartBar, IconCloudUpload, IconCog } from '@appwrite.io/pink-icons-svelte';
|
||||
import { IconCloudUpload, IconCog } from '@appwrite.io/pink-icons-svelte';
|
||||
import { resolveRoute, withPath } from '$lib/stores/navigation';
|
||||
import type { Page } from '@sveltejs/kit';
|
||||
import { type Models, Query } from '@appwrite.io/console';
|
||||
@@ -104,7 +104,6 @@ export const customRetainingOptions = [
|
||||
|
||||
export const databaseSubNavigationItems = [
|
||||
{ title: 'Backups', href: 'backups', icon: IconCloudUpload },
|
||||
{ title: 'Usage', href: 'usage', icon: IconChartBar },
|
||||
{ title: 'Settings', href: 'settings', icon: IconCog }
|
||||
];
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
import Bandwidth from './bandwidth.svelte';
|
||||
import Requests from './requests.svelte';
|
||||
import { usage } from './store';
|
||||
import { periodToDates } from '$lib/layout/usage.svelte';
|
||||
import { periodToDates } from '$lib/layout/usageHelpers';
|
||||
import { canWriteProjects } from '$lib/stores/roles';
|
||||
import { Card, Layout, Typography } from '@appwrite.io/pink-svelte';
|
||||
import { writable, type Writable } from 'svelte/store';
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
import { bytesToSize, humanFileSize, mbSecondsToGBHours } from '$lib/helpers/sizeConvertion';
|
||||
import { BarChart, Legend } from '$lib/charts';
|
||||
import { formatNum } from '$lib/helpers/string';
|
||||
import { total } from '$lib/layout/usage.svelte';
|
||||
import { total } from '$lib/layout/usageHelpers';
|
||||
import { base } from '$app/paths';
|
||||
import { formatCurrency, formatNumberWithCommas, clampMin } from '$lib/helpers/numbers';
|
||||
import { getCountryName } from '$lib/helpers/diallingCodes.js';
|
||||
|
||||
Reference in new issue
Block a user