@@ -3,7 +3,11 @@ import { type Project } from "~/models/project.server";
33import { type User } from "~/models/user.server" ;
44import { FEATURE_FLAG } from "~/v3/featureFlags" ;
55import { makeFlag } from "~/v3/featureFlags.server" ;
6- import { defaultVisibilityFilter , resolveComputeAccess } from "~/v3/regionAccess.server" ;
6+ import {
7+ defaultVisibilityFilter ,
8+ resolveComputeAccess ,
9+ resolveEffectiveDefaultWorkerGroupId ,
10+ } from "~/v3/regionAccess.server" ;
711import { BasePresenter } from "./basePresenter.server" ;
812import { getCurrentPlan } from "~/services/platform.v3.server" ;
913
@@ -24,10 +28,12 @@ export class RegionsPresenter extends BasePresenter {
2428 public async call ( {
2529 userId,
2630 projectSlug,
31+ environmentId,
2732 isAdmin = false ,
2833 } : {
2934 userId : User [ "id" ] ;
3035 projectSlug : Project [ "slug" ] ;
36+ environmentId ?: string ;
3137 isAdmin ?: boolean ;
3238 } ) {
3339 const project = await this . _replica . project . findFirst ( {
@@ -65,6 +71,20 @@ export class RegionsPresenter extends BasePresenter {
6571 throw new Error ( "Default worker instance group not found" ) ;
6672 }
6773
74+ const environment = environmentId
75+ ? await this . _replica . runtimeEnvironment . findFirst ( {
76+ select : { defaultWorkerGroupId : true } ,
77+ where : { id : environmentId } ,
78+ } )
79+ : null ;
80+
81+ // env default -> project default -> global default
82+ const effectiveDefaultId = resolveEffectiveDefaultWorkerGroupId ( {
83+ environmentDefaultWorkerGroupId : environment ?. defaultWorkerGroupId ,
84+ projectDefaultWorkerGroupId : project . defaultWorkerGroupId ,
85+ globalDefaultWorkerGroupId : defaultWorkerInstanceGroupId ,
86+ } ) ;
87+
6888 const hasComputeAccess = await resolveComputeAccess (
6989 this . _replica ,
7090 project . organization . featureFlags
@@ -103,12 +123,14 @@ export class RegionsPresenter extends BasePresenter {
103123 cloudProvider : region . cloudProvider ?? undefined ,
104124 location : region . location ?? undefined ,
105125 staticIPs : region . staticIPs ?? undefined ,
106- isDefault : region . id === defaultWorkerInstanceGroupId ,
126+ isDefault : region . id === effectiveDefaultId ,
107127 isHidden : region . hidden ,
108128 workloadType : region . workloadType ,
109129 } ) ) ;
110130
111- if ( project . defaultWorkerGroupId ) {
131+ // The effective default may not be in the visible list (e.g. a hidden
132+ // region set as the env/project default) — fetch and include it.
133+ if ( effectiveDefaultId && ! regions . some ( ( region ) => region . id === effectiveDefaultId ) ) {
112134 const defaultWorkerGroup = await this . _replica . workerInstanceGroup . findFirst ( {
113135 select : {
114136 id : true ,
@@ -121,16 +143,10 @@ export class RegionsPresenter extends BasePresenter {
121143 hidden : true ,
122144 workloadType : true ,
123145 } ,
124- where : { id : project . defaultWorkerGroupId } ,
146+ where : { id : effectiveDefaultId } ,
125147 } ) ;
126148
127149 if ( defaultWorkerGroup ) {
128- // Unset the default region
129- const defaultRegion = regions . find ( ( region ) => region . isDefault ) ;
130- if ( defaultRegion ) {
131- defaultRegion . isDefault = false ;
132- }
133-
134150 regions . push ( {
135151 id : defaultWorkerGroup . id ,
136152 name : defaultWorkerGroup . name ,
0 commit comments