Skip to content

Commit 25372d6

Browse files
committed
Only allow selecting a single branch
1 parent 5d0d0ae commit 25372d6

1 file changed

Lines changed: 35 additions & 37 deletions

File tree

  • apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.environment-variables.new

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.environment-variables.new/route.tsx

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export default function Page() {
188188
const project = useProject();
189189
const environment = useEnvironment();
190190
const [selectedEnvironmentIds, setSelectedEnvironmentIds] = useState<Set<string>>(new Set());
191-
const [selectedBranchIds, setSelectedBranchIds] = useState<string[]>([]);
191+
const [selectedBranchId, setSelectedBranchId] = useState<string | undefined>(undefined);
192192

193193
const branchEnvironments = environments.filter((env) => env.branchName);
194194
const nonBranchEnvironments = environments.filter((env) => !env.branchName);
@@ -221,7 +221,7 @@ export default function Page() {
221221
if (environmentType === "PREVIEW") {
222222
// If PREVIEW is checked, clear all other selections including branches
223223
newSet.clear();
224-
setSelectedBranchIds([]);
224+
225225
newSet.add(environmentId);
226226
} else {
227227
// If a non-PREVIEW environment is checked, remove PREVIEW if it's selected
@@ -230,7 +230,7 @@ export default function Page() {
230230
newSet.delete(previewEnv.id);
231231
}
232232
newSet.add(environmentId);
233-
setSelectedBranchIds([]);
233+
setSelectedBranchId(undefined);
234234
}
235235
} else {
236236
newSet.delete(environmentId);
@@ -240,17 +240,12 @@ export default function Page() {
240240
});
241241
};
242242

243-
const handleBranchChange = (branchIds: string[]) => {
244-
setSelectedBranchIds(branchIds);
245-
setSelectedEnvironmentIds((prev) => {
246-
const newSet = new Set(prev);
247-
// Remove PREVIEW environment if it was selected
248-
const previewEnv = environments.find((env) => env.branchName === null);
249-
if (previewEnv) {
250-
newSet.delete(previewEnv.id);
243+
const handleBranchChange = (branchId: string) => {
244+
if (branchId === "all") {
245+
setSelectedBranchId(undefined);
246+
} else {
247+
setSelectedBranchId(branchId);
251248
}
252-
return newSet;
253-
});
254249
};
255250

256251
const [revealAll, setRevealAll] = useState(true);
@@ -274,13 +269,13 @@ export default function Page() {
274269
<Fieldset className="max-h-[70vh] overflow-y-auto p-4 scrollbar-thin scrollbar-track-transparent scrollbar-thumb-charcoal-600">
275270
<InputGroup fullWidth>
276271
<Label>Environments</Label>
277-
{selectedBranchIds.length > 0
278-
? selectedBranchIds.map((id) => (
272+
{selectedBranchId ? (
273+
<input type="hidden" name="environmentIds" value={selectedBranchId} />
274+
) : (
275+
Array.from(selectedEnvironmentIds).map((id) => (
279276
<input key={id} type="hidden" name="environmentIds" value={id} />
280277
))
281-
: Array.from(selectedEnvironmentIds).map((id) => (
282-
<input key={id} type="hidden" name="environmentIds" value={id} />
283-
))}
278+
)}
284279
<div className="flex items-center gap-2">
285280
{nonBranchEnvironments.map((environment) => (
286281
<CheckboxWithLabel
@@ -349,23 +344,22 @@ export default function Page() {
349344

350345
{previewIsSelected && (
351346
<InputGroup fullWidth>
352-
<Label>Preview branch override (optional)</Label>
347+
<Label>Select branch</Label>
348+
<div className="flex items-center gap-1">
353349
<Select
354350
variant="tertiary/medium"
355-
value={selectedBranchIds}
351+
value={selectedBranchId ?? "all"}
356352
setValue={handleBranchChange}
357-
placeholder="No override"
358-
items={branchEnvironments}
359-
className="w-fit"
353+
placeholder="All branches"
354+
items={[{ id: "all", branchName: "All branches" }, ...branchEnvironments]}
355+
className="w-fit min-w-52"
360356
filter={{
361-
keys: [(item) => item.branchName?.replace(/\//g, " ").replace(/_/g, " ") ?? ""],
357+
keys: [
358+
(item) => item.branchName?.replace(/\//g, " ").replace(/_/g, " ") ?? "",
359+
],
362360
}}
363-
text={(vals) =>
364-
vals.length > 0
365-
? vals
366-
?.map((env) => branchEnvironments.find((b) => b.id === env)?.branchName)
367-
.join(", ")
368-
: null
361+
text={(val) =>
362+
val ? branchEnvironments.find((b) => b.id === val)?.branchName : null
369363
}
370364
dropdownIcon
371365
>
@@ -377,12 +371,16 @@ export default function Page() {
377371
))
378372
}
379373
</Select>
380-
<Hint>
381-
You can select branches to override variables.{" "}
382-
{selectedBranchIds.length > 0
383-
? "The variables below will be overriden for runs on these branches."
384-
: "No overrides are currently set."}
385-
</Hint>
374+
{selectedBranchId !== "all" && selectedBranchId !== undefined && (
375+
<Button
376+
variant="minimal/medium"
377+
type="button"
378+
onClick={() => setSelectedBranchId(undefined)}
379+
LeadingIcon={XMarkIcon}
380+
/>
381+
)}
382+
</div>
383+
<Hint>Select a branch to override variables in the Preview environment.</Hint>
386384
</InputGroup>
387385
)}
388386

@@ -547,7 +545,7 @@ function VariableFields({
547545
type="button"
548546
onClick={() => {
549547
requestIntent(formRef.current ?? undefined, list.append(variablesFields.name));
550-
append([{ key: "", value: "" }]);
548+
list.append(variablesFields.name, { defaultValue: [{ key: "", value: "" }] });
551549
}}
552550
LeadingIcon={PlusIcon}
553551
>

0 commit comments

Comments
 (0)