Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix empty group validation and ensure env can only be added once

Matheus Nogueira1c0570afea91
diff --git a/frontend/src/pages/project/SettingsPage/components/CrossProjectSharingSection/ShareSecretsSheet.tsx b/frontend/src/pages/project/SettingsPage/components/CrossProjectSharingSection/ShareSecretsSheet.tsx
index 66ad72cb4c..7bbf2d90bb 100644
--- a/frontend/src/pages/project/SettingsPage/components/CrossProjectSharingSection/ShareSecretsSheet.tsx
+++ b/frontend/src/pages/project/SettingsPage/components/CrossProjectSharingSection/ShareSecretsSheet.tsx
@@ -116,6 +116,7 @@ type EnvironmentGroupRowProps = {
group: EnvironmentGroup;
index: number;
environments: { id: string; slug: string; name: string }[];
+ usedEnvironments: Set<string>;
onChangeEnvironment: (index: number, env: string) => void;
onAddPath: (index: number, path: string) => void;
onRemovePath: (index: number, pathIndex: number) => void;
@@ -126,6 +127,7 @@ const EnvironmentGroupRow = ({
group,
index,
environments,
+ usedEnvironments,
onChangeEnvironment,
onAddPath,
onRemovePath,
@@ -156,11 +158,13 @@ const EnvironmentGroupRow = ({
<SelectValue placeholder="Select environment" />
</SelectTrigger>
<SelectContent position="popper">
- {environments.map((env) => (
- <SelectItem key={env.id} value={env.slug}>
- {env.name}
- </SelectItem>
- ))}
+ {environments
+ .filter((env) => !usedEnvironments.has(env.slug))
+ .map((env) => (
+ <SelectItem key={env.id} value={env.slug}>
+ {env.name}
+ </SelectItem>
+ ))}
</SelectContent>
</Select>
</div>
@@ -255,7 +259,10 @@ export const ShareSecretsSheet = ({
const availableProjects = projects.filter((p) => p.id !== currentProject.id);
- const hasValidEntry = groups.some((g) => g.environment && g.secretPaths.length > 0);
+ const usedEnvironments = new Set(groups.map((g) => g.environment).filter(Boolean));
+
+ const hasValidEntry =
+ groups.length > 0 && groups.every((g) => g.environment && g.secretPaths.length > 0);
const handleChangeEnvironment = (index: number, env: string) => {
setGroups((prev) =>
@@ -393,6 +400,7 @@ export const ShareSecretsSheet = ({
group={group}
index={index}
environments={currentProject.environments}
+ usedEnvironments={usedEnvironments}
onChangeEnvironment={handleChangeEnvironment}
onAddPath={handleAddPath}
onRemovePath={handleRemovePath}
@@ -401,10 +409,12 @@ export const ShareSecretsSheet = ({
))}
</div>
- <Button variant="outline" size="sm" className="w-fit" onClick={handleAddGroup}>
- <Layers className="size-3.5" />
- Add another environment
- </Button>
+ {groups.length < currentProject.environments.length && (
+ <Button variant="outline" size="sm" className="w-fit" onClick={handleAddGroup}>
+ <Layers className="size-3.5" />
+ Add another environment
+ </Button>
+ )}
<div className="flex justify-center py-2">
<ArrowDown className="size-4 text-muted" />