Skip to content

Fix: region based url being undefined in the URL #1811

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
50 changes: 26 additions & 24 deletions src/lib/components/regionEndpoint.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,30 @@
: '';
</script>

<Copy value={getProjectEndpoint()} appendTo="parent" copyText="Copy endpoint">
<div
class="flex u-gap-8 u-cross-center interactive-text-output is-buttons-on-top u-text-center"
style:min-inline-size="0"
style:display="inline-flex">
<span
style:white-space="nowrap"
class="text u-line-height-1-5"
style:overflow="hidden"
style:word-break="break-all"
use:truncateText
style:font-family="unset">
{$projectRegion?.name}
</span>
{#if $projectRegion}
<Copy value={getProjectEndpoint()} appendTo="parent" copyText="Copy endpoint">
<div
class="flex u-gap-8 u-cross-center interactive-text-output is-buttons-on-top u-text-center"
style:min-inline-size="0"
style:display="inline-flex">
<span
style:white-space="nowrap"
class="text u-line-height-1-5"
style:overflow="hidden"
style:word-break="break-all"
use:truncateText
style:font-family="unset">
{$projectRegion?.name}
</span>

{#if flagSrc}
<img
style="border-radius: 2.5px"
src={flagSrc}
alt={$projectRegion?.name}
width={16}
height={12} />
{/if}
</div>
</Copy>
{#if flagSrc}
<img
style="border-radius: 2.5px"
src={flagSrc}
alt={$projectRegion?.name}
width={16}
height={12} />
{/if}
</div>
</Copy>
{/if}
20 changes: 14 additions & 6 deletions src/routes/(console)/organization-[organization]/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,22 @@ export const load: PageLoad = async ({ params, url, route, depends, parent }) =>
return redirect(301, `/console/organization-${params.organization}/billing`);
}

const projects = await sdk.forConsole.projects.list([
Query.offset(offset),
Query.equal('teamId', params.organization),
Query.limit(limit),
Query.orderDesc('')
]);

// set `default` or something else,
// `undefined` in the url looks really off!
for (const project of projects.projects) {
project.region ??= 'default';
}

return {
offset,
limit,
projects: await sdk.forConsole.projects.list([
Query.offset(offset),
Query.equal('teamId', params.organization),
Query.limit(limit),
Query.orderDesc('')
])
projects
};
};
4 changes: 3 additions & 1 deletion src/routes/(console)/regions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { get } from 'svelte/store';
import { sdk } from '$lib/stores/sdk';
import { isCloud } from '$lib/system';
import { regions } from '$lib/stores/organization';

let lastLoadedOrganization = null;
Expand All @@ -10,10 +11,11 @@ let lastLoadedOrganization = null;
* Prevents unnecessary API calls if the regions are already loaded for the same organization.
*/
export async function loadAvailableRegions(orgId: string): Promise<void> {
if (!isCloud) return;

try {
const storedRegions = get(regions);

// note that regions can vary based on an organization's plan!
if (storedRegions?.regions && lastLoadedOrganization === orgId) {
// already loaded for this organization, fast path return.
return;
Expand Down