Skip to content

Conversation

@ivan-ottinger
Copy link
Contributor

@ivan-ottinger ivan-ottinger commented Aug 6, 2025

Related issues

Proposed Changes

Pressable is no longer setting sandbox environment type for their sandbox sites. Instead, these sites are now using the development environment type. Because of that, we are adjusting the related environment badges in Studio to use Development badge for sites with development environment type set.

Related discussion: p1753471348570109-slack-C08AHBHGDEZ.

Together with this change we are also removing support for the local environment type (and related badge and Push / Pull modal copy). Only the following three environment types will be represented in badges: Production, Staging and Development. All other environments, including local will use Production as their badge.

We are also adjusting the logic of getSiteEnvironment to rely on site.isStaging for WordPress.com sites - instead of environment type. More context can be found here.

Testing Instructions

  1. Check out the PR branch and build the app with npm start.

Testing with Pressable site

  1. Connect one of your Pressable sites to one of your Studio sites.
  2. Through the Network Admin's Settings tab, change the jetpack_callable_wp_get_environment_type of your connected Pressable sits to any value (e.g. local, staging, production, development).
  3. When reviewing the site badge in Studio:
  • if the development environment type is used, the Development badge should be rendered and use the blue color that was previously used for Sandbox badges
  • if the local environment type is used, the site should have the Production badge; if you click the Push / Pull button, the copy for the production site should be displayed in the modal (not for local)
  • staging and production environment types should be respected and related badges displayed in Studio UI

Testing with WordPress.com site

  1. Connect one of your WordPress.com sites (that has staging site linked) to one of your Studio sites.
  2. The Production and Staging badges should render correctly in Studio.

General

  1. Badges displayed in the Sync modal should be consistent with badges in the list of already-connected sites on the Sync tab.

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

@ivan-ottinger ivan-ottinger self-assigned this Aug 6, 2025
@ivan-ottinger ivan-ottinger changed the title Simplify Environment badge logic and replace the sandbox environment type with development Replace the sandbox environment type with development and simplify Environment badge logic Aug 6, 2025
@ivan-ottinger ivan-ottinger requested a review from a team August 6, 2025 13:24
Copy link
Member

@sejas sejas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, Ivan! The code looks clean and simple. I tested it, and it works well except for an edge case. If a WPcom user set a custom environment type, Studio displays different labels in the sites modal and in the connected sites screens.

I think we should be consistent and display always the environment type set by the user.

Happy Path works great

Screenshot 2025-08-06 at 15 08 28

Inconsistent results for WPcom sites with custom labels

Screenshot 2025-08-06 at 15 29 38 Screenshot 2025-08-06 at 15 29 42

It seems we should update the code in

{ ! isPressable && (
<>
<EnvironmentBadge type="production" selected={ isSelected } />
{ site.stagingSiteIds.length > 0 && (
<EnvironmentBadge type="staging" selected={ isSelected } />
) }
</>
) }
{ isPressable && (
<EnvironmentBadge type={ getSiteEnvironment( site ) } selected={ isSelected } />
) }

@ivan-ottinger
Copy link
Contributor Author

Thank you for the review, Antonio!

I tested it, and it works well except for an edge case. If a WPcom user set a custom environment type, Studio displays different labels in the sites modal and in the connected sites screens.

I think we should be consistent and display always the environment type set by the user.

Indeed! That's a great catch! Thank you for noticing that. I will address it tomorrow morning. 🙂

@wojtekn
Copy link
Contributor

wojtekn commented Aug 6, 2025

What happens if the user sets this variable to an unsupported environment type?

return connectedSite.environmentType ?? 'production';
}
return connectedSite.isStaging ? 'staging' : 'production';
return connectedSite.environmentType ?? 'production';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sejas
Copy link
Member

sejas commented Aug 6, 2025

What happens if the user sets this variable to an unsupported environment type?

If the environment type is not supported, I suggest that Studio will display the badge as Production.
I added the check in my PR https://github.com/Automattic/studio/pull/1648/files#diff-d7212615886d109b1f34adab097f47d9877e00f7e088fbef173bc190cb37ab8a

const EnvironmentSchema = z.enum( [ 'production', 'staging', 'development', 'local' ] );
export type EnvironmentType = z.infer< typeof EnvironmentSchema >;

export const getSiteEnvironment = ( site: SyncSite ): EnvironmentType => {
	const parsed = EnvironmentSchema.safeParse( site.environmentType );
	return parsed.success ? parsed.data : 'production';
};

@ivan-ottinger ivan-ottinger changed the title Replace the sandbox environment type with development and simplify Environment badge logic Replace the Sandbox environment badge with Development and ensure all envrionment_type values are respected Aug 7, 2025
@sejas
Copy link
Member

sejas commented Aug 7, 2025

@ivan-ottinger , I've merged #1648

@ivan-ottinger ivan-ottinger force-pushed the update/environment-badge-logic branch from 9e3036b to cc9f76f Compare August 7, 2025 10:41
@ivan-ottinger
Copy link
Contributor Author

@ivan-ottinger , I've merged #1648

Thank you, Antonio. This PR is now ready for another review round. I have also updated the PR title, description and testing instructions.

Copy link
Member

@sejas sejas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ivan-ottinger , I tested the PR and works great. I see the real Environment type in the modal and when the site is connected.
I left a suggestion about removing renderStagingSiteBadge. It's not a strong opinion, so let me know what you think.

Screenshot 2025-08-07 at 15 17 48 Screenshot 2025-08-07 at 15 17 42

@wojtekn
Copy link
Contributor

wojtekn commented Aug 8, 2025

@ivan-ottinger @sejas the part with supporting "local" as a type of remote environment seems a bit weird.

Should we diverge from core here and support only labels that make sense as labels used by WordPress.com or Pressable (production, staging, development), and ignore the rest? Or take a step back and only support labels that we show in the WordPress.com sites dashboard, so we would go back to using production and staging?

@ivan-ottinger
Copy link
Contributor Author

[...] the part with supporting "local" as a type of remote environment seems a bit weird.

I see what you mean.

Should we diverge from core here and support only labels that make sense as labels used by WordPress.com or Pressable (production, staging, development), and ignore the rest?

If I am understand your point of view correctly, in the case of local environment type (or some other non-core value) we would not display any badge, right?

In that case we would need to rethink the copy displayed on the sync modal as well though. Instead of Push to Development it could say Push to {site-title / site-url}

Curious to hear what Antonio thinks as well.

@wojtekn
Copy link
Contributor

wojtekn commented Aug 8, 2025

@ivan-ottinger maybe we should follow what @sejas proposed above?

  • production -> Production
  • staging -> Staging
  • development -> Development
  • anything else -> Production

@ivan-ottinger
Copy link
Contributor Author

@ivan-ottinger maybe we should follow what @sejas proposed above?

  • production -> Production
  • staging -> Staging
  • development -> Development
  • anything else -> Production

Yes, that should work. 👍🏼


There's one issue I have observed with relying on the environment_type for WordPress.com sites:

With the current staging site sync logic (on the WordPress.com side), the environment_type is synced as well. As a result we end up with both sites having the Production badge (as an example):

Markup on 2025-08-08 at 13:20:25

We could adjust the getSiteEnvironment change introduced in https://github.com/Automattic/studio/pull/1648/files#diff-d7212615886d109b1f34adab097f47d9877e00f7e088fbef173bc190cb37ab8aR8-R10. to still rely on connectedSite.isStaging for WordPress.com sites.

@wojtekn
Copy link
Contributor

wojtekn commented Aug 8, 2025

Good catch @ivan-ottinger . It makes sense to have such a series of fallbacks indeed.

@sejas
Copy link
Member

sejas commented Aug 8, 2025

I see both solutions can be a bit confusing for some users, but keeping the old logic that limited WPcom to only use production and staging seems the most reasonable.
Just leaving here why the other approach also made sense. It seems that the environment type is displayed in Calypso overview for Agency sites. See the screenshots p1752755426181769/1752734657.162979-slack-C06DRMD6VPZ

@ivan-ottinger ivan-ottinger changed the title Replace the Sandbox environment badge with Development and ensure all envrionment_type values are respected Update environment types and related badge handling Aug 8, 2025
@ivan-ottinger
Copy link
Contributor Author

I see both solutions can be a bit confusing for some users, but keeping the old logic that limited WPcom to only use production and staging seems the most reasonable.

Yes, I agree that neither of the two solutions is 100% ideal.

I have updated the PR (including the title, description and testing instructions). Feel free to take another look if you like.

Copy link
Member

@sejas sejas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ivan-ottinger , great work! 🚢
WPcom sites will display only Production and Staging based on isStaging.
Pressable sites will display any valid Studio environment type (Production, Staging, Development).

@ivan-ottinger ivan-ottinger merged commit 109fddc into trunk Aug 8, 2025
12 checks passed
@ivan-ottinger ivan-ottinger deleted the update/environment-badge-logic branch August 8, 2025 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants