Skip to content

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

feat(ui): suggest honey token names from type and environment (#8727)

Andrew Huange1f4117f7418
diff --git a/frontend/src/components/honey-tokens/forms/HoneyTokenDetailsFields.tsx b/frontend/src/components/honey-tokens/forms/HoneyTokenDetailsFields.tsx
index d2fcdedca3..1d3489bc01 100644
--- a/frontend/src/components/honey-tokens/forms/HoneyTokenDetailsFields.tsx
+++ b/frontend/src/components/honey-tokens/forms/HoneyTokenDetailsFields.tsx
@@ -1,11 +1,28 @@
-import { Controller, useFormContext } from "react-hook-form";
+import { Controller, useFormContext, useWatch } from "react-hook-form";
+import slugify from "@sindresorhus/slugify";
import { Field, FieldContent, FieldError, FieldLabel, Input, TextArea } from "@app/components/v3";
+import { HONEY_TOKEN_MAP } from "@app/helpers/honeyTokens";
import { THoneyTokenForm } from "./schemas";
-export const HoneyTokenDetailsFields = () => {
+type Props = {
+ isUpdate: boolean;
+};
+
+export const HoneyTokenDetailsFields = ({ isUpdate }: Props) => {
const { control } = useFormContext<THoneyTokenForm>();
+ const [type, environment] = useWatch({ control, name: ["type", "environment"] });
+
+ const suggestedName =
+ isUpdate || !environment?.slug
+ ? ""
+ : slugify(`${HONEY_TOKEN_MAP[type].name} honey token ${environment.slug}`, {
+ lowercase: true,
+ decamelize: false
+ })
+ .slice(0, 64)
+ .replace(/-+$/, "");
return (
<div className="flex flex-col gap-4">
@@ -18,6 +35,7 @@ export const HoneyTokenDetailsFields = () => {
autoFocus
value={value}
onChange={onChange}
+ suggestedValue={suggestedName}
placeholder="aws-canary-prod-key"
isError={Boolean(error)}
autoComplete="off"
diff --git a/frontend/src/components/honey-tokens/forms/HoneyTokenForm.tsx b/frontend/src/components/honey-tokens/forms/HoneyTokenForm.tsx
index d57defda3f..628e83e0ef 100644
--- a/frontend/src/components/honey-tokens/forms/HoneyTokenForm.tsx
+++ b/frontend/src/components/honey-tokens/forms/HoneyTokenForm.tsx
@@ -263,7 +263,7 @@ export const HoneyTokenForm = ({
<HoneyTokenConfigurationFields environments={environments} />
)}
{currentStep.key === "mapping" && <HoneyTokenMappingFields />}
- {currentStep.key === "details" && <HoneyTokenDetailsFields />}
+ {currentStep.key === "details" && <HoneyTokenDetailsFields isUpdate={isUpdate} />}
</>
);