Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix(frontend): address encryption tab backup dialog review feedback
andrewhuhh3645310498d8
diff --git a/frontend/src/components/v3/generic/Empty/Empty.stories.tsx b/frontend/src/components/v3/generic/Empty/Empty.stories.tsxindex 36f08d6dd2..489d413d56 100644--- a/frontend/src/components/v3/generic/Empty/Empty.stories.tsx+++ b/frontend/src/components/v3/generic/Empty/Empty.stories.tsx@@ -27,6 +27,13 @@ import {* at the page level the frame-less look is intentional. When nesting `Empty` inside a* `Card`, `Sheet`, or `Dialog`, add `className="border"` to activate the dashed frame* so the empty state reads as visually distinct from its container.+ *+ * **`frame` prop** — an alternate, SVG-drawn frame for surfaces that want a more+ * pronounced dashed (or solid) boundary than the CSS border gives — e.g. a+ * drag-and-drop target. `stroke-dasharray` allows a longer dash/gap than+ * `border-style: dashed` supports, without losing the rounded corners the way+ * `border-image` would. Opt-in and independent from `className="border"`; existing+ * consumers are unaffected. Recolor with `frameClassName` (defaults to `text-border`).*/const meta = {title: "Generic/Empty",@@ -233,3 +240,39 @@ export const InsideCard: Story = {</Card>)};++export const WithSvgFrame: Story = {+ name: "Variant: SVG Frame (Dashed / Solid)",+ parameters: {+ docs: {+ description: {+ story:+ 'Pass `frame="dashed"` or `frame="solid"` for the SVG-drawn boundary — used by `FileDropzone` for its passive (dashed) and drag-active (solid, recolored via `frameClassName`) states. Prefer this over `className="border"` when the dash proportions need to stand out, such as an interactive drop target.'+ }+ }+ },+ render: () => (+ <div className="flex gap-4">+ <Empty frame="dashed" className="w-72">+ <EmptyHeader>+ <EmptyMedia variant="icon">+ <UploadIcon />+ </EmptyMedia>+ <EmptyTitle>Dashed frame</EmptyTitle>+ <EmptyDescription>frame="dashed"</EmptyDescription>+ </EmptyHeader>+ </Empty>+ <Empty frame="solid" frameClassName="text-info" className="w-72 bg-info/10">+ <EmptyHeader>+ <EmptyMedia variant="icon">+ <UploadIcon />+ </EmptyMedia>+ <EmptyTitle>Solid frame</EmptyTitle>+ <EmptyDescription>+ frame="solid" frameClassName="text-info"+ </EmptyDescription>+ </EmptyHeader>+ </Empty>+ </div>+ )+};diff --git a/frontend/src/components/v3/generic/Empty/Empty.tsx b/frontend/src/components/v3/generic/Empty/Empty.tsxindex 3f8c18baf8..2a2669d16b 100644--- a/frontend/src/components/v3/generic/Empty/Empty.tsx+++ b/frontend/src/components/v3/generic/Empty/Empty.tsx@@ -2,17 +2,64 @@ import { cva, VariantProps } from "cva";import { cn } from "../../utils";-function Empty({ className, ...props }: React.ComponentProps<"div">) {- return (+type EmptyFrameProps = {+ // Draws the dashed/solid frame with an SVG rect instead of a CSS border.+ // CSS `border-style: dashed` has no dash-length control; `stroke-dasharray`+ // does, and unlike `border-image` it still respects the rounded corners.+ // Opt-in and off by default so existing `className="border"` consumers+ // (the CSS-border convention documented in this file's stories) render+ // unchanged — this is a distinct, additive frame for new call sites.+ frame?: "none" | "dashed" | "solid";+ // Merged onto the frame's default `text-border` (e.g. to recolor on drag-active)+ frameClassName?: string;+};++function Empty({+ className,+ frame = "none",+ frameClassName,+ children,+ ...props+}: React.ComponentProps<"div"> & EmptyFrameProps) {+ const box = (<divdata-slot="empty"className={cn("flex min-w-0 flex-1 flex-col items-center justify-center gap-6 rounded-md border-dashed border-border bg-container p-6 text-center text-balance text-foreground shadow-inner md:p-12",+ frame !== "none" && "relative",className)}{...props}- />+ >+ {frame !== "none" && (+ <svg+ aria-hidden="true"+ className={cn(+ "pointer-events-none absolute inset-0 size-full text-border transition-colors duration-75",+ frameClassName+ )}+ >+ <rect+ x="1"+ y="1"+ rx="4"+ fill="none"+ stroke="currentColor"+ strokeWidth="2"+ strokeDasharray={frame === "dashed" ? "10 6" : undefined}+ style={{ width: "calc(100% - 2px)", height: "calc(100% - 2px)" }}+ />+ </svg>+ )}+ {children}+ </div>);++ // Only the SVG-framed variant gets outer breathing room — the plain CSS-border+ // convention (className="border") keeps its existing flush layout untouched.+ if (frame === "none") return box;++ return <div className="p-0.5">{box}</div>;}function EmptyHeader({ className, ...props }: React.ComponentProps<"div">) {diff --git a/frontend/src/components/v3/generic/FileDropzone/FileDropzone.stories.tsx b/frontend/src/components/v3/generic/FileDropzone/FileDropzone.stories.tsxnew file mode 100644index 0000000000..32f3b91990--- /dev/null+++ b/frontend/src/components/v3/generic/FileDropzone/FileDropzone.stories.tsx@@ -0,0 +1,135 @@+import { useState } from "react";+import type { Meta, StoryObj } from "@storybook/react-vite";++import { FileDropzone } from "./FileDropzone";++/**+ * FileDropzone is the standard file-upload surface: a dashed drop target that+ * doubles as a click-to-browse button, with an accented "Choose file" affordance+ * and an optional accepted-types line. While a file is dragged over it, the+ * frame highlights with the info tint and the title swaps to a drop prompt.+ *+ * Selection is delivered through `onFilesSelect` with the files chosen in that+ * interaction — an empty array signals an invalid drop (e.g. a file dragged out+ * of VS Code), so callers can raise their own error. Single-file by default;+ * pass `multiple` to allow several files per interaction.+ *+ * The component does not own the selected-file state. Pass `files` to render+ * the selected files as rows (icon, truncating name with the extension always+ * visible, size), and `onFileRemove` to expose a remove action on each row.+ * Omit `files` when selection immediately advances to another step, as in the+ * secrets import dialog.+ */+const meta = {+ title: "Generic/FileDropzone",+ component: FileDropzone,+ parameters: {+ layout: "centered"+ },+ tags: ["autodocs"],+ args: {+ className: "w-[480px]",+ onFilesSelect: () => {}+ },+ argTypes: {+ className: {+ table: {+ disable: true+ }+ }+ }+} satisfies Meta<typeof FileDropzone>;++export default meta;+type Story = StoryObj<typeof meta>;++export const Default: Story = {+ name: "Example: Default",+ parameters: {+ docs: {+ description: {+ story:+ "Single-file dropzone with an accepted-types description. Selecting or dropping a file replaces the previous selection."+ }+ }+ },+ render: (args) => {+ const [files, setFiles] = useState<File[]>([]);+ return (+ <FileDropzone+ {...args}+ accept=".env,.json,.yml"+ description=".env, .json, or .yml"+ files={files}+ onFilesSelect={(selected) => setFiles(selected.slice(0, 1))}+ onFileRemove={(_, index) => setFiles((prev) => prev.filter((__, i) => i !== index))}+ />+ );+ }+};++export const Multiple: Story = {+ name: "Variant: Multiple",+ parameters: {+ docs: {+ description: {+ story:+ "Pass `multiple` to accept several files per interaction. The caller owns the list, so append incoming files to keep prior selections."+ }+ }+ },+ render: (args) => {+ const [files, setFiles] = useState<File[]>([]);+ return (+ <FileDropzone+ {...args}+ multiple+ description="Any file type"+ files={files}+ onFilesSelect={(selected) => setFiles((prev) => [...prev, ...selected])}+ onFileRemove={(_, index) => setFiles((prev) => prev.filter((__, i) => i !== index))}+ />+ );+ }+};++export const WithFile: Story = {+ name: "Example: With Selected File",+ parameters: {+ docs: {+ description: {+ story:+ "A selected file renders as a row with icon, truncating name (extension always visible), size, and a remove action when `onFileRemove` is provided."+ }+ }+ },+ render: (args) => {+ const [files, setFiles] = useState<File[]>([+ new File(["x".repeat(4096)], "kms-backup-acme-example-project-secretManager.infisical.txt", {+ type: "text/plain"+ })+ ]);+ return (+ <FileDropzone+ {...args}+ accept=".txt"+ description=".infisical.txt backup file"+ files={files}+ onFilesSelect={(selected) => setFiles(selected.slice(0, 1))}+ onFileRemove={(_, index) => setFiles((prev) => prev.filter((__, i) => i !== index))}+ />+ );+ }+};++export const Disabled: Story = {+ name: "Variant: Disabled",+ parameters: {+ docs: {+ description: {+ story: "Disabled surfaces dim and ignore both clicks and drops — use for permission gates."+ }+ }+ },+ render: (args) => <FileDropzone {...args} isDisabled description="Any file type" />+};diff --git a/frontend/src/components/v3/generic/FileDropzone/FileDropzone.tsx b/frontend/src/components/v3/generic/FileDropzone/FileDropzone.tsxnew file mode 100644index 0000000000..f75543862c--- /dev/null+++ b/frontend/src/components/v3/generic/FileDropzone/FileDropzone.tsx@@ -0,0 +1,160 @@+import { ChangeEvent, DragEvent, ReactNode, useState } from "react";+import { FileTextIcon, UploadIcon, XIcon } from "lucide-react";++import { cn } from "../../utils";+import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from "../Empty";+import { IconButton } from "../IconButton";+import { Item, ItemActions, ItemContent, ItemGroup, ItemMedia } from "../Item";++// Split so the base name can truncate while the extension stays visible+const splitFileName = (fileName: string) => {+ const extIndex = fileName.lastIndexOf(".");+ if (extIndex <= 0) return { base: fileName, ext: "" };+ return { base: fileName.slice(0, extIndex), ext: fileName.slice(extIndex) };+};++const formatFileSize = (bytes: number) => {+ if (bytes < 1024) return `${bytes} B`;+ if (bytes < 1024 * 1024) return `${Math.round(bytes / 1024)} KB`;+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;+};++type FileDropzoneProps = {+ // Files chosen in this interaction (click or drop). Receives an empty array+ // when a drop carries no real file (e.g. dragging out of VS Code), so+ // callers can surface their own error message for that case.+ onFilesSelect: (files: File[]) => void;+ // Selected files to display as rows under the dropzone. Omit to render the+ // surface alone (e.g. when selection immediately advances to another step).+ files?: File[];+ // Renders a remove action on each file row when provided+ onFileRemove?: (file: File, index: number) => void;+ multiple?: boolean;+ accept?: string;+ title?: ReactNode;+ dropTitle?: ReactNode;+ description?: ReactNode;+ isDisabled?: boolean;+ className?: string;+};++function FileDropzone({+ onFilesSelect,+ files,+ onFileRemove,+ multiple = false,+ accept,+ title,+ dropTitle,+ description,+ isDisabled,+ className+}: FileDropzoneProps) {+ const [isDragActive, setIsDragActive] = useState(false);++ const handleDrag = (e: DragEvent) => {+ e.preventDefault();+ e.stopPropagation();+ if (isDisabled) return;+ if (e.type === "dragenter" || e.type === "dragover") {+ setIsDragActive(true);+ } else if (e.type === "dragleave") {+ setIsDragActive(false);+ }+ };++ const handleDrop = (e: DragEvent) => {+ e.preventDefault();+ e.stopPropagation();+ if (isDisabled || !e.dataTransfer) return;+ e.dataTransfer.dropEffect = "copy";+ setIsDragActive(false);+ const dropped = Array.from(e.dataTransfer.files);+ onFilesSelect(multiple ? dropped : dropped.slice(0, 1));+ };++ const handleChange = (e: ChangeEvent<HTMLInputElement>) => {+ e.preventDefault();+ onFilesSelect(Array.from(e.target.files ?? []));+ e.target.value = "";+ };++ return (+ <div data-slot="file-dropzone" className={cn("flex min-w-0 flex-col gap-4", className)}>+ <Empty+ frame={isDragActive ? "solid" : "dashed"}+ frameClassName={isDragActive ? "text-info" : undefined}+ className={cn(+ "cursor-pointer bg-transparent transition-colors duration-75",+ isDragActive && "bg-info/10",+ isDisabled && "pointer-events-none opacity-50"+ )}+ onDragEnter={handleDrag}+ onDragLeave={handleDrag}+ onDragOver={handleDrag}+ onDrop={handleDrop}+ >+ <EmptyHeader>+ <EmptyMedia variant="icon">+ <UploadIcon />+ </EmptyMedia>+ <EmptyTitle>+ {isDragActive+ ? (dropTitle ?? `Drop your file${multiple ? "s" : ""} here`)+ : (title ?? (+ <>+ Drag & drop or <span className="text-info">Choose file</span> to upload+ </>+ ))}+ </EmptyTitle>+ {description && <EmptyDescription>{description}</EmptyDescription>}+ </EmptyHeader>+ <input+ type="file"+ disabled={isDisabled}+ multiple={multiple}+ className="absolute top-0 left-0 h-full w-full cursor-pointer opacity-0"+ accept={accept}+ onChange={handleChange}+ />+ </Empty>+ {!!files?.length && (+ <ItemGroup>+ {files.map((file, index) => {+ const { base, ext } = splitFileName(file.name);+ return (+ // eslint-disable-next-line react/no-array-index-key+ <Item key={`${file.name}-${index}`} variant="outline" size="xs" role="listitem">+ <ItemMedia variant="icon">+ <FileTextIcon />+ </ItemMedia>+ <ItemContent className="min-w-0">+ <div className="flex max-w-full min-w-0 items-baseline text-sm text-foreground">+ <span className="min-w-0 truncate">{base}</span>+ <span className="shrink-0">{ext}</span>+ </div>+ <span className="text-xs text-muted">{formatFileSize(file.size)}</span>+ </ItemContent>+ {onFileRemove && (+ <ItemActions>+ <IconButton+ variant="ghost"+ size="xs"+ aria-label={`Remove ${file.name}`}+ onClick={() => onFileRemove(file, index)}+ >+ <XIcon />+ </IconButton>+ </ItemActions>+ )}+ </Item>+ );+ })}+ </ItemGroup>+ )}+ </div>+ );+}++export { FileDropzone };+export type { FileDropzoneProps };diff --git a/frontend/src/components/v3/generic/FileDropzone/index.ts b/frontend/src/components/v3/generic/FileDropzone/index.tsnew file mode 100644index 0000000000..7dd382d866--- /dev/null+++ b/frontend/src/components/v3/generic/FileDropzone/index.ts@@ -0,0 +1 @@+export * from "./FileDropzone";diff --git a/frontend/src/components/v3/generic/index.ts b/frontend/src/components/v3/generic/index.tsindex b41de02428..9574c7b68e 100644--- a/frontend/src/components/v3/generic/index.ts+++ b/frontend/src/components/v3/generic/index.ts@@ -17,6 +17,7 @@ export * from "./Dialog";export * from "./Dropdown";export * from "./Empty";export * from "./Field";+export * from "./FileDropzone";export * from "./HoverCard";export * from "./IconButton";export * from "./Input";diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/SecretDropzone/ImportSecretsModal.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/SecretDropzone/ImportSecretsModal.tsxindex 8d88a609a9..84ef913428 100644--- a/frontend/src/pages/secret-manager/OverviewPage/components/SecretDropzone/ImportSecretsModal.tsx+++ b/frontend/src/pages/secret-manager/OverviewPage/components/SecretDropzone/ImportSecretsModal.tsx@@ -1,4 +1,4 @@-import { ChangeEvent, DragEvent, useCallback, useState } from "react";+import { useCallback, useState } from "react";import { subject } from "@casl/ability";import {ClipboardPasteIcon,@@ -8,10 +8,8 @@ import {InfoIcon,MessageSquareIcon,TagsIcon,- UploadIcon,WrapTextIcon} from "lucide-react";-import { twMerge } from "tailwind-merge";import { createNotification } from "@app/components/notifications";import { ProjectPermissionCan } from "@app/components/permissions";@@ -23,14 +21,10 @@ import {DialogFooter,DialogHeader,DialogTitle,- Empty,- EmptyDescription,- EmptyHeader,- EmptyMedia,- EmptyTitle,Field,FieldContent,FieldLabel,+ FileDropzone,IconButton,Input,Switch,@@ -88,7 +82,6 @@ const ImportSecretsContent = ({const { permission } = useProjectPermission();const [parsedSecrets, setParsedSecrets] = useState<TParsedEnv | null>(null);const [selectedEnvs, setSelectedEnvs] = useState<{ name: string; slug: string }[]>([]);- const [isDragActive, setDragActive] = useToggle();const [isImporting, setIsImporting] = useToggle();const [isPasteOpen, setIsPasteOpen] = useState(false);const [csvData, setCsvData] = useState<CsvData | null>(null);@@ -157,31 +150,6 @@ const ImportSecretsContent = ({[handleParsedSecrets]);- const handleDrag = (e: DragEvent) => {- e.preventDefault();- e.stopPropagation();- if (e.type === "dragenter" || e.type === "dragover") {- setDragActive.on();- } else if (e.type === "dragleave") {- setDragActive.off();- }- };-- const handleDrop = (e: DragEvent) => {- e.preventDefault();- e.stopPropagation();- if (!e.dataTransfer) return;- e.dataTransfer.dropEffect = "copy";- setDragActive.off();- parseFile(e.dataTransfer.files[0]);- };-- const handleFileUpload = (e: ChangeEvent<HTMLInputElement>) => {- e.preventDefault();- parseFile(e.target?.files?.[0]);- e.target.value = "";- };-const handleImport = async () => {if (!activeSecrets || !selectedEnvs.length) return;@@ -449,36 +417,12 @@ const ImportSecretsContent = ({})}>{(isAllowed) => (- <Empty- className={twMerge(- "relative cursor-pointer border transition-colors duration-75",- isDragActive && "bg-container-hover"- )}- onDragEnter={handleDrag}- onDragLeave={handleDrag}- onDragOver={handleDrag}- onDrop={handleDrop}- >- <EmptyHeader>- <EmptyMedia variant="icon">- <UploadIcon />- </EmptyMedia>- <EmptyTitle>- {isDragActive ? "Drop your file here" : "Upload your secrets"}- </EmptyTitle>- <EmptyDescription>- Drag and drop your .env, .json, .yml, .csv, .pfx, .pem, or .crt files here, or- click to browse- </EmptyDescription>- </EmptyHeader>- <input- type="file"- disabled={!isAllowed}- className="absolute top-0 left-0 h-full w-full cursor-pointer opacity-0"- accept=".txt,.env,.yml,.yaml,.json,.csv,.pfx,.pem,.crt"- onChange={handleFileUpload}- />- </Empty>+ <FileDropzone+ isDisabled={!isAllowed}+ accept=".txt,.env,.yml,.yaml,.json,.csv,.pfx,.pem,.crt"+ description=".env, .json, .yml, .csv, .pfx, .pem, or .crt"+ onFilesSelect={(files) => parseFile(files[0])}+ />)}</ProjectPermissionCan>diff --git a/frontend/src/pages/secret-manager/SettingsPage/components/EncryptionTab/EncryptionTab.tsx b/frontend/src/pages/secret-manager/SettingsPage/components/EncryptionTab/EncryptionTab.tsxindex a61eea4cd9..9e033954d4 100644--- a/frontend/src/pages/secret-manager/SettingsPage/components/EncryptionTab/EncryptionTab.tsx+++ b/frontend/src/pages/secret-manager/SettingsPage/components/EncryptionTab/EncryptionTab.tsx@@ -1,8 +1,7 @@-import { ChangeEvent, useRef, useState } from "react";+import { useState } from "react";import { Controller, useForm } from "react-hook-form";import { zodResolver } from "@hookform/resolvers/zod";import FileSaver from "file-saver";-import { UploadIcon } from "lucide-react";import { z } from "zod";import { createNotification } from "@app/components/notifications";@@ -23,6 +22,7 @@ import {Field,FieldError,FieldLabel,+ FileDropzone,Select,SelectContent,SelectItem,@@ -131,10 +131,9 @@ const LoadBackupModal = ({org?: Organization;workspace: Project;}) => {- const fileUploadRef = useRef<HTMLInputElement>(null);const { mutateAsync: loadKmsBackup, isPending } = useLoadProjectKmsBackup(project.id);const [backupContent, setBackupContent] = useState("");- const [backupFileName, setBackupFileName] = useState("");+ const [backupFiles, setBackupFiles] = useState<File[]>([]);const handleOpenChange = (state: boolean) => {// Clear on every open-change (open and close), not only close: a FileReader@@ -142,7 +141,7 @@ const LoadBackupModal = ({// clearing on reopen recovers from that stale state (Continue would otherwise// be enabled with no filename shown).setBackupContent("");- setBackupFileName("");+ setBackupFiles([]);onOpenChange(state);};@@ -183,12 +182,6 @@ const LoadBackupModal = ({}};- const handleFileUpload = (e: ChangeEvent<HTMLInputElement>) => {- e.preventDefault();- parseFile(e.target?.files?.[0]);- setBackupFileName(e.target?.files?.[0]?.name || "");- };-return (<Dialog open={isOpen} onOpenChange={handleOpenChange}><DialogContent className="max-w-lg">@@ -199,31 +192,20 @@ const LoadBackupModal = ({KMS.</DialogDescription></DialogHeader>- <input- id="fileSelect"- className="hidden"- type="file"+ <FileDropzoneaccept=".txt"- onChange={handleFileUpload}- ref={fileUploadRef}+ description=".infisical.txt backup file"+ files={backupFiles}+ onFilesSelect={(files) => {+ const file = files[0];+ parseFile(file);+ setBackupFiles(file ? [file] : []);+ }}+ onFileRemove={() => {+ setBackupFiles([]);+ setBackupContent("");+ }}/>- <div className="flex flex-col items-center gap-2 py-2">- <Button- type="button"- variant="outline"- onClick={() => {- fileUploadRef?.current?.click();- }}- >- <UploadIcon className="size-4" />- Choose Backup File- </Button>- {backupFileName && (- <span className="max-w-full truncate px-4 text-center text-sm text-muted">- {backupFileName}- </span>- )}- </div><DialogFooter><Button variant="outline" onClick={() => handleOpenChange(false)}>Cancel