From b5c93d0e4741158b71e2883c905ac57a9158a560 Mon Sep 17 00:00:00 2001 From: Aditya Hegde Date: Thu, 19 Dec 2024 18:32:51 +0530 Subject: [PATCH] Improve navigation --- .../features/billing/plans/PlanQuotas.svelte | 20 +++++---- .../src/features/navigation/nav-utils.ts | 4 ++ .../-/project-breakdown/+page.ts | 34 --------------- .../+page.svelte | 0 .../-/projects-breakdown/+page.ts | 41 +++++++++++++++++++ 5 files changed, 58 insertions(+), 41 deletions(-) delete mode 100644 web-admin/src/routes/[organization]/-/project-breakdown/+page.ts rename web-admin/src/routes/[organization]/-/{project-breakdown => projects-breakdown}/+page.svelte (100%) create mode 100644 web-admin/src/routes/[organization]/-/projects-breakdown/+page.ts diff --git a/web-admin/src/features/billing/plans/PlanQuotas.svelte b/web-admin/src/features/billing/plans/PlanQuotas.svelte index 49578daac40..4f00c4e8f70 100644 --- a/web-admin/src/features/billing/plans/PlanQuotas.svelte +++ b/web-admin/src/features/billing/plans/PlanQuotas.svelte @@ -39,9 +39,9 @@ {#if $usageMetrics?.data} - {#if singleProjectLimit && storageLimitBytesPerDeployment && storageLimitBytesPerDeployment !== "-1"} -
-
Data Size
+
+
Data Size
+ {#if singleProjectLimit && storageLimitBytesPerDeployment && storageLimitBytesPerDeployment !== "-1"}
{formatUsageVsQuota(totalOrgUsage, storageLimitBytesPerDeployment)}
-
- {:else} - - {/if} + {:else} + + See project size breakdown + + {/if} +
{/if} diff --git a/web-admin/src/features/navigation/nav-utils.ts b/web-admin/src/features/navigation/nav-utils.ts index c7752ad9676..787c31bda13 100644 --- a/web-admin/src/features/navigation/nav-utils.ts +++ b/web-admin/src/features/navigation/nav-utils.ts @@ -27,6 +27,10 @@ export function isProjectPage(page: Page): boolean { ); } +export function isProjectsBreakdownPage(page: Page): boolean { + return page.route.id === "/[organization]/-/projects-breakdown"; +} + export function withinProject(page: Page): boolean { return !!page.route?.id?.startsWith("/[organization]/[project]"); } diff --git a/web-admin/src/routes/[organization]/-/project-breakdown/+page.ts b/web-admin/src/routes/[organization]/-/project-breakdown/+page.ts deleted file mode 100644 index 0593053512a..00000000000 --- a/web-admin/src/routes/[organization]/-/project-breakdown/+page.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { - adminServiceGetBillingProjectCredentials, - getAdminServiceGetBillingProjectCredentialsQueryKey, -} from "@rilldata/web-admin/client"; -import { queryClient } from "@rilldata/web-common/lib/svelte-query/globalQueryClient"; -import { fixLocalhostRuntimePort } from "@rilldata/web-common/runtime-client/fix-localhost-runtime-port"; -import type { Runtime } from "@rilldata/web-common/runtime-client/runtime-store"; - -export const load = async ({ params, parent }) => { - const { organizationPermissions } = await parent(); - if (!organizationPermissions.manageProjects) { - // TODO - } - const { organization } = params; - const billingProjectCredsResp = await queryClient.fetchQuery({ - queryKey: getAdminServiceGetBillingProjectCredentialsQueryKey({ - organization, - }), - queryFn: () => adminServiceGetBillingProjectCredentials({ organization }), - }); - const runtime: Runtime = { - host: fixLocalhostRuntimePort(billingProjectCredsResp.runtimeHost), - instanceId: billingProjectCredsResp.instanceId, - jwt: { - token: billingProjectCredsResp.accessToken, - authContext: "embed", - receivedAt: Date.now(), - }, - }; - - return { - runtime, - }; -}; diff --git a/web-admin/src/routes/[organization]/-/project-breakdown/+page.svelte b/web-admin/src/routes/[organization]/-/projects-breakdown/+page.svelte similarity index 100% rename from web-admin/src/routes/[organization]/-/project-breakdown/+page.svelte rename to web-admin/src/routes/[organization]/-/projects-breakdown/+page.svelte diff --git a/web-admin/src/routes/[organization]/-/projects-breakdown/+page.ts b/web-admin/src/routes/[organization]/-/projects-breakdown/+page.ts new file mode 100644 index 00000000000..470df896805 --- /dev/null +++ b/web-admin/src/routes/[organization]/-/projects-breakdown/+page.ts @@ -0,0 +1,41 @@ +import { + adminServiceGetBillingProjectCredentials, + getAdminServiceGetBillingProjectCredentialsQueryKey, +} from "@rilldata/web-admin/client"; +import { queryClient } from "@rilldata/web-common/lib/svelte-query/globalQueryClient"; +import { fixLocalhostRuntimePort } from "@rilldata/web-common/runtime-client/fix-localhost-runtime-port"; +import type { Runtime } from "@rilldata/web-common/runtime-client/runtime-store"; +import { error } from "@sveltejs/kit"; + +export const load = async ({ params, parent }) => { + const { organizationPermissions } = await parent(); + if (!organizationPermissions.manageProjects) { + throw error(404, "Page not found"); + } + + try { + const { organization } = params; + const billingProjectCredsResp = await queryClient.fetchQuery({ + queryKey: getAdminServiceGetBillingProjectCredentialsQueryKey({ + organization, + }), + queryFn: () => adminServiceGetBillingProjectCredentials({ organization }), + }); + const runtime: Runtime = { + host: fixLocalhostRuntimePort(billingProjectCredsResp.runtimeHost), + instanceId: billingProjectCredsResp.instanceId, + jwt: { + token: billingProjectCredsResp.accessToken, + authContext: "embed", + receivedAt: Date.now(), + }, + }; + + return { + runtime, + }; + } catch (err) { + const statusCode = err?.response?.status || 500; + throw error(statusCode, "Failed to fetch project breakdown"); + } +};