Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
improve frontend component
Matheus Nogueirac6c351474e3f
diff --git a/backend/src/server/routes/v1/project-grant-router.ts b/backend/src/server/routes/v1/project-grant-router.tsindex c89eabc690..d3795236f0 100644--- a/backend/src/server/routes/v1/project-grant-router.ts+++ b/backend/src/server/routes/v1/project-grant-router.ts@@ -55,6 +55,7 @@ export const registerProjectGrantRouter = async (server: FastifyZodProvider) =>environmentName: z.string(),environmentSlug: z.string(),sourceProjectName: z.string(),+ sourceProjectSlug: z.string(),secretCount: z.number()}).array()})diff --git a/backend/src/services/project-grant/project-grant-dal.ts b/backend/src/services/project-grant/project-grant-dal.tsindex b35bb276b5..bf1747c1d7 100644--- a/backend/src/services/project-grant/project-grant-dal.ts+++ b/backend/src/services/project-grant/project-grant-dal.ts@@ -55,6 +55,7 @@ export const projectGrantDALFactory = (db: TDbClient) => {`${TableName.Environment}.name as environmentName`,`${TableName.Environment}.slug as environmentSlug`,`sourceProject.name as sourceProjectName`,+ `sourceProject.slug as sourceProjectSlug`,db.raw(`(SELECT COUNT(*)::integer FROM "${TableName.SecretV2}" WHERE "folderId" = "${TableName.ProjectFolderGrant}"."sourceFolderId" AND "type" = 'shared') as "secretCount"`)@@ -65,6 +66,7 @@ export const projectGrantDALFactory = (db: TDbClient) => {environmentName: string;environmentSlug: string;sourceProjectName: string;+ sourceProjectSlug: string;secretCount: number;})[];};diff --git a/frontend/src/components/v2/InfisicalSecretInput/InfisicalSecretInput.tsx b/frontend/src/components/v2/InfisicalSecretInput/InfisicalSecretInput.tsxindex d97a970f87..d1d99f3673 100644--- a/frontend/src/components/v2/InfisicalSecretInput/InfisicalSecretInput.tsx+++ b/frontend/src/components/v2/InfisicalSecretInput/InfisicalSecretInput.tsx@@ -131,7 +131,7 @@ export const InfisicalSecretInput = forwardRef<HTMLTextAreaElement, Props>(}, [debouncedValue]);const isPopupOpen = Boolean(suggestionSource.isOpen) && isFocused;- const showWizard = isPopupOpen && !suggestionSource.isDeep;+ const showWizard = isPopupOpen && (!suggestionSource.isDeep || suggestionSource.value.startsWith("@"));const handleWizardSelect = (referenceContent: string) => {const { left } = suggestionSource;@@ -503,6 +503,7 @@ export const InfisicalSecretInput = forwardRef<HTMLTextAreaElement, Props>(isEnabled={isPopupOpen}onSelect={handleWizardSelect}onFocusItem={() => inputRef.current?.focus()}+ currentInput={suggestionSource.value}/>) : (<divdiff --git a/frontend/src/components/v3/platform/SecretInput/InfisicalSecretInput.tsx b/frontend/src/components/v3/platform/SecretInput/InfisicalSecretInput.tsxindex 4ef9d7826b..5336c85b25 100644--- a/frontend/src/components/v3/platform/SecretInput/InfisicalSecretInput.tsx+++ b/frontend/src/components/v3/platform/SecretInput/InfisicalSecretInput.tsx@@ -71,9 +71,10 @@ export const InfisicalSecretInput = forwardRef<HTMLTextAreaElement, Props>(const openRefLeft = (() => {const left = getIndexOfUnclosedRefToTheLeft(debouncedValue, currentCursorPosition - 1);if (left === -1) return -1;- // Only open the wizard when the cursor is right after ${ with no dots yet typed- // (typing env.folder... is handled inline; wizard is for fresh ${)const partial = debouncedValue.slice(left + 1, currentCursorPosition);+ // Cross-project refs (starting with @) keep the wizard open through dots+ if (partial.startsWith("@")) return left;+ // For same-project refs, dots are handled inline, wizard is only for fresh ${if (partial.includes(".")) return -1;return left;})();@@ -257,6 +258,7 @@ export const InfisicalSecretInput = forwardRef<HTMLTextAreaElement, Props>(isEnabled={isPopupOpen}onSelect={handleWizardSelect}onFocusItem={() => inputRef.current?.focus()}+ currentInput={openRefLeft !== -1 ? debouncedValue.slice(openRefLeft + 1, currentCursorPosition) : ""}/></PopoverPrimitive.Content></PopoverPrimitive.Portal>diff --git a/frontend/src/components/v3/platform/SecretInput/SecretReferenceWizard.tsx b/frontend/src/components/v3/platform/SecretInput/SecretReferenceWizard.tsxindex 0cf0c5a56f..3a493c4d9e 100644--- a/frontend/src/components/v3/platform/SecretInput/SecretReferenceWizard.tsx+++ b/frontend/src/components/v3/platform/SecretInput/SecretReferenceWizard.tsx@@ -1,4 +1,4 @@-import { useMemo, useState } from "react";+import { useEffect, useMemo, useState } from "react";import { ArrowLeftIcon, ChevronRightIcon, FolderIcon, KeyRoundIcon, LayersIcon } from "lucide-react";import { useProject } from "@app/context";@@ -23,6 +23,7 @@ type Props = {onSelect: (referenceContent: string) => void;isEnabled: boolean;onFocusItem: () => void;+ currentInput?: string;};const INITIAL_STATE: WizardState = {@@ -33,7 +34,7 @@ const INITIAL_STATE: WizardState = {secretPath: "/"};-export const SecretReferenceWizard = ({ onSelect, isEnabled, onFocusItem }: Props) => {+export const SecretReferenceWizard = ({ onSelect, isEnabled, onFocusItem, currentInput = "" }: Props) => {const { currentProject } = useProject();const projectId = currentProject?.id || "";@@ -87,6 +88,89 @@ export const SecretReferenceWizard = ({ onSelect, isEnabled, onFocusItem }: Prop});}, [receivedGrants]);+ const parsedInput = useMemo(() => {+ if (!currentInput.startsWith("@")) return null;+ const segments = currentInput.slice(1).split(".");+ const projectSlug = segments[0] || "";+ const hasProjectDot = currentInput.indexOf(".") !== -1;+ const envSlug = segments[1] || "";+ const hasEnvDot = segments.length > 2;+ const folderSegments = hasEnvDot ? segments.slice(2, -1) : [];+ const lastSegment = hasEnvDot ? segments[segments.length - 1] : "";++ return { projectSlug, hasProjectDot, envSlug, hasEnvDot, folderSegments, lastSegment };+ }, [currentInput]);++ useEffect(() => {+ if (!parsedInput) return;++ const { projectSlug, hasProjectDot, envSlug, hasEnvDot, folderSegments } = parsedInput;++ if (!hasProjectDot) {+ setState({+ ...INITIAL_STATE,+ tab: "another-project",+ step: "project"+ });+ return;+ }++ const matchedGrant = uniqueSourceProjects.find(+ (g) => g.sourceProjectSlug.toLowerCase() === projectSlug.toLowerCase()+ );+ if (!matchedGrant) {+ setState({+ ...INITIAL_STATE,+ tab: "another-project",+ step: "project"+ });+ return;+ }++ if (!hasEnvDot) {+ setState({+ tab: "another-project",+ step: "env",+ selectedProjectGrant: matchedGrant,+ env: null,+ secretPath: "/"+ });+ return;+ }++ const envGrants =+ receivedGrants?.filter((g) => g.sourceProjectId === matchedGrant.sourceProjectId) || [];+ const matchedEnv = envGrants.find(+ (g) => g.environmentSlug.toLowerCase() === envSlug.toLowerCase()+ );++ if (!matchedEnv) {+ setState({+ tab: "another-project",+ step: "env",+ selectedProjectGrant: matchedGrant,+ env: null,+ secretPath: "/"+ });+ return;+ }++ const secretPath =+ folderSegments.length > 0 ? `/${folderSegments.join("/")}/` : "/";++ setState({+ tab: "another-project",+ step: "browse",+ selectedProjectGrant: matchedGrant,+ env: { slug: matchedEnv.environmentSlug, name: matchedEnv.environmentName },+ secretPath+ });+ }, [parsedInput, uniqueSourceProjects, receivedGrants]);++ const projectFilter = parsedInput && !parsedInput.hasProjectDot ? parsedInput.projectSlug.toLowerCase() : "";+ const envFilter = parsedInput?.hasProjectDot && !parsedInput.hasEnvDot ? parsedInput.envSlug.toLowerCase() : "";+ const browseFilter = parsedInput?.hasEnvDot ? parsedInput.lastSegment.toLowerCase() : "";+const availableEnvs = useMemo(() => {if (state.tab === "this-project") {return (currentProject?.environments || []).map((e) => ({ name: e.name, slug: e.slug }));@@ -173,18 +257,25 @@ export const SecretReferenceWizard = ({ onSelect, isEnabled, onFocusItem }: PropsetState((prev) => ({ ...prev, secretPath: newPath }));};- const renderProjectStep = () => (+ const renderProjectStep = () => {+ const filteredProjects = projectFilter+ ? uniqueSourceProjects.filter((g) =>+ g.sourceProjectSlug.toLowerCase().includes(projectFilter)+ )+ : uniqueSourceProjects;++ return (<div className="flex flex-col">- {uniqueSourceProjects.length === 0 ? (+ {filteredProjects.length === 0 ? (<div className="flex flex-col items-center justify-center py-8 text-sm text-muted">- No projects have shared secrets with you+ {projectFilter ? "No matching projects" : "No projects have shared secrets with you"}</div>) : (<><div className="px-2 py-1.5 text-[10px] font-semibold uppercase tracking-wider text-muted">Projects that shared with you</div>- {uniqueSourceProjects.map((grant) => (+ {filteredProjects.map((grant) => (<buttonkey={grant.sourceProjectId}type="button"@@ -208,8 +299,14 @@ export const SecretReferenceWizard = ({ onSelect, isEnabled, onFocusItem }: Prop)}</div>);+ };++ const renderEnvStep = () => {+ const filteredEnvs = envFilter+ ? availableEnvs.filter((e) => e.slug.toLowerCase().includes(envFilter))+ : availableEnvs;- const renderEnvStep = () => (+ return (<div className="flex flex-col">{state.selectedProjectGrant && (<button@@ -228,12 +325,12 @@ export const SecretReferenceWizard = ({ onSelect, isEnabled, onFocusItem }: Prop<div className="px-2 py-1.5 text-[10px] font-semibold uppercase tracking-wider text-muted">Environments</div>- {availableEnvs.length === 0 ? (+ {filteredEnvs.length === 0 ? (<div className="flex items-center justify-center py-6 text-sm text-muted">- No environments available+ {envFilter ? "No matching environments" : "No environments available"}</div>) : (- availableEnvs.map((env) => (+ filteredEnvs.map((env) => (<buttonkey={env.slug}type="button"@@ -254,10 +351,15 @@ export const SecretReferenceWizard = ({ onSelect, isEnabled, onFocusItem }: Prop)}</div>);+ };const renderBrowseStep = () => {- const folderList = folders || [];- const secretList = secrets || [];+ const folderList = browseFilter+ ? (folders || []).filter((f) => f.name.toLowerCase().includes(browseFilter))+ : folders || [];+ const secretList = browseFilter+ ? (secrets || []).filter((s) => s.key.toLowerCase().includes(browseFilter))+ : secrets || [];const isEmpty = folderList.length === 0 && secretList.length === 0;return (diff --git a/frontend/src/hooks/api/projectGrants/types.ts b/frontend/src/hooks/api/projectGrants/types.tsindex 10f39cb692..0a30c4c5b0 100644--- a/frontend/src/hooks/api/projectGrants/types.ts+++ b/frontend/src/hooks/api/projectGrants/types.ts@@ -23,6 +23,7 @@ export type TProjectGrantReceived = {environmentName: string;environmentSlug: string;sourceProjectName: string;+ sourceProjectSlug: string;secretCount: number;};