Skip to content

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

fix(cert-manager): stack and guard the CA install connection creation dialog

Claudee9b55a6b22c9
diff --git a/AGENTS.md b/AGENTS.md
index 80fde2c7f3..3523b1b9e1 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -28,7 +28,7 @@ When building frontend UI, follow [DESIGN.md](DESIGN.md) for the v3 design syste
Before changing a shared frontend component's lifecycle, read the [shared component lifecycle ledger](frontend/src/components/COMPONENT_LIFECYCLE.md) for current deprecations, blockers, and replacement decisions.
-Pickers for entities a user may need to create first (app connections, gateways, and similar) must offer an inline "Create new X" row, gated on the create permission, so the user never has to leave the flow. Build them with the v3 `Combobox` and its `creation` prop, which renders that row; `Combobox` replaces both the deprecated `FilterableSelect` and `CreatableSelect`. For app connections, use `creation.mode = "dialog"` and have `renderForm` render `AppConnectionForm` with the app preset, selecting the new connection and calling `complete` in its `onComplete` (see `CaInstallCertModal/VenafiCaInstallForm.tsx`).
+Pickers for entities a user may need to create first (app connections, gateways, and similar) must offer an inline "Create new X" row, gated on the create permission, so the user never has to leave the flow. Build them with the v3 `Combobox` and its `creation` prop, which renders that row; `Combobox` replaces both the deprecated `FilterableSelect` and `CreatableSelect`. For app connections, use `creation.mode = "dialog"` and have `renderForm` render `AppConnectionForm` with the app preset, selecting the new connection and calling `complete` in its `onComplete`, and route `onDismiss` and the form's cancel through `useDiscardChangesGuard` (see `CaInstallCertModal/useConnectionCreation.tsx`). A v2 `Modal` parent sits at `z-[60]`, above v3 overlays, so drop it to `z-50` (`className` and `overlayClassName`) when it hosts one.
## Issue and PR Guidelines
diff --git a/frontend/src/components/v3/generic/Combobox/Combobox.tsx b/frontend/src/components/v3/generic/Combobox/Combobox.tsx
index 7cc02fc7e9..185017cb1d 100644
--- a/frontend/src/components/v3/generic/Combobox/Combobox.tsx
+++ b/frontend/src/components/v3/generic/Combobox/Combobox.tsx
@@ -57,6 +57,8 @@ type ComboboxDialogCreationConfig<TOption> = ComboboxCreationBaseConfig<TOption>
renderForm: (props: ComboboxDialogCreationRenderProps) => React.ReactNode;
/** Prevent dismissing the dialog while caller-owned persistence is pending. */
isPending?: boolean;
+ /** Intercepts Escape, outside press, and the close button (e.g. to confirm discarding changes); call `cancel` to close. */
+ onDismiss?: (cancel: () => void) => void;
};
type ComboboxCreationConfig<TOption> =
@@ -752,9 +754,11 @@ const useComboboxDialogCreation = <TOption,>({
const onOpenChange = React.useCallback(
(nextOpen: boolean) => {
- if (!nextOpen) cancel();
+ if (nextOpen) return;
+ if (dialogCreation?.onDismiss) dialogCreation.onDismiss(cancel);
+ else cancel();
},
- [cancel]
+ [cancel, dialogCreation]
);
const onCloseAutoFocus = React.useCallback(
diff --git a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CaInstallCertModal/AdcsCaInstallForm.tsx b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CaInstallCertModal/AdcsCaInstallForm.tsx
index fb3ddfc630..61ce082120 100644
--- a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CaInstallCertModal/AdcsCaInstallForm.tsx
+++ b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CaInstallCertModal/AdcsCaInstallForm.tsx
@@ -13,9 +13,7 @@ import {
SelectItem
} from "@app/components/v2";
import { Combobox, Field, FieldError, FieldLabel } from "@app/components/v3";
-import { ProjectPermissionSub, useProject, useProjectPermission } from "@app/context";
-import { ProjectPermissionAppConnectionActions } from "@app/context/ProjectPermissionContext/types";
-import { APP_CONNECTION_MAP } from "@app/helpers/appConnections";
+import { useProject } from "@app/context";
import {
CaSigningConfigType,
useCreateCaSigningConfig,
@@ -27,7 +25,8 @@ import { useListAvailableAppConnections } from "@app/hooks/api/appConnections";
import { useAzureAdcsConnectionListTemplates } from "@app/hooks/api/appConnections/azure-adcs";
import { AppConnection } from "@app/hooks/api/appConnections/enums";
import { UsePopUpState } from "@app/hooks/usePopUp";
-import { AppConnectionForm } from "@app/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm";
+
+import { useConnectionCreation } from "./useConnectionCreation";
const schema = z.object({
appConnectionId: z.string().min(1, "App connection is required"),
@@ -53,18 +52,13 @@ export const AdcsCaInstallForm = ({ caId, handlePopUpToggle }: Props) => {
const { data: availableAdcsConnections, isPending: isAdcsPending } =
useListAvailableAppConnections(AppConnection.AzureADCS, currentProject.id);
- const { permission } = useProjectPermission();
- const createConnectionLabel = `Create ${APP_CONNECTION_MAP[AppConnection.AzureADCS].name} Connection`;
- const canCreateConnection = permission.can(
- ProjectPermissionAppConnectionActions.Create,
- ProjectPermissionSub.AppConnections
- );
const {
control,
handleSubmit,
reset,
watch,
+ setValue,
formState: { isSubmitting }
} = useForm<FormData>({
resolver: zodResolver(schema),
@@ -73,6 +67,10 @@ export const AdcsCaInstallForm = ({ caId, handlePopUpToggle }: Props) => {
}
});
+ const connectionCreation = useConnectionCreation(AppConnection.AzureADCS, (connection) => {
+ setValue("appConnectionId", connection.id, { shouldValidate: true });
+ });
+
const selectedConnectionId = watch("appConnectionId");
const { data: templates = [], isPending: isTemplatesLoading } =
@@ -158,29 +156,7 @@ export const AdcsCaInstallForm = ({ caId, handlePopUpToggle }: Props) => {
placeholder="Select an Azure AD CS connection..."
getOptionLabel={(option) => option.name}
getOptionValue={(option) => option.id}
- creation={
- canCreateConnection
- ? {
- mode: "dialog",
- title: createConnectionLabel,
- description: "The new connection is selected once it is created.",
- emptyLabel: createConnectionLabel,
- formatLabel: () => createConnectionLabel,
- renderForm: ({ complete, cancel }) => (
- <AppConnectionForm
- app={AppConnection.AzureADCS}
- projectId={currentProject.id}
- projectType={currentProject.type}
- onComplete={(connection) => {
- onChange(connection.id);
- complete();
- }}
- onCancel={cancel}
- />
- )
- }
- : undefined
- }
+ creation={connectionCreation}
/>
<FieldError errors={[error]} />
</Field>
diff --git a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CaInstallCertModal/AdcsNativeCaInstallForm.tsx b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CaInstallCertModal/AdcsNativeCaInstallForm.tsx
index 40b5dbe5d0..862c2924c7 100644
--- a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CaInstallCertModal/AdcsNativeCaInstallForm.tsx
+++ b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CaInstallCertModal/AdcsNativeCaInstallForm.tsx
@@ -13,9 +13,7 @@ import {
SelectItem
} from "@app/components/v2";
import { Combobox, Field, FieldError, FieldLabel } from "@app/components/v3";
-import { ProjectPermissionSub, useProject, useProjectPermission } from "@app/context";
-import { ProjectPermissionAppConnectionActions } from "@app/context/ProjectPermissionContext/types";
-import { APP_CONNECTION_MAP } from "@app/helpers/appConnections";
+import { useProject } from "@app/context";
import {
CaSigningConfigType,
useCreateCaSigningConfig,
@@ -27,7 +25,8 @@ import { useListAvailableAppConnections } from "@app/hooks/api/appConnections";
import { useAdcsConnectionListCertificateTemplates } from "@app/hooks/api/appConnections/adcs";
import { AppConnection } from "@app/hooks/api/appConnections/enums";
import { UsePopUpState } from "@app/hooks/usePopUp";
-import { AppConnectionForm } from "@app/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm";
+
+import { useConnectionCreation } from "./useConnectionCreation";
const schema = z.object({
appConnectionId: z.string().min(1, "App connection is required"),
@@ -47,18 +46,13 @@ export const AdcsNativeCaInstallForm = ({ caId, handlePopUpToggle }: Props) => {
const { data: availableAdcsConnections, isPending: isAdcsPending } =
useListAvailableAppConnections(AppConnection.ADCS, currentProject.id);
- const { permission } = useProjectPermission();
- const createConnectionLabel = `Create ${APP_CONNECTION_MAP[AppConnection.ADCS].name} Connection`;
- const canCreateConnection = permission.can(
- ProjectPermissionAppConnectionActions.Create,
- ProjectPermissionSub.AppConnections
- );
const {
control,
handleSubmit,
reset,
watch,
+ setValue,
formState: { isSubmitting }
} = useForm<FormData>({
resolver: zodResolver(schema),
@@ -67,6 +61,10 @@ export const AdcsNativeCaInstallForm = ({ caId, handlePopUpToggle }: Props) => {
}
});
+ const connectionCreation = useConnectionCreation(AppConnection.ADCS, (connection) => {
+ setValue("appConnectionId", connection.id, { shouldValidate: true });
+ });
+
const selectedConnectionId = watch("appConnectionId");
const { data: templates = [], isPending: isTemplatesLoading } =
@@ -144,29 +142,7 @@ export const AdcsNativeCaInstallForm = ({ caId, handlePopUpToggle }: Props) => {
placeholder="Select a Microsoft ADCS connection..."
getOptionLabel={(option) => option.name}
getOptionValue={(option) => option.id}
- creation={
- canCreateConnection
- ? {
- mode: "dialog",
- title: createConnectionLabel,
- description: "The new connection is selected once it is created.",
- emptyLabel: createConnectionLabel,
- formatLabel: () => createConnectionLabel,
- renderForm: ({ complete, cancel }) => (
- <AppConnectionForm
- app={AppConnection.ADCS}
- projectId={currentProject.id}
- projectType={currentProject.type}
- onComplete={(connection) => {
- onChange(connection.id);
- complete();
- }}
- onCancel={cancel}
- />
- )
- }
- : undefined
- }
+ creation={connectionCreation}
/>
<FieldError errors={[error]} />
</Field>
diff --git a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CaInstallCertModal/CaInstallCertModal.tsx b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CaInstallCertModal/CaInstallCertModal.tsx
index 4c3e033d65..d69f56074d 100644
--- a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CaInstallCertModal/CaInstallCertModal.tsx
+++ b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CaInstallCertModal/CaInstallCertModal.tsx
@@ -388,9 +388,12 @@ export const CaInstallCertModal = ({ popUp, handlePopUpToggle }: Props) => {
handlePopUpToggle("installCaCert", isOpen);
}}
>
+ {/* z-50 (not the v2 default z-[60]) so the connection pickers' v3 creation dialog
+ (z-50, portaled later) stacks above this modal instead of behind it. */}
<ModalContent
title={getTitle()}
- className="max-w-lg"
+ className="z-50 max-w-lg"
+ overlayClassName="z-50"
bodyClassName={needsOverflowVisible ? "overflow-visible" : undefined}
subTitle={getSubTitle()}
>
diff --git a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CaInstallCertModal/VenafiCaInstallForm.tsx b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CaInstallCertModal/VenafiCaInstallForm.tsx
index 7118de234d..060ebaeabb 100644
--- a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CaInstallCertModal/VenafiCaInstallForm.tsx
+++ b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CaInstallCertModal/VenafiCaInstallForm.tsx
@@ -13,9 +13,7 @@ import {
SelectItem
} from "@app/components/v2";
import { Combobox, Field, FieldError, FieldLabel } from "@app/components/v3";
-import { ProjectPermissionSub, useProject, useProjectPermission } from "@app/context";
-import { ProjectPermissionAppConnectionActions } from "@app/context/ProjectPermissionContext/types";
-import { APP_CONNECTION_MAP } from "@app/helpers/appConnections";
+import { useProject } from "@app/context";
import {
CaSigningConfigType,
useCreateCaSigningConfig,
@@ -32,7 +30,8 @@ import {
useVenafiConnectionListIssuingTemplates
} from "@app/hooks/api/appConnections/venafi";
import { UsePopUpState } from "@app/hooks/usePopUp";
-import { AppConnectionForm } from "@app/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm";
+
+import { useConnectionCreation } from "./useConnectionCreation";
const schema = z.object({
appConnectionId: z.string().min(1, "App connection is required"),
@@ -59,12 +58,6 @@ export const VenafiCaInstallForm = ({ caId, handlePopUpToggle }: Props) => {
const { data: availableVenafiConnections, isPending: isVenafiPending } =
useListAvailableAppConnections(AppConnection.Venafi, currentProject.id);
- const { permission } = useProjectPermission();
- const createConnectionLabel = `Create ${APP_CONNECTION_MAP[AppConnection.Venafi].name} Connection`;
- const canCreateConnection = permission.can(
- ProjectPermissionAppConnectionActions.Create,
- ProjectPermissionSub.AppConnections
- );
const {
control,
@@ -80,6 +73,12 @@ export const VenafiCaInstallForm = ({ caId, handlePopUpToggle }: Props) => {
}
});
+ const connectionCreation = useConnectionCreation(AppConnection.Venafi, (connection) => {
+ setValue("appConnectionId", connection.id, { shouldValidate: true });
+ setValue("applicationId", "");
+ setValue("issuingTemplateId", "");
+ });
+
const selectedConnectionId = watch("appConnectionId");
const selectedApplicationId = watch("applicationId");
@@ -179,31 +178,7 @@ export const VenafiCaInstallForm = ({ caId, handlePopUpToggle }: Props) => {
placeholder="Select a Venafi connection..."
getOptionLabel={(option) => option.name}
getOptionValue={(option) => option.id}
- creation={
- canCreateConnection
- ? {
- mode: "dialog",
- title: createConnectionLabel,
- description: "The new connection is selected once it is created.",
- emptyLabel: createConnectionLabel,
- formatLabel: () => createConnectionLabel,
- renderForm: ({ complete, cancel }) => (
- <AppConnectionForm
- app={AppConnection.Venafi}
- projectId={currentProject.id}
- projectType={currentProject.type}
- onComplete={(connection) => {
- onChange(connection.id);
- setValue("applicationId", "");
- setValue("issuingTemplateId", "");
- complete();
- }}
- onCancel={cancel}
- />
- )
- }
- : undefined
- }
+ creation={connectionCreation}
/>
<FieldError errors={[error]} />
</Field>
diff --git a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CaInstallCertModal/useConnectionCreation.tsx b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CaInstallCertModal/useConnectionCreation.tsx
new file mode 100644
index 0000000000..040b73b1d8
--- /dev/null
+++ b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CaInstallCertModal/useConnectionCreation.tsx
@@ -0,0 +1,81 @@
+import { useRef, useState } from "react";
+
+import { ComboboxDialogCreationConfig, DiscardChangesAlertDialog } from "@app/components/v3";
+import { ProjectPermissionSub, useProject, useProjectPermission } from "@app/context";
+import { ProjectPermissionAppConnectionActions } from "@app/context/ProjectPermissionContext/types";
+import { APP_CONNECTION_MAP } from "@app/helpers/appConnections";
+import { useDiscardChangesGuard } from "@app/hooks";
+import { TAppConnection, TAvailableAppConnection } from "@app/hooks/api/appConnections";
+import { AppConnection } from "@app/hooks/api/appConnections/enums";
+import { AppConnectionForm } from "@app/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm";
+
+export const useConnectionCreation = (
+ app: AppConnection,
+ onCreated: (connection: TAppConnection) => void
+): ComboboxDialogCreationConfig<TAvailableAppConnection> | undefined => {
+ const { currentProject } = useProject();
+ const { permission } = useProjectPermission();
+ const [isDirty, setIsDirty] = useState(false);
+ const cancelRef = useRef<VoidFunction>(() => {});
+ // Bumped on dismissal so a create request that resolves after the dialog closed is ignored.
+ const attemptRef = useRef(0);
+
+ const { confirmDiscard, isDiscardDialogOpen, requestDiscard, setIsDiscardDialogOpen } =
+ useDiscardChangesGuard({
+ isDirty,
+ onDiscard: () => {
+ attemptRef.current += 1;
+ setIsDirty(false);
+ cancelRef.current();
+ }
+ });
+
+ const requestCancel = (cancel: VoidFunction) => {
+ cancelRef.current = cancel;
+ requestDiscard();
+ };
+
+ if (
+ !permission.can(
+ ProjectPermissionAppConnectionActions.Create,
+ ProjectPermissionSub.AppConnections
+ )
+ )
+ return undefined;
+
+ const label = `Create ${APP_CONNECTION_MAP[app].name} Connection`;
+ const attempt = attemptRef.current;
+
+ return {
+ mode: "dialog",
+ title: label,
+ description: "The new connection is selected once it is created.",
+ emptyLabel: label,
+ formatLabel: () => label,
+ onDismiss: requestCancel,
+ renderForm: ({ complete, cancel }) => (
+ <>
+ <AppConnectionForm
+ app={app}
+ projectId={currentProject.id}
+ projectType={currentProject.type}
+ onDirtyChange={setIsDirty}
+ onComplete={(connection) => {
+ if (attempt !== attemptRef.current) return;
+ setIsDirty(false);
+ onCreated(connection);
+ complete();
+ }}
+ onCancel={() => requestCancel(cancel)}
+ />
+ <DiscardChangesAlertDialog
+ open={isDiscardDialogOpen}
+ onOpenChange={setIsDiscardDialogOpen}
+ onDiscard={confirmDiscard}
+ title="Discard Connection Setup?"
+ description="Your progress configuring this connection will be lost."
+ />
+ </>
+ )
+ };
+};