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 = ({ }} >