Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add project breakdown page #6310

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions web-admin/src/features/billing/plans/PlanQuotas.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,26 @@
</div>

{#if $usageMetrics?.data}
{#if singleProjectLimit && storageLimitBytesPerDeployment && storageLimitBytesPerDeployment !== "-1"}
<div class="quota-entry">
<div class="quota-entry-title">Data Size</div>
<div class="quota-entry">
<div class="quota-entry-title">Data Size</div>
{#if singleProjectLimit && storageLimitBytesPerDeployment && storageLimitBytesPerDeployment !== "-1"}
<div>
<Progress
value={totalOrgUsage}
max={Number(storageLimitBytesPerDeployment)}
/>
{formatUsageVsQuota(totalOrgUsage, storageLimitBytesPerDeployment)}
</div>
</div>
{:else}
<!-- TODO: once we have the dashboard support link to it -->
{/if}
{:else}
<a
href={`/${organization}/-/projects-breakdown`}
class="text-primary-600 text-xs"
data-sveltekit-preload-data="off"
>
See project size breakdown
</a>
{/if}
</div>
{/if}
</div>

Expand Down
4 changes: 4 additions & 0 deletions web-admin/src/features/navigation/nav-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script lang="ts">
import ExploreEmbed from "@rilldata/web-admin/features/embeds/ExploreEmbed.svelte";
import { useValidExplores } from "@rilldata/web-common/features/dashboards/selectors";
import { runtime } from "@rilldata/web-common/runtime-client/runtime-store";

$: instanceId = $runtime.instanceId;
$: explores = useValidExplores(instanceId);
$: exploreName = $explores.data?.[0]?.meta?.name?.name;
</script>

{#if exploreName}
<ExploreEmbed {instanceId} {exploreName} />
{/if}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<script lang="ts">
import ProjectBreakdownDashboard from "@rilldata/web-admin/features/organizations/project-breakdown/ProjectBreakdownDashboard.svelte";
import { queryClient } from "@rilldata/web-common/lib/svelte-query/globalQueryClient";
import { invalidateRuntimeQueries } from "@rilldata/web-common/runtime-client/invalidation";
import RuntimeProvider from "@rilldata/web-common/runtime-client/RuntimeProvider.svelte";
import type { PageData } from "./$types";

export let data: PageData;
$: ({ runtime } = data);
// Seeing the data using the same project but with different jwt will not get automatically invalidated.
// Since we do not have jwt as part of the query key we need to invalidate the queries for this instanceId
$: invalidateRuntimeQueries(queryClient, runtime.instanceId);
</script>

<RuntimeProvider
instanceId={runtime.instanceId}
host={runtime.host}
jwt={runtime.jwt.token}
authContext={runtime.jwt.authContext}
>
<ProjectBreakdownDashboard />
</RuntimeProvider>
41 changes: 41 additions & 0 deletions web-admin/src/routes/[organization]/-/projects-breakdown/+page.ts
Original file line number Diff line number Diff line change
@@ -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");
}
};
Loading