Skip to content

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

fix: requested changes

Daniel Hougaard3a8219db0386
diff --git a/frontend/src/views/SecretMainPage/components/CreateSecretForm/CreateSecretForm.tsx b/frontend/src/views/SecretMainPage/components/CreateSecretForm/CreateSecretForm.tsx
index 17c99ac8ca..1d2d1ead15 100644
--- a/frontend/src/views/SecretMainPage/components/CreateSecretForm/CreateSecretForm.tsx
+++ b/frontend/src/views/SecretMainPage/components/CreateSecretForm/CreateSecretForm.tsx
@@ -1,4 +1,4 @@
-import { ClipboardEvent } from "react";
+import { ClipboardEvent, useRef } from "react";
import { Controller, useForm } from "react-hook-form";
import { faTriangleExclamation } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
@@ -60,7 +60,7 @@ export const CreateSecretForm = ({
canReadTags ? workspaceId : ""
);
- const secretValue = watch("value");
+ const secretKeyInputRef = useRef<HTMLInputElement>(null);
const secretKey = watch("key");
const slugSchema = z.string().trim().toLowerCase().min(1);
@@ -116,13 +116,15 @@ export const CreateSecretForm = ({
const pastedContent = e.clipboardData.getData("text");
const { key, value } = getKeyValue(pastedContent, delimitters);
- if (!secretKey) {
+ const isWholeKeyHighlighted =
+ secretKeyInputRef.current &&
+ secretKeyInputRef.current.selectionStart === 0 &&
+ secretKeyInputRef.current.selectionEnd === secretKeyInputRef.current.value.length;
+
+ if (!secretKey || isWholeKeyHighlighted) {
setValue("key", key);
- }
- if (!secretValue) {
setValue("value", value);
}
-
if (!secretKey) {
e.preventDefault();
}
@@ -138,6 +140,7 @@ export const CreateSecretForm = ({
>
<Input
{...register("key")}
+ ref={secretKeyInputRef}
placeholder="Type your secret name"
onPaste={handlePaste}
autoCapitalization={autoCapitalize}
diff --git a/frontend/src/views/SecretOverviewPage/components/CreateSecretForm/CreateSecretForm.tsx b/frontend/src/views/SecretOverviewPage/components/CreateSecretForm/CreateSecretForm.tsx
index ce44c9881d..48a8bc9f6d 100644
--- a/frontend/src/views/SecretOverviewPage/components/CreateSecretForm/CreateSecretForm.tsx
+++ b/frontend/src/views/SecretOverviewPage/components/CreateSecretForm/CreateSecretForm.tsx
@@ -1,4 +1,4 @@
-import { ClipboardEvent } from "react";
+import { ClipboardEvent, useRef } from "react";
import { Controller, useForm } from "react-hook-form";
import { subject } from "@casl/ability";
import { faTriangleExclamation } from "@fortawesome/free-solid-svg-icons";
@@ -62,7 +62,7 @@ export const CreateSecretForm = ({ secretPath = "/", onClose }: Props) => {
canReadTags ? workspaceId : ""
);
- const secretValue = watch("value");
+ const secretKeyInputRef = useRef<HTMLInputElement>(null);
const secretKey = watch("key");
const handleFormSubmit = async ({ key, value, environments: selectedEnv, tags }: TFormSchema) => {
@@ -160,13 +160,15 @@ export const CreateSecretForm = ({ secretPath = "/", onClose }: Props) => {
const pastedContent = e.clipboardData.getData("text");
const { key, value } = getKeyValue(pastedContent, delimitters);
- if (!secretKey) {
+ const isWholeKeyHighlighted =
+ secretKeyInputRef.current &&
+ secretKeyInputRef.current.selectionStart === 0 &&
+ secretKeyInputRef.current.selectionEnd === secretKeyInputRef.current.value.length;
+
+ if (!secretKey || isWholeKeyHighlighted) {
setValue("key", key);
- }
- if (!secretValue) {
setValue("value", value);
}
-
if (!secretKey) {
e.preventDefault();
}
@@ -201,6 +203,7 @@ export const CreateSecretForm = ({ secretPath = "/", onClose }: Props) => {
>
<Input
{...register("key")}
+ ref={secretKeyInputRef}
placeholder="Type your secret name"
onPaste={handlePaste}
autoCapitalization={currentWorkspace?.autoCapitalization}