Skip to content

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

improvement(cert-manager): migrate signer and inventory controls to v3 (#8845)

Andrew Huanga21a33561c52
diff --git a/frontend/src/pages/cert-manager/CertificateRequestsPage/components/CertificateRequestRow.tsx b/frontend/src/pages/cert-manager/CertificateRequestsPage/components/CertificateRequestRow.tsx
index bf10af7247..802bc9fdf0 100644
--- a/frontend/src/pages/cert-manager/CertificateRequestsPage/components/CertificateRequestRow.tsx
+++ b/frontend/src/pages/cert-manager/CertificateRequestsPage/components/CertificateRequestRow.tsx
@@ -7,7 +7,6 @@ import { ExternalLinkIcon } from "lucide-react";
import { createNotification } from "@app/components/notifications";
import { getCertificateDisplayName } from "@app/components/utilities/certificateDisplayUtils";
import { truncateSerialNumber } from "@app/components/utilities/serialNumberUtils";
-import { Tooltip } from "@app/components/v2";
import {
Badge,
DropdownMenu,
@@ -16,7 +15,10 @@ import {
DropdownMenuTrigger,
IconButton,
TableCell,
- TableRow
+ TableRow,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger
} from "@app/components/v3";
import { useOrganization, useProject } from "@app/context";
import {
@@ -91,38 +93,35 @@ export const CertificateRequestRow = ({ request, onViewCertificates, application
case CertificateRequestStatus.FAILED:
case CertificateRequestStatus.REJECTED:
return (
- <Tooltip
- position="top"
- content={errorMessage || "Certificate request failed"}
- className="max-w-sm break-words"
- >
- <div>
+ <Tooltip>
+ <TooltipTrigger>
<Badge variant="danger">Failed</Badge>
- </div>
+ </TooltipTrigger>
+ <TooltipContent className="max-w-sm break-words">
+ {errorMessage || "Certificate request failed"}
+ </TooltipContent>
</Tooltip>
);
case CertificateRequestStatus.PENDING:
return (
- <Tooltip
- position="top"
- content={pendingMessage || "Awaiting issuance"}
- className="max-w-sm break-words"
- >
- <div>
+ <Tooltip>
+ <TooltipTrigger>
<Badge variant="info">Pending Issuance</Badge>
- </div>
+ </TooltipTrigger>
+ <TooltipContent className="max-w-sm break-words">
+ {pendingMessage || "Awaiting issuance"}
+ </TooltipContent>
</Tooltip>
);
case CertificateRequestStatus.PENDING_VALIDATION:
return (
- <Tooltip
- position="top"
- content={pendingMessage || "Awaiting CA validation"}
- className="max-w-sm break-words"
- >
- <div>
+ <Tooltip>
+ <TooltipTrigger>
<Badge variant="warning">Pending Validation</Badge>
- </div>
+ </TooltipTrigger>
+ <TooltipContent className="max-w-sm break-words">
+ {pendingMessage || "Awaiting CA validation"}
+ </TooltipContent>
</Tooltip>
);
case CertificateRequestStatus.PENDING_APPROVAL:
@@ -180,10 +179,15 @@ export const CertificateRequestRow = ({ request, onViewCertificates, application
<TableCell>{getStatusBadge(request)}</TableCell>
<TableCell isTruncatable>{request.profileName || "—"}</TableCell>
<TableCell className="whitespace-nowrap text-accent">
- <Tooltip content={format(new Date(request.createdAt), "MMM dd, yyyy HH:mm:ss")}>
- <time dateTime={request.createdAt}>
- {format(new Date(request.createdAt), "yyyy-MM-dd")}
- </time>
+ <Tooltip>
+ <TooltipTrigger>
+ <time dateTime={request.createdAt}>
+ {format(new Date(request.createdAt), "yyyy-MM-dd")}
+ </time>
+ </TooltipTrigger>
+ <TooltipContent>
+ {format(new Date(request.createdAt), "MMM dd, yyyy HH:mm:ss")}
+ </TooltipContent>
</Tooltip>
</TableCell>
<TableCell>
diff --git a/frontend/src/pages/cert-manager/CertificateRequestsPage/components/CertificateRequestsSection.tsx b/frontend/src/pages/cert-manager/CertificateRequestsPage/components/CertificateRequestsSection.tsx
index 34152153a1..2535b5b7e1 100644
--- a/frontend/src/pages/cert-manager/CertificateRequestsPage/components/CertificateRequestsSection.tsx
+++ b/frontend/src/pages/cert-manager/CertificateRequestsPage/components/CertificateRequestsSection.tsx
@@ -5,7 +5,6 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { SearchIcon } from "lucide-react";
import { twMerge } from "tailwind-merge";
-import { FilterableSelect } from "@app/components/v2";
import {
Button,
Card,
@@ -14,6 +13,7 @@ import {
CardDescription,
CardHeader,
CardTitle,
+ Combobox,
DropdownMenu,
DropdownMenuContent,
DropdownMenuTrigger,
@@ -316,17 +316,17 @@ export const CertificateRequestsSection = ({
</button>
)}
</div>
- <FilterableSelect
+ <Combobox
+ aria-label="Certificate Profiles"
value={pendingProfileIds.map((id) => ({
value: id,
label: profilesData?.certificateProfiles?.find((p) => p.id === id)?.slug || id
}))}
- onChange={(selectedOptions) => {
- const ids = Array.isArray(selectedOptions)
- ? selectedOptions.map((opt) => opt.value)
- : [];
- setPendingProfileIds(ids);
- }}
+ onValueChange={(selectedOptions) =>
+ setPendingProfileIds(selectedOptions.map((opt) => opt.value))
+ }
+ getOptionValue={(option) => option.value}
+ getOptionLabel={(option) => option.label}
options={
profilesData?.certificateProfiles?.map((profile) => ({
value: profile.id,
@@ -334,10 +334,8 @@ export const CertificateRequestsSection = ({
})) || []
}
placeholder="Select certificate profiles..."
- className="w-full border-border-control bg-surface-hover text-foreground-soft"
- isMulti
+ multiple
isLoading={!profilesData}
- maxMenuHeight={120}
/>
</div>
@@ -398,47 +396,51 @@ export const CertificateRequestsSection = ({
</DropdownMenu>
</div>
- <Table>
- <TableHeader>
- <TableRow>
- <TableHead className="max-w-[200px] min-w-[120px]">SAN / CN</TableHead>
- <TableHead className="max-w-[120px] min-w-[90px]">Serial #</TableHead>
- <TableHead className="w-[120px]">Status</TableHead>
- <TableHead className="max-w-[140px] min-w-[80px]">Profile</TableHead>
- <TableHead className="w-[110px]">Created</TableHead>
- <TableHead className="w-5" />
- </TableRow>
- </TableHeader>
- <TableBody>
- {isLoading &&
- Array.from({ length: 6 }).map((_, i) => (
- <TableRow key={`request-skeleton-${i + 1}`}>
- {Array.from({ length: 6 }).map((__, j) => (
- <TableCell key={`request-skeleton-cell-${j + 1}`}>
- <Skeleton className="h-4 w-full" />
- </TableCell>
- ))}
- </TableRow>
- ))}
- {!isLoading && isError && (
+ {(isLoading ||
+ isError ||
+ Boolean(certificateRequestsData?.certificateRequests?.length)) && (
+ <Table>
+ <TableHeader>
<TableRow>
- <TableCell colSpan={6} className="py-8 text-center text-danger">
- Failed to load certificate requests. Please try again.
- </TableCell>
+ <TableHead className="max-w-[200px] min-w-[120px]">SAN / CN</TableHead>
+ <TableHead className="max-w-[120px] min-w-[90px]">Serial #</TableHead>
+ <TableHead className="w-[120px]">Status</TableHead>
+ <TableHead className="max-w-[140px] min-w-[80px]">Profile</TableHead>
+ <TableHead className="w-[110px]">Created</TableHead>
+ <TableHead className="w-5" />
</TableRow>
- )}
- {!isLoading &&
- !isError &&
- certificateRequestsData?.certificateRequests?.map((request) => (
- <CertificateRequestRow
- key={request.id}
- request={request}
- onViewCertificates={handleViewCertificates}
- applicationName={applicationName}
- />
- ))}
- </TableBody>
- </Table>
+ </TableHeader>
+ <TableBody>
+ {isLoading &&
+ Array.from({ length: 6 }).map((_, i) => (
+ <TableRow key={`request-skeleton-${i + 1}`}>
+ {Array.from({ length: 6 }).map((__, j) => (
+ <TableCell key={`request-skeleton-cell-${j + 1}`}>
+ <Skeleton className="h-4 w-full" />
+ </TableCell>
+ ))}
+ </TableRow>
+ ))}
+ {!isLoading && isError && (
+ <TableRow>
+ <TableCell colSpan={6} className="py-8 text-center text-danger">
+ Failed to load certificate requests. Please try again.
+ </TableCell>
+ </TableRow>
+ )}
+ {!isLoading &&
+ !isError &&
+ certificateRequestsData?.certificateRequests?.map((request) => (
+ <CertificateRequestRow
+ key={request.id}
+ request={request}
+ onViewCertificates={handleViewCertificates}
+ applicationName={applicationName}
+ />
+ ))}
+ </TableBody>
+ </Table>
+ )}
{!isLoading && !isError && certificateRequestsData?.certificateRequests?.length === 0 && (
<Empty className="border">
diff --git a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateManagePkiSyncsModal.tsx b/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateManagePkiSyncsModal.tsx
index d7d2e6e98d..cb8d9f77a0 100644
--- a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateManagePkiSyncsModal.tsx
+++ b/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateManagePkiSyncsModal.tsx
@@ -1,5 +1,4 @@
import { useEffect, useMemo, useState } from "react";
-import { faPlus, faSearch } from "@fortawesome/free-solid-svg-icons";
import { useNavigate } from "@tanstack/react-router";
import { createNotification } from "@app/components/notifications";
@@ -10,19 +9,26 @@ import {
import {
Button,
Checkbox,
- EmptyState,
+ DiscardChangesAlertDialog,
+ Empty,
+ EmptyDescription,
+ EmptyHeader,
+ EmptyTitle,
Input,
- Modal,
- ModalContent,
Pagination,
+ Sheet,
+ SheetContent,
+ SheetDescription,
+ SheetFooter,
+ SheetHeader,
+ SheetTitle,
Table,
- TableContainer,
- TBody,
- Td,
- Th,
- THead,
- Tr
-} from "@app/components/v2";
+ TableBody,
+ TableCell,
+ TableHead,
+ TableHeader,
+ TableRow
+} from "@app/components/v3";
import { ROUTE_PATHS } from "@app/const/routes";
import { useOrganization, useProject } from "@app/context";
import { PKI_SYNC_MAP } from "@app/helpers/pkiSyncs";
@@ -32,6 +38,7 @@ import {
useRemoveCertificatesFromPkiSync
} from "@app/hooks/api/pkiSyncs";
import { TPkiSync } from "@app/hooks/api/pkiSyncs/types";
+import { useDiscardChangesGuard } from "@app/hooks/useDiscardChangesGuard";
import { ApplicationTab } from "@app/pages/cert-manager/ApplicationDetailsByIDPage/application-tabs";
import { IntegrationsListPageTabs } from "@app/types/integrations";
@@ -106,6 +113,14 @@ export const CertificateManagePkiSyncsModal = ({
setCurrentPage(1);
};
+ const { isDiscardDialogOpen, setIsDiscardDialogOpen, requestDiscard, confirmDiscard } =
+ useDiscardChangesGuard({
+ isDirty:
+ selectedSyncIds.size !== initialSyncIds.size ||
+ Array.from(selectedSyncIds).some((id) => !initialSyncIds.has(id)),
+ onDiscard: handleClose
+ });
+
const handleNavigateToPkiSyncs = () => {
if (!currentProject?.id) return;
@@ -133,16 +148,17 @@ export const CertificateManagePkiSyncsModal = ({
};
useEffect(() => {
- if (!certificateId || !pkiSyncs || pkiSyncs.length === 0) return;
+ if (!popUp.isOpen || !certificateId || pkiSyncs.length === 0) return;
const currentSyncIds = new Set(
pkiSyncs.filter((sync) => sync.hasCertificate).map((sync) => sync.id)
);
setSelectedSyncIds(currentSyncIds);
setInitialSyncIds(new Set(currentSyncIds));
- }, [certificateId, pkiSyncs]);
+ }, [popUp.isOpen, certificateId, pkiSyncs]);
const handleSyncToggle = (syncId: string) => {
+ if (isSubmitting) return;
setSelectedSyncIds((prev) => {
const newSet = new Set(prev);
if (newSet.has(syncId)) {
@@ -199,131 +215,141 @@ export const CertificateManagePkiSyncsModal = ({
};
return (
- <Modal isOpen={popUp.isOpen} onOpenChange={handleClose}>
- <ModalContent
- title="Manage PKI Syncs"
- subTitle={`Select which PKI syncs "${commonName}" should be part of`}
- className="max-w-3xl"
+ <>
+ <Sheet
+ open={popUp.isOpen}
+ onOpenChange={(open) => {
+ if (!open && !isSubmitting) requestDiscard();
+ }}
>
- <div className="mb-4">
- <Input
- value={searchTerm}
- onChange={(e) => setSearchTerm(e.target.value)}
- placeholder="Search PKI syncs by name..."
- />
- </div>
- <div className="mt-4 max-h-96 overflow-y-auto">
- {isPending && (
- <div className="flex h-32 items-center justify-center">
- <div className="text-label-secondary">Loading PKI syncs...</div>
- </div>
- )}
- {!isPending && pkiSyncs.length === 0 && (
- <EmptyState title="No PKI syncs available" icon={faPlus}>
- <div className="mt-1">
- Create a{" "}
- <button
- type="button"
- onClick={handleNavigateToPkiSyncs}
- className="cursor-pointer underline hover:text-label"
- >
- PKI sync
- </button>{" "}
- first to manage certificate syncing.
+ <SheetContent size="form" isPending={isSubmitting}>
+ <SheetHeader>
+ <SheetTitle>Manage PKI Syncs</SheetTitle>
+ <SheetDescription>{`Select which PKI syncs "${commonName}" should be part of.`}</SheetDescription>
+ </SheetHeader>
+ <div className="flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto p-4">
+ <Input
+ aria-label="Search PKI syncs"
+ disabled={isSubmitting}
+ value={searchTerm}
+ onChange={(e) => setSearchTerm(e.target.value)}
+ placeholder="Search PKI syncs by name..."
+ />
+ {isPending && (
+ <div className="flex h-32 items-center justify-center">
+ <div className="text-muted">Loading PKI syncs...</div>
</div>
- </EmptyState>
- )}
- {!isPending && pkiSyncs.length > 0 && filteredSyncs.length === 0 && searchTerm && (
- <EmptyState title="No PKI syncs found" icon={faSearch}>
- <div className="mt-1">
- No PKI syncs match your search criteria. Try a different search term.
- </div>
- </EmptyState>
- )}
- {!isPending && filteredSyncs.length > 0 && (
- <TableContainer>
+ )}
+ {!isPending && pkiSyncs.length === 0 && (
+ <Empty className="border">
+ <EmptyHeader>
+ <EmptyTitle>No PKI Syncs Available</EmptyTitle>
+ <EmptyDescription>
+ Create a{" "}
+ <button
+ type="button"
+ onClick={handleNavigateToPkiSyncs}
+ className="cursor-pointer underline"
+ >
+ PKI sync
+ </button>{" "}
+ first to manage certificate syncing.
+ </EmptyDescription>
+ </EmptyHeader>
+ </Empty>
+ )}
+ {!isPending && pkiSyncs.length > 0 && filteredSyncs.length === 0 && searchTerm && (
+ <Empty className="border">
+ <EmptyHeader>
+ <EmptyTitle>No PKI Syncs Found</EmptyTitle>
+ <EmptyDescription>
+ No PKI syncs match your search criteria. Try a different search term.
+ </EmptyDescription>
+ </EmptyHeader>
+ </Empty>
+ )}
+ {!isPending && filteredSyncs.length > 0 && (
<Table>
- <THead>
- <Tr>
- <Th className="w-12" />
- <Th className="w-1/2">Name</Th>
- <Th className="w-1/2">Destination</Th>
- </Tr>
- </THead>
- <TBody>
+ <TableHeader>
+ <TableRow>
+ <TableHead className="w-12" />
+ <TableHead className="w-1/2">Name</TableHead>
+ <TableHead className="w-1/2">Destination</TableHead>
+ </TableRow>
+ </TableHeader>
+ <TableBody>
{paginatedSyncs.map((sync) => {
const unavailableReason = getSyncUnavailableReason(sync);
const managesItsOwnCertificates = Boolean(unavailableReason);
return (
- <Tr
+ <TableRow
key={sync.id}
- className={
- managesItsOwnCertificates
- ? "opacity-60"
- : "cursor-pointer hover:bg-surface-hover"
- }
+ className={managesItsOwnCertificates ? "opacity-60" : "cursor-pointer"}
onClick={() => !managesItsOwnCertificates && handleSyncToggle(sync.id)}
>
- <Td>
+ <TableCell onClick={(event) => event.stopPropagation()}>
<Checkbox
+ aria-label={`Select ${sync.name}`}
isChecked={selectedSyncIds.has(sync.id)}
- isDisabled={managesItsOwnCertificates}
+ isDisabled={managesItsOwnCertificates || isSubmitting}
onCheckedChange={() => handleSyncToggle(sync.id)}
id={`sync-${sync.id}`}
/>
- </Td>
- <Td className="w-1/2 max-w-0">
+ </TableCell>
+ <TableCell className="w-1/2 max-w-0">
<div className="truncate" title={sync.name}>
{sync.name}
</div>
{unavailableReason && (
<div className="truncate text-xs text-muted">{unavailableReason}</div>
)}
- </Td>
- <Td className="w-1/2 max-w-0">
+ </TableCell>
+ <TableCell className="w-1/2 max-w-0">
<div
className="truncate capitalize"
title={PKI_SYNC_MAP[sync.destination].name}
>
{PKI_SYNC_MAP[sync.destination].name}
</div>
- </Td>
- </Tr>
+ </TableCell>
+ </TableRow>
);
})}
- </TBody>
+ </TableBody>
</Table>
- </TableContainer>
- )}
- {!isPending && filteredSyncs.length > PER_PAGE && (
- <div className="mt-4">
- <Pagination
- count={filteredSyncs.length}
- page={currentPage}
- perPage={PER_PAGE}
- onChangePage={setCurrentPage}
- onChangePerPage={() => {}}
- />
- </div>
- )}
- </div>
+ )}
+ {!isPending && filteredSyncs.length > PER_PAGE && (
+ <div className="mt-4">
+ <Pagination
+ count={filteredSyncs.length}
+ page={currentPage}
+ perPage={PER_PAGE}
+ perPageList={[PER_PAGE]}
+ onChangePage={setCurrentPage}
+ onChangePerPage={() => {}}
+ />
+ </div>
+ )}
+ </div>
- <div className="mt-6 flex justify-end gap-3">
- <Button variant="outline_bg" onClick={handleClose} isDisabled={isSubmitting}>
- Cancel
- </Button>
- <Button
- variant="solid"
- colorSchema="primary"
- onClick={handleSaveChanges}
- isDisabled={isSubmitting}
- isLoading={isSubmitting}
- >
- Save Changes
- </Button>
- </div>
- </ModalContent>
- </Modal>
+ <SheetFooter className="justify-end border-t">
+ <Button variant="ghost" onClick={requestDiscard} isDisabled={isSubmitting}>
+ Cancel
+ </Button>
+ <Button variant="project" onClick={handleSaveChanges} isPending={isSubmitting}>
+ Save Changes
+ </Button>
+ </SheetFooter>
+ </SheetContent>
+ </Sheet>
+ <DiscardChangesAlertDialog
+ open={isDiscardDialogOpen}
+ onOpenChange={setIsDiscardDialogOpen}
+ onDiscard={confirmDiscard}
+ title="Discard Changes?"
+ description="Your PKI sync selection changes will be lost."
+ />
+ </>
);
};
diff --git a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateManageRenewalModal.tsx b/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateManageRenewalModal.tsx
index 6b10260230..97d4944c1a 100644
--- a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateManageRenewalModal.tsx
+++ b/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateManageRenewalModal.tsx
@@ -1,13 +1,31 @@
import { useEffect, useMemo } from "react";
import { Controller, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
+import { CircleAlertIcon } from "lucide-react";
import { z } from "zod";
import { createNotification } from "@app/components/notifications";
-import { Button, FormControl, Input, Modal, ModalContent } from "@app/components/v2";
+import {
+ Alert,
+ AlertDescription,
+ AlertTitle,
+ Button,
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+ DiscardChangesAlertDialog,
+ Field,
+ FieldError,
+ FieldLabel,
+ Input
+} from "@app/components/v3";
import { useProject } from "@app/context";
import { useUpdateRenewalConfig } from "@app/hooks/api";
import { useGetCertificateProfileById } from "@app/hooks/api/certificateProfiles";
+import { useDiscardChangesGuard } from "@app/hooks/useDiscardChangesGuard";
import { UsePopUpState } from "@app/hooks/usePopUp";
const DEFAULT_RENEWAL_BEFORE_DAYS = 20;
@@ -48,58 +66,6 @@ type Props = {
handlePopUpToggle: (popUpName: keyof UsePopUpState<["manageRenewal"]>, state?: boolean) => void;
};
-const RenewalConfigForm = ({
- control,
- errors,
- onSubmit,
- isLoading,
- buttonText,
- onCancel
-}: {
- control: any;
- errors: { renewBeforeDays?: { message?: string } };
- onSubmit: (e?: React.BaseSyntheticEvent) => Promise<void>;
- isLoading: boolean;
- buttonText: string;
- onCancel: () => void;
-}) => (
- <form onSubmit={onSubmit}>
- <FormControl
- label="Auto-renew days before expiry"
- isError={Boolean(errors.renewBeforeDays)}
- errorText={errors.renewBeforeDays?.message}
- className="mb-6"
- >
- <Controller
- control={control}
- name="renewBeforeDays"
- render={({ field }) => (
- <Input
- {...field}
- type="number"
- min={MIN_RENEWAL_BEFORE_DAYS}
- max={MAX_RENEWAL_BEFORE_DAYS}
- onChange={(e) => {
- const value = parseInt(e.target.value, 10);
- field.onChange(value);
- }}
- placeholder="Enter days before expiration"
- />
- )}
- />
- </FormControl>
-
- <div className="flex justify-end gap-3">
- <Button type="button" colorSchema="secondary" variant="plain" onClick={onCancel}>
- Cancel
- </Button>
- <Button type="submit" colorSchema="primary" isLoading={isLoading} isDisabled={isLoading}>
- {buttonText}
- </Button>
- </div>
- </form>
-);
-
export const CertificateManageRenewalModal = ({ popUp, handlePopUpToggle }: Props) => {
const { currentProject } = useProject();
const { mutateAsync: updateRenewalConfig, isPending: isUpdatingConfig } =
@@ -145,7 +111,7 @@ export const CertificateManageRenewalModal = ({ popUp, handlePopUpToggle }: Prop
const {
control,
handleSubmit,
- formState: { errors },
+ formState: { isDirty, isSubmitting },
reset
} = useForm<FormData>({
resolver: zodResolver(formSchema),
@@ -154,6 +120,13 @@ export const CertificateManageRenewalModal = ({ popUp, handlePopUpToggle }: Prop
}
});
+ const isPending = isUpdatingConfig || isSubmitting;
+ const { isDiscardDialogOpen, setIsDiscardDialogOpen, requestDiscard, confirmDiscard } =
+ useDiscardChangesGuard({
+ isDirty,
+ onDiscard: () => handlePopUpToggle("manageRenewal", false)
+ });
+
useEffect(() => {
if (popUp.manageRenewal.isOpen) {
reset({
@@ -201,54 +174,76 @@ export const CertificateManageRenewalModal = ({ popUp, handlePopUpToggle }: Prop
}
return (
- <Modal
- isOpen={popUp?.manageRenewal?.isOpen}
- onOpenChange={(isOpen) => {
- handlePopUpToggle("manageRenewal", isOpen);
- }}
- >
- <ModalContent title={getModalTitle()}>
- {hasRenewalError && (
- <div className="mb-6 rounded-md border border-danger bg-danger/20 p-4">
- <div className="flex items-start gap-3">
- <div className="mt-1 flex h-5 w-5 items-center justify-center rounded-full bg-danger">
- <span className="text-xs font-bold text-white">!</span>
- </div>
- <div className="flex-1">
- <h3 className="font-normal text-danger">Automatic Renewal Failed</h3>
- <p className="mt-1 text-sm text-danger">
- The last automatic renewal attempt failed: {certificateData.renewalError}
- </p>
- <p className="mt-2 text-sm text-danger">
- You can reconfigure auto-renewal below or disable it completely.
- </p>
- </div>
- </div>
- </div>
- )}
-
- {(!isAutoRenewalEnabled || hasRenewalError) && (
- <RenewalConfigForm
- control={control}
- errors={errors}
- onSubmit={handleSubmit(onUpdateRenewal)}
- isLoading={isUpdatingConfig}
- buttonText={isAutoRenewalEnabled ? "Update Configuration" : "Enable Auto-Renewal"}
- onCancel={() => handlePopUpToggle("manageRenewal", false)}
- />
- )}
-
- {isAutoRenewalEnabled && !hasRenewalError && (
- <RenewalConfigForm
- control={control}
- errors={errors}
- onSubmit={handleSubmit(onUpdateRenewal)}
- isLoading={isUpdatingConfig}
- buttonText="Update Configuration"
- onCancel={() => handlePopUpToggle("manageRenewal", false)}
- />
- )}
- </ModalContent>
- </Modal>
+ <>
+ <Dialog
+ open={popUp.manageRenewal.isOpen}
+ onOpenChange={(open) => {
+ if (!open && !isPending) requestDiscard();
+ }}
+ >
+ <DialogContent isPending={isPending}>
+ <DialogHeader>
+ <DialogTitle>{getModalTitle()}</DialogTitle>
+ <DialogDescription>
+ Configure when this certificate is automatically renewed.
+ </DialogDescription>
+ </DialogHeader>
+ {hasRenewalError && (
+ <Alert variant="danger">
+ <CircleAlertIcon />
+ <AlertTitle>Automatic Renewal Failed</AlertTitle>
+ <AlertDescription>
+ The last automatic renewal attempt failed: {certificateData.renewalError}
+ </AlertDescription>
+ </Alert>
+ )}
+ <form id="certificate-renewal-form" onSubmit={handleSubmit(onUpdateRenewal)}>
+ <Controller
+ control={control}
+ name="renewBeforeDays"
+ render={({ field, fieldState: { error } }) => (
+ <Field>
+ <FieldLabel htmlFor="certificate-renewal-days">
+ Auto-Renew Days Before Expiry
+ </FieldLabel>
+ <Input
+ {...field}
+ id="certificate-renewal-days"
+ type="number"
+ min={MIN_RENEWAL_BEFORE_DAYS}
+ max={MAX_RENEWAL_BEFORE_DAYS}
+ disabled={isPending}
+ isError={Boolean(error)}
+ onChange={(event) => field.onChange(parseInt(event.target.value, 10))}
+ placeholder="Enter days before expiration"
+ />
+ <FieldError errors={[error]} />
+ </Field>
+ )}
+ />
+ </form>
+ <DialogFooter>
+ <Button variant="ghost" onClick={requestDiscard} isDisabled={isPending}>
+ Cancel
+ </Button>
+ <Button
+ type="submit"
+ form="certificate-renewal-form"
+ variant="project"
+ isPending={isPending}
+ >
+ {isAutoRenewalEnabled ? "Update Configuration" : "Enable Auto-Renewal"}
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ <DiscardChangesAlertDialog
+ open={isDiscardDialogOpen}
+ onOpenChange={setIsDiscardDialogOpen}
+ onDiscard={confirmDiscard}
+ title="Discard Changes?"
+ description="Your auto-renewal configuration changes will be lost."
+ />
+ </>
);
};
diff --git a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateRenewalConfigModal.tsx b/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateRenewalConfigModal.tsx
deleted file mode 100644
index 015b02de5f..0000000000
--- a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateRenewalConfigModal.tsx
+++ /dev/null
@@ -1,169 +0,0 @@
-import { Controller, useForm } from "react-hook-form";
-import { zodResolver } from "@hookform/resolvers/zod";
-import { z } from "zod";
-
-import { createNotification } from "@app/components/notifications";
-import { Button, FormControl, Input, Modal, ModalContent } from "@app/components/v2";
-import { useProject } from "@app/context";
-import { useUpdateRenewalConfig } from "@app/hooks/api";
-import { UsePopUpState } from "@app/hooks/usePopUp";
-
-const createFormSchema = (ttlDays: number) =>
- z.object({
- renewBeforeDays: z
- .number()
- .min(1, "Renewal days must be at least 1")
- .max(365, "Renewal days cannot exceed 365")
- .refine(
- (value) => value < ttlDays,
- (value) => ({
- message: `Renewal days (${value}) must be less than certificate TTL (${ttlDays} days)`
- })
- )
- });
-
-type FormData = z.infer<ReturnType<typeof createFormSchema>>;
-
-type Props = {
- popUp: UsePopUpState<["configureRenewal"]>;
- handlePopUpToggle: (
- popUpName: keyof UsePopUpState<["configureRenewal"]>,
- state?: boolean
- ) => void;
-};
-
-export const CertificateRenewalConfigModal = ({ popUp, handlePopUpToggle }: Props) => {
- const { currentProject } = useProject();
- const { mutateAsync: updateRenewalConfig, isPending: isSubmitting } = useUpdateRenewalConfig();
-
- const certificateData = popUp.configureRenewal.data as {
- certificateId: string;
- commonName: string;
- profileId: string;
- renewBeforeDays?: number;
- ttlDays: number;
- };
-
- const formSchema = createFormSchema(certificateData.ttlDays);
-
- const {
- control,
- handleSubmit,
- formState: { errors },
- watch
- } = useForm<FormData>({
- resolver: zodResolver(formSchema),
- defaultValues: {
- renewBeforeDays: certificateData?.renewBeforeDays || 1
- }
- });
-
- const renewBeforeDays = watch("renewBeforeDays");
-
- const onSubmit = async (data: FormData) => {
- if (!currentProject?.slug) {
- createNotification({
- text: "Certificate Manager could not be loaded. Please refresh and try again.",
- type: "error"
- });
- return;
- }
-
- await updateRenewalConfig({
- certificateId: certificateData.certificateId,
- renewBeforeDays: data.renewBeforeDays
- });
-
- createNotification({
- text: "Successfully updated auto-renewal configuration",
- type: "success"
- });
-
- handlePopUpToggle("configureRenewal", false);
- };
-
- return (
- <Modal
- isOpen={popUp?.configureRenewal?.isOpen}
- onOpenChange={(isOpen) => {
- handlePopUpToggle("configureRenewal", isOpen);
- }}
- >
- <ModalContent title={`Configure Auto-Renewal: ${certificateData?.commonName || ""}`}>
- <form onSubmit={handleSubmit(onSubmit)}>
- <div className="mb-4">
- <p className="mb-4 text-sm text-label">
- Configure when this certificate should be automatically renewed. The certificate will
- be renewed when it has the specified number of days remaining before expiration.
- </p>
-
- <div className="mb-4 rounded border bg-surface-raised p-3">
- <p className="text-sm text-label">
- <strong>Certificate TTL:</strong> {certificateData?.ttlDays} days
- </p>
- <p className="text-sm text-label">
- <strong>Current Setting:</strong>{" "}
- {certificateData?.renewBeforeDays
- ? `${certificateData.renewBeforeDays} days before expiration`
- : "Disabled"}
- </p>
- </div>
-
- <Controller
- control={control}
- name="renewBeforeDays"
- render={({ field }) => (
- <FormControl
- label="Renew Before Days"
- isError={Boolean(errors.renewBeforeDays)}
- errorText={errors.renewBeforeDays?.message}
- >
- <Input
- {...field}
- type="number"
- min={1}
- max={certificateData?.ttlDays ? certificateData.ttlDays - 1 : undefined}
- placeholder="Enter days before expiration"
- onChange={(e) => {
- const value = parseInt(e.target.value, 10);
- field.onChange(Number.isNaN(value) ? 0 : value);
- }}
- />
- </FormControl>
- )}
- />
-
- {renewBeforeDays && certificateData?.ttlDays && (
- <div className="mt-2 rounded bg-project/20 p-2">
- <p className="text-sm text-project">
- {renewBeforeDays >= certificateData.ttlDays
- ? "⚠️ Renewal days must be less than certificate TTL"
- : `✓ Certificate will be renewed ${renewBeforeDays} days before expiration`}
- </p>
- </div>
- )}
- </div>
-
- <div className="flex items-center gap-2">
- <Button
- className="mr-4"
- size="sm"
- type="submit"
- isLoading={isSubmitting}
- isDisabled={isSubmitting || renewBeforeDays >= (certificateData?.ttlDays || 0)}
- >
- Update Configuration
- </Button>
- <Button
- colorSchema="secondary"
- variant="plain"
- onClick={() => handlePopUpToggle("configureRenewal", false)}
- >
- Cancel
- </Button>
- </div>
- </form>
- </ModalContent>
- </Modal>
- );
-};
diff --git a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateRenewalDisableModal.tsx b/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateRenewalDisableModal.tsx
deleted file mode 100644
index 4324058484..0000000000
--- a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateRenewalDisableModal.tsx
+++ /dev/null
@@ -1,85 +0,0 @@
-import { createNotification } from "@app/components/notifications";
-import { Button, Modal, ModalContent } from "@app/components/v2";
-import { useProject } from "@app/context";
-import { useUpdateRenewalConfig } from "@app/hooks/api";
-import { UsePopUpState } from "@app/hooks/usePopUp";
-
-type Props = {
- popUp: UsePopUpState<["disableRenewal"]>;
- handlePopUpToggle: (popUpName: keyof UsePopUpState<["disableRenewal"]>, state?: boolean) => void;
-};
-
-export const CertificateRenewalDisableModal = ({ popUp, handlePopUpToggle }: Props) => {
- const { currentProject } = useProject();
- const { mutateAsync: updateRenewalConfig, isPending: isSubmitting } = useUpdateRenewalConfig();
-
- const certificateData = popUp.disableRenewal.data as {
- certificateId: string;
- commonName: string;
- };
-
- const onDisableConfirm = async () => {
- if (!currentProject?.slug) {
- createNotification({
- text: "Certificate Manager could not be loaded. Please refresh and try again.",
- type: "error"
- });
- return;
- }
-
- await updateRenewalConfig({
- certificateId: certificateData.certificateId,
- enableAutoRenewal: false
- });
-
- createNotification({
- text: "Successfully disabled auto-renewal",
- type: "success"
- });
-
- handlePopUpToggle("disableRenewal", false);
- };
-
- return (
- <Modal
- isOpen={popUp?.disableRenewal?.isOpen}
- onOpenChange={(isOpen) => {
- handlePopUpToggle("disableRenewal", isOpen);
- }}
- >
- <ModalContent title={`Disable Auto-Renewal: ${certificateData?.commonName || ""}`}>
- <div className="mb-4">
- <p className="mb-3 text-sm text-label">
- Are you sure you want to disable auto-renewal for this certificate?
- </p>
- <div className="rounded border border-warning/50 bg-warning/20 p-3">
- <p className="text-sm text-warning">
- <strong>Warning:</strong> Once disabled, this certificate will not be automatically
- renewed and may expire without notice. You can re-enable auto-renewal at any time.
- </p>
- </div>
- </div>
-
- <div className="flex items-center gap-2">
- <Button
- className="mr-4"
- size="sm"
- colorSchema="danger"
- onClick={onDisableConfirm}
- isLoading={isSubmitting}
- isDisabled={isSubmitting}
- >
- Disable Auto-Renewal
- </Button>
- <Button
- colorSchema="secondary"
- variant="plain"
- onClick={() => handlePopUpToggle("disableRenewal", false)}
- >
- Cancel
- </Button>
- </div>
- </ModalContent>
- </Modal>
- );
-};
diff --git a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificatesTable.tsx b/frontend/src/pages/cert-manager/CertificatesPage/components/CertificatesTable.tsx
index b4aa523b97..be410ed0ef 100644
--- a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificatesTable.tsx
+++ b/frontend/src/pages/cert-manager/CertificatesPage/components/CertificatesTable.tsx
@@ -306,10 +306,11 @@ export const CertificatesTable = ({
const [applicationFilterSearch, setApplicationFilterSearch] = useState("");
const [debouncedApplicationFilterSearch] = useDebounce(applicationFilterSearch);
- const { data: applicationOptionsResponse } = useListPkiApplications(
- { search: debouncedApplicationFilterSearch || undefined, limit: 20 },
- { enabled: !applicationId }
- );
+ const { data: applicationOptionsResponse, isFetching: isFetchingApplicationOptions } =
+ useListPkiApplications(
+ { search: debouncedApplicationFilterSearch || undefined, limit: 20 },
+ { enabled: !applicationId }
+ );
const selectedApplicationIds = useMemo(() => {
const ids = new Set<string>();
@@ -785,6 +786,11 @@ export const CertificatesTable = ({
onSaveView={canCreateViews ? () => setIsSaveViewOpen(true) : undefined}
dynamicFieldOptions={dynamicFieldOptions}
onDynamicFieldSearch={{ applicationId: setApplicationFilterSearch }}
+ dynamicFieldLoading={{
+ applicationId:
+ applicationFilterSearch !== debouncedApplicationFilterSearch ||
+ isFetchingApplicationOptions
+ }}
hiddenFieldKeys={applicationId ? ["applicationId"] : undefined}
/>
</PopoverContent>
diff --git a/frontend/src/pages/cert-manager/CertificatesPage/components/FilterBuilder.tsx b/frontend/src/pages/cert-manager/CertificatesPage/components/FilterBuilder.tsx
index bb86685e2b..1e3022a4ea 100644
--- a/frontend/src/pages/cert-manager/CertificatesPage/components/FilterBuilder.tsx
+++ b/frontend/src/pages/cert-manager/CertificatesPage/components/FilterBuilder.tsx
@@ -4,7 +4,7 @@ import { CalendarIcon, PlusIcon, Trash2Icon } from "lucide-react";
import {
Button,
Calendar,
- FilterableSelect,
+ Combobox,
IconButton,
Input,
Popover,
@@ -28,6 +28,7 @@ type Props = {
onSaveView?: () => void;
dynamicFieldOptions?: Record<string, { value: string; label: string }[]>;
onDynamicFieldSearch?: Record<string, (query: string) => void>;
+ dynamicFieldLoading?: Record<string, boolean>;
hiddenFieldKeys?: string[];
};
@@ -105,6 +106,7 @@ const FilterRow = ({
onRemove,
dynamicFieldOptions: dynOpts,
onDynamicFieldSearch,
+ dynamicFieldLoading,
availableFields
}: {
rule: FilterRule;
@@ -112,6 +114,7 @@ const FilterRow = ({
onRemove: () => void;
dynamicFieldOptions?: Record<string, { value: string; label: string }[]>;
onDynamicFieldSearch?: Record<string, (query: string) => void>;
+ dynamicFieldLoading?: Record<string, boolean>;
availableFields: FilterFieldDefinition[];
}) => {
const fieldDef = getFieldDef(rule.field, dynOpts);
@@ -151,36 +154,31 @@ const FilterRow = ({
}
case "multi-select": {
const currentValues = Array.isArray(rule.value) ? rule.value : [];
- const selectedOptions = currentValues
- .map((v) => {
- const opt = options.find((o) => o.value === v);
- return opt ? { value: opt.value, label: opt.label } : null;
- })
- .filter(Boolean) as { value: string; label: string }[];
+ const selectedOptions = currentValues.map(
+ (value) => options.find((option) => option.value === value) ?? { value, label: value }
+ );
const serverSearch = onDynamicFieldSearch?.[rule.field];
return (
- <FilterableSelect
- isMulti
+ <Combobox
+ aria-label={`${fieldDef.label} values`}
+ multiple
value={selectedOptions}
- onChange={(opts) => {
- const selected = Array.isArray(opts) ? opts.map((o) => o.value) : [];
- onUpdate({ ...rule, value: selected });
+ onValueChange={(opts) => {
+ onUpdate({ ...rule, value: opts.map((option) => option.value) });
}}
options={options}
+ getOptionValue={(option) => option.value}
+ getOptionLabel={(option) => option.label}
placeholder="Select..."
- className="w-full text-sm"
- maxMenuHeight={160}
- menuPortalTarget={document.body}
- menuPosition="fixed"
{...(serverSearch
? {
- filterOption: () => true,
- onInputChange: (value, { action }) => {
- if (action === "input-change") serverSearch(value);
- },
- onMenuClose: () => serverSearch("")
+ onSearchChange: serverSearch,
+ isLoading: dynamicFieldLoading?.[rule.field],
+ onPopupOpenChange: (open) => {
+ if (!open) serverSearch("");
+ }
}
: {})}
/>
@@ -292,6 +290,7 @@ export const FilterBuilder = ({
onSaveView,
dynamicFieldOptions,
onDynamicFieldSearch,
+ dynamicFieldLoading,
hiddenFieldKeys
}: Props) => {
const availableFields = hiddenFieldKeys?.length
@@ -360,6 +359,7 @@ export const FilterBuilder = ({
onRemove={() => handleRemoveRule(index)}
dynamicFieldOptions={dynamicFieldOptions}
onDynamicFieldSearch={onDynamicFieldSearch}
+ dynamicFieldLoading={dynamicFieldLoading}
availableFields={availableFields}
/>
</div>
diff --git a/frontend/src/pages/cert-manager/CodeSigningPage/components/CreateSignerWizard/ApprovalPolicyStep.tsx b/frontend/src/pages/cert-manager/CodeSigningPage/components/CreateSignerWizard/ApprovalPolicyStep.tsx
index 3fe4126622..9cd8b50f8f 100644
--- a/frontend/src/pages/cert-manager/CodeSigningPage/components/CreateSignerWizard/ApprovalPolicyStep.tsx
+++ b/frontend/src/pages/cert-manager/CodeSigningPage/components/CreateSignerWizard/ApprovalPolicyStep.tsx
@@ -2,6 +2,7 @@ import { ClockIcon, PlusIcon, ShieldIcon, XIcon } from "lucide-react";
import {
Button,
+ Combobox,
Empty,
EmptyContent,
EmptyDescription,
@@ -12,7 +13,6 @@ import {
FieldContent,
FieldDescription,
FieldLabel,
- FilterableSelect,
Input,
Select,
SelectContent,
@@ -120,7 +120,6 @@ export const ApprovalPolicyStep = ({
const takenGroups = new Set(s.approverGroupIds);
const isTaken = (o: ApproverOption) =>
o.kind === "user" ? takenUsers.has(o.value) : takenGroups.has(o.value);
- const optionsForStep = approverOptions.filter((o) => !isTaken(o));
const valueForStep = approverOptions.filter(isTaken);
return (
@@ -150,18 +149,17 @@ export const ApprovalPolicyStep = ({
<div className="grid grid-cols-[1fr_140px] gap-3">
<Field>
- <FieldLabel>Approvers</FieldLabel>
+ <FieldLabel htmlFor={`create-signer-approvers-${s.key}`}>Approvers</FieldLabel>
<FieldContent>
- <FilterableSelect<ApproverOption>
- isMulti
- options={optionsForStep}
- groupBy="kind"
- getGroupHeaderLabel={(g) => (g === "group" ? "Groups" : "Users")}
- getOptionValue={(o) => approverOptionKey(o as ApproverOption)}
- isOptionSelected={(o) => isTaken(o as ApproverOption)}
+ <Combobox
+ id={`create-signer-approvers-${s.key}`}
+ multiple
+ options={approverOptions}
+ getOptionGroup={(option) => (option.kind === "group" ? "Groups" : "Users")}
+ getOptionValue={approverOptionKey}
+ getOptionLabel={(option) => option.label}
value={valueForStep}
- onChange={(selected) => {
- const picks = (selected as ApproverOption[] | null) ?? [];
+ onValueChange={(picks) => {
patchStep(s.key, {
approverUserIds: picks
.filter((p) => p.kind === "user")
@@ -172,7 +170,7 @@ export const ApprovalPolicyStep = ({
});
}}
placeholder="Pick approvers from members..."
- noOptionsMessage={() => "Add member users in the previous step first."}
+ emptyMessage="Add member users in the previous step first."
/>
<FieldDescription>Approvers must already be members.</FieldDescription>
</FieldContent>
diff --git a/frontend/src/pages/cert-manager/CodeSigningPage/components/CreateSignerWizard/CreateSignerWizard.tsx b/frontend/src/pages/cert-manager/CodeSigningPage/components/CreateSignerWizard/CreateSignerWizard.tsx
index 2cf02a712f..926c7f772a 100644
--- a/frontend/src/pages/cert-manager/CodeSigningPage/components/CreateSignerWizard/CreateSignerWizard.tsx
+++ b/frontend/src/pages/cert-manager/CodeSigningPage/components/CreateSignerWizard/CreateSignerWizard.tsx
@@ -2,13 +2,14 @@ import { useEffect, useMemo, useState } from "react";
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { AxiosError } from "axios";
-import { PenTool } from "lucide-react";
import {
Button,
+ DiscardChangesAlertDialog,
DocumentationLinkBadge,
Sheet,
SheetContent,
+ SheetDescription,
SheetFooter,
SheetHeader,
SheetTitle,
@@ -33,6 +34,7 @@ import {
useCreateSigner
} from "@app/hooks/api/signers";
import { useGetOrgUsers } from "@app/hooks/api/users";
+import { useDiscardChangesGuard } from "@app/hooks/useDiscardChangesGuard";
import {
ExternalOrderMode,
@@ -213,13 +215,8 @@ export const CreateSignerWizard = ({ isOpen, onOpenChange, projectId }: Props) =
});
};
- const handleClose = (open: boolean) => {
- if (!open && submitting) return;
- if (!open) reset();
- onOpenChange(open);
- };
-
const onCreate = async () => {
+ if (submitting) return;
setSubmitting(true);
try {
const approvalPolicy =
@@ -312,6 +309,7 @@ export const CreateSignerWizard = ({ isOpen, onOpenChange, projectId }: Props) =
};
const goNext = async () => {
+ if (submitting) return;
if (step === 0) {
const ok = await basicsForm.trigger();
if (!ok) return;
@@ -392,10 +390,22 @@ export const CreateSignerWizard = ({ isOpen, onOpenChange, projectId }: Props) =
const dirty =
step > 0 ||
- state.name !== "" ||
- state.commonName !== "" ||
- state.pendingMembers.length > 0 ||
- state.policySteps.length > 0;
+ basicsForm.formState.isDirty ||
+ certificateForm.formState.isDirty ||
+ JSON.stringify(state) !== JSON.stringify(INITIAL_WIZARD_STATE);
+ const { confirmDiscard, isDiscardDialogOpen, requestDiscard, setIsDiscardDialogOpen } =
+ useDiscardChangesGuard({
+ isDirty: dirty,
+ onDiscard: () => {
+ reset();
+ onOpenChange(false);
+ }
+ });
+ const handleClose = (open: boolean) => {
+ if (submitting) return;
+ if (open) onOpenChange(true);
+ else requestDiscard();
+ };
const currentStep = STEPS[step];
const ctaLabel = isLast ? "Create Signer" : "Continue";
@@ -408,159 +418,169 @@ export const CreateSignerWizard = ({ isOpen, onOpenChange, projectId }: Props) =
const ctaDisabled = isLast && (hasEmptyPolicyStep || missingConstraints);
return (
- <Sheet open={isOpen} onOpenChange={handleClose}>
- <SheetContent size="workspace" className="flex h-full max-h-full flex-col gap-y-0">
- <SheetHeader className="border-b">
- <SheetTitle>
- <div className="flex w-full items-start gap-2">
- <div className="flex h-10 w-10 items-center justify-center rounded-md bg-project/10 text-project">
- <PenTool className="h-5 w-5" />
- </div>
- <div>
- <div className="flex items-center gap-x-2 text-label">
- Create Signer
- <DocumentationLinkBadge href={PkiDocsUrls.codeSigning.signers.create} />
- </div>
- <p className="text-sm leading-4 text-muted">
- A code-signing certificate with the members and approval policy that govern its
- use.
+ <>
+ <Sheet open={isOpen} onOpenChange={handleClose}>
+ <SheetContent size="workspace" isPending={submitting}>
+ <SheetHeader>
+ <SheetTitle className="flex items-center gap-2">
+ Create Signer
+ <DocumentationLinkBadge href={PkiDocsUrls.codeSigning.signers.create} />
+ </SheetTitle>
+ <SheetDescription>
+ A code-signing certificate with the members and approval policy that govern its use.
+ </SheetDescription>
+ </SheetHeader>
+
+ <div className="flex min-h-0 flex-1 flex-col">
+ <div className="flex min-h-0 flex-1 overflow-hidden">
+ <aside className="flex w-60 shrink-0 flex-col border-r border-border px-5 py-6">
+ <p className="mb-5 text-[11px] font-medium tracking-wider text-muted uppercase">
+ Setup steps
</p>
- </div>
- </div>
- </SheetTitle>
- </SheetHeader>
-
- <div className="flex min-h-0 flex-1 flex-col">
- <div className="flex min-h-0 flex-1 overflow-hidden">
- <aside className="flex w-60 shrink-0 flex-col border-r border-border px-5 py-6">
- <p className="mb-5 text-[11px] font-medium tracking-wider text-muted uppercase">
- Setup steps
- </p>
- <Stepper
- activeStep={step}
- orientation="vertical"
- onStepChange={(i) => {
- if (i < step && !submitting) setStep(i);
- }}
+ <Stepper
+ activeStep={step}
+ orientation="vertical"
+ onStepChange={(i) => {
+ if (i < step && !submitting) setStep(i);
+ }}
+ >
+ <StepperList>
+ {STEPS.map((s, i) => (
+ <StepperStep
+ key={s.name}
+ index={i}
+ title={s.name}
+ description={s.shortDescription}
+ />
+ ))}
+ </StepperList>
+ </Stepper>
+ </aside>
+
+ <fieldset
+ disabled={submitting}
+ className="flex min-w-0 flex-1 flex-col gap-y-2 overflow-y-auto px-8 py-6"
>
- <StepperList>
- {STEPS.map((s, i) => (
- <StepperStep
- key={s.name}
- index={i}
- title={s.name}
- description={s.shortDescription}
- />
- ))}
- </StepperList>
- </Stepper>
- </aside>
-
- <div className="flex min-w-0 flex-1 flex-col gap-y-2 overflow-y-auto px-8 py-6">
- <div className="mb-6">
- <h2 className="text-lg font-normal text-foreground">{currentStep.title}</h2>
- <p className="mt-1 text-sm text-muted">{currentStep.subtitle}</p>
- </div>
-
- {step === 0 && <BasicsStep form={basicsForm} />}
- {step === 1 && (
- <CertificateStep
- form={certificateForm}
- caOptions={caOptions}
- isCasLoading={cas.isPending}
- />
- )}
- {step === 2 && (
- <SignerKeyStep
- control={certificateForm.control}
- requiresHsm={caCaps.requiresHsm}
- minRsaKeyBits={caCaps.minRsaKeyBits}
- hsmConnectorOptions={hsmConnectorOptions}
- isHsmConnectorsLoading={isHsmConnectorsLoading}
- importCheckError={importCheckError}
- />
- )}
- {step === 3 && (
- <MembersStep
- userOptions={userOptions.filter((u) => u.value !== user.id)}
- identityOptions={identityOptions}
- groupOptions={groupOptions}
- state={state}
- setState={setState}
- isUsersLoading={usersQuery.isPending}
- isIdentitiesLoading={identitiesQuery.isPending}
- isGroupsLoading={groupsQuery.isPending}
- creator={{ id: user.id, label: creatorLabel }}
- />
- )}
- {step === 4 && (
- <ApprovalPolicyStep
- state={state}
- setState={setState}
- approverOptions={[
- { value: user.id, label: creatorLabel, kind: "user" as const },
- ...state.pendingMembers
- .filter((m) => m.role !== SignerMemberRole.Auditor)
- .filter((m) => m.kind === "user" || m.kind === "group")
- .map((m) => ({
- value: m.id,
- label: m.label,
- kind: m.kind as "user" | "group"
- }))
- ]}
- />
- )}
- </div>
+ <div className="mb-6">
+ <h2 className="text-lg font-normal text-foreground">{currentStep.title}</h2>
+ <p className="mt-1 text-sm text-muted">{currentStep.subtitle}</p>
+ </div>
- <aside className="hidden w-80 shrink-0 flex-col gap-4 overflow-y-auto border-l border-border px-6 py-6 lg:flex">
- <div className="mb-auto">
- <div className="flex items-center justify-between gap-2">
- <p className="text-[11px] font-medium tracking-wider text-muted uppercase">
- Step {step + 1} · {currentStep.rightLabel}
+ {step === 0 && <BasicsStep form={basicsForm} />}
+ {step === 1 && (
+ <CertificateStep
+ form={certificateForm}
+ caOptions={caOptions}
+ isCasLoading={cas.isPending}
+ />
+ )}
+ {step === 2 && (
+ <SignerKeyStep
+ control={certificateForm.control}
+ requiresHsm={caCaps.requiresHsm}
+ minRsaKeyBits={caCaps.minRsaKeyBits}
+ hsmConnectorOptions={hsmConnectorOptions}
+ isHsmConnectorsLoading={isHsmConnectorsLoading}
+ importCheckError={importCheckError}
+ />
+ )}
+ {step === 3 && (
+ <MembersStep
+ userOptions={userOptions.filter((u) => u.value !== user.id)}
+ identityOptions={identityOptions}
+ groupOptions={groupOptions}
+ state={state}
+ setState={setState}
+ isUsersLoading={usersQuery.isPending}
+ isIdentitiesLoading={identitiesQuery.isPending}
+ isGroupsLoading={groupsQuery.isPending}
+ creator={{ id: user.id, label: creatorLabel }}
+ />
+ )}
+ {step === 4 && (
+ <ApprovalPolicyStep
+ state={state}
+ setState={setState}
+ approverOptions={[
+ { value: user.id, label: creatorLabel, kind: "user" as const },
+ ...state.pendingMembers
+ .filter((m) => m.role !== SignerMemberRole.Auditor)
+ .filter((m) => m.kind === "user" || m.kind === "group")
+ .map((m) => ({
+ value: m.id,
+ label: m.label,
+ kind: m.kind as "user" | "group"
+ }))
+ ]}
+ />
+ )}
+ </fieldset>
+
+ <aside className="hidden w-80 shrink-0 flex-col gap-4 overflow-y-auto border-l border-border px-6 py-6 lg:flex">
+ <div className="mb-auto">
+ <div className="flex items-center justify-between gap-2">
+ <p className="text-[11px] font-medium tracking-wider text-muted uppercase">
+ Step {step + 1} · {currentStep.rightLabel}
+ </p>
+ <DocumentationLinkBadge href={currentStep.docsUrl} />
+ </div>
+ <p className="mt-4 text-sm font-semibold text-foreground">What this step does</p>
+ <p className="mt-2 text-sm leading-relaxed text-muted">
+ {currentStep.rightDescription}
</p>
- <DocumentationLinkBadge href={currentStep.docsUrl} />
</div>
- <p className="mt-4 text-sm font-semibold text-foreground">What this step does</p>
- <p className="mt-2 text-sm leading-relaxed text-muted">
- {currentStep.rightDescription}
- </p>
- </div>
- </aside>
- </div>
+ </aside>
+ </div>
- <SheetFooter className="shrink-0 items-center justify-between border-t">
- <span className="text-xs text-muted">
- {/* eslint-disable-next-line no-nested-ternary */}
- {hasEmptyPolicyStep
- ? `Step ${firstEmptyPolicyStepIndex + 1} needs at least one approver, or remove it.`
- : // eslint-disable-next-line no-nested-ternary
- missingConstraints
- ? "Set at least one of 'signatures per approval' or 'signing window'."
- : dirty
- ? "Unsaved changes"
- : ""}
- </span>
- <div className="flex items-center gap-3">
- <span className="text-xs text-muted">
- Step {step + 1} of {STEPS.length}
- </span>
+ <SheetFooter className="shrink-0 items-center justify-between border-t">
{step > 0 && (
- <Button variant="outline" onClick={goBack} isDisabled={submitting}>
+ <Button
+ variant="outline"
+ onClick={goBack}
+ isDisabled={submitting}
+ className="mr-auto"
+ >
Back
</Button>
)}
- <Button
- variant="project"
- onClick={goNext}
- isPending={submitting}
- isDisabled={ctaDisabled}
- >
- {ctaLabel}
- </Button>
- </div>
- </SheetFooter>
- </div>
- </SheetContent>
- </Sheet>
+ <span className="text-xs text-muted">
+ {/* eslint-disable-next-line no-nested-ternary */}
+ {hasEmptyPolicyStep
+ ? `Step ${firstEmptyPolicyStepIndex + 1} needs at least one approver, or remove it.`
+ : // eslint-disable-next-line no-nested-ternary
+ missingConstraints
+ ? "Set at least one of 'signatures per approval' or 'signing window'."
+ : dirty
+ ? "Unsaved changes"
+ : ""}
+ </span>
+ <div className="flex items-center gap-3">
+ <span className="text-xs text-muted">
+ Step {step + 1} of {STEPS.length}
+ </span>
+ <Button variant="ghost" onClick={() => handleClose(false)} isDisabled={submitting}>
+ Cancel
+ </Button>
+ <Button
+ variant="project"
+ onClick={goNext}
+ isPending={submitting}
+ isDisabled={ctaDisabled}
+ >
+ {ctaLabel}
+ </Button>
+ </div>
+ </SheetFooter>
+ </div>
+ </SheetContent>
+ </Sheet>
+ <DiscardChangesAlertDialog
+ open={isDiscardDialogOpen}
+ onOpenChange={setIsDiscardDialogOpen}
+ onDiscard={confirmDiscard}
+ title="Discard Changes?"
+ description="Your signer setup progress will be lost."
+ />
+ </>
);
};
diff --git a/frontend/src/pages/cert-manager/CodeSigningPage/components/WizardAddMemberModal.tsx b/frontend/src/pages/cert-manager/CodeSigningPage/components/WizardAddMemberModal.tsx
index 90d5393ad9..e3bdd9b606 100644
--- a/frontend/src/pages/cert-manager/CodeSigningPage/components/WizardAddMemberModal.tsx
+++ b/frontend/src/pages/cert-manager/CodeSigningPage/components/WizardAddMemberModal.tsx
@@ -1,19 +1,21 @@
-import { useEffect, useState } from "react";
+import { useEffect, useId, useState } from "react";
import { HardDriveIcon, UserIcon, UsersIcon } from "lucide-react";
import {
Button,
+ Combobox,
Dialog,
+ DialogBody,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
+ DiscardChangesAlertDialog,
Field,
FieldContent,
FieldGroup,
FieldLabel,
- FilterableSelect,
Select,
SelectContent,
SelectItem,
@@ -25,6 +27,7 @@ import {
signerMemberRoleDescriptions,
signerMemberRoleLabels
} from "@app/hooks/api/signers";
+import { useDiscardChangesGuard } from "@app/hooks/useDiscardChangesGuard";
export type WizardMemberKind = "user" | "identity" | "group";
type Option = { value: string; label: string };
@@ -65,9 +68,16 @@ export const WizardAddMemberModal = ({
takenKeys,
onAdd
}: Props) => {
+ const formId = useId();
+ const memberId = useId();
const [kind, setKind] = useState<WizardMemberKind>("user");
const [member, setMember] = useState<Option | null>(null);
const [role, setRole] = useState<SignerMemberRole>(SignerMemberRole.Operator);
+ const { confirmDiscard, isDiscardDialogOpen, requestDiscard, setIsDiscardDialogOpen } =
+ useDiscardChangesGuard({
+ isDirty: kind !== "user" || member !== null || role !== SignerMemberRole.Operator,
+ onDiscard: () => onOpenChange(false)
+ });
useEffect(() => {
if (!isOpen) {
@@ -99,95 +109,121 @@ export const WizardAddMemberModal = ({
};
return (
- <Dialog open={isOpen} onOpenChange={onOpenChange}>
- <DialogContent className="max-w-md">
- <DialogHeader>
- <DialogTitle>Add member</DialogTitle>
- <DialogDescription>
- Pick a user, machine identity, or group, and the role they should have on this signer.
- </DialogDescription>
- </DialogHeader>
+ <>
+ <Dialog open={isOpen} onOpenChange={(open) => (open ? onOpenChange(true) : requestDiscard())}>
+ <DialogContent className="max-w-md">
+ <DialogHeader>
+ <DialogTitle>Add member</DialogTitle>
+ <DialogDescription>
+ Pick a user, machine identity, or group, and the role they should have on this signer.
+ </DialogDescription>
+ </DialogHeader>
- <FieldGroup>
- <Field>
- <FieldLabel>Type</FieldLabel>
- <FieldContent>
- <Select
- value={kind}
- onValueChange={(v) => {
- setKind(v as WizardMemberKind);
- setMember(null);
- }}
- >
- <SelectTrigger className="w-full">
- <SelectValue />
- </SelectTrigger>
- <SelectContent>
- {(["user", "identity", "group"] as WizardMemberKind[]).map((k) => (
- <SelectItem key={k} value={k}>
- <span className="flex items-center gap-2">
- {/* eslint-disable-next-line no-nested-ternary */}
- {k === "user" ? (
- <UserIcon className="h-3.5 w-3.5" />
- ) : k === "identity" ? (
- <HardDriveIcon className="h-3.5 w-3.5" />
- ) : (
- <UsersIcon className="h-3.5 w-3.5" />
- )}
- {KIND_LABEL[k]}
- </span>
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
- </FieldContent>
- </Field>
+ <DialogBody>
+ <form
+ id={formId}
+ onSubmit={(event) => {
+ event.preventDefault();
+ handleAdd();
+ }}
+ >
+ <FieldGroup>
+ <Field>
+ <FieldLabel>Type</FieldLabel>
+ <FieldContent>
+ <Select
+ value={kind}
+ onValueChange={(v) => {
+ setKind(v as WizardMemberKind);
+ setMember(null);
+ }}
+ >
+ <SelectTrigger className="w-full">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ {(["user", "identity", "group"] as WizardMemberKind[]).map((k) => (
+ <SelectItem key={k} value={k}>
+ <span className="flex items-center gap-2">
+ {/* eslint-disable-next-line no-nested-ternary */}
+ {k === "user" ? (
+ <UserIcon className="h-3.5 w-3.5" />
+ ) : k === "identity" ? (
+ <HardDriveIcon className="h-3.5 w-3.5" />
+ ) : (
+ <UsersIcon className="h-3.5 w-3.5" />
+ )}
+ {KIND_LABEL[k]}
+ </span>
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ </FieldContent>
+ </Field>
- <Field>
- <FieldLabel>{KIND_LABEL[kind]}</FieldLabel>
- <FieldContent>
- <FilterableSelect
- isLoading={loadingByKind[kind]}
- options={filteredOptions}
- value={member}
- onChange={(selected) => setMember((selected as Option | null) ?? null)}
- placeholder={`Pick a ${KIND_LABEL[kind].toLowerCase()}...`}
- noOptionsMessage={() =>
- `No ${KIND_LABEL[kind].toLowerCase()}s available — they may already be added.`
- }
- />
- </FieldContent>
- </Field>
+ <Field>
+ <FieldLabel htmlFor={memberId}>{KIND_LABEL[kind]}</FieldLabel>
+ <FieldContent>
+ <Combobox
+ key={kind}
+ id={memberId}
+ isLoading={loadingByKind[kind]}
+ options={filteredOptions}
+ getOptionValue={(option) => option.value}
+ getOptionLabel={(option) => option.label}
+ includeMissingSelectedOptions={false}
+ value={member}
+ onValueChange={setMember}
+ placeholder={`Pick a ${KIND_LABEL[kind].toLowerCase()}...`}
+ emptyMessage={`No ${KIND_LABEL[kind].toLowerCase()}s available — they may already be added.`}
+ />
+ </FieldContent>
+ </Field>
- <Field>
- <FieldLabel>Role</FieldLabel>
- <FieldContent>
- <Select value={role} onValueChange={(v) => setRole(v as SignerMemberRole)}>
- <SelectTrigger className="w-full">
- <SelectValue />
- </SelectTrigger>
- <SelectContent position="popper" align="start" sideOffset={4}>
- {Object.values(SignerMemberRole).map((r) => (
- <SelectItem key={r} value={r} description={signerMemberRoleDescriptions[r]}>
- {signerMemberRoleLabels[r]}
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
- </FieldContent>
- </Field>
- </FieldGroup>
+ <Field>
+ <FieldLabel>Role</FieldLabel>
+ <FieldContent>
+ <Select value={role} onValueChange={(v) => setRole(v as SignerMemberRole)}>
+ <SelectTrigger className="w-full">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent position="popper" align="start" sideOffset={4}>
+ {Object.values(SignerMemberRole).map((r) => (
+ <SelectItem
+ key={r}
+ value={r}
+ description={signerMemberRoleDescriptions[r]}
+ >
+ {signerMemberRoleLabels[r]}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ </FieldContent>
+ </Field>
+ </FieldGroup>
+ </form>
+ </DialogBody>
- <DialogFooter>
- <Button variant="outline" onClick={() => onOpenChange(false)}>
- Cancel
- </Button>
- <Button variant="project" onClick={handleAdd} isDisabled={!member}>
- <Icon className="h-3.5 w-3.5" />
- <span>Add to signer</span>
- </Button>
- </DialogFooter>
- </DialogContent>
- </Dialog>
+ <DialogFooter>
+ <Button variant="ghost" onClick={requestDiscard}>
+ Cancel
+ </Button>
+ <Button type="submit" form={formId} variant="project" isDisabled={!member}>
+ <Icon className="h-3.5 w-3.5" />
+ <span>Add to signer</span>
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ <DiscardChangesAlertDialog
+ open={isDiscardDialogOpen}
+ onOpenChange={setIsDiscardDialogOpen}
+ onDiscard={confirmDiscard}
+ title="Discard Changes?"
+ description="Your member selection and role will be lost."
+ />
+ </>
);
};
diff --git a/frontend/src/pages/cert-manager/SignerDetailPage/components/AddSignerMemberModal.tsx b/frontend/src/pages/cert-manager/SignerDetailPage/components/AddSignerMemberModal.tsx
index b490cf8d47..5d1922be08 100644
--- a/frontend/src/pages/cert-manager/SignerDetailPage/components/AddSignerMemberModal.tsx
+++ b/frontend/src/pages/cert-manager/SignerDetailPage/components/AddSignerMemberModal.tsx
@@ -1,21 +1,23 @@
-import { useMemo, useState } from "react";
+import { useId, useMemo, useState } from "react";
import { HardDriveIcon, UserIcon, UsersIcon } from "lucide-react";
import { createNotification } from "@app/components/notifications";
import {
Button,
ButtonGroup,
+ Combobox,
Dialog,
+ DialogBody,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
+ DiscardChangesAlertDialog,
Field,
FieldContent,
FieldGroup,
FieldLabel,
- FilterableSelect,
Select,
SelectContent,
SelectItem,
@@ -36,6 +38,7 @@ import {
useAddSignerUserMembers
} from "@app/hooks/api/signers";
import { useGetOrgUsers } from "@app/hooks/api/users";
+import { useDiscardChangesGuard } from "@app/hooks/useDiscardChangesGuard";
type Props = {
isOpen: boolean;
@@ -48,18 +51,14 @@ type Kind = "user" | "identity" | "group";
type Option = { value: string; label: string };
-const formatMemberOptionLabel = (option: Option, meta: { context: "menu" | "value" }) => (
- <span className={meta.context === "value" ? "block max-w-[22rem] truncate" : "block truncate"}>
- {option.label}
- </span>
-);
-
export const AddSignerMemberModal = ({
isOpen,
onOpenChange,
signerId,
existingMembers
}: Props) => {
+ const formId = useId();
+ const memberId = useId();
const { currentOrg } = useOrganization();
const { currentProject } = useProject();
const orgId = currentOrg?.id ?? "";
@@ -128,12 +127,28 @@ export const AddSignerMemberModal = ({
setRole(SignerMemberRole.Operator);
};
+ const close = () => {
+ reset();
+ onOpenChange(false);
+ };
+ const { confirmDiscard, isDiscardDialogOpen, requestDiscard, setIsDiscardDialogOpen } =
+ useDiscardChangesGuard({
+ isDirty:
+ kind !== "user" ||
+ selectedUsers.length > 0 ||
+ selectedIdentities.length > 0 ||
+ selectedGroups.length > 0 ||
+ role !== SignerMemberRole.Operator,
+ onDiscard: close
+ });
const handleClose = (open: boolean) => {
- if (!open) reset();
- onOpenChange(open);
+ if (submitting) return;
+ if (open) onOpenChange(true);
+ else requestDiscard();
};
const onSubmit = async () => {
+ if (submitting) return;
setSubmitting(true);
try {
if (kind === "user" && selectedUsers.length > 0) {
@@ -160,7 +175,7 @@ export const AddSignerMemberModal = ({
);
createNotification({ type: "success", text: "Members added" });
}
- handleClose(false);
+ close();
} catch (err) {
createNotification({
type: "error",
@@ -184,84 +199,122 @@ export const AddSignerMemberModal = ({
else if (kind === "identity") setSelectedIdentities(next);
else setSelectedGroups(next);
};
+ const selectionLabel = { user: "users", identity: "identities", group: "groups" }[kind];
+ const isLoading = {
+ user: usersQuery.isPending,
+ identity: projectIdentitiesQuery.isPending,
+ group: groupsQuery.isPending
+ }[kind];
return (
- <Dialog open={isOpen} onOpenChange={handleClose}>
- <DialogContent className="max-w-xl">
- <DialogHeader>
- <DialogTitle>Add member</DialogTitle>
- <DialogDescription>
- Pick existing org members, machine identities, or groups to attach to this signer.
- </DialogDescription>
- </DialogHeader>
+ <>
+ <Dialog open={isOpen} onOpenChange={handleClose}>
+ <DialogContent className="max-w-xl" isPending={submitting}>
+ <DialogHeader>
+ <DialogTitle>Add member</DialogTitle>
+ <DialogDescription>
+ Pick existing org members, machine identities, or groups to attach to this signer.
+ </DialogDescription>
+ </DialogHeader>
- <FieldGroup>
- <ButtonGroup className="w-full">
- {[
- { value: "user" as const, label: "Users", icon: UserIcon },
- { value: "identity" as const, label: "Machine Identities", icon: HardDriveIcon },
- { value: "group" as const, label: "Groups", icon: UsersIcon }
- ].map((opt) => {
- const Icon = opt.icon;
- return (
- <Button
- key={opt.value}
- variant={kind === opt.value ? "project" : "outline"}
- onClick={() => setKind(opt.value)}
- className="flex-1"
- >
- <Icon className="h-3.5 w-3.5" />
- <span>{opt.label}</span>
- </Button>
- );
- })}
- </ButtonGroup>
+ <DialogBody>
+ <form
+ id={formId}
+ onSubmit={(event) => {
+ event.preventDefault();
+ onSubmit();
+ }}
+ >
+ <fieldset disabled={submitting}>
+ <FieldGroup>
+ <ButtonGroup className="w-full">
+ {[
+ { value: "user" as const, label: "Users", icon: UserIcon },
+ {
+ value: "identity" as const,
+ label: "Machine Identities",
+ icon: HardDriveIcon
+ },
+ { value: "group" as const, label: "Groups", icon: UsersIcon }
+ ].map((opt) => {
+ const Icon = opt.icon;
+ return (
+ <Button
+ key={opt.value}
+ variant={kind === opt.value ? "project" : "outline"}
+ onClick={() => setKind(opt.value)}
+ className="flex-1"
+ >
+ <Icon className="h-3.5 w-3.5" />
+ <span>{opt.label}</span>
+ </Button>
+ );
+ })}
+ </ButtonGroup>
- <Field>
- <FieldLabel>
- {/* eslint-disable-next-line no-nested-ternary */}
- Select {kind === "user" ? "users" : kind === "identity" ? "identities" : "groups"}
- </FieldLabel>
- <FieldContent>
- <FilterableSelect
- isMulti
- options={optionsForKind}
- value={valueForKind}
- onChange={(selected) => setSelected((selected as Option[] | null) ?? [])}
- placeholder="Pick..."
- formatOptionLabel={formatMemberOptionLabel}
- />
- </FieldContent>
- </Field>
+ <Field>
+ <FieldLabel htmlFor={memberId}>Select {selectionLabel}</FieldLabel>
+ <FieldContent>
+ <Combobox
+ key={kind}
+ id={memberId}
+ multiple
+ options={optionsForKind}
+ getOptionValue={(option) => option.value}
+ getOptionLabel={(option) => option.label}
+ includeMissingSelectedOptions={false}
+ value={valueForKind}
+ onValueChange={setSelected}
+ isDisabled={submitting}
+ isLoading={isLoading}
+ placeholder="Pick..."
+ />
+ </FieldContent>
+ </Field>
- <Field>
- <FieldLabel>Role</FieldLabel>
- <FieldContent>
- <Select value={role} onValueChange={(v) => setRole(v as SignerMemberRole)}>
- <SelectTrigger className="w-full">
- <SelectValue />
- </SelectTrigger>
- <SelectContent position="popper" align="start" sideOffset={4}>
- {Object.values(SignerMemberRole).map((r) => (
- <SelectItem key={r} value={r} description={signerMemberRoleDescriptions[r]}>
- {signerMemberRoleLabels[r]}
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
- </FieldContent>
- </Field>
- </FieldGroup>
+ <Field>
+ <FieldLabel>Role</FieldLabel>
+ <FieldContent>
+ <Select value={role} onValueChange={(v) => setRole(v as SignerMemberRole)}>
+ <SelectTrigger className="w-full">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent position="popper" align="start" sideOffset={4}>
+ {Object.values(SignerMemberRole).map((r) => (
+ <SelectItem
+ key={r}
+ value={r}
+ description={signerMemberRoleDescriptions[r]}
+ >
+ {signerMemberRoleLabels[r]}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ </FieldContent>
+ </Field>
+ </FieldGroup>
+ </fieldset>
+ </form>
+ </DialogBody>
- <DialogFooter>
- <Button variant="outline" onClick={() => handleClose(false)}>
- Cancel
- </Button>
- <Button variant="project" onClick={onSubmit} isPending={submitting}>
- Add members
- </Button>
- </DialogFooter>
- </DialogContent>
- </Dialog>
+ <DialogFooter>
+ <Button variant="ghost" onClick={() => handleClose(false)} isDisabled={submitting}>
+ Cancel
+ </Button>
+ <Button type="submit" form={formId} variant="project" isPending={submitting}>
+ Add members
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ <DiscardChangesAlertDialog
+ open={isDiscardDialogOpen}
+ onOpenChange={setIsDiscardDialogOpen}
+ onDiscard={confirmDiscard}
+ title="Discard Changes?"
+ description="Your member selections and role will be lost."
+ />
+ </>
);
};
diff --git a/frontend/src/pages/cert-manager/SignerDetailPage/components/EditSignerPolicyModal/ApproversStep.tsx b/frontend/src/pages/cert-manager/SignerDetailPage/components/EditSignerPolicyModal/ApproversStep.tsx
index 84be41ad41..96c4822136 100644
--- a/frontend/src/pages/cert-manager/SignerDetailPage/components/EditSignerPolicyModal/ApproversStep.tsx
+++ b/frontend/src/pages/cert-manager/SignerDetailPage/components/EditSignerPolicyModal/ApproversStep.tsx
@@ -2,12 +2,12 @@ import { ArrowDownIcon, InfoIcon, PlusIcon, ShieldIcon, XIcon } from "lucide-rea
import {
Button,
+ Combobox,
Field,
FieldContent,
FieldDescription,
FieldGroup,
FieldLabel,
- FilterableSelect,
IconButton,
Input
} from "@app/components/v3";
@@ -89,29 +89,22 @@ export const ApproversStep = ({
<FieldGroup className="mt-3 grid grid-cols-1 gap-3 md:grid-cols-3">
<div className="md:col-span-2">
<Field>
- <FieldLabel>Approvers</FieldLabel>
+ <FieldLabel htmlFor={`edit-signer-approvers-${s.key}`}>Approvers</FieldLabel>
<FieldContent>
- <FilterableSelect
- isMulti
+ <Combobox
+ id={`edit-signer-approvers-${s.key}`}
+ multiple
options={approverOptions}
- groupBy="kind"
- getGroupHeaderLabel={(g) => (g === "group" ? "Groups" : "Users")}
- getOptionValue={(o) =>
- approverKey((o as ApproverOption).kind, (o as ApproverOption).value)
- }
- isOptionSelected={(o) => {
- const opt = o as ApproverOption;
- return s.approvers.some(
- (a) => a.kind === opt.kind && a.value === opt.value
- );
- }}
+ getOptionGroup={(option) => (option.kind === "group" ? "Groups" : "Users")}
+ getOptionValue={(option) => approverKey(option.kind, option.value)}
+ getOptionLabel={(option) => option.label}
+ includeMissingSelectedOptions={false}
value={s.approvers}
- onChange={(selected) => {
- const opts = (selected ?? []) as ApproverOption[];
- onUpdateStep(s.key, { approvers: opts });
+ onValueChange={(approvers) => {
+ onUpdateStep(s.key, { approvers });
}}
placeholder="Pick approvers from members..."
- noOptionsMessage={() => "No eligible members"}
+ emptyMessage="No eligible members"
/>
<FieldDescription>Approvers must already be members.</FieldDescription>
</FieldContent>
diff --git a/frontend/src/pages/cert-manager/SignerDetailPage/components/EditSignerPolicyModal/EditSignerPolicyModal.tsx b/frontend/src/pages/cert-manager/SignerDetailPage/components/EditSignerPolicyModal/EditSignerPolicyModal.tsx
index 02e96f9fc7..b134eca7d8 100644
--- a/frontend/src/pages/cert-manager/SignerDetailPage/components/EditSignerPolicyModal/EditSignerPolicyModal.tsx
+++ b/frontend/src/pages/cert-manager/SignerDetailPage/components/EditSignerPolicyModal/EditSignerPolicyModal.tsx
@@ -1,12 +1,13 @@
import { useEffect, useMemo, useState } from "react";
-import { ShieldIcon } from "lucide-react";
import { createNotification } from "@app/components/notifications";
import {
Button,
+ DiscardChangesAlertDialog,
DocumentationLinkBadge,
Sheet,
SheetContent,
+ SheetDescription,
SheetFooter,
SheetHeader,
SheetTitle,
@@ -20,6 +21,7 @@ import {
useListSignerMembers,
useUpdateSignerPolicy
} from "@app/hooks/api/signers";
+import { useDiscardChangesGuard } from "@app/hooks/useDiscardChangesGuard";
import { PkiDocsUrls } from "../../../pki-docs-urls";
import { ApproversStep } from "./ApproversStep";
@@ -138,9 +140,43 @@ export const EditSignerPolicyModal = ({
const updateStep = (key: string, patch: Partial<StepDraft>) =>
setSteps((prev) => prev.map((s) => (s.key === key ? { ...s, ...patch } : s)));
+ const close = () => {
+ setStep(0);
+ onOpenChange(false);
+ };
+ const policyDraft = {
+ steps: steps.map((s) => ({
+ name: s.name,
+ requiredApprovals: s.requiredApprovals,
+ approvers: s.approvers.map((a) => approverKey(a.kind, a.value))
+ })),
+ maxSignings,
+ maxWindow
+ };
+ const initialPolicyDraft = {
+ steps: (existingPolicy?.steps ?? []).map((s) => ({
+ name: s.name ?? "",
+ requiredApprovals: s.requiredApprovals,
+ approvers: s.approvers
+ .filter((a) => a.type === "user" || a.type === "group")
+ .map((a) => approverKey(a.type as ApproverKind, a.id))
+ })),
+ maxSignings: existingPolicy?.steps.length
+ ? (existingPolicy.constraints.maxSignings ?? null)
+ : null,
+ maxWindow: existingPolicy?.steps.length
+ ? (existingPolicy.constraints.maxWindowDuration ?? null)
+ : null
+ };
+ const { confirmDiscard, isDiscardDialogOpen, requestDiscard, setIsDiscardDialogOpen } =
+ useDiscardChangesGuard({
+ isDirty: JSON.stringify(policyDraft) !== JSON.stringify(initialPolicyDraft),
+ onDiscard: close
+ });
const handleClose = (open: boolean) => {
- if (!open) setStep(0);
- onOpenChange(open);
+ if (submitting) return;
+ if (open) onOpenChange(true);
+ else requestDiscard();
};
const totalApprovers = steps.reduce((sum, s) => sum + s.approvers.length, 0);
@@ -161,6 +197,7 @@ export const EditSignerPolicyModal = ({
const limitsInvalid = steps.length > 0 && maxSignings == null && maxWindow == null;
const onSave = async () => {
+ if (submitting) return;
if (limitsInvalid) {
setShowLimitsError(true);
if (safeStep !== 1) setStep(1);
@@ -211,7 +248,7 @@ export const EditSignerPolicyModal = ({
})),
constraints: steps.length === 0 ? undefined : { maxSignings, maxWindowDuration: maxWindow }
});
- handleClose(false);
+ close();
} catch (err) {
createNotification({
type: "error",
@@ -227,132 +264,148 @@ export const EditSignerPolicyModal = ({
const isCreating = !existingPolicy?.hasSteps;
return (
- <Sheet open={isOpen} onOpenChange={handleClose}>
- <SheetContent size="workspace" className="flex h-full max-h-full flex-col gap-y-0">
- <SheetHeader className="border-b">
- <SheetTitle>
- <div className="flex w-full items-start gap-2">
- <div className="flex h-10 w-10 items-center justify-center rounded-md bg-warning/10 text-warning">
- <ShieldIcon className="h-5 w-5" />
- </div>
- <div>
- <div className="flex items-center gap-x-2 text-label">
- {isCreating ? "Add approval policy" : "Edit approval policy"}
- <DocumentationLinkBadge href={PkiDocsUrls.codeSigning.approvals.policy} />
- </div>
- <p className="text-sm leading-4 text-muted">
- Choose who approves, and how much each approval gives.
+ <>
+ <Sheet open={isOpen} onOpenChange={handleClose}>
+ <SheetContent size="workspace" isPending={submitting}>
+ <SheetHeader>
+ <SheetTitle className="flex items-center gap-2">
+ {isCreating ? "Add Approval Policy" : "Edit Approval Policy"}
+ <DocumentationLinkBadge href={PkiDocsUrls.codeSigning.approvals.policy} />
+ </SheetTitle>
+ <SheetDescription>
+ Choose who approves, and how much each approval gives.
+ </SheetDescription>
+ </SheetHeader>
+
+ <div className="flex min-h-0 flex-1 flex-col">
+ <div className="flex min-h-0 flex-1 overflow-hidden">
+ <aside className="flex w-60 shrink-0 flex-col border-r border-border px-5 py-6">
+ <p className="mb-5 text-[11px] font-medium tracking-wider text-muted uppercase">
+ Setup steps
</p>
- </div>
- </div>
- </SheetTitle>
- </SheetHeader>
+ <Stepper
+ activeStep={safeStep}
+ orientation="vertical"
+ onStepChange={(i) => {
+ if (i < safeStep && !submitting) setStep(i);
+ }}
+ >
+ <StepperList>
+ {WIZARD_STEPS.map((s, i) => (
+ <StepperStep
+ key={s.title}
+ index={i}
+ title={s.title}
+ description={s.subtitle}
+ />
+ ))}
+ </StepperList>
+ </Stepper>
+ </aside>
- <div className="flex min-h-0 flex-1 flex-col">
- <div className="flex min-h-0 flex-1 overflow-hidden">
- <aside className="flex w-60 shrink-0 flex-col border-r border-border px-5 py-6">
- <p className="mb-5 text-[11px] font-medium tracking-wider text-muted uppercase">
- Setup steps
- </p>
- <Stepper
- activeStep={safeStep}
- orientation="vertical"
- onStepChange={(i) => {
- if (i < safeStep) setStep(i);
- }}
+ <fieldset
+ disabled={submitting}
+ className="flex min-w-0 flex-1 flex-col gap-y-2 overflow-y-auto px-8 py-6"
>
- <StepperList>
- {WIZARD_STEPS.map((s, i) => (
- <StepperStep key={s.title} index={i} title={s.title} description={s.subtitle} />
- ))}
- </StepperList>
- </Stepper>
- </aside>
-
- <div className="flex min-w-0 flex-1 flex-col gap-y-2 overflow-y-auto px-8 py-6">
- {!showLimitsTab ? (
- <ApproversStep
- steps={steps}
- approverOptions={approverOptions}
- onAddStep={addStep}
- onRemoveStep={removeStep}
- onUpdateStep={updateStep}
- />
- ) : (
- <LimitsStep
- maxSignings={maxSignings}
- setMaxSignings={setMaxSignings}
- maxWindow={maxWindow}
- setMaxWindow={setMaxWindow}
- showError={showLimitsError && limitsInvalid}
- />
- )}
- </div>
+ {!showLimitsTab ? (
+ <ApproversStep
+ steps={steps}
+ approverOptions={approverOptions}
+ onAddStep={addStep}
+ onRemoveStep={removeStep}
+ onUpdateStep={updateStep}
+ />
+ ) : (
+ <LimitsStep
+ maxSignings={maxSignings}
+ setMaxSignings={setMaxSignings}
+ maxWindow={maxWindow}
+ setMaxWindow={setMaxWindow}
+ showError={showLimitsError && limitsInvalid}
+ />
+ )}
+ </fieldset>
- <aside className="hidden w-80 shrink-0 flex-col gap-4 overflow-y-auto border-l border-border px-6 py-6 lg:flex">
- <div className="mb-auto">
- <div className="flex items-center justify-between gap-2">
- <p className="text-[11px] font-medium tracking-wider text-muted uppercase">
- Step {safeStep + 1} · {WIZARD_STEPS[safeStep].title.toUpperCase()}
+ <aside className="hidden w-80 shrink-0 flex-col gap-4 overflow-y-auto border-l border-border px-6 py-6 lg:flex">
+ <div className="mb-auto">
+ <div className="flex items-center justify-between gap-2">
+ <p className="text-[11px] font-medium tracking-wider text-muted uppercase">
+ Step {safeStep + 1} · {WIZARD_STEPS[safeStep].title.toUpperCase()}
+ </p>
+ <DocumentationLinkBadge href={WIZARD_STEPS[safeStep].docsUrl} />
+ </div>
+ <p className="mt-4 text-sm font-semibold text-foreground">What this step does</p>
+ <p className="mt-2 text-sm leading-relaxed text-muted">
+ {!showLimitsTab
+ ? 'Approvals run in order. Each step has its own approvers and a "required" count: the number of approvers that must approve before moving on.'
+ : "Limits decide how many signatures one approval can make and how long it stays valid before expiring."}
</p>
- <DocumentationLinkBadge href={WIZARD_STEPS[safeStep].docsUrl} />
</div>
- <p className="mt-4 text-sm font-semibold text-foreground">What this step does</p>
- <p className="mt-2 text-sm leading-relaxed text-muted">
- {!showLimitsTab
- ? 'Approvals run in order. Each step has its own approvers and a "required" count: the number of approvers that must approve before moving on.'
- : "Limits decide how many signatures one approval can make and how long it stays valid before expiring."}
- </p>
- </div>
- </aside>
- </div>
+ </aside>
+ </div>
- <SheetFooter className="shrink-0 items-center justify-between border-t">
- <span className="text-xs text-muted">
- {/* eslint-disable-next-line no-nested-ternary */}
- {hasEmptyStep
- ? `Step ${firstEmptyStepIndex + 1} needs at least one approver, or remove it.`
- : // eslint-disable-next-line no-nested-ternary
- hasOverCommittedStep
- ? `Step ${firstOverCommittedStepIndex + 1}: required approvals can't exceed the number of approvers. Add a group to allow more.`
- : // eslint-disable-next-line no-nested-ternary
- steps.length === 0
- ? "Approval is not configured"
- : `${steps.length} step${steps.length === 1 ? "" : "s"} · ${totalApprovers} approver${
- totalApprovers === 1 ? "" : "s"
- }`}
- </span>
- <div className="flex items-center gap-3">
- <span className="text-xs text-muted">
- Step {safeStep + 1} of {WIZARD_STEPS.length}
- </span>
+ <SheetFooter className="shrink-0 items-center justify-between border-t">
{safeStep > 0 && (
- <Button variant="outline" onClick={() => setStep((s) => s - 1)}>
- Back
- </Button>
- )}
- {!isLast ? (
- <Button
- variant="project"
- onClick={() => setStep((s) => s + 1)}
- isDisabled={stepOneInvalid}
- >
- Continue
- </Button>
- ) : (
<Button
- variant="project"
- onClick={onSave}
- isPending={submitting}
- isDisabled={stepOneInvalid}
+ variant="outline"
+ onClick={() => setStep((s) => s - 1)}
+ isDisabled={submitting}
+ className="mr-auto"
>
- Save policy
+ Back
</Button>
)}
- </div>
- </SheetFooter>
- </div>
- </SheetContent>
- </Sheet>
+ <span className="text-xs text-muted">
+ {/* eslint-disable-next-line no-nested-ternary */}
+ {hasEmptyStep
+ ? `Step ${firstEmptyStepIndex + 1} needs at least one approver, or remove it.`
+ : // eslint-disable-next-line no-nested-ternary
+ hasOverCommittedStep
+ ? `Step ${firstOverCommittedStepIndex + 1}: required approvals can't exceed the number of approvers. Add a group to allow more.`
+ : // eslint-disable-next-line no-nested-ternary
+ steps.length === 0
+ ? "Approval is not configured"
+ : `${steps.length} step${steps.length === 1 ? "" : "s"} · ${totalApprovers} approver${
+ totalApprovers === 1 ? "" : "s"
+ }`}
+ </span>
+ <div className="flex items-center gap-3">
+ <span className="text-xs text-muted">
+ Step {safeStep + 1} of {WIZARD_STEPS.length}
+ </span>
+ <Button variant="ghost" onClick={() => handleClose(false)} isDisabled={submitting}>
+ Cancel
+ </Button>
+ {!isLast ? (
+ <Button
+ variant="project"
+ onClick={() => setStep((s) => s + 1)}
+ isDisabled={stepOneInvalid}
+ >
+ Continue
+ </Button>
+ ) : (
+ <Button
+ variant="project"
+ onClick={onSave}
+ isPending={submitting}
+ isDisabled={stepOneInvalid}
+ >
+ Save policy
+ </Button>
+ )}
+ </div>
+ </SheetFooter>
+ </div>
+ </SheetContent>
+ </Sheet>
+ <DiscardChangesAlertDialog
+ open={isDiscardDialogOpen}
+ onOpenChange={setIsDiscardDialogOpen}
+ onDiscard={confirmDiscard}
+ title="Discard Changes?"
+ description="Your approval policy changes will be lost."
+ />
+ </>
);
};
diff --git a/frontend/src/pages/cert-manager/SignerDetailPage/components/PreApproveSigningSheet.tsx b/frontend/src/pages/cert-manager/SignerDetailPage/components/PreApproveSigningSheet.tsx
index 2d51fd6a04..1532722c48 100644
--- a/frontend/src/pages/cert-manager/SignerDetailPage/components/PreApproveSigningSheet.tsx
+++ b/frontend/src/pages/cert-manager/SignerDetailPage/components/PreApproveSigningSheet.tsx
@@ -1,11 +1,12 @@
-import { useEffect, useMemo, useState } from "react";
+import { useEffect, useId, useMemo, useState } from "react";
import { Controller, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
-import { BadgeCheckIcon } from "lucide-react";
import { z } from "zod";
import {
Button,
+ Combobox,
+ DiscardChangesAlertDialog,
DocumentationLinkBadge,
Field,
FieldContent,
@@ -13,10 +14,10 @@ import {
FieldError,
FieldGroup,
FieldLabel,
- FilterableSelect,
Input,
Sheet,
SheetContent,
+ SheetDescription,
SheetFooter,
SheetHeader,
SheetTitle,
@@ -29,6 +30,7 @@ import {
useListEffectiveSignerMembers,
usePreApproveSigning
} from "@app/hooks/api/signers";
+import { useDiscardChangesGuard } from "@app/hooks/useDiscardChangesGuard";
import {
pickDeclaredScope,
ScopeFieldsFormSection,
@@ -75,6 +77,7 @@ const schema = z
type FormData = z.infer<typeof schema>;
export const PreApproveSigningSheet = ({ isOpen, onOpenChange, signerId }: Props) => {
+ const memberId = useId();
const users = useListEffectiveSignerMembers({ signerId, kind: "user" });
const identities = useListEffectiveSignerMembers({ signerId, kind: "identity" });
const { data: policy } = useGetSignerPolicy(signerId);
@@ -114,7 +117,12 @@ export const PreApproveSigningSheet = ({ isOpen, onOpenChange, signerId }: Props
scope: []
});
- const { control, handleSubmit, reset } = useForm<FormData>({
+ const {
+ control,
+ handleSubmit,
+ reset,
+ formState: { isDirty }
+ } = useForm<FormData>({
resolver: zodResolver(schema),
defaultValues: buildDefaults()
});
@@ -124,12 +132,20 @@ export const PreApproveSigningSheet = ({ isOpen, onOpenChange, signerId }: Props
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [maxSignings, maxWindowDuration]);
+ const close = () => {
+ reset(buildDefaults());
+ onOpenChange(false);
+ };
+ const { confirmDiscard, isDiscardDialogOpen, requestDiscard, setIsDiscardDialogOpen } =
+ useDiscardChangesGuard({ isDirty, onDiscard: close });
const handleClose = (open: boolean) => {
- if (!open) reset(buildDefaults());
- onOpenChange(open);
+ if (submitting) return;
+ if (open) onOpenChange(true);
+ else requestDiscard();
};
const onSubmit = async (data: FormData) => {
+ if (submitting) return;
setSubmitting(true);
try {
const [kind, id] = data.granteeKey.split(":");
@@ -142,7 +158,7 @@ export const PreApproveSigningSheet = ({ isOpen, onOpenChange, signerId }: Props
requestedWindowDuration: resolveSigningWindow(data.requestedWindowDuration),
scope: pickDeclaredScope(data.scope)
});
- handleClose(false);
+ close();
} catch {
// The mutation cache reports the failure, so showing it here would duplicate the toast.
// Caught only so the sheet stays open for another attempt.
@@ -152,143 +168,156 @@ export const PreApproveSigningSheet = ({ isOpen, onOpenChange, signerId }: Props
};
return (
- <Sheet open={isOpen} onOpenChange={handleClose}>
- <SheetContent size="wide" className="flex h-full max-h-full flex-col gap-y-0">
- <SheetHeader className="border-b">
- <SheetTitle>
- <div className="flex w-full items-start gap-2">
- <div className="flex h-10 w-10 items-center justify-center rounded-md bg-warning/10 text-warning">
- <BadgeCheckIcon className="h-5 w-5" />
- </div>
- <div>
- <div className="flex items-center gap-x-2 text-label">Pre-approve signing</div>
- <p className="text-sm leading-4 text-muted">
- Grant an Operator or machine identity a signed-off window without an approval
- flow.
- </p>
- </div>
- </div>
- </SheetTitle>
- </SheetHeader>
+ <>
+ <Sheet open={isOpen} onOpenChange={handleClose}>
+ <SheetContent size="wide" isPending={submitting}>
+ <SheetHeader>
+ <SheetTitle>Pre-approve Signing</SheetTitle>
+ <SheetDescription>
+ Grant an Operator or machine identity a signed-off window without an approval flow.
+ </SheetDescription>
+ </SheetHeader>
- <form className="flex min-h-0 flex-1 flex-col" onSubmit={handleSubmit(onSubmit)}>
- <div className="flex min-h-0 flex-1 overflow-hidden">
- <div className="flex min-w-0 flex-1 flex-col gap-y-2 overflow-y-auto px-8 py-6">
- <FieldGroup>
- <Controller
- name="granteeKey"
- control={control}
- render={({ field, fieldState: { error } }) => (
- <Field>
- <FieldLabel>Member</FieldLabel>
- <FieldContent>
- <FilterableSelect
- options={memberOptions}
- value={memberOptions.find((o) => o.value === field.value) ?? null}
- onChange={(selected) =>
- field.onChange((selected as MemberOption | null)?.value ?? "")
- }
- placeholder="Pick a member..."
- isError={Boolean(error)}
- />
- <FieldError errors={[error]} />
- </FieldContent>
- </Field>
- )}
- />
+ <form className="flex min-h-0 flex-1 flex-col" onSubmit={handleSubmit(onSubmit)}>
+ <div className="flex min-h-0 flex-1 overflow-hidden">
+ <fieldset
+ disabled={submitting}
+ className="flex min-w-0 flex-1 flex-col gap-y-2 overflow-y-auto px-8 py-6"
+ >
+ <FieldGroup>
+ <Controller
+ name="granteeKey"
+ control={control}
+ render={({ field, fieldState: { error } }) => (
+ <Field>
+ <FieldLabel htmlFor={memberId}>Member</FieldLabel>
+ <FieldContent>
+ <Combobox
+ ref={field.ref}
+ id={memberId}
+ name={field.name}
+ onBlur={field.onBlur}
+ options={memberOptions}
+ getOptionValue={(option) => option.value}
+ getOptionLabel={(option) => option.label}
+ value={memberOptions.find((o) => o.value === field.value) ?? null}
+ onValueChange={(selected) => field.onChange(selected?.value ?? "")}
+ isLoading={users.isPending || identities.isPending}
+ isDisabled={submitting}
+ placeholder="Pick a member..."
+ isError={Boolean(error)}
+ />
+ <FieldError errors={[error]} />
+ </FieldContent>
+ </Field>
+ )}
+ />
- <Controller
- name="requestedSignings"
- control={control}
- render={({ field, fieldState: { error } }) => (
- <Field>
- <FieldLabel>How many signatures</FieldLabel>
- <FieldContent>
- <Input
- type="number"
- min={1}
- max={maxSignings ?? undefined}
- value={field.value ?? ""}
- onChange={(e) => {
- const raw = e.target.value;
- field.onChange(raw === "" ? null : Number(raw));
- }}
- placeholder={
- maxSignings
- ? `Up to ${maxSignings}`
- : "Leave empty to rely on the time window"
- }
- isError={Boolean(error)}
- />
- <FieldDescription>
- {maxSignings
- ? `Policy caps each approval at ${maxSignings} signature${maxSignings === 1 ? "" : "s"}.`
- : "Leave empty to rely on the time window."}
- </FieldDescription>
- <FieldError errors={[error]} />
- </FieldContent>
- </Field>
- )}
- />
+ <Controller
+ name="requestedSignings"
+ control={control}
+ render={({ field, fieldState: { error } }) => (
+ <Field>
+ <FieldLabel>How many signatures</FieldLabel>
+ <FieldContent>
+ <Input
+ type="number"
+ min={1}
+ max={maxSignings ?? undefined}
+ value={field.value ?? ""}
+ onChange={(e) => {
+ const raw = e.target.value;
+ field.onChange(raw === "" ? null : Number(raw));
+ }}
+ placeholder={
+ maxSignings
+ ? `Up to ${maxSignings}`
+ : "Leave empty to rely on the time window"
+ }
+ isError={Boolean(error)}
+ />
+ <FieldDescription>
+ {maxSignings
+ ? `Policy caps each approval at ${maxSignings} signature${maxSignings === 1 ? "" : "s"}.`
+ : "Leave empty to rely on the time window."}
+ </FieldDescription>
+ <FieldError errors={[error]} />
+ </FieldContent>
+ </Field>
+ )}
+ />
- <SigningWindowField
- control={control}
- name="requestedWindowDuration"
- maxWindowDuration={maxWindowDuration}
- />
+ <SigningWindowField
+ control={control}
+ name="requestedWindowDuration"
+ maxWindowDuration={maxWindowDuration}
+ />
- <ScopeFieldsFormSection control={control} />
+ <ScopeFieldsFormSection control={control} />
- <Controller
- name="justification"
- control={control}
- render={({ field, fieldState: { error } }) => (
- <Field>
- <FieldLabel>Reason</FieldLabel>
- <FieldContent>
- <TextArea
- {...field}
- placeholder="Why is this being pre-approved?"
- rows={3}
- isError={Boolean(error)}
- />
- <FieldError errors={[error]} />
- </FieldContent>
- </Field>
- )}
- />
- </FieldGroup>
- </div>
+ <Controller
+ name="justification"
+ control={control}
+ render={({ field, fieldState: { error } }) => (
+ <Field>
+ <FieldLabel>Reason</FieldLabel>
+ <FieldContent>
+ <TextArea
+ {...field}
+ placeholder="Why is this being pre-approved?"
+ rows={3}
+ isError={Boolean(error)}
+ />
+ <FieldError errors={[error]} />
+ </FieldContent>
+ </Field>
+ )}
+ />
+ </FieldGroup>
+ </fieldset>
- <aside className="hidden w-80 shrink-0 flex-col gap-4 overflow-y-auto border-l border-border px-6 py-6 lg:flex">
- <div className="mb-auto">
- <div className="flex items-center justify-between gap-2">
- <p className="text-[11px] font-medium tracking-wider text-muted uppercase">
- Pre-approving
+ <aside className="hidden w-80 shrink-0 flex-col gap-4 overflow-y-auto border-l border-border px-6 py-6 lg:flex">
+ <div className="mb-auto">
+ <div className="flex items-center justify-between gap-2">
+ <p className="text-[11px] font-medium tracking-wider text-muted uppercase">
+ Pre-approving
+ </p>
+ <DocumentationLinkBadge href={PkiDocsUrls.codeSigning.approvals.preApprove} />
+ </div>
+ <p className="mt-4 text-sm font-semibold text-foreground">What this does</p>
+ <p className="mt-2 text-sm leading-relaxed text-muted">
+ Pre-approving skips the review step: the moment you save, the member you pick
+ can sign. It produces the same access record an approved request would, so it
+ appears on the Approvals tab with its own signature counter and expiry, and you
+ can revoke it there at any time.
</p>
- <DocumentationLinkBadge href={PkiDocsUrls.codeSigning.approvals.preApprove} />
</div>
- <p className="mt-4 text-sm font-semibold text-foreground">What this does</p>
- <p className="mt-2 text-sm leading-relaxed text-muted">
- Pre-approving skips the review step: the moment you save, the member you pick can
- sign. It produces the same access record an approved request would, so it appears
- on the Approvals tab with its own signature counter and expiry, and you can revoke
- it there at any time.
- </p>
- </div>
- </aside>
- </div>
+ </aside>
+ </div>
- <SheetFooter className="flex-row items-center justify-end border-t">
- <Button type="button" variant="outline" onClick={() => handleClose(false)}>
- Cancel
- </Button>
- <Button type="submit" variant="project" isPending={submitting}>
- Pre-approve
- </Button>
- </SheetFooter>
- </form>
- </SheetContent>
- </Sheet>
+ <SheetFooter className="flex-row items-center justify-end border-t">
+ <Button
+ type="button"
+ variant="ghost"
+ onClick={() => handleClose(false)}
+ isDisabled={submitting}
+ >
+ Cancel
+ </Button>
+ <Button type="submit" variant="project" isPending={submitting}>
+ Pre-approve
+ </Button>
+ </SheetFooter>
+ </form>
+ </SheetContent>
+ </Sheet>
+ <DiscardChangesAlertDialog
+ open={isDiscardDialogOpen}
+ onOpenChange={setIsDiscardDialogOpen}
+ onDiscard={confirmDiscard}
+ title="Discard Changes?"
+ description="Your signing pre-approval changes will be lost."
+ />
+ </>
);
};