Skip to content

Commit 69453b4

Browse files
committed
fix(webapp): explain when no Vercel environment can be mapped to Staging
The Staging build settings show "Set a Vercel environment for Staging first." whenever the project has a staging environment and no mapping, but the control that sets the mapping only rendered when the Vercel project had at least one custom environment. A project with none - or one whose custom environments could not be fetched - got an instruction with nothing to act on. The mapping row now always renders alongside that hint, and says what to do when there is nothing to choose from. The build settings hint matches. TRI-13488
1 parent 7c40441 commit 69453b4

1 file changed

Lines changed: 64 additions & 50 deletions

File tree

apps/webapp/app/routes/resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.vercel.tsx

Lines changed: 64 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -822,9 +822,15 @@ function ConnectedVercelProjectForm({
822822
hasPreviewEnvironment
823823
);
824824

825+
const hasVercelCustomEnvironments = customEnvironments.length > 0;
826+
825827
const disabledEnvSlugsForBuildSettings: Partial<Record<EnvSlug, string>> | undefined =
826828
hasStagingEnvironment && !configValues.vercelStagingEnvironment
827-
? { stg: "Set a Vercel environment for Staging first." }
829+
? {
830+
stg: hasVercelCustomEnvironments
831+
? "Set a Vercel environment for Staging first."
832+
: "Add a custom environment to this project in Vercel to use Staging.",
833+
}
828834
: undefined;
829835

830836
return (
@@ -935,60 +941,68 @@ function ConnectedVercelProjectForm({
935941
ref={clearTriggerVersionInputRef}
936942
/>
937943

938-
{/* Staging environment mapping */}
939-
{hasStagingEnvironment && customEnvironments && customEnvironments.length > 0 && (
944+
{hasStagingEnvironment && (
940945
<SettingsRow
941946
title="Vercel environment for Staging"
942947
description="Required to enable the Staging options below."
943948
action={
944-
<div data-unlock-target="staging-env">
945-
<Select
946-
value={configValues.vercelStagingEnvironment?.environmentId || ""}
947-
setValue={(value) => {
948-
if (!Array.isArray(value)) {
949-
const env = customEnvironments?.find((e) => e.id === value);
950-
setConfigValues((prev) => {
951-
const next = {
952-
...prev,
953-
vercelStagingEnvironment: env
954-
? { environmentId: env.id, displayName: env.slug }
955-
: null,
956-
};
957-
// When clearing the staging mapping, strip "stg" from build settings
958-
if (!env) {
959-
next.pullEnvVarsBeforeBuild = prev.pullEnvVarsBeforeBuild.filter(
960-
(s) => s !== "stg"
961-
);
962-
next.discoverEnvVars = prev.discoverEnvVars.filter((s) => s !== "stg");
963-
}
964-
return next;
965-
});
949+
!hasVercelCustomEnvironments ? (
950+
<Paragraph variant="extra-small" className="w-64">
951+
This Vercel project has no custom environments. Add one in Vercel under Settings{" "}
952+
&rarr; Environments, then reload this page.
953+
</Paragraph>
954+
) : (
955+
<div data-unlock-target="staging-env">
956+
<Select
957+
value={configValues.vercelStagingEnvironment?.environmentId || ""}
958+
setValue={(value) => {
959+
if (!Array.isArray(value)) {
960+
const env = customEnvironments?.find((e) => e.id === value);
961+
setConfigValues((prev) => {
962+
const next = {
963+
...prev,
964+
vercelStagingEnvironment: env
965+
? { environmentId: env.id, displayName: env.slug }
966+
: null,
967+
};
968+
// When clearing the staging mapping, strip "stg" from build settings
969+
if (!env) {
970+
next.pullEnvVarsBeforeBuild = prev.pullEnvVarsBeforeBuild.filter(
971+
(s) => s !== "stg"
972+
);
973+
next.discoverEnvVars = prev.discoverEnvVars.filter((s) => s !== "stg");
974+
}
975+
return next;
976+
});
977+
}
978+
}}
979+
items={[{ id: "", slug: "None" }, ...customEnvironments]}
980+
variant="secondary/small"
981+
placeholder="Select environment"
982+
dropdownIcon
983+
text={
984+
configValues.vercelStagingEnvironment ? (
985+
<StagingEnvOption
986+
name={configValues.vercelStagingEnvironment.displayName}
987+
/>
988+
) : (
989+
"None"
990+
)
966991
}
967-
}}
968-
items={[{ id: "", slug: "None" }, ...customEnvironments]}
969-
variant="secondary/small"
970-
placeholder="Select environment"
971-
dropdownIcon
972-
text={
973-
configValues.vercelStagingEnvironment ? (
974-
<StagingEnvOption name={configValues.vercelStagingEnvironment.displayName} />
975-
) : (
976-
"None"
977-
)
978-
}
979-
>
980-
{[
981-
<SelectItem key="" value="">
982-
<span className="text-text-bright">None</span>
983-
</SelectItem>,
984-
...customEnvironments.map((env) => (
985-
<SelectItem key={env.id} value={env.id}>
986-
<StagingEnvOption name={env.slug} />
987-
</SelectItem>
988-
)),
989-
]}
990-
</Select>
991-
</div>
992+
>
993+
{[
994+
<SelectItem key="" value="">
995+
<span className="text-text-bright">None</span>
996+
</SelectItem>,
997+
...customEnvironments.map((env) => (
998+
<SelectItem key={env.id} value={env.id}>
999+
<StagingEnvOption name={env.slug} />
1000+
</SelectItem>
1001+
)),
1002+
]}
1003+
</Select>
1004+
</div>
1005+
)
9921006
}
9931007
/>
9941008
)}

0 commit comments

Comments
 (0)