Skip to content

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

feat(ui): refactor secret dependency tree view

Daniel Hougaard94143a8a2adb
diff --git a/frontend/src/components/secrets/SecretReferenceDetails/SecretReferenceDetails.tsx b/frontend/src/components/secrets/SecretReferenceDetails/SecretReferenceDetails.tsx
index d6297a8882..8e777755ea 100644
--- a/frontend/src/components/secrets/SecretReferenceDetails/SecretReferenceDetails.tsx
+++ b/frontend/src/components/secrets/SecretReferenceDetails/SecretReferenceDetails.tsx
@@ -8,18 +8,25 @@ import {
} from "react-complex-tree";
import { faExclamationTriangle, faEye, faEyeSlash } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+import {
+ Background,
+ BackgroundVariant,
+ ConnectionLineType,
+ Controls,
+ ReactFlow,
+ ReactFlowProvider
+} from "@xyflow/react";
import { AxiosError } from "axios";
import { createNotification } from "@app/components/notifications";
import { FormControl, FormLabel, SecretInput, Spinner, Tooltip } from "@app/components/v2";
import { useProject } from "@app/context";
import { useGetSecretReferences, useGetSecretReferenceTree } from "@app/hooks/api";
-import {
- ApiErrorTypes,
- TApiErrors,
- TSecretDependencyTreeNode,
- TSecretReferenceTraceNode
-} from "@app/hooks/api/types";
+import { ApiErrorTypes, TApiErrors, TSecretReferenceTraceNode } from "@app/hooks/api/types";
+
+import { SecretReferenceEdge } from "./edges/SecretReferenceEdge";
+import { SecretNode } from "./nodes/SecretNode";
+import { convertDependencyTreeToFlow } from "./utils/convertToFlowElements";
import "./SecretReferenceTree.css";
@@ -46,7 +53,6 @@ const createNodeId = (node: TSecretReferenceTraceNode, parentId?: string): strin
return parentId ? `${parentId}>${baseId}` : baseId;
};
-// Convert TSecretReferenceTraceNode to react-complex-tree format
const convertToTreeItems = (
node: TSecretReferenceTraceNode,
secretKey: string,
@@ -56,7 +62,6 @@ const convertToTreeItems = (
const items: Record<TreeItemIndex, TreeItem<TreeNodeData>> = {};
const nodeId = createNodeId(node, parentId);
- // Check for circular reference
const circularKey = `${node.environment}:${node.secretPath}:${node.key}`;
const isCircular = visitedPath.has(circularKey);
const newVisitedPath = new Set([...visitedPath, circularKey]);
@@ -87,7 +92,6 @@ const convertToTreeItems = (
}
};
- // Add a hidden root container that has this node as its only child
if (!parentId) {
items.root = {
index: "root",
@@ -100,183 +104,6 @@ const convertToTreeItems = (
return items;
};
-// Invert the dependency tree so leaf nodes become roots
-// This transforms "A is referenced by B is referenced by C" into "C → B → A"
-// which reads as "C references B which references A"
-const invertDependencyTree = (tree: TSecretDependencyTreeNode): TSecretDependencyTreeNode[] => {
- // Collect all paths from root to leaves
- const paths: TSecretDependencyTreeNode[][] = [];
-
- const collectPaths = (
- node: TSecretDependencyTreeNode,
- currentPath: TSecretDependencyTreeNode[],
- visited: Set<string>
- ) => {
- const nodeKey = `${node.environment}:${node.secretPath}:${node.key}`;
-
- // if circular reference, save path up to this point (including circular node) and stop
- if (visited.has(nodeKey)) {
- if (currentPath.length > 0) {
- paths.push([...currentPath, node]);
- }
- return;
- }
-
- const newPath = [...currentPath, node];
- const newVisited = new Set([...visited, nodeKey]);
-
- if (node.children.length === 0) {
- // Leaf node - save this path
- paths.push(newPath);
- } else {
- // Continue traversing
- node.children.forEach((child) => collectPaths(child, newPath, newVisited));
- }
- };
-
- collectPaths(tree, [], new Set());
-
- // If no paths (only root with no children), return empty
- if (paths.length === 0) return [];
-
- // Build inverted trees from paths
- // Each path becomes a chain: leaf → ... → root
- const invertedRoots: Map<string, TSecretDependencyTreeNode> = new Map();
-
- paths.forEach((path) => {
- // Reverse the path so leaf is first, root is last
- const reversed = [...path].reverse();
-
- // Build the chain
- let currentNode: TSecretDependencyTreeNode | null = null;
-
- reversed.forEach((node, idx) => {
- const nodeKey = `${node.environment}:${node.secretPath}:${node.key}`;
- const isLeaf = idx === 0;
-
- if (isLeaf) {
- // Check if we already have this leaf as a root
- if (invertedRoots.has(nodeKey)) {
- currentNode = invertedRoots.get(nodeKey)!;
- } else {
- currentNode = {
- key: node.key,
- environment: node.environment,
- secretPath: node.secretPath,
- children: []
- };
- invertedRoots.set(nodeKey, currentNode);
- }
- } else if (currentNode) {
- // Check if this node already exists as a child
- const existingChild = currentNode.children.find(
- (c) =>
- c.key === node.key &&
- c.environment === node.environment &&
- c.secretPath === node.secretPath
- );
-
- if (existingChild) {
- currentNode = existingChild;
- } else {
- const newNode: TSecretDependencyTreeNode = {
- key: node.key,
- environment: node.environment,
- secretPath: node.secretPath,
- children: []
- };
- currentNode.children.push(newNode);
- currentNode = newNode;
- }
- }
- });
- });
-
- return Array.from(invertedRoots.values());
-};
-
-// Convert dependency tree from API to react-complex-tree format
-// The tree is inverted so that leaf nodes (top-level dependents) are shown first
-const convertDependencyTreeToItems = (
- tree: TSecretDependencyTreeNode,
- rootSecretKey: string
-): { items: Record<TreeItemIndex, TreeItem<TreeNodeData>>; topLevelIds: string[] } => {
- const items: Record<TreeItemIndex, TreeItem<TreeNodeData>> = {};
-
- // Invert the tree so dependencies flow naturally (top → bottom)
- const invertedRoots = invertDependencyTree(tree);
-
- // If no dependents, return empty
- if (invertedRoots.length === 0) {
- return { items: {}, topLevelIds: [] };
- }
-
- const processNode = (
- node: TSecretDependencyTreeNode,
- parentId: string | undefined,
- depth: number,
- visited: Set<string>
- ): string => {
- const nodeKey = `${node.environment}:${node.secretPath}:${node.key}`;
- const nodeId = parentId ? `${parentId}>${nodeKey}` : nodeKey;
-
- // check if this is the original root secret (the one being viewed)
- const isOriginalRoot = node.key === rootSecretKey && depth > 0;
- const displayName = `${node.environment}${node.secretPath === "/" ? "" : node.secretPath.split("/").join(".")}.${node.key}`;
-
- // check for circular reference - still create the item but with no children
- if (visited.has(nodeKey)) {
- items[nodeId] = {
- index: nodeId,
- isFolder: false,
- children: [],
- data: {
- title: displayName,
- isRoot: isOriginalRoot,
- isNested: depth > 0
- }
- };
- return nodeId;
- }
- const newVisited = new Set([...visited, nodeKey]);
-
- const childIds: string[] = [];
- node.children.forEach((child) => {
- const childId = processNode(child, nodeId, depth + 1, newVisited);
- childIds.push(childId);
- });
-
- items[nodeId] = {
- index: nodeId,
- isFolder: childIds.length > 0,
- children: childIds,
- data: {
- title: displayName,
- isRoot: isOriginalRoot,
- isNested: depth > 0
- }
- };
-
- return nodeId;
- };
-
- const topLevelIds: string[] = [];
- invertedRoots.forEach((root) => {
- const rootId = processNode(root, undefined, 0, new Set());
- topLevelIds.push(rootId);
- });
-
- // Add hidden root container
- items.root = {
- index: "root",
- isFolder: true,
- children: topLevelIds,
- data: { title: "root", isRoot: false }
- };
-
- return { items, topLevelIds };
-};
-
const hasCircularReferences = (
node: TSecretReferenceTraceNode,
visitedPath: Set<string> = new Set()
@@ -291,38 +118,27 @@ const hasCircularReferences = (
return node.children.some((child) => hasCircularReferences(child, newVisitedPath));
};
-// Custom tree item renderer
-const renderItemTitle = ({
- item,
- isDependency
-}: {
- item: TreeItem<TreeNodeData>;
- isDependency?: boolean;
-}) => {
+const renderItemTitle = ({ item }: { item: TreeItem<TreeNodeData> }) => {
const { title, value, isRoot } = item.data;
return (
<span className="flex items-center gap-1">
<span className={isRoot ? "font-medium" : ""}>{title}</span>
- {!isDependency && (
- <Tooltip className="max-w-md break-words" content={value || "No value"}>
- <span className={`px-1 text-xs ${value ? "text-mineshaft-400" : "text-red-400"}`}>
- <FontAwesomeIcon icon={value ? faEye : faEyeSlash} size="sm" />
- </span>
- </Tooltip>
- )}
+ <Tooltip className="max-w-md break-words" content={value || "No value"}>
+ <span className={`px-1 text-xs ${value ? "text-mineshaft-400" : "text-red-400"}`}>
+ <FontAwesomeIcon icon={value ? faEye : faEyeSlash} size="sm" />
+ </span>
+ </Tooltip>
</span>
);
};
const SecretTree = ({
- isDependency,
items,
rootId,
treeId,
defaultExpandedIds = []
}: {
- isDependency?: boolean;
items: Record<TreeItemIndex, TreeItem<TreeNodeData>>;
rootId: string;
treeId: string;
@@ -349,13 +165,16 @@ const SecretTree = ({
canDragAndDrop={false}
canDropOnFolder={false}
canReorderItems={false}
- renderItemTitle={(props) => renderItemTitle({ ...props, isDependency })}
+ renderItemTitle={renderItemTitle}
>
<Tree treeId={treeId} rootItem={rootId} />
</UncontrolledTreeEnvironment>
);
};
+const NODE_TYPES = { secretNode: SecretNode };
+const EDGE_TYPES = { secretEdge: SecretReferenceEdge };
+
const SecretDependencyTree = ({ secretPath, environment, secretKey }: Props) => {
const { currentProject } = useProject();
const projectId = currentProject?.id || "";
@@ -372,10 +191,9 @@ const SecretDependencyTree = ({ secretPath, environment, secretKey }: Props) =>
const tree = data?.tree;
- const treeItems = useMemo(() => {
- if (!tree) return { items: {}, rootId: "", topLevelIds: [] };
- const { items, topLevelIds } = convertDependencyTreeToItems(tree, secretKey);
- return { items, rootId: "root", topLevelIds };
+ const flowData = useMemo(() => {
+ if (!tree || tree.children.length === 0) return null;
+ return convertDependencyTreeToFlow(tree, secretKey);
}, [tree, secretKey]);
useEffect(() => {
@@ -406,33 +224,43 @@ const SecretDependencyTree = ({ secretPath, environment, secretKey }: Props) =>
);
}
- const hasDependencies = tree && tree.children?.length > 0;
-
- if (!hasDependencies) {
+ if (!flowData || flowData.nodes.length === 0) {
return (
<div className="flex items-center justify-center py-4">
- <span className="text-mineshaft-400">No secrets reference this secret</span>
+ <span className="text-sm text-mineshaft-400">No secrets reference this secret</span>
</div>
);
}
return (
<div>
- <div className="secret-tree-container relative max-h-96 thin-scrollbar overflow-auto rounded-md border border-mineshaft-600 bg-bunker-700 p-3 text-sm text-mineshaft-200">
- {isError && (
- <div className="flex items-center justify-center py-4">
+ <div className="h-72 w-full rounded-md border border-mineshaft-600">
+ {isError ? (
+ <div className="flex h-full items-center justify-center">
<FontAwesomeIcon icon={faExclamationTriangle} className="mr-2 text-red-500" />
<p className="text-red-500">Error fetching secret dependency tree</p>
</div>
- )}
- {!isError && treeItems.rootId && (
- <SecretTree
- isDependency
- items={treeItems.items}
- rootId={treeItems.rootId}
- treeId="dependency-tree"
- defaultExpandedIds={treeItems.topLevelIds}
- />
+ ) : (
+ <ReactFlowProvider>
+ <ReactFlow
+ nodes={flowData.nodes}
+ edges={flowData.edges}
+ nodeTypes={NODE_TYPES}
+ edgeTypes={EDGE_TYPES}
+ colorMode="dark"
+ nodesDraggable={false}
+ edgesReconnectable={false}
+ nodesConnectable={false}
+ connectionLineType={ConnectionLineType.SmoothStep}
+ fitView
+ fitViewOptions={{ padding: 0.3 }}
+ minZoom={0.1}
+ proOptions={{ hideAttribution: true }}
+ >
+ <Background color="#5d5f64" bgColor="#111419" variant={BackgroundVariant.Dots} />
+ <Controls position="bottom-left" showInteractive={false} />
+ </ReactFlow>
+ </ReactFlowProvider>
)}
</div>
<div className="mt-2 text-xs text-mineshaft-400">
@@ -462,7 +290,6 @@ export const SecretReferenceTree = ({ secretPath, environment, secretKey }: Prop
if (!tree) return { items: {}, rootId: "", expandId: "" };
const items = convertToTreeItems(tree, secretKey);
const actualRootId = createNodeId(tree);
- // Return "root" as rootId since that's the container, and actualRootId for expanding
return { items, rootId: "root", expandId: actualRootId };
}, [tree, secretKey]);
diff --git a/frontend/src/components/secrets/SecretReferenceDetails/edges/SecretReferenceEdge.tsx b/frontend/src/components/secrets/SecretReferenceDetails/edges/SecretReferenceEdge.tsx
new file mode 100644
index 0000000000..f6f44e1117
--- /dev/null
+++ b/frontend/src/components/secrets/SecretReferenceDetails/edges/SecretReferenceEdge.tsx
@@ -0,0 +1,35 @@
+import { BaseEdge, BaseEdgeProps, EdgeProps, getSmoothStepPath } from "@xyflow/react";
+
+export const SecretReferenceEdge = ({
+ id,
+ sourceX,
+ sourceY,
+ targetX,
+ targetY,
+ markerStart,
+ markerEnd,
+ data
+}: Omit<BaseEdgeProps, "path"> & EdgeProps) => {
+ const [edgePath] = getSmoothStepPath({
+ sourceX,
+ sourceY,
+ targetX,
+ targetY
+ });
+
+ const isCircular = data?.isCircular as boolean | undefined;
+
+ return (
+ <BaseEdge
+ id={id}
+ markerStart={markerStart}
+ markerEnd={markerEnd}
+ style={{
+ strokeDasharray: "5",
+ strokeWidth: 1,
+ stroke: isCircular ? "#ef4444" : "#707174"
+ }}
+ path={edgePath}
+ />
+ );
+};
diff --git a/frontend/src/components/secrets/SecretReferenceDetails/nodes/SecretNode.tsx b/frontend/src/components/secrets/SecretReferenceDetails/nodes/SecretNode.tsx
new file mode 100644
index 0000000000..7eda5d2627
--- /dev/null
+++ b/frontend/src/components/secrets/SecretReferenceDetails/nodes/SecretNode.tsx
@@ -0,0 +1,117 @@
+/* eslint-disable no-nested-ternary */
+import { useCallback, useEffect, useRef, useState } from "react";
+import { faKey, faQuestionCircle } from "@fortawesome/free-solid-svg-icons";
+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+import { Handle, NodeProps, Position } from "@xyflow/react";
+import { FolderIcon, LayersIcon } from "lucide-react";
+import { twMerge } from "tailwind-merge";
+
+import { Tooltip } from "@app/components/v2";
+import { Badge } from "@app/components/v3";
+
+type SecretNodeData = {
+ secretKey: string;
+ environment: string;
+ secretPath: string;
+ isRoot: boolean;
+ isCircular: boolean;
+};
+
+export const SecretNode = ({ data }: NodeProps & { data: SecretNodeData }) => {
+ const { secretKey, environment, secretPath, isRoot, isCircular } = data;
+
+ const capitalizedEnv = environment.charAt(0).toUpperCase() + environment.slice(1);
+
+ const pathTextRef = useRef<HTMLSpanElement>(null);
+ const iconBadgeRef = useRef<HTMLSpanElement>(null);
+ const [isPathTruncated, setIsPathTruncated] = useState(false);
+
+ useEffect(() => {
+ const el = iconBadgeRef.current;
+ if (el) {
+ el.style.width = `${el.offsetHeight}px`;
+ }
+ });
+
+ const checkTruncation = useCallback(() => {
+ const el = pathTextRef.current;
+ if (el) {
+ setIsPathTruncated(el.scrollWidth > el.clientWidth);
+ }
+ }, []);
+
+ const pathBadge = (
+ <Badge variant="neutral" isTruncatable onMouseEnter={checkTruncation}>
+ <FolderIcon />
+ <span ref={pathTextRef}>{secretPath}</span>
+ </Badge>
+ );
+
+ return (
+ <>
+ <Handle
+ type="target"
+ className="pointer-events-none cursor-pointer! opacity-0"
+ position={Position.Top}
+ />
+ <Tooltip
+ className="text-xs"
+ content={isRoot ? "This is the secret whose dependencies are being viewed" : undefined}
+ isDisabled={!isRoot}
+ >
+ <div className="relative">
+ {isCircular && (
+ <Tooltip content="This secret contains circular references. Circular references are not expanded and will lead to errors when you attempt to use them.">
+ <Badge variant="danger" className="absolute -top-6 right-0">
+ Circular
+ <FontAwesomeIcon className="size-2" icon={faQuestionCircle} />
+ </Badge>
+ </Tooltip>
+ )}
+ <div
+ className={twMerge(
+ "flex h-full w-full items-stretch gap-2.5 rounded-md border border-mineshaft bg-mineshaft-800 p-2 font-inter shadow-lg",
+ isCircular && "border-red/40",
+ isRoot && "border-project/40"
+ )}
+ >
+ <Badge
+ variant={isCircular ? "danger" : isRoot ? "project" : "neutral"}
+ className="!aspect-square h-auto !w-auto !min-w-0 shrink-0 self-stretch"
+ >
+ <FontAwesomeIcon icon={faKey} />
+ </Badge>
+ <div className="flex min-w-0 flex-col">
+ <span
+ className={twMerge(
+ "truncate text-xs text-mineshaft-100",
+ isRoot && "font-semibold"
+ )}
+ >
+ {secretKey}
+ </span>
+ <div className="mt-0.5 flex items-center gap-1.5">
+ <Badge variant="neutral">
+ <LayersIcon className="size-3" />
+ {capitalizedEnv}
+ </Badge>
+ {isPathTruncated ? (
+ <Tooltip className="max-w-xs text-xs break-all" content={secretPath}>
+ {pathBadge}
+ </Tooltip>
+ ) : (
+ pathBadge
+ )}
+ </div>
+ </div>
+ </div>
+ </div>
+ </Tooltip>
+ <Handle
+ type="source"
+ className="pointer-events-none cursor-pointer! opacity-0"
+ position={Position.Bottom}
+ />
+ </>
+ );
+};
diff --git a/frontend/src/components/secrets/SecretReferenceDetails/utils/convertToFlowElements.ts b/frontend/src/components/secrets/SecretReferenceDetails/utils/convertToFlowElements.ts
new file mode 100644
index 0000000000..521b61fce9
--- /dev/null
+++ b/frontend/src/components/secrets/SecretReferenceDetails/utils/convertToFlowElements.ts
@@ -0,0 +1,160 @@
+import { Edge, MarkerType, Node } from "@xyflow/react";
+
+import { TSecretDependencyTreeNode } from "@app/hooks/api/secrets/types";
+
+import { positionElements } from "./positionElements";
+
+const NODE_WIDTH = 200;
+const NODE_HEIGHT = 58;
+
+type SecretNodeData = {
+ secretKey: string;
+ environment: string;
+ secretPath: string;
+ isRoot: boolean;
+ isCircular: boolean;
+};
+
+const makeNodeKey = (env: string, path: string, key: string) => `${env}:${path}:${key}`;
+
+// Invert dependency tree so leaf nodes become roots
+const invertDependencyTree = (tree: TSecretDependencyTreeNode): TSecretDependencyTreeNode[] => {
+ const paths: TSecretDependencyTreeNode[][] = [];
+
+ const collectPaths = (
+ node: TSecretDependencyTreeNode,
+ currentPath: TSecretDependencyTreeNode[],
+ visited: Set<string>
+ ) => {
+ const nodeKey = makeNodeKey(node.environment, node.secretPath, node.key);
+
+ if (visited.has(nodeKey)) {
+ if (currentPath.length > 0) {
+ paths.push([...currentPath, node]);
+ }
+ return;
+ }
+
+ const newPath = [...currentPath, node];
+ const newVisited = new Set([...visited, nodeKey]);
+
+ if (node.children.length === 0) {
+ paths.push(newPath);
+ } else {
+ node.children.forEach((child) => collectPaths(child, newPath, newVisited));
+ }
+ };
+
+ collectPaths(tree, [], new Set());
+
+ if (paths.length === 0) return [];
+
+ const invertedRoots: Map<string, TSecretDependencyTreeNode> = new Map();
+
+ paths.forEach((path) => {
+ const reversed = [...path].reverse();
+ let currentNode: TSecretDependencyTreeNode | null = null;
+
+ reversed.forEach((node, idx) => {
+ const nodeKey = makeNodeKey(node.environment, node.secretPath, node.key);
+
+ if (idx === 0) {
+ if (invertedRoots.has(nodeKey)) {
+ currentNode = invertedRoots.get(nodeKey)!;
+ } else {
+ currentNode = {
+ key: node.key,
+ environment: node.environment,
+ secretPath: node.secretPath,
+ children: []
+ };
+ invertedRoots.set(nodeKey, currentNode);
+ }
+ } else if (currentNode) {
+ const existingChild = currentNode.children.find(
+ (c) =>
+ c.key === node.key &&
+ c.environment === node.environment &&
+ c.secretPath === node.secretPath
+ );
+
+ if (existingChild) {
+ currentNode = existingChild;
+ } else {
+ const newNode: TSecretDependencyTreeNode = {
+ key: node.key,
+ environment: node.environment,
+ secretPath: node.secretPath,
+ children: []
+ };
+ currentNode.children.push(newNode);
+ currentNode = newNode;
+ }
+ }
+ });
+ });
+
+ return Array.from(invertedRoots.values());
+};
+
+// Walk the dependency tree (incoming references) and produce React Flow elements
+export const convertDependencyTreeToFlow = (
+ tree: TSecretDependencyTreeNode,
+ rootSecretKey: string
+) => {
+ const invertedRoots = invertDependencyTree(tree);
+
+ if (invertedRoots.length === 0) {
+ return { nodes: [], edges: [] };
+ }
+
+ const nodes: Node<SecretNodeData>[] = [];
+ const edges: Edge[] = [];
+
+ const walk = (
+ node: TSecretDependencyTreeNode,
+ parentId: string | undefined,
+ depth: number,
+ visited: Set<string>
+ ) => {
+ const nodeKey = makeNodeKey(node.environment, node.secretPath, node.key);
+ const isCircular = visited.has(nodeKey);
+ const nodeId = parentId ? `${parentId}>${nodeKey}` : nodeKey;
+ const isOriginalRoot = node.key === rootSecretKey && depth > 0;
+
+ nodes.push({
+ id: nodeId,
+ type: "secretNode",
+ position: { x: 0, y: 0 },
+ width: NODE_WIDTH,
+ height: NODE_HEIGHT,
+ data: {
+ secretKey: node.key,
+ environment: node.environment,
+ secretPath: node.secretPath,
+ isRoot: isOriginalRoot,
+ isCircular
+ }
+ });
+
+ if (parentId) {
+ edges.push({
+ id: `e-${parentId}-${nodeId}`,
+ source: parentId,
+ target: nodeId,
+ type: "secretEdge",
+ markerEnd: { type: MarkerType.Arrow, color: isCircular ? "#ef4444" : "#707174" },
+ data: { isCircular }
+ });
+ }
+
+ if (!isCircular) {
+ const newVisited = new Set([...visited, nodeKey]);
+ node.children.forEach((child) => walk(child, nodeId, depth + 1, newVisited));
+ }
+ };
+
+ invertedRoots.forEach((root) => walk(root, undefined, 0, new Set()));
+
+ return positionElements(nodes, edges);
+};
diff --git a/frontend/src/components/secrets/SecretReferenceDetails/utils/positionElements.ts b/frontend/src/components/secrets/SecretReferenceDetails/utils/positionElements.ts
new file mode 100644
index 0000000000..4547ff9ca1
--- /dev/null
+++ b/frontend/src/components/secrets/SecretReferenceDetails/utils/positionElements.ts
@@ -0,0 +1,40 @@
+import Dagre from "@dagrejs/dagre";
+import { Edge, Node } from "@xyflow/react";
+
+export const positionElements = (nodes: Node[], edges: Edge[]) => {
+ const dagre = new Dagre.graphlib.Graph({ directed: true })
+ .setDefaultEdgeLabel(() => ({}))
+ .setGraph({
+ rankdir: "TB",
+ nodesep: 50,
+ ranksep: 70
+ });
+
+ nodes.forEach((node) => {
+ dagre.setNode(node.id, {
+ width: node.width || 150,
+ height: node.height || 40
+ });
+ });
+
+ edges.forEach((edge) => dagre.setEdge(edge.source, edge.target));
+
+ Dagre.layout(dagre, {});
+
+ const positionedNodes = nodes.map((node) => {
+ const { x, y } = dagre.node(node.id);
+
+ return {
+ ...node,
+ position: {
+ x: x - (node.width ? node.width / 2 : 0),
+ y: y - (node.height ? node.height / 2 : 0)
+ }
+ };
+ });
+
+ return {
+ nodes: positionedNodes,
+ edges
+ };
+};
diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/SecretOverviewTableRow/SecretEditRow.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/SecretOverviewTableRow/SecretEditRow.tsx
index 48d2eacd22..682f4f8da8 100644
--- a/frontend/src/pages/secret-manager/OverviewPage/components/SecretOverviewTableRow/SecretEditRow.tsx
+++ b/frontend/src/pages/secret-manager/OverviewPage/components/SecretOverviewTableRow/SecretEditRow.tsx
@@ -397,6 +397,7 @@ export const SecretEditRow = ({
</div>
</ModalTrigger>
<ModalContent
+ className="max-w-3xl"
title="Secret Reference Details"
subTitle="Visual breakdown of secrets referenced by this secret."
onOpenAutoFocus={(e) => e.preventDefault()} // prevents secret input from displaying value on open
diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretEditTableRow.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretEditTableRow.tsx
index 1f0373493e..98a53bb431 100644
--- a/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretEditTableRow.tsx
+++ b/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretEditTableRow.tsx
@@ -1035,6 +1035,7 @@ export const SecretEditTableRow = ({
</UnstableDropdownMenu>
<Modal isOpen={isSecretReferenceOpen} onOpenChange={setIsSecretReferenceOpen}>
<ModalContent
+ className="max-w-3xl"
title="Secret Reference Details"
subTitle="Visual breakdown of secrets referenced by this secret."
onOpenAutoFocus={(e) => e.preventDefault()}
diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/SecretListView/SecretDetailSidebar.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/SecretListView/SecretDetailSidebar.tsx
index 5a4b68e56b..3492797c6e 100644
--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/SecretListView/SecretDetailSidebar.tsx
+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/SecretListView/SecretDetailSidebar.tsx
@@ -361,6 +361,7 @@ export const SecretDetailSidebar = ({
}
>
<ModalContent
+ className="max-w-3xl"
title="Secret Reference Details"
subTitle="Visual breakdown of secrets referenced by this secret."
onOpenAutoFocus={(e) => e.preventDefault()}