Skip to content

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

refactor(secret-sync): unify secret path input with remote folder browsing

Igor Correaa9c2fdccd5c0
diff --git a/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/ExternalInfisicalSyncFields.tsx b/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/ExternalInfisicalSyncFields.tsx
index 6c97ac3297..a574580477 100644
--- a/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/ExternalInfisicalSyncFields.tsx
+++ b/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/ExternalInfisicalSyncFields.tsx
@@ -3,7 +3,8 @@ import { Controller, useFormContext, useWatch } from "react-hook-form";
import { SingleValue } from "react-select";
import { SecretSyncConnectionField } from "@app/components/secret-syncs/forms/SecretSyncConnectionField";
-import { FilterableSelect, FormControl, Input } from "@app/components/v2";
+import { FilterableSelect, FormControl } from "@app/components/v2";
+import { SecretPathInput } from "@app/components/v2/SecretPathInput";
import {
TRemoteInfisicalEnvironmentFolderTree,
TRemoteInfisicalProject,
@@ -22,42 +23,44 @@ export const ExternalInfisicalSyncFields = () => {
const connectionId = useWatch({ name: "connection.id", control });
const projectId = useWatch({ name: "destinationConfig.projectId", control });
const environmentSlug = useWatch({ name: "destinationConfig.environment", control });
+ const currentSecretPath = useWatch({ name: "destinationConfig.secretPath", control });
const { data: projects = [], isPending: isProjectsLoading } =
useExternalInfisicalConnectionListProjects(connectionId, {
enabled: Boolean(connectionId)
});
- const {
- data: folderTree = {},
- isPending: isFolderTreeLoading,
- isError: isFolderTreeError
- } = useExternalInfisicalConnectionGetEnvironmentFolderTree(connectionId, projectId, {
- enabled: Boolean(connectionId) && Boolean(projectId)
- });
+ const { data: folderTree = {} } = useExternalInfisicalConnectionGetEnvironmentFolderTree(
+ connectionId,
+ projectId,
+ { enabled: Boolean(connectionId) && Boolean(projectId) }
+ );
const environments = useMemo(() => {
return projects.find((p) => p.id === projectId)?.environments ?? [];
}, [projects, projectId]);
- const folderOptions = useMemo(() => {
- const root = { path: "/", name: "Root" };
- if (!environmentSlug) return [root];
+ const childFolderNamesAtPath = useMemo(() => {
+ if (!environmentSlug) return [];
const tree = folderTree as TRemoteInfisicalEnvironmentFolderTree;
- // Remote API may key by env slug or by env id; support both
const envData =
tree[environmentSlug] ?? Object.values(tree).find((env) => env.slug === environmentSlug);
- const folders = (envData?.folders ?? []).filter((f) => f.path !== "/");
- return [root, ...folders];
- }, [folderTree, environmentSlug]);
+ const allFolders = envData?.folders ?? [];
+
+ const browsedPath =
+ currentSecretPath && !currentSecretPath.endsWith("/")
+ ? `${currentSecretPath}/`
+ : (currentSecretPath ?? "/");
- // When folder tree fails or returns empty, allow manual path entry, since the target env might not have the API
- // modified to allow MI access to folder tree yet
- const showManualPathInput =
- Boolean(connectionId && projectId && environmentSlug) &&
- !isFolderTreeLoading &&
- (isFolderTreeError || folderOptions.length <= 1);
+ return allFolders
+ .filter((f) => {
+ if (!f.path.startsWith(browsedPath)) return false;
+ const remainder = f.path.slice(browsedPath.length);
+ return remainder.length > 0 && !remainder.includes("/");
+ })
+ .map((f) => f.name);
+ }, [folderTree, environmentSlug, currentSecretPath]);
return (
<>
@@ -133,25 +136,13 @@ export const ExternalInfisicalSyncFields = () => {
isError={Boolean(error?.message)}
label="Secret path"
tooltipText="The folder path on the remote Infisical instance to sync secrets to"
- helperText={showManualPathInput ? "Enter the path (e.g. / or /my-folder)" : undefined}
>
- {showManualPathInput ? (
- <Input value={value} onChange={(e) => onChange(e.target.value)} placeholder="/" />
- ) : (
- <FilterableSelect
- isLoading={isFolderTreeLoading && Boolean(projectId)}
- isDisabled={!connectionId || !projectId || !environmentSlug}
- value={folderOptions.find((f) => f.path === value) ?? folderOptions[0]}
- onChange={(option) => {
- const v = option as SingleValue<{ path: string; name: string }>;
- onChange(v?.path ?? "/");
- }}
- options={folderOptions}
- placeholder="Select a path..."
- getOptionLabel={(option) => option.path}
- getOptionValue={(option) => option.path}
- />
- )}
+ <SecretPathInput
+ isDisabled={!connectionId || !projectId || !environmentSlug}
+ value={value}
+ onChange={onChange}
+ folderNames={childFolderNamesAtPath}
+ />
</FormControl>
)}
/>
diff --git a/frontend/src/components/v2/SecretPathInput/SecretPathInput.tsx b/frontend/src/components/v2/SecretPathInput/SecretPathInput.tsx
index b9c9fbe65b..dca7b29cab 100644
--- a/frontend/src/components/v2/SecretPathInput/SecretPathInput.tsx
+++ b/frontend/src/components/v2/SecretPathInput/SecretPathInput.tsx
@@ -19,6 +19,7 @@ type Props = Omit<InputHTMLAttributes<HTMLInputElement>, "size" | "onChange"> &
environment?: string;
containerClassName?: string;
onChange?: (arg: string) => void;
+ folderNames?: string[];
};
export const SecretPathInput = ({
@@ -26,6 +27,7 @@ export const SecretPathInput = ({
onChange,
environment,
value: propValue,
+ folderNames: folderNamesProp,
...props
}: Props) => {
const [inputValue, setInputValue] = useState(propValue ?? "");
@@ -58,15 +60,16 @@ export const SecretPathInput = ({
}, [debouncedInputValue]);
useEffect(() => {
+ const activeFolders = folderNamesProp ?? folders;
const searchFragment = debouncedInputValue.split("/").pop() || "";
- const filteredSuggestions = folders
+ const filteredSuggestions = activeFolders
.filter((suggestionEntry) =>
suggestionEntry.toUpperCase().startsWith(searchFragment.toUpperCase())
)
.sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()));
setSuggestions(filteredSuggestions);
- }, [debouncedInputValue, folders]);
+ }, [debouncedInputValue, folders, folderNamesProp]);
const handleSuggestionSelect = (selectedIndex: number) => {
if (!suggestions[selectedIndex]) {
@@ -76,7 +79,7 @@ export const SecretPathInput = ({
const validPaths = inputValue.split("/");
validPaths.pop();
- const newValue = `${validPaths.join("/")}/${suggestions[selectedIndex]}`;
+ const newValue = `${validPaths.join("/")}/${suggestions[selectedIndex]}/`;
onChange?.(newValue);
setInputValue(newValue);
setSecretPath(newValue);
diff --git a/frontend/src/hooks/api/appConnections/external-infisical/types.ts b/frontend/src/hooks/api/appConnections/external-infisical/types.ts
index bbef7e60d0..20aa9d70b9 100644
--- a/frontend/src/hooks/api/appConnections/external-infisical/types.ts
+++ b/frontend/src/hooks/api/appConnections/external-infisical/types.ts
@@ -2,7 +2,6 @@ export type TRemoteInfisicalProject = {
id: string;
name: string;
slug: string;
- type: string;
environments: Array<{ id: string; name: string; slug: string }>;
};