remove: hardcoded project region.

This commit is contained in:
Darshan
2025-03-16 18:32:27 +05:30
parent 67dbebc331
commit f391888987
2 changed files with 18 additions and 12 deletions
@@ -56,7 +56,7 @@ export const load: PageLoad = async ({ params, parent }) => {
sdk.forConsole.billing.getOrganizationPlan(org.$id)
]);
const projectNames: { [key: string]: Models.Project } = {};
const projects: { [key: string]: Models.Project } = {};
if (usage?.projects?.length > 0) {
// in batches of 100 (the max number of values in a query)
const requests = [];
@@ -75,17 +75,17 @@ export const load: PageLoad = async ({ params, parent }) => {
const responses = await Promise.all(requests);
for (const response of responses) {
for (const project of response.projects) {
projectNames[project.$id] = project;
projects[project.$id] = project;
}
}
}
return {
organizationUsage: usage,
projectNames,
plan,
invoices,
projects,
currentInvoice,
organizationMembers,
plan
organizationUsage: usage
};
};
@@ -46,10 +46,15 @@
}
}
function getProjectUsageLink(region: string, projectId: string): string {
function getProjectUsageLink(projectId: string): string {
const region = data.projects[projectId]?.region ?? 'fra';
return `${base}/project-${region}-${projectId}/settings/usage`;
}
function getProjectName(projectId: string): string {
return data.projects[projectId]?.name ?? 'Unknown';
}
function groupByProject(
metric: Metric | undefined,
estimate?: Estimate,
@@ -63,12 +68,14 @@
}> {
const data = [];
for (const project of projects) {
const projectId = project.projectId;
if (metric) {
const usage = project[metric];
if (!usage) continue;
data.push({
projectId: project.projectId,
projectId,
usage: usage ?? 0,
estimate: estimate ? project[estimate] : undefined
});
@@ -78,7 +85,7 @@
if (reads || writes) {
data.push({
projectId: project.projectId,
projectId,
databasesReads: reads,
databasesWrites: writes
});
@@ -143,7 +150,7 @@
{#if !$canSeeProjects}
<TableRow>
<TableCell title="Project">
{data.projectNames[project.projectId]?.name ?? 'Unknown'}
{getProjectName(project.projectId)}
</TableCell>
{#if databaseOperationMetric}
<TableCell title="Reads">
@@ -165,10 +172,9 @@
{/if}
</TableRow>
{:else}
<!-- TODO: hardcoded region -->
<TableRowLink href={getProjectUsageLink('fra1', project.projectId)}>
<TableRowLink href={getProjectUsageLink(project.projectId)}>
<TableCell title="Project">
{data.projectNames[project.projectId]?.name ?? 'Unknown'}
{getProjectName(project.projectId)}
</TableCell>
{#if databaseOperationMetric}
<TableCell title="Reads">