Skip to content

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

feat(ui): suggest app connection names from provider and auth method (#8723)

Andrew Huanga9d81dfa8934
diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GenericAppConnectionFields.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GenericAppConnectionFields.tsx
index 4745a1b427..90a64ca54f 100644
--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GenericAppConnectionFields.tsx
+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GenericAppConnectionFields.tsx
@@ -1,4 +1,5 @@
-import { useFormContext } from "react-hook-form";
+import { useFormContext, useWatch } from "react-hook-form";
+import slugify from "@sindresorhus/slugify";
import { z } from "zod";
import {
@@ -9,6 +10,9 @@ import {
Input,
TextArea
} from "@app/components/v3";
+import { APP_CONNECTION_MAP } from "@app/helpers/appConnections";
+import { TAppConnection } from "@app/hooks/api/appConnections";
+import { AppConnection } from "@app/hooks/api/appConnections/enums";
import { slugSchema } from "@app/lib/schemas";
export const rotationSchema = z.object({
@@ -37,11 +41,33 @@ export const genericAppConnectionFieldsSchema = z.object({
rotation: rotationSchema.optional()
});
+const getSuggestedConnectionName = (app?: AppConnection, method?: TAppConnection["method"]) => {
+ if (!app || !method || !APP_CONNECTION_MAP[app]) return "";
+
+ const providerSlug = slugify(APP_CONNECTION_MAP[app].name, {
+ lowercase: true,
+ decamelize: false
+ });
+ const providerWords = providerSlug.split("-");
+ const methodWords = slugify(method, { lowercase: true }).split("-");
+ while (methodWords.length > 1 && providerWords.includes(methodWords[0])) methodWords.shift();
+
+ return [providerSlug, ...methodWords].join("-").slice(0, 64).replace(/-+$/, "");
+};
+
export const GenericAppConnectionsFields = () => {
const {
register,
+ control,
formState: { errors }
- } = useFormContext<{ name: string; description?: string | null }>();
+ } = useFormContext<{
+ name: string;
+ description?: string | null;
+ app?: AppConnection;
+ method?: TAppConnection["method"];
+ }>();
+ const [app, method] = useWatch({ control, name: ["app", "method"] });
+ const suggestedName = getSuggestedConnectionName(app, method);
return (
<>
@@ -51,6 +77,7 @@ export const GenericAppConnectionsFields = () => {
id="app-connection-name"
autoFocus
placeholder="my-app-connection"
+ suggestedValue={suggestedName}
isError={Boolean(errors.name?.message)}
{...register("name")}
autoComplete="off"