diff --git a/frontend/src/components/v2/InfisicalSecretInput/InfisicalSecretInput.tsx b/frontend/src/components/v2/InfisicalSecretInput/InfisicalSecretInput.tsx index b6888ba8c7..c95d9ad239 100644 --- a/frontend/src/components/v2/InfisicalSecretInput/InfisicalSecretInput.tsx +++ b/frontend/src/components/v2/InfisicalSecretInput/InfisicalSecretInput.tsx @@ -1,5 +1,5 @@ import { TextareaHTMLAttributes, useEffect, useRef, useState } from "react"; -import { faFolder, faKey } from "@fortawesome/free-solid-svg-icons"; +import { faFolder, faFolderOpen, faKey } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import * as Popover from "@radix-ui/react-popover"; import { twMerge } from "tailwind-merge"; @@ -109,6 +109,11 @@ export const InfisicalSecretInput = ({ const currentListReference: ReferenceItem[] = []; const isNested = currentReference?.includes("."); + if (!currentReference) { + setListReference(currentListReference); + return; + } + if (!environment) { currentWorkspace?.environments.forEach((env) => { currentListReference.unshift({ @@ -116,18 +121,11 @@ export const InfisicalSecretInput = ({ type: ReferenceType.ENVIRONMENT }); }); - } - - if (!environment || !currentReference) { - setListReference(currentListReference); - return; - } - - if (isNested) { + } else if (isNested) { folders?.forEach((folder) => { currentListReference.unshift({ name: folder, type: ReferenceType.FOLDER }); }); - } else { + } else if (environment) { currentWorkspace?.environments.forEach((env) => { currentListReference.unshift({ name: env.slug, @@ -182,8 +180,9 @@ export const InfisicalSecretInput = ({ } }; - const handleSuggestionSelect = () => { - const selectedSuggestion = listReference[highlightedIndex]; + const handleSuggestionSelect = (selectedIndex?: number) => { + const selectedSuggestion = listReference[selectedIndex ?? highlightedIndex]; + // update current reference based on selection const indexIter = getIndexOfUnclosedRefToTheLeft(currentCursorPosition); if (indexIter === -1) { @@ -290,26 +289,44 @@ export const InfisicalSecretInput = ({ }} >
- {listReference.map((item, i) => ( -
+ {listReference.map((item, i) => { + let entryIcon; + if (item.type === ReferenceType.SECRET) { + entryIcon = faKey; + } else if (item.type === ReferenceType.ENVIRONMENT) { + entryIcon = faFolderOpen; + } else { + entryIcon = faFolder; + } + + return (
{ + e.preventDefault(); + setHighlightedIndex(i); + handleSuggestionSelect(i); + }} + style={{ pointerEvents: "auto" }} + className="flex items-center justify-between border-b border-mineshaft-600 px-2 text-left last:border-b-0" + key={`secret-reference-secret-${i + 1}`} > -
-
- +
+
+
+ +
+
{item.name}
-
{item.name}
-
- ))} + ); + })}