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
feat(frontend): virtualize secret preview tables in bulk actions (#8542)
Andrew Huangddd1cfb33ce1
diff --git a/frontend/src/components/v3/generic/Table/Table.stories.tsx b/frontend/src/components/v3/generic/Table/Table.stories.tsxindex 85ca88b3a9..df30967934 100644--- a/frontend/src/components/v3/generic/Table/Table.stories.tsx+++ b/frontend/src/components/v3/generic/Table/Table.stories.tsx@@ -32,7 +32,8 @@ import {TableHead,TableHeader,TableRow,- type TableSortDirection+ type TableSortDirection,+ TableVirtualBody} from "./Table";type Identity = {@@ -194,6 +195,44 @@ export const StickyHeader: Story = {)};+const virtualizedRows = Array.from({ length: 10000 }, (_, i) => ({+ key: `SECRET_KEY_${String(i + 1).padStart(5, "0")}`,+ value: `value-${i + 1}`+}));++export const Virtualized: Story = {+ name: "Example: Virtualized Rows",+ parameters: {+ docs: {+ description: {+ story:+ "Use `TableVirtualBody` in place of `TableBody` when a table can render thousands of rows. Only the rows in view are mounted. Constrain the container height with `containerClassName`, and spread the `rowProps` from the render function onto each `TableRow` so rows of varying height are measured. Give columns fixed widths (`table-fixed`, or fixed or truncated cell widths) so they don't resize as rows mount while scrolling."+ }+ }+ },+ render: () => (+ <Table className="w-full table-fixed" containerClassName="max-h-80 overflow-y-auto">+ <TableHeader sticky>+ <TableRow>+ <TableHead>Key</TableHead>+ <TableHead>Value</TableHead>+ </TableRow>+ </TableHeader>+ <TableVirtualBody count={virtualizedRows.length}>+ {(index, rowProps) => {+ const row = virtualizedRows[index];+ return (+ <TableRow key={row.key} {...rowProps}>+ <TableCell className="font-mono text-xs">{row.key}</TableCell>+ <TableCell className="font-mono text-xs">{row.value}</TableCell>+ </TableRow>+ );+ }}+ </TableVirtualBody>+ </Table>+ )+};+export const WithCaption: Story = {name: "Anatomy: With Caption",parameters: {diff --git a/frontend/src/components/v3/generic/Table/Table.tsx b/frontend/src/components/v3/generic/Table/Table.tsxindex 4c70c3db96..559fd10d11 100644--- a/frontend/src/components/v3/generic/Table/Table.tsx+++ b/frontend/src/components/v3/generic/Table/Table.tsx@@ -1,4 +1,5 @@import * as React from "react";+import { useVirtualizer } from "@tanstack/react-virtual";import { cn } from "@app/components/v3/utils";@@ -61,13 +62,75 @@ function TableHeader({);}-function TableBody({ className, ...props }: React.ComponentProps<"tbody">) {+const TableBody = React.forwardRef<HTMLTableSectionElement, React.ComponentProps<"tbody">>(+ ({ className, ...props }, ref) => {+ return (+ <tbody+ ref={ref}+ data-slot="table-body"+ className={cn(+ "[&>tr:last-of-type]:border-b-0 [&>tr:last-of-type>td]:border-b-0",+ className+ )}+ {...props}+ />+ );+ }+);++TableBody.displayName = "TableBody";++type TableVirtualRowProps = {+ ref: (element: HTMLTableRowElement | null) => void;+ "data-index": number;+ "aria-rowindex": number;+};++function TableVirtualBody({+ className,+ count,+ estimateRowHeight = 41,+ children+}: {+ className?: string;+ count: number;+ estimateRowHeight?: number;+ children: (index: number, rowProps: TableVirtualRowProps) => React.ReactNode;+}) {+ const bodyRef = React.useRef<HTMLTableSectionElement>(null);+ const virtualizer = useVirtualizer({+ count,+ getScrollElement: () => bodyRef.current?.closest("[data-slot=table-container]") ?? null,+ estimateSize: () => estimateRowHeight,+ overscan: 10+ });+ const [headerRowCount, setHeaderRowCount] = React.useState(1);+ React.useLayoutEffect(() => {+ const table = bodyRef.current?.closest("table");+ if (!table) return;+ const headerRows = Array.from(table.tHead?.rows ?? []);+ headerRows.forEach((row, index) => row.setAttribute("aria-rowindex", String(index + 1)));+ table.setAttribute("aria-rowcount", String(headerRows.length + count));+ setHeaderRowCount(headerRows.length);+ }, [count]);+ const virtualRows = virtualizer.getVirtualItems();+ const padTop = virtualRows[0]?.start ?? 0;+ const padBottom = virtualRows.length+ ? virtualizer.getTotalSize() - virtualRows[virtualRows.length - 1].end+ : 0;+return (- <tbody- data-slot="table-body"- className={cn("[&>tr:last-of-type]:border-b-0 [&>tr:last-of-type>td]:border-b-0", className)}- {...props}- />+ <TableBody ref={bodyRef} className={className}>+ {padTop > 0 && <tr aria-hidden style={{ height: padTop }} />}+ {virtualRows.map((virtualRow) =>+ children(virtualRow.index, {+ ref: virtualizer.measureElement,+ "data-index": virtualRow.index,+ "aria-rowindex": headerRowCount + virtualRow.index + 1+ })+ )}+ {padBottom > 0 && <tr aria-hidden style={{ height: padBottom }} />}+ </TableBody>);}@@ -226,5 +289,7 @@ export {TableHeader,TableHeadLabel,TableRow,- type TableSortDirection+ type TableSortDirection,+ TableVirtualBody,+ type TableVirtualRowProps};diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/SecretDropzone/ImportSecretsModal.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/SecretDropzone/ImportSecretsModal.tsxindex 2a05f13e64..053376a896 100644--- a/frontend/src/pages/secret-manager/OverviewPage/components/SecretDropzone/ImportSecretsModal.tsx+++ b/frontend/src/pages/secret-manager/OverviewPage/components/SecretDropzone/ImportSecretsModal.tsx@@ -28,11 +28,11 @@ import {SheetHeader,SheetTitle,Table,- TableBody,TableCell,TableHead,TableHeader,TableRow,+ TableVirtualBody,Tabs,TabsContent,TabsList,@@ -131,6 +131,7 @@ const ImportSecretsContent = ({});const activeSecrets = initialParsedSecrets || parsedSecrets;+ const secretEntries = useMemo(() => Object.entries(activeSecrets ?? {}), [activeSecrets]);const secretCount = activeSecrets ? Object.keys(activeSecrets).length : 0;const hasTagsToResolve = activeSecrets? Object.values(activeSecrets).some((s) => s.tagSlugs?.length)@@ -573,8 +574,9 @@ const ImportSecretsContent = ({</TableHead></TableRow></TableHeader>- <TableBody>- {Object.entries(activeSecrets!).map(([key, secretData]) => {+ <TableVirtualBody count={secretEntries.length}>+ {(index, rowProps) => {+ const [key, secretData] = secretEntries[index];const isVisible = visibleSecretKeys.has(key);const hasComments = secretData.comments.some((c) => c);const hasTags = Boolean(secretData.tagSlugs?.length);@@ -583,7 +585,7 @@ const ImportSecretsContent = ({const editableKey = secretData.isFileSecret === true;const editedKey = keyOverrides[key] ?? key;return (- <TableRow key={key}>+ <TableRow key={key} {...rowProps}><TableCell isTruncatable className="w-1/2 overflow-hidden font-mono text-xs"><div className="flex w-full items-center gap-1.5">{editableKey ? (@@ -677,8 +679,8 @@ const ImportSecretsContent = ({</TableCell></TableRow>);- })}- </TableBody>+ }}+ </TableVirtualBody></Table></div><Field>diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/components/BulkSelectionTable/BulkSelectionTable.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/components/BulkSelectionTable/BulkSelectionTable.tsxindex e21b365f8c..a08bb06321 100644--- a/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/components/BulkSelectionTable/BulkSelectionTable.tsx+++ b/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/components/BulkSelectionTable/BulkSelectionTable.tsx@@ -1,6 +1,13 @@import { FolderIcon, KeyIcon, TagsIcon, TrashIcon } from "lucide-react";-import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@app/components/v3";+import {+ Table,+ TableCell,+ TableHead,+ TableHeader,+ TableRow,+ TableVirtualBody+} from "@app/components/v3";import { cn } from "@app/components/v3/utils";import { ProjectEnv } from "@app/hooks/api/projects/types";@@ -42,34 +49,37 @@ export const BulkSelectionTable = ({ action, items, environments, containerClass))}</TableRow></TableHeader>- <TableBody>- {items.map((item) => (- <TableRow key={`${item.type}-${item.name}`} className="group">- <TableCell className="sticky left-0 z-10 bg-container transition-colors duration-75 group-hover:bg-container-hover">- {item.type === "folder" ? (- <FolderIcon className="size-4 text-folder" />- ) : (- <KeyIcon className="size-4 text-secret" />- )}- </TableCell>- <TableCell- className="sticky left-10 z-10 w-32 max-w-32 min-w-32 bg-container shadow-[inset_-1px_0_0_var(--color-border)] transition-colors duration-75 group-hover:bg-container-hover sm:w-72 sm:max-w-72 sm:min-w-72"- isTruncatable- >- {item.name}- </TableCell>- {environments.map((environment) => (- <TableCell key={environment.slug} className="border-r text-center last:border-r-0">- {item.envSlugs.has(environment.slug) ? (- <ActionIcon className={cn("inline-block size-4", actionIconClassName)} />+ <TableVirtualBody count={items.length}>+ {(index, rowProps) => {+ const item = items[index];+ return (+ <TableRow key={`${item.type}-${item.name}`} className="group" {...rowProps}>+ <TableCell className="sticky left-0 z-10 bg-container transition-colors duration-75 group-hover:bg-container-hover">+ {item.type === "folder" ? (+ <FolderIcon className="size-4 text-folder" />) : (- <span className="text-muted">—</span>+ <KeyIcon className="size-4 text-secret" />)}</TableCell>- ))}- </TableRow>- ))}- </TableBody>+ <TableCell+ className="sticky left-10 z-10 w-32 max-w-32 min-w-32 bg-container shadow-[inset_-1px_0_0_var(--color-border)] transition-colors duration-75 group-hover:bg-container-hover sm:w-72 sm:max-w-72 sm:min-w-72"+ isTruncatable+ >+ {item.name}+ </TableCell>+ {environments.map((environment) => (+ <TableCell key={environment.slug} className="border-r text-center last:border-r-0">+ {item.envSlugs.has(environment.slug) ? (+ <ActionIcon className={cn("inline-block size-4", actionIconClassName)} />+ ) : (+ <span className="text-muted">—</span>+ )}+ </TableCell>+ ))}+ </TableRow>+ );+ }}+ </TableVirtualBody></Table>);};