Skip to content

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

edit datasource in sheet

Matheus Nogueira74afcc0979e3
diff --git a/frontend/src/components/secret-scanning/CreateSecretScanningDataSourceSheet.tsx b/frontend/src/components/secret-scanning/CreateSecretScanningDataSourceSheet.tsx
index d8a0a67560..9c9d3da419 100644
--- a/frontend/src/components/secret-scanning/CreateSecretScanningDataSourceSheet.tsx
+++ b/frontend/src/components/secret-scanning/CreateSecretScanningDataSourceSheet.tsx
@@ -5,7 +5,7 @@ import { TSecretScanningDataSourceForm } from "@app/components/secret-scanning/f
import { DiscardChangesAlertDialog, Sheet, SheetContent } from "@app/components/v3";
import { useDiscardChangesGuard } from "@app/hooks/useDiscardChangesGuard";
-import { CreateSecretScanningDataSourceForm } from "./forms";
+import { SecretScanningDataSourceForm } from "./forms";
import {
SecretScanningDataSourcePopupContext,
useSecretScanningDataSourcePopupRegistry
@@ -81,7 +81,7 @@ export const CreateSecretScanningDataSourceSheet = ({ isOpen, onOpenChange }: Pr
>
<SheetContent size="wide" onEscapeKeyDown={popupRegistry.onEscapeKeyDown}>
<SecretScanningDataSourcePopupContext.Provider value={popupRegistry.onPopupOpenChange}>
- <CreateSecretScanningDataSourceForm
+ <SecretScanningDataSourceForm
initialType={initialFormData?.type}
initialFormData={initialFormData}
onComplete={closeSheet}
diff --git a/frontend/src/components/secret-scanning/EditSecretScanningDataSourceModal.tsx b/frontend/src/components/secret-scanning/EditSecretScanningDataSourceModal.tsx
deleted file mode 100644
index e5f32b738f..0000000000
--- a/frontend/src/components/secret-scanning/EditSecretScanningDataSourceModal.tsx
+++ /dev/null
@@ -1,44 +0,0 @@
-import { Modal, ModalContent } from "@app/components/v2";
-import { TSecretScanningDataSource } from "@app/hooks/api/secretScanningV2";
-
-import { SecretScanningDataSourceForm } from "./forms";
-import { SecretScanningDataSourceModalHeader } from "./SecretScanningDataSourceModalHeader";
-import {
- SecretScanningDataSourcePopupContext,
- useSecretScanningDataSourcePopupRegistry
-} from "./SecretScanningDataSourcePopupContext";
-
-type Props = {
- isOpen: boolean;
- onOpenChange: (isOpen: boolean) => void;
- dataSource?: TSecretScanningDataSource;
-};
-
-export const EditSecretScanningDataSourceModal = ({
- dataSource,
- onOpenChange,
- ...props
-}: Props) => {
- const popupRegistry = useSecretScanningDataSourcePopupRegistry();
- if (!dataSource) return null;
-
- return (
- <Modal {...props} onOpenChange={onOpenChange}>
- <ModalContent
- onEscapeKeyDown={popupRegistry.onEscapeKeyDown}
- title={<SecretScanningDataSourceModalHeader isConfigured type={dataSource.type} />}
- className="max-w-2xl"
- bodyClassName="overflow-visible"
- >
- <SecretScanningDataSourcePopupContext.Provider value={popupRegistry.onPopupOpenChange}>
- <SecretScanningDataSourceForm
- onComplete={() => onOpenChange(false)}
- onCancel={() => onOpenChange(false)}
- dataSource={dataSource}
- type={dataSource.type}
- />
- </SecretScanningDataSourcePopupContext.Provider>
- </ModalContent>
- </Modal>
- );
-};
diff --git a/frontend/src/components/secret-scanning/EditSecretScanningDataSourceSheet.tsx b/frontend/src/components/secret-scanning/EditSecretScanningDataSourceSheet.tsx
new file mode 100644
index 0000000000..caa6b63c49
--- /dev/null
+++ b/frontend/src/components/secret-scanning/EditSecretScanningDataSourceSheet.tsx
@@ -0,0 +1,66 @@
+import { useCallback, useState } from "react";
+
+import { DiscardChangesAlertDialog, Sheet, SheetContent } from "@app/components/v3";
+import { TSecretScanningDataSource } from "@app/hooks/api/secretScanningV2";
+import { useDiscardChangesGuard } from "@app/hooks/useDiscardChangesGuard";
+
+import { SecretScanningDataSourceForm } from "./forms";
+import {
+ SecretScanningDataSourcePopupContext,
+ useSecretScanningDataSourcePopupRegistry
+} from "./SecretScanningDataSourcePopupContext";
+
+type Props = {
+ isOpen: boolean;
+ onOpenChange: (isOpen: boolean) => void;
+ dataSource?: TSecretScanningDataSource;
+};
+
+export const EditSecretScanningDataSourceSheet = ({ isOpen, onOpenChange, dataSource }: Props) => {
+ const popupRegistry = useSecretScanningDataSourcePopupRegistry();
+ const [isDirty, setIsDirty] = useState(false);
+
+ const closeSheet = useCallback(() => {
+ setIsDirty(false);
+ onOpenChange(false);
+ }, [onOpenChange]);
+
+ const { confirmDiscard, isDiscardDialogOpen, requestDiscard, setIsDiscardDialogOpen } =
+ useDiscardChangesGuard({ isDirty, onDiscard: closeSheet });
+
+ return (
+ <>
+ <Sheet
+ open={isOpen && Boolean(dataSource)}
+ onOpenChange={(open) => {
+ if (open) {
+ onOpenChange(true);
+ return;
+ }
+ requestDiscard();
+ }}
+ >
+ <SheetContent size="wide" onEscapeKeyDown={popupRegistry.onEscapeKeyDown}>
+ {dataSource && (
+ <SecretScanningDataSourcePopupContext.Provider value={popupRegistry.onPopupOpenChange}>
+ <SecretScanningDataSourceForm
+ key={dataSource.id}
+ dataSource={dataSource}
+ onComplete={closeSheet}
+ onCancel={requestDiscard}
+ onDirtyChange={setIsDirty}
+ />
+ </SecretScanningDataSourcePopupContext.Provider>
+ )}
+ </SheetContent>
+ </Sheet>
+ <DiscardChangesAlertDialog
+ open={isDiscardDialogOpen}
+ onOpenChange={setIsDiscardDialogOpen}
+ onDiscard={confirmDiscard}
+ title="Discard Changes?"
+ description="Your changes to this data source will be lost."
+ />
+ </>
+ );
+};
diff --git a/frontend/src/components/secret-scanning/SecretScanningDataSourceModalHeader.tsx b/frontend/src/components/secret-scanning/SecretScanningDataSourceModalHeader.tsx
deleted file mode 100644
index 2d269f0b93..0000000000
--- a/frontend/src/components/secret-scanning/SecretScanningDataSourceModalHeader.tsx
+++ /dev/null
@@ -1,34 +0,0 @@
-import { DocumentationLinkBadge } from "@app/components/v3";
-import { ProviderIcon } from "@app/components/v3/platform/ProviderIcon";
-import { SECRET_SCANNING_DATA_SOURCE_MAP } from "@app/helpers/secretScanningV2";
-import { SecretScanningDataSource } from "@app/hooks/api/secretScanningV2";
-
-type Props = {
- type: SecretScanningDataSource;
- isConfigured: boolean;
-};
-
-export const SecretScanningDataSourceModalHeader = ({ type, isConfigured }: Props) => {
- const dataSourceDetails = SECRET_SCANNING_DATA_SOURCE_MAP[type];
-
- return (
- <div className="flex w-full items-start gap-2">
- <ProviderIcon
- alt={`${dataSourceDetails.name} logo`}
- icon={dataSourceDetails.image}
- className="h-12 rounded-md bg-surface-recessed p-2"
- />
- <div>
- <div className="flex items-center gap-x-2 text-label">
- {dataSourceDetails.name} Data Source
- <DocumentationLinkBadge
- href={`https://infisical.com/docs/documentation/platform/secret-scanning/${type}`}
- />
- </div>
- <p className="text-sm leading-4 text-muted">
- {isConfigured ? "Edit" : "Connect a"} {dataSourceDetails.name} Data Source
- </p>
- </div>
- </div>
- );
-};
diff --git a/frontend/src/components/secret-scanning/forms/CreateSecretScanningDataSourceForm.tsx b/frontend/src/components/secret-scanning/forms/CreateSecretScanningDataSourceForm.tsx
deleted file mode 100644
index c5e72cfd43..0000000000
--- a/frontend/src/components/secret-scanning/forms/CreateSecretScanningDataSourceForm.tsx
+++ /dev/null
@@ -1,381 +0,0 @@
-import { useEffect, useState } from "react";
-import { DefaultValues, FieldPath, FormProvider, useForm, useWatch } from "react-hook-form";
-import { zodResolver } from "@hookform/resolvers/zod";
-
-import { createNotification } from "@app/components/notifications";
-import {
- Button,
- DocumentationLinkBadge,
- Loader,
- SheetDescription,
- SheetFooter,
- SheetHeader,
- SheetTitle,
- Stepper,
- StepperList,
- StepperStep
-} from "@app/components/v3";
-import { ProviderIcon } from "@app/components/v3/platform/ProviderIcon";
-import { useProject } from "@app/context";
-import {
- doesDataSourceSupportDiscovery,
- RESOURCE_DESCRIPTION_HELPER,
- SECRET_SCANNING_DATA_SOURCE_MAP
-} from "@app/helpers/secretScanningV2";
-import {
- SecretScanningDataSource,
- TSecretScanningDataSource,
- useSecretScanningDataSourceOptions
-} from "@app/hooks/api/secretScanningV2";
-import { useCreateSecretScanningDataSource } from "@app/hooks/api/secretScanningV2/mutations";
-import { GitLabDataSourceScope } from "@app/hooks/api/secretScanningV2/types/gitlab-data-source";
-
-import { SecretScanningDataSourceSchema, TSecretScanningDataSourceForm } from "./schemas";
-import {
- SecretScanningDataSourceConnectionFields,
- SecretScanningDataSourceScanFields
-} from "./SecretScanningDataSourceConfigFields";
-import { SecretScanningDataSourceDetailsFields } from "./SecretScanningDataSourceDetailsFields";
-import { SecretScanningDataSourceReviewFields } from "./SecretScanningDataSourceReviewFields";
-
-type TFormField = FieldPath<TSecretScanningDataSourceForm>;
-
-enum FormStep {
- Provider = 0,
- Connection = 1,
- Scan = 2,
- Details = 3,
- Review = 4
-}
-
-const getDefaultConfig = (type: SecretScanningDataSource) => {
- switch (type) {
- case SecretScanningDataSource.GitHub:
- return {};
- case SecretScanningDataSource.Bitbucket:
- return { workspaceSlug: "" };
- case SecretScanningDataSource.GitLab:
- return { scope: GitLabDataSourceScope.Account };
- default:
- throw new Error(`Unhandled data source type: ${type}`);
- }
-};
-
-const getDefaultValues = (type: SecretScanningDataSource) =>
- ({
- type,
- isHistoricalScanEnabled: true,
- isScanNewCommitsEnabled: true,
- isDiscoveryEnabled: doesDataSourceSupportDiscovery({ type, config: getDefaultConfig(type) }),
- config: getDefaultConfig(type)
- }) as DefaultValues<TSecretScanningDataSourceForm>;
-
-const CONNECTION_STEP_FIELDS: Record<SecretScanningDataSource, TFormField[]> = {
- [SecretScanningDataSource.GitHub]: ["connection"],
- [SecretScanningDataSource.Bitbucket]: ["connection", "config.workspaceSlug"],
- [SecretScanningDataSource.GitLab]: [
- "connection",
- "config.scope",
- "config.projectId",
- "config.groupId"
- ]
-};
-
-const CONNECTION_STEP_INFO: Record<SecretScanningDataSource, string> = {
- [SecretScanningDataSource.GitHub]:
- "The App Connection is how Secret Scanning reads your GitHub repositories. It cannot be changed after the data source is created.",
- [SecretScanningDataSource.Bitbucket]:
- "The App Connection is how Secret Scanning reads your Bitbucket repositories, and the workspace tells it where to look. The connection cannot be changed after the data source is created.",
- [SecretScanningDataSource.GitLab]:
- "The App Connection is how Secret Scanning reads your GitLab projects. Without a group, the data source covers every project the connection can read. GitLab only reports new projects through group webhooks, so a group is required to discover them. Connection and group cannot be changed after the data source is created."
-};
-
-const getSteps = (type: SecretScanningDataSource) => {
- const { name: platform } = SECRET_SCANNING_DATA_SOURCE_MAP[type];
- const { pluralNoun, verb } = RESOURCE_DESCRIPTION_HELPER[type];
-
- return [
- {
- name: "Provider",
- description: platform,
- title: "Choose a Provider",
- subtitle: "Pick the platform this data source will scan.",
- info: "",
- fields: [] as TFormField[]
- },
- {
- name: "Connection",
- description: "Connection and scope",
- title: `Connect to ${platform}`,
- subtitle: "Choose the App Connection and, if needed, narrow its scope.",
- info: CONNECTION_STEP_INFO[type],
- fields: CONNECTION_STEP_FIELDS[type]
- },
- {
- name: "Scan Options",
- description: "Scan behavior",
- title: "Configure Scanning",
- subtitle: "Decide when this data source gets scanned.",
- info: `Historical scan checks existing history once ${pluralNoun} are enabled. Scan New Commits keeps watching each ${verb}. Discovery automatically enables newly added ${pluralNoun}.`,
- fields: [
- "isHistoricalScanEnabled",
- "isScanNewCommitsEnabled",
- "isDiscoveryEnabled"
- ] as TFormField[]
- },
- {
- name: "Details",
- description: "Name and description",
- title: "Name This Data Source",
- subtitle: "Give the data source a name your team will recognize.",
- info: "This name appears in the data source list, in findings, and in audit logs.",
- fields: ["name", "description"] as TFormField[]
- },
- {
- name: "Review",
- description: "Confirm configuration",
- title: "Review and Create",
- subtitle: "Confirm the details below, then create the data source.",
- info: "You can change scan options, name, and description later from the data source's settings.",
- fields: [] as TFormField[]
- }
- ];
-};
-
-const ProviderCard = ({
- type,
- onClick
-}: {
- type: SecretScanningDataSource;
- onClick: () => void;
-}) => {
- const { name, image } = SECRET_SCANNING_DATA_SOURCE_MAP[type];
- const { pluralNoun } = RESOURCE_DESCRIPTION_HELPER[type];
-
- return (
- <button
- type="button"
- onClick={onClick}
- className="group flex cursor-pointer flex-col gap-3 rounded-md border border-border bg-card p-4 text-left transition-colors hover:border-border-strong hover:bg-surface-hover/50"
- >
- <div className="flex items-start justify-between gap-2">
- <div className="flex h-9 w-9 items-center justify-center rounded-md bg-surface-hover">
- <ProviderIcon icon={image} alt={`${name} logo`} className="h-6 w-6 object-contain" />
- </div>
- <span className="text-[10px] font-medium tracking-wider text-muted uppercase">
- Version Control
- </span>
- </div>
- <div className="flex flex-col gap-1">
- <p className="text-sm font-semibold text-foreground">{name}</p>
- <p className="text-xs leading-relaxed text-muted">
- Scan {pluralNoun} hosted on {name} for leaked secrets.
- </p>
- </div>
- </button>
- );
-};
-
-const ProviderFields = ({ onSelect }: { onSelect: (type: SecretScanningDataSource) => void }) => {
- const { isPending, data: options } = useSecretScanningDataSourceOptions();
-
- if (isPending) return <Loader size="md" label="Loading data source options" />;
-
- return (
- <div className="grid grid-cols-1 gap-3 md:grid-cols-2 lg:grid-cols-3">
- {options?.map(({ type }) => (
- <ProviderCard key={type} type={type} onClick={() => onSelect(type)} />
- ))}
- </div>
- );
-};
-
-type Props = {
- initialType?: SecretScanningDataSource;
- initialFormData?: Partial<TSecretScanningDataSourceForm>;
- onComplete: (dataSource: TSecretScanningDataSource) => void;
- onCancel: () => void;
- onDirtyChange: (isDirty: boolean) => void;
-};
-
-export const CreateSecretScanningDataSourceForm = ({
- initialType = SecretScanningDataSource.GitHub,
- initialFormData,
- onComplete,
- onCancel,
- onDirtyChange
-}: Props) => {
- const { currentProject } = useProject();
- const createDataSource = useCreateSecretScanningDataSource();
-
- const [step, setStep] = useState(initialFormData ? FormStep.Connection : FormStep.Provider);
-
- const formMethods = useForm<TSecretScanningDataSourceForm>({
- resolver: zodResolver(SecretScanningDataSourceSchema),
- defaultValues: {
- ...getDefaultValues(initialType),
- ...initialFormData
- } as DefaultValues<TSecretScanningDataSourceForm>,
- // Step validation uses trigger(), which does not put the form into its submitted state.
- // Validate changes from the start so a field's error clears as soon as it is corrected.
- mode: "onChange",
- reValidateMode: "onChange"
- });
-
- const {
- control,
- handleSubmit,
- reset,
- trigger,
- formState: { isDirty, isSubmitting }
- } = formMethods;
-
- const type = useWatch({ control, name: "type" });
- const hasUnsavedChanges = isDirty || Boolean(initialFormData);
-
- useEffect(() => {
- onDirtyChange(hasUnsavedChanges);
- return () => onDirtyChange(false);
- }, [hasUnsavedChanges, onDirtyChange]);
-
- const steps = getSteps(type);
- const currentStep = steps[step];
- const isFinalStep = step === FormStep.Review;
- const { name: platform, image } = SECRET_SCANNING_DATA_SOURCE_MAP[type];
- const { pluralNoun } = RESOURCE_DESCRIPTION_HELPER[type];
-
- const onSubmit = async ({ connection, ...formData }: TSecretScanningDataSourceForm) => {
- const dataSource = await createDataSource.mutateAsync({
- ...formData,
- isDiscoveryEnabled: formData.isDiscoveryEnabled && doesDataSourceSupportDiscovery(formData),
- connectionId: connection?.id,
- projectId: currentProject.id
- });
-
- createNotification({
- text: `${platform} data source "${dataSource.name}" created`,
- type: "success"
- });
- onComplete(dataSource);
- };
-
- const handleNext = async () => {
- if (isFinalStep) {
- await handleSubmit(onSubmit)();
- return;
- }
-
- if (!(await trigger(currentStep.fields))) return;
-
- setStep((prev) => prev + 1);
- };
-
- const handleBack = () => {
- if (step === FormStep.Provider) {
- onCancel();
- return;
- }
-
- setStep((prev) => prev - 1);
- };
-
- return (
- <FormProvider {...formMethods}>
- <SheetHeader>
- <div className="flex items-start gap-3">
- <ProviderIcon icon={image} alt="" className="size-9 object-contain" />
- <div className="flex flex-col gap-1">
- <div className="flex items-center gap-2">
- <SheetTitle>{platform} Data Source</SheetTitle>
- <DocumentationLinkBadge
- href={`https://infisical.com/docs/documentation/platform/secret-scanning/${type}`}
- />
- </div>
- <SheetDescription>
- Connect a {platform} data source to scan its {pluralNoun}.
- </SheetDescription>
- </div>
- </div>
- </SheetHeader>
-
- <form
- className="flex min-h-0 flex-1 overflow-hidden"
- onSubmit={(e) => {
- e.preventDefault();
- handleNext();
- }}
- id="create-secret-scanning-data-source-form"
- >
- {step !== FormStep.Provider && (
- <aside className="hidden w-56 shrink-0 flex-col gap-4 overflow-y-auto border-r border-border p-5 md:flex">
- <p className="text-xs font-medium tracking-wider text-muted uppercase">Setup Steps</p>
- <Stepper activeStep={step} onStepChange={setStep}>
- <StepperList>
- {steps.map((s, index) => (
- <StepperStep
- key={s.name}
- index={index}
- title={s.name}
- description={s.description}
- />
- ))}
- </StepperList>
- </Stepper>
- </aside>
- )}
-
- <div className="flex min-w-0 flex-1 flex-col gap-6 overflow-y-auto px-4 py-4 sm:px-8 sm:py-6">
- <div className="flex flex-col gap-1">
- <h3 className="text-lg text-foreground">{currentStep.title}</h3>
- <p className="text-sm text-accent">{currentStep.subtitle}</p>
- </div>
-
- {step === FormStep.Provider && (
- <ProviderFields
- onSelect={(newType) => {
- if (newType !== type) reset(getDefaultValues(newType));
- setStep(FormStep.Connection);
- }}
- />
- )}
- {step === FormStep.Connection && <SecretScanningDataSourceConnectionFields />}
- {step === FormStep.Scan && <SecretScanningDataSourceScanFields />}
- {step === FormStep.Details && <SecretScanningDataSourceDetailsFields />}
- {step === FormStep.Review && <SecretScanningDataSourceReviewFields />}
- </div>
-
- {step !== FormStep.Provider && (
- <aside className="hidden w-64 shrink-0 flex-col gap-3 overflow-y-auto border-l border-border p-5 lg:flex">
- <p className="text-xs font-medium tracking-wider text-muted uppercase">
- Step {step + 1} · {currentStep.name}
- </p>
- <p className="text-sm font-medium text-foreground">What this step does</p>
- <p className="text-sm leading-relaxed text-accent">{currentStep.info}</p>
- </aside>
- )}
- </form>
-
- <SheetFooter className="items-center justify-between border-t">
- <span className="text-xs text-muted">
- Step {step + 1} of {steps.length}
- </span>
- <div className="flex gap-2">
- <Button variant="outline" onClick={handleBack} isDisabled={isSubmitting}>
- {step === FormStep.Provider ? "Cancel" : "Back"}
- </Button>
- {step !== FormStep.Provider && (
- <Button
- variant="ss"
- type="submit"
- form="create-secret-scanning-data-source-form"
- isPending={isSubmitting}
- isDisabled={isSubmitting}
- >
- {isFinalStep ? "Create Data Source" : "Continue"}
- </Button>
- )}
- </div>
- </SheetFooter>
- </FormProvider>
- );
-};
diff --git a/frontend/src/components/secret-scanning/forms/SecretScanningDataSourceForm.tsx b/frontend/src/components/secret-scanning/forms/SecretScanningDataSourceForm.tsx
index aab479ab1b..512ed7bf9b 100644
--- a/frontend/src/components/secret-scanning/forms/SecretScanningDataSourceForm.tsx
+++ b/frontend/src/components/secret-scanning/forms/SecretScanningDataSourceForm.tsx
@@ -1,200 +1,430 @@
-import { useState } from "react";
-import { FormProvider, useForm } from "react-hook-form";
-import { Tab } from "@headlessui/react";
+import { useEffect, useState } from "react";
+import { DefaultValues, FieldPath, FormProvider, useForm, useWatch } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
-import { twMerge } from "tailwind-merge";
import { createNotification } from "@app/components/notifications";
-import { Button } from "@app/components/v3";
+import {
+ Button,
+ DocumentationLinkBadge,
+ Loader,
+ SheetDescription,
+ SheetFooter,
+ SheetHeader,
+ SheetTitle,
+ Stepper,
+ StepperList,
+ StepperStep
+} from "@app/components/v3";
+import { ProviderIcon } from "@app/components/v3/platform/ProviderIcon";
import { useProject } from "@app/context";
import {
doesDataSourceSupportDiscovery,
+ RESOURCE_DESCRIPTION_HELPER,
SECRET_SCANNING_DATA_SOURCE_MAP
} from "@app/helpers/secretScanningV2";
import {
SecretScanningDataSource,
- TSecretScanningDataSource
+ TSecretScanningDataSource,
+ useSecretScanningDataSourceOptions
} from "@app/hooks/api/secretScanningV2";
import {
useCreateSecretScanningDataSource,
useUpdateSecretScanningDataSource
} from "@app/hooks/api/secretScanningV2/mutations";
+import { GitLabDataSourceScope } from "@app/hooks/api/secretScanningV2/types/gitlab-data-source";
import { SecretScanningDataSourceSchema, TSecretScanningDataSourceForm } from "./schemas";
-import { SecretScanningDataSourceConfigFields } from "./SecretScanningDataSourceConfigFields";
+import {
+ SecretScanningDataSourceConnectionFields,
+ SecretScanningDataSourceScanFields
+} from "./SecretScanningDataSourceConfigFields";
import { SecretScanningDataSourceDetailsFields } from "./SecretScanningDataSourceDetailsFields";
import { SecretScanningDataSourceReviewFields } from "./SecretScanningDataSourceReviewFields";
-type Props = {
- onComplete: (dataSource: TSecretScanningDataSource) => void;
- type: SecretScanningDataSource;
- onCancel: () => void;
- dataSource?: TSecretScanningDataSource;
- initialFormData?: Partial<TSecretScanningDataSourceForm>;
+type TFormField = FieldPath<TSecretScanningDataSourceForm>;
+
+enum FormStep {
+ Provider = 0,
+ Connection = 1,
+ Scan = 2,
+ Details = 3,
+ Review = 4
+}
+
+const getDefaultConfig = (type: SecretScanningDataSource) => {
+ switch (type) {
+ case SecretScanningDataSource.GitHub:
+ return {};
+ case SecretScanningDataSource.Bitbucket:
+ return { workspaceSlug: "" };
+ case SecretScanningDataSource.GitLab:
+ return { scope: GitLabDataSourceScope.Account };
+ default:
+ throw new Error(`Unhandled data source type: ${type}`);
+ }
};
-const FORM_TABS: { name: string; key: string; fields: (keyof TSecretScanningDataSourceForm)[] }[] =
- [
+const getDefaultValues = (type: SecretScanningDataSource) =>
+ ({
+ type,
+ isHistoricalScanEnabled: true,
+ isScanNewCommitsEnabled: true,
+ isDiscoveryEnabled: doesDataSourceSupportDiscovery({ type, config: getDefaultConfig(type) }),
+ config: getDefaultConfig(type)
+ }) as DefaultValues<TSecretScanningDataSourceForm>;
+
+const CONNECTION_STEP_FIELDS: Record<SecretScanningDataSource, TFormField[]> = {
+ [SecretScanningDataSource.GitHub]: ["connection"],
+ [SecretScanningDataSource.Bitbucket]: ["connection", "config.workspaceSlug"],
+ [SecretScanningDataSource.GitLab]: [
+ "connection",
+ "config.scope",
+ "config.projectId",
+ "config.groupId"
+ ]
+};
+
+const CONNECTION_STEP_INFO: Record<SecretScanningDataSource, string> = {
+ [SecretScanningDataSource.GitHub]:
+ "The App Connection is how Secret Scanning reads your GitHub repositories. It cannot be changed after the data source is created.",
+ [SecretScanningDataSource.Bitbucket]:
+ "The App Connection is how Secret Scanning reads your Bitbucket repositories, and the workspace tells it where to look. The connection cannot be changed after the data source is created.",
+ [SecretScanningDataSource.GitLab]:
+ "The App Connection is how Secret Scanning reads your GitLab projects. Without a group, the data source covers every project the connection can read. GitLab only reports new projects through group webhooks, so a group is required to discover them. Connection and group cannot be changed after the data source is created."
+};
+
+const getSteps = (type: SecretScanningDataSource, isEdit: boolean) => {
+ const { name: platform } = SECRET_SCANNING_DATA_SOURCE_MAP[type];
+ const { pluralNoun, verb } = RESOURCE_DESCRIPTION_HELPER[type];
+
+ return [
+ {
+ name: "Provider",
+ description: platform,
+ title: "Choose a Provider",
+ subtitle: "Pick the platform this data source will scan.",
+ info: "",
+ fields: [] as TFormField[]
+ },
{
- name: "Configuration",
- key: "config",
+ name: "Connection",
+ description: "Connection and scope",
+ title: `Connect to ${platform}`,
+ subtitle: isEdit
+ ? "The App Connection and scope are fixed once the data source is created."
+ : "Choose the App Connection and, if needed, narrow its scope.",
+ info: CONNECTION_STEP_INFO[type],
+ fields: CONNECTION_STEP_FIELDS[type]
+ },
+ {
+ name: "Scan Options",
+ description: "Scan behavior",
+ title: "Configure Scanning",
+ subtitle: "Decide when this data source gets scanned.",
+ info: `Historical scan checks existing history once ${pluralNoun} are enabled. Scan New Commits keeps watching each ${verb}. Discovery automatically enables newly added ${pluralNoun}.`,
fields: [
- "config",
"isHistoricalScanEnabled",
"isScanNewCommitsEnabled",
- "isDiscoveryEnabled",
- "connection"
- ]
+ "isDiscoveryEnabled"
+ ] as TFormField[]
},
- { name: "Details", key: "details", fields: ["name", "description"] },
- { name: "Review", key: "review", fields: [] }
+ {
+ name: "Details",
+ description: "Name and description",
+ title: "Name This Data Source",
+ subtitle: "Give the data source a name your team will recognize.",
+ info: "This name appears in the data source list, in findings, and in audit logs.",
+ fields: ["name", "description"] as TFormField[]
+ },
+ {
+ name: "Review",
+ description: "Confirm configuration",
+ title: isEdit ? "Review and Save" : "Review and Create",
+ subtitle: isEdit
+ ? "Confirm the details below, then save your changes."
+ : "Confirm the details below, then create the data source.",
+ info: isEdit
+ ? "Saving updates the data source right away. Changes to scan options apply to the next scan or commit."
+ : "You can change scan options, name, and description later from the data source's settings.",
+ fields: [] as TFormField[]
+ }
];
+};
-export const SecretScanningDataSourceForm = ({
+const ProviderCard = ({
type,
+ onClick
+}: {
+ type: SecretScanningDataSource;
+ onClick: () => void;
+}) => {
+ const { name, image } = SECRET_SCANNING_DATA_SOURCE_MAP[type];
+ const { pluralNoun } = RESOURCE_DESCRIPTION_HELPER[type];
+
+ return (
+ <button
+ type="button"
+ onClick={onClick}
+ className="group flex cursor-pointer flex-col gap-3 rounded-md border border-border bg-card p-4 text-left transition-colors hover:border-border-strong hover:bg-surface-hover/50"
+ >
+ <div className="flex items-start justify-between gap-2">
+ <div className="flex h-9 w-9 items-center justify-center rounded-md bg-surface-hover">
+ <ProviderIcon icon={image} alt={`${name} logo`} className="h-6 w-6 object-contain" />
+ </div>
+ <span className="text-[10px] font-medium tracking-wider text-muted uppercase">
+ Version Control
+ </span>
+ </div>
+ <div className="flex flex-col gap-1">
+ <p className="text-sm font-semibold text-foreground">{name}</p>
+ <p className="text-xs leading-relaxed text-muted">
+ Scan {pluralNoun} hosted on {name} for leaked secrets.
+ </p>
+ </div>
+ </button>
+ );
+};
+
+const ProviderFields = ({ onSelect }: { onSelect: (type: SecretScanningDataSource) => void }) => {
+ const { isPending, data: options } = useSecretScanningDataSourceOptions();
+
+ if (isPending) return <Loader size="md" label="Loading data source options" />;
+
+ return (
+ <div className="grid grid-cols-1 gap-3 md:grid-cols-2 lg:grid-cols-3">
+ {options?.map(({ type }) => (
+ <ProviderCard key={type} type={type} onClick={() => onSelect(type)} />
+ ))}
+ </div>
+ );
+};
+
+type Props = {
+ dataSource?: TSecretScanningDataSource;
+ initialType?: SecretScanningDataSource;
+ initialFormData?: Partial<TSecretScanningDataSourceForm>;
+ onComplete: (dataSource: TSecretScanningDataSource) => void;
+ onCancel: () => void;
+ onDirtyChange: (isDirty: boolean) => void;
+};
+
+export const SecretScanningDataSourceForm = ({
+ dataSource,
+ initialType = SecretScanningDataSource.GitHub,
+ initialFormData,
onComplete,
onCancel,
- dataSource,
- initialFormData
+ onDirtyChange
}: Props) => {
+ const { currentProject } = useProject();
const createDataSource = useCreateSecretScanningDataSource();
const updateDataSource = useUpdateSecretScanningDataSource();
- const { currentProject } = useProject();
- const { name: sourceType } = SECRET_SCANNING_DATA_SOURCE_MAP[type];
+ const isEdit = Boolean(dataSource);
- const [selectedTabIndex, setSelectedTabIndex] = useState(0);
+ const [step, setStep] = useState(
+ isEdit || initialFormData ? FormStep.Connection : FormStep.Provider
+ );
const formMethods = useForm<TSecretScanningDataSourceForm>({
resolver: zodResolver(SecretScanningDataSourceSchema),
- defaultValues: dataSource ?? {
- type,
- isHistoricalScanEnabled: true,
- isScanNewCommitsEnabled: true,
- isDiscoveryEnabled: true,
- ...(initialFormData as object)
- },
+ defaultValues: (dataSource ?? {
+ ...getDefaultValues(initialType),
+ ...initialFormData
+ }) as DefaultValues<TSecretScanningDataSourceForm>,
+ // Step validation uses trigger(), which does not put the form into its submitted state.
+ // Validate changes from the start so a field's error clears as soon as it is corrected.
+ mode: "onChange",
reValidateMode: "onChange"
});
- const onSubmit = async ({ connection, ...form }: TSecretScanningDataSourceForm) => {
- const formData = {
- ...form,
- isDiscoveryEnabled: form.isDiscoveryEnabled && doesDataSourceSupportDiscovery(form)
- };
- const mutation = dataSource
- ? updateDataSource.mutateAsync({
- dataSourceId: dataSource.id,
- projectId: dataSource.projectId,
- ...formData
- })
- : createDataSource.mutateAsync({
- ...formData,
- connectionId: connection?.id,
- projectId: currentProject.id
- });
- const source = await mutation;
-
- createNotification({
- text: `Successfully ${source ? "updated" : "created"} ${sourceType} Data Source`,
- type: "success"
- });
- onComplete(source);
- };
-
- const handlePrev = () => {
- if (selectedTabIndex === 0) {
- onCancel();
- return;
- }
-
- setSelectedTabIndex((prev) => prev - 1);
- };
-
const {
+ control,
handleSubmit,
+ reset,
trigger,
- formState: { isSubmitting }
+ formState: { isDirty, isSubmitting }
} = formMethods;
- const isStepValid = async (index: number) => trigger(FORM_TABS[index].fields);
+ const type = useWatch({ control, name: "type" });
+ const hasUnsavedChanges = isDirty || Boolean(initialFormData);
+
+ useEffect(() => {
+ onDirtyChange(hasUnsavedChanges);
+ return () => onDirtyChange(false);
+ }, [hasUnsavedChanges, onDirtyChange]);
+
+ const steps = getSteps(type, isEdit);
+ const firstStep = isEdit ? FormStep.Connection : FormStep.Provider;
+ const currentStep = steps[step];
+ const isFinalStep = step === FormStep.Review;
- const isFinalStep = selectedTabIndex === FORM_TABS.length - 1;
+ let submitLabel = "Continue";
+ if (isFinalStep) submitLabel = isEdit ? "Save Changes" : "Create Data Source";
+
+ const { name: platform, image } = SECRET_SCANNING_DATA_SOURCE_MAP[type];
+ const { pluralNoun } = RESOURCE_DESCRIPTION_HELPER[type];
+
+ const onSubmit = async ({ connection, ...formData }: TSecretScanningDataSourceForm) => {
+ const isDiscoveryEnabled =
+ formData.isDiscoveryEnabled && doesDataSourceSupportDiscovery(formData);
+
+ if (dataSource) {
+ const updated = await updateDataSource.mutateAsync({
+ type: dataSource.type,
+ dataSourceId: dataSource.id,
+ projectId: dataSource.projectId,
+ name: formData.name,
+ description: formData.description,
+ config: formData.config,
+ isHistoricalScanEnabled: formData.isHistoricalScanEnabled,
+ isScanNewCommitsEnabled: formData.isScanNewCommitsEnabled,
+ isDiscoveryEnabled
+ });
+
+ createNotification({
+ text: `${platform} data source "${updated.name}" updated`,
+ type: "success"
+ });
+ onComplete(updated);
+ return;
+ }
+
+ const created = await createDataSource.mutateAsync({
+ ...formData,
+ isDiscoveryEnabled,
+ connectionId: connection?.id,
+ projectId: currentProject.id
+ });
+
+ createNotification({
+ text: `${platform} data source "${created.name}" created`,
+ type: "success"
+ });
+ onComplete(created);
+ };
const handleNext = async () => {
if (isFinalStep) {
- handleSubmit(onSubmit)();
+ await handleSubmit(onSubmit)();
return;
}
- const isValid = await isStepValid(selectedTabIndex);
-
- if (!isValid) return;
+ if (!(await trigger(currentStep.fields))) return;
- setSelectedTabIndex((prev) => prev + 1);
+ setStep((prev) => prev + 1);
};
- const isTabEnabled = async (index: number) => {
- let isEnabled = true;
- for (let i = index - 1; i >= 0; i -= 1) {
- // eslint-disable-next-line no-await-in-loop
- isEnabled = isEnabled && (await isStepValid(i));
+ const handleBack = () => {
+ if (step === firstStep) {
+ onCancel();
+ return;
}
- return isEnabled;
+ setStep((prev) => prev - 1);
};
return (
- <form className={twMerge(isFinalStep && "max-h-[70vh] overflow-y-auto")}>
- <FormProvider {...formMethods}>
- <Tab.Group selectedIndex={selectedTabIndex} onChange={setSelectedTabIndex}>
- <Tab.List className="-pb-1 mb-6 w-full border-b-2 border-border-control">
- {FORM_TABS.map((tab, index) => (
- <Tab
- onClick={async (e) => {
- e.preventDefault();
- const isEnabled = await isTabEnabled(index);
- setSelectedTabIndex((prev) => (isEnabled ? index : prev));
- }}
- className={({ selected }) =>
- `-mb-[0.14rem] whitespace-nowrap ${index > selectedTabIndex ? "opacity-30" : ""} px-4 py-2 text-sm font-medium outline-hidden disabled:opacity-60 ${
- selected
- ? "border-b-2 border-border-bright text-foreground-secondary"
- : "text-label-secondary"
- }`
- }
- key={tab.key}
- >
- {index + 1}. {tab.name}
- </Tab>
- ))}
- </Tab.List>
- <Tab.Panels>
- <Tab.Panel>
- <SecretScanningDataSourceConfigFields />
- </Tab.Panel>
- <Tab.Panel>
- <SecretScanningDataSourceDetailsFields />
- </Tab.Panel>
- <Tab.Panel>
- <SecretScanningDataSourceReviewFields />
- </Tab.Panel>
- </Tab.Panels>
- </Tab.Group>
- </FormProvider>
- <div className="flex w-full flex-row-reverse justify-between gap-4 pt-4">
- <Button
- onClick={handleNext}
- type="button"
- isPending={isSubmitting}
- isDisabled={isSubmitting}
- variant="ss"
- >
- {isFinalStep ? `${dataSource ? "Update" : "Create"} Data Source` : "Next"}
- </Button>
- <Button type="button" onClick={handlePrev} variant="ghost">
- Back
- </Button>
- </div>
- </form>
+ <FormProvider {...formMethods}>
+ <SheetHeader>
+ <div className="flex items-start gap-3">
+ <ProviderIcon icon={image} alt="" className="size-9 object-contain" />
+ <div className="flex flex-col gap-1">
+ <div className="flex items-center gap-2">
+ <SheetTitle>{platform} Data Source</SheetTitle>
+ <DocumentationLinkBadge
+ href={`https://infisical.com/docs/documentation/platform/secret-scanning/${type}`}
+ />
+ </div>
+ <SheetDescription>
+ {dataSource
+ ? `Edit the scan options and details of "${dataSource.name}".`
+ : `Connect a ${platform} data source to scan its ${pluralNoun}.`}
+ </SheetDescription>
+ </div>
+ </div>
+ </SheetHeader>
+
+ <form
+ className="flex min-h-0 flex-1 overflow-hidden"
+ onSubmit={(e) => {
+ e.preventDefault();
+ handleNext();
+ }}
+ id="secret-scanning-data-source-form"
+ >
+ {step !== FormStep.Provider && (
+ <aside className="hidden w-56 shrink-0 flex-col gap-4 overflow-y-auto border-r border-border p-5 md:flex">
+ <p className="text-xs font-medium tracking-wider text-muted uppercase">
+ {isEdit ? "Steps" : "Setup Steps"}
+ </p>
+ <Stepper activeStep={step} onStepChange={setStep}>
+ <StepperList>
+ {steps.map((s, index) => (
+ <StepperStep
+ key={s.name}
+ index={index}
+ title={s.name}
+ description={s.description}
+ disabled={isEdit && index === FormStep.Provider}
+ />
+ ))}
+ </StepperList>
+ </Stepper>
+ </aside>
+ )}
+
+ <div className="flex min-w-0 flex-1 flex-col gap-6 overflow-y-auto px-4 py-4 sm:px-8 sm:py-6">
+ <div className="flex flex-col gap-1">
+ <h3 className="text-lg text-foreground">{currentStep.title}</h3>
+ <p className="text-sm text-accent">{currentStep.subtitle}</p>
+ </div>
+
+ {step === FormStep.Provider && (
+ <ProviderFields
+ onSelect={(newType) => {
+ if (newType !== type) reset(getDefaultValues(newType));
+ setStep(FormStep.Connection);
+ }}
+ />
+ )}
+ {step === FormStep.Connection && <SecretScanningDataSourceConnectionFields />}
+ {step === FormStep.Scan && <SecretScanningDataSourceScanFields />}
+ {step === FormStep.Details && <SecretScanningDataSourceDetailsFields />}
+ {step === FormStep.Review && <SecretScanningDataSourceReviewFields />}
+ </div>
+
+ {step !== FormStep.Provider && (
+ <aside className="hidden w-64 shrink-0 flex-col gap-3 overflow-y-auto border-l border-border p-5 lg:flex">
+ <p className="text-xs font-medium tracking-wider text-muted uppercase">
+ Step {step + 1} · {currentStep.name}
+ </p>
+ <p className="text-sm font-medium text-foreground">What this step does</p>
+ <p className="text-sm leading-relaxed text-accent">{currentStep.info}</p>
+ </aside>
+ )}
+ </form>
+
+ <SheetFooter className="items-center justify-between border-t">
+ <span className="text-xs text-muted">
+ Step {step + 1} of {steps.length}
+ </span>
+ <div className="flex gap-2">
+ <Button variant="outline" onClick={handleBack} isDisabled={isSubmitting}>
+ {step === firstStep ? "Cancel" : "Back"}
+ </Button>
+ {step !== FormStep.Provider && (
+ <Button
+ variant="ss"
+ type="submit"
+ form="secret-scanning-data-source-form"
+ isPending={isSubmitting}
+ isDisabled={isSubmitting}
+ >
+ {submitLabel}
+ </Button>
+ )}
+ </div>
+ </SheetFooter>
+ </FormProvider>
);
};
diff --git a/frontend/src/components/secret-scanning/forms/index.ts b/frontend/src/components/secret-scanning/forms/index.ts
index c7cb03851d..de0f590dbb 100644
--- a/frontend/src/components/secret-scanning/forms/index.ts
+++ b/frontend/src/components/secret-scanning/forms/index.ts
@@ -1,2 +1 @@
-export * from "./CreateSecretScanningDataSourceForm";
export * from "./SecretScanningDataSourceForm";
diff --git a/frontend/src/components/secret-scanning/index.ts b/frontend/src/components/secret-scanning/index.ts
index 51076da2be..356c76418f 100644
--- a/frontend/src/components/secret-scanning/index.ts
+++ b/frontend/src/components/secret-scanning/index.ts
@@ -1,3 +1,3 @@
export * from "./CreateSecretScanningDataSourceSheet";
-export * from "./EditSecretScanningDataSourceModal";
+export * from "./EditSecretScanningDataSourceSheet";
export * from "./SecretScanningScanStatus";
diff --git a/frontend/src/pages/secret-scanning/SecretScanningDataSourcesPage/components/SecretScanningDataSourcesSection.tsx b/frontend/src/pages/secret-scanning/SecretScanningDataSourcesPage/components/SecretScanningDataSourcesSection.tsx
index 8552a119ab..542532112a 100644
--- a/frontend/src/pages/secret-scanning/SecretScanningDataSourcesPage/components/SecretScanningDataSourcesSection.tsx
+++ b/frontend/src/pages/secret-scanning/SecretScanningDataSourcesPage/components/SecretScanningDataSourcesSection.tsx
@@ -7,7 +7,7 @@ import { createNotification } from "@app/components/notifications";
import { ProjectPermissionCan } from "@app/components/permissions";
import {
CreateSecretScanningDataSourceSheet,
- EditSecretScanningDataSourceModal
+ EditSecretScanningDataSourceSheet
} from "@app/components/secret-scanning";
import { DeleteSecretScanningDataSourceModal } from "@app/components/secret-scanning/DeleteSecretScanningDataSourceModal";
import {
@@ -409,7 +409,7 @@ export const SecretScanningDataSourcesSection = () => {
isOpen={popUp.deleteDataSource.isOpen}
dataSource={popUp.deleteDataSource.data}
/>
- <EditSecretScanningDataSourceModal
+ <EditSecretScanningDataSourceSheet
onOpenChange={(isOpen) => handlePopUpToggle("editDataSource", isOpen)}
isOpen={popUp.editDataSource.isOpen}
dataSource={popUp.editDataSource.data}