Skip to content

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

adjustment: used enum for reference type

Sheen Capadngan918734b26bd2
diff --git a/frontend/src/components/v2/InfisicalSecretInput/InfisicalSecretInput.tsx b/frontend/src/components/v2/InfisicalSecretInput/InfisicalSecretInput.tsx
index 5987e9278b..09f42ff7dc 100644
--- a/frontend/src/components/v2/InfisicalSecretInput/InfisicalSecretInput.tsx
+++ b/frontend/src/components/v2/InfisicalSecretInput/InfisicalSecretInput.tsx
@@ -8,7 +8,7 @@ import {
} from "@app/helpers/secret-reference";
import { useToggle } from "@app/hooks";
-import SecretReferenceSelect from "./SecretReferenceSelect";
+import SecretReferenceSelect, { ReferenceType } from "./SecretReferenceSelect";
const replaceContentWithDot = (str: string) => {
let finalStr = "";
@@ -194,7 +194,7 @@ export const InfisicalSecretInput = forwardRef<HTMLTextAreaElement, Props>(
slug
}: {
name: string;
- type: "folder" | "secret" | "environment";
+ type: ReferenceType;
slug?: string;
}) => {
setShowReferencePopup(false);
@@ -218,22 +218,22 @@ export const InfisicalSecretInput = forwardRef<HTMLTextAreaElement, Props>(
];
let oldReferenceStr = oldReference.slice(2, -1);
- let currentPath = type === "environment" ? slug! : name;
+ let currentPath = type === ReferenceType.ENVIRONMENT ? slug! : name;
currentPath = currentPath.replace(/\./g, "\\.");
let replaceReference = "";
let offset = 3;
switch (type) {
- case "folder":
+ case ReferenceType.FOLDER:
replaceReference = `${oldReferenceStr}${currentPath}.`;
offset -= 1;
break;
- case "secret": {
+ case ReferenceType.SECRET: {
if (oldReferenceStr.indexOf(".") === -1) oldReferenceStr = "";
replaceReference = `${oldReferenceStr}${currentPath}`;
break;
}
- case "environment":
+ case ReferenceType.ENVIRONMENT:
replaceReference = `${currentPath}.`;
offset -= 1;
break;
@@ -244,10 +244,10 @@ export const InfisicalSecretInput = forwardRef<HTMLTextAreaElement, Props>(
setValue(newValue);
// TODO: there should be a better way to do
onChange?.({ target: { value: newValue } } as any);
- setShowReferencePopup(type !== "secret");
+ setShowReferencePopup(type !== ReferenceType.SECRET);
const timeout = setTimeout(() => {
setIsSecretFocused.on();
- if (type !== "secret") setReferenceKey(replaceReference);
+ if (type !== ReferenceType.SECRET) setReferenceKey(replaceReference);
const caretPos = start.length + replaceReference.length + offset;
setCaretPos(caretPos);
clearTimeout(timeout);
diff --git a/frontend/src/components/v2/InfisicalSecretInput/SecretReferenceSelect.tsx b/frontend/src/components/v2/InfisicalSecretInput/SecretReferenceSelect.tsx
index 454e3600c7..6d2157af3d 100644
--- a/frontend/src/components/v2/InfisicalSecretInput/SecretReferenceSelect.tsx
+++ b/frontend/src/components/v2/InfisicalSecretInput/SecretReferenceSelect.tsx
@@ -16,7 +16,11 @@ import { useGetUserWsKey } from "@app/hooks/api";
import { useGetFoldersByEnv } from "@app/hooks/api/secretFolders/queries";
import { useGetProjectSecrets } from "@app/hooks/api/secrets/queries";
-type ReferenceType = "environment" | "folder" | "secret";
+export enum ReferenceType {
+ ENVIRONMENT = "environment",
+ FOLDER = "folder",
+ SECRET = "secret"
+}
type Props = {
open: boolean;
@@ -30,7 +34,7 @@ type Props = {
type ReferenceItem = {
name: string;
- type: "folder" | "secret";
+ type: ReferenceType.FOLDER | ReferenceType.SECRET;
slug?: string;
};
@@ -95,12 +99,12 @@ export default function SecretReferenceSelect({
if (isNested) {
folders?.forEach((folder) => {
- currentListReference.unshift({ name: folder, type: "folder" });
+ currentListReference.unshift({ name: folder, type: ReferenceType.FOLDER });
});
}
secrets?.forEach((secret) => {
- currentListReference.unshift({ name: secret.key, type: "secret" });
+ currentListReference.unshift({ name: secret.key, type: ReferenceType.SECRET });
});
setListReference(currentListReference);
@@ -179,7 +183,7 @@ export default function SecretReferenceSelect({
<SelectPrimitive.Item
className="flex items-center justify-between border-b border-mineshaft-600 px-2 text-left last:border-b-0"
key={`secret-reference-env-${i + 1}`}
- value={JSON.stringify({ ...env, type: "environment" })}
+ value={JSON.stringify({ ...env, type: ReferenceType.ENVIRONMENT })}
asChild
>
<SelectPrimitive.ItemText asChild>