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
fix(agent-vault): move the add dialogs to Combobox, and stop telling an empty org its groups are added
Scott Wilson0bc7ba78f305
diff --git a/frontend/src/hooks/api/agentVault/queries.tsx b/frontend/src/hooks/api/agentVault/queries.tsxindex eac1816291..36c54f3833 100644--- a/frontend/src/hooks/api/agentVault/queries.tsx+++ b/frontend/src/hooks/api/agentVault/queries.tsx@@ -76,13 +76,18 @@ export const useListAgentVaultMembers = <T extends AgentVaultMemberType = AgentV});};+// One page is enough for a picker: past it the admin searches. The default lives here so both add+// dialogs page the same way.+const AVAILABLE_MEMBER_LIMIT = 50;+export const useListAvailableAgentVaultMembers = <T extends AgentVaultMemberType = AgentVaultMemberType>(- params: TListAgentVaultMembersDTO & { actorType?: T } = {},+ { limit = AVAILABLE_MEMBER_LIMIT, ...rest }: TListAgentVaultMembersDTO & { actorType?: T } = {},enabled = true) => {const { currentOrg } = useOrganization();+ const params = { ...rest, limit };return useQuery({queryKey: agentVaultKeys.availableMemberList(currentOrg.id, params),diff --git a/frontend/src/pages/agent-vault/AgentVaultAccessControlPage/components/AddGroupDialog.tsx b/frontend/src/pages/agent-vault/AgentVaultAccessControlPage/components/AddGroupDialog.tsxindex 1c7a84488b..9d0919a05a 100644--- a/frontend/src/pages/agent-vault/AgentVaultAccessControlPage/components/AddGroupDialog.tsx+++ b/frontend/src/pages/agent-vault/AgentVaultAccessControlPage/components/AddGroupDialog.tsx@@ -1,8 +1,11 @@import { useMemo, useState } from "react";+import { Link } from "@tanstack/react-router";+import { ArrowRightIcon } from "lucide-react";import { createNotification } from "@app/components/notifications";import {Button,+ Combobox,Dialog,DialogContent,DialogDescription,@@ -12,12 +15,13 @@ import {Field,FieldContent,FieldDescription,- FieldLabel,- FilterableSelect+ FieldLabel} from "@app/components/v3";+import { useOrganization } from "@app/context";import { useDebounce } from "@app/hooks";import {useAddAgentVaultMembers,+ useListAgentVaultMembers,useListAvailableAgentVaultMembers} from "@app/hooks/api/agentVault";import { AgentVaultMemberType } from "@app/hooks/api/agentVault/enums";@@ -25,8 +29,6 @@ import { ProjectMembershipRole } from "@app/hooks/api/roles/types";import { ProductRoleField } from "./ProductRoleField";-const CANDIDATE_LIMIT = 50;-type TOption = { value: string; label: string };type Props = {@@ -35,6 +37,7 @@ type Props = {};export const AddGroupDialog = ({ isOpen, onOpenChange }: Props) => {+ const { currentOrg } = useOrganization();const addMembers = useAddAgentVaultMembers();const [group, setGroup] = useState<TOption | null>(null);@@ -43,11 +46,13 @@ export const AddGroupDialog = ({ isOpen, onOpenChange }: Props) => {const [debouncedSearch] = useDebounce(search);const { data, isFetching } = useListAvailableAgentVaultMembers(- {- actorType: AgentVaultMemberType.Group,- search: debouncedSearch.trim() || undefined,- limit: CANDIDATE_LIMIT- },+ { actorType: AgentVaultMemberType.Group, search: debouncedSearch.trim() || undefined },+ isOpen+ );+ // Only for the empty state: with nothing available, this is what tells an organization that has no+ // groups at all apart from one whose groups are all already members.+ const { data: memberData } = useListAgentVaultMembers(+ { actorType: AgentVaultMemberType.Group, limit: 1 },isOpen);@@ -56,7 +61,12 @@ export const AddGroupDialog = ({ isOpen, onOpenChange }: Props) => {[data]);- const isListTruncated = (data?.totalCount ?? 0) > options.length;+ const availableCount = data?.totalCount ?? 0;+ const isListTruncated = availableCount > options.length;+ // A search that matches nothing is not an empty organization, so it keeps the picker and answers+ // inside the dropdown instead.+ const hasNothingToAdd = Boolean(data) && availableCount === 0 && !debouncedSearch.trim();+ const orgHasNoGroups = hasNothingToAdd && (memberData?.totalCount ?? 0) === 0;const handleClose = () => {setGroup(null);@@ -100,55 +110,80 @@ export const AddGroupDialog = ({ isOpen, onOpenChange }: Props) => {</DialogDescription></DialogHeader>- <Field>- <FieldLabel>Group</FieldLabel>- <FieldContent>- <FilterableSelect- value={group}- onChange={(value) => setGroup((value ?? null) as TOption | null)}- options={options}- placeholder="Search groups..."- getOptionLabel={(option) => option.label}- getOptionValue={(option) => option.value}- isLoading={isFetching || search !== debouncedSearch}- onInputChange={(value, actionMeta) => {- if (actionMeta.action === "input-change") setSearch(value);- }}- filterOption={() => true}- noOptionsMessage={() =>- search- ? "No group matches that is not already a member"- : "Every group in the organization is already a member"- }- />- {isListTruncated && (- <FieldDescription>- Search by name to find groups that are not listed.- </FieldDescription>- )}- </FieldContent>- </Field>-- <Field>- <FieldLabel>Product Role</FieldLabel>- <FieldContent>- <ProductRoleField value={role} onChange={setRole} idPrefix="add-group-role" />- </FieldContent>- </Field>-- <DialogFooter>- <Button variant="outline" onClick={handleClose}>- Cancel- </Button>- <Button- variant="av"- isPending={addMembers.isPending}- isDisabled={!group}- onClick={handleAdd}- >- Add Group- </Button>- </DialogFooter>+ {hasNothingToAdd ? (+ <div className="flex flex-col gap-4">+ <p className="text-sm">+ {orgHasNoGroups+ ? "Your organization has no groups yet. Create one at the organization level to add it to Agent Vault."+ : "Every group in your organization is already added. To add another, create one at the organization level first."}+ </p>+ <DialogFooter>+ <Button variant="outline" onClick={handleClose}>+ Cancel+ </Button>+ <Button asChild variant="av">+ <Link+ to={"/organizations/$orgId/access-management" as const}+ params={{ orgId: currentOrg.id }}+ search={{ selectedTab: "groups" }}+ >+ Go to organization groups <ArrowRightIcon />+ </Link>+ </Button>+ </DialogFooter>+ </div>+ ) : (+ <>+ <Field>+ <FieldLabel htmlFor="agent-vault-add-group">Group</FieldLabel>+ <FieldContent>+ <Combobox+ id="agent-vault-add-group"+ options={options}+ value={group}+ shouldFilter={false}+ isLoading={isFetching}+ includeMissingSelectedOptions+ onInputValueChange={setSearch}+ getOptionValue={(option) => option.value}+ getOptionLabel={(option) => option.label}+ placeholder="Pick a group"+ searchPlaceholder="Search groups..."+ searchAriaLabel="Search groups"+ emptyMessage="No groups match your search"+ modal+ onValueChange={(next) => setGroup(next ?? null)}+ />+ {isListTruncated && (+ <FieldDescription>+ Search by name to find groups that are not listed.+ </FieldDescription>+ )}+ </FieldContent>+ </Field>++ <Field>+ <FieldLabel>Product Role</FieldLabel>+ <FieldContent>+ <ProductRoleField value={role} onChange={setRole} idPrefix="add-group-role" />+ </FieldContent>+ </Field>++ <DialogFooter>+ <Button variant="outline" onClick={handleClose}>+ Cancel+ </Button>+ <Button+ variant="av"+ isPending={addMembers.isPending}+ isDisabled={!group}+ onClick={handleAdd}+ >+ Add Group+ </Button>+ </DialogFooter>+ </>+ )}</DialogContent></Dialog>);diff --git a/frontend/src/pages/agent-vault/AgentVaultAccessControlPage/components/InviteMembersDialog.tsx b/frontend/src/pages/agent-vault/AgentVaultAccessControlPage/components/InviteMembersDialog.tsxindex 20e5e125db..fa04242daa 100644--- a/frontend/src/pages/agent-vault/AgentVaultAccessControlPage/components/InviteMembersDialog.tsx+++ b/frontend/src/pages/agent-vault/AgentVaultAccessControlPage/components/InviteMembersDialog.tsx@@ -6,6 +6,7 @@ import {Alert,AlertDescription,Button,+ Combobox,Dialog,DialogContent,DialogDescription,@@ -15,8 +16,7 @@ import {Field,FieldContent,FieldDescription,- FieldLabel,- FilterableSelect+ FieldLabel} from "@app/components/v3";import { useOrganization } from "@app/context";import { useDebounce } from "@app/hooks";@@ -32,8 +32,6 @@ import { getRequesterStatus } from "@app/lib/fn/requesterStatus";import { ProductRoleField } from "./ProductRoleField";-const CANDIDATE_LIMIT = 50;-type TCandidate = { value: string; label: string; email: string };type Props = {@@ -64,11 +62,7 @@ export const InviteMembersDialog = ({ isOpen, onOpenChange }: Props) => {const { data: availableData, isFetching: isCandidatesFetching } =useListAvailableAgentVaultMembers(- {- actorType: AgentVaultMemberType.User,- search: debouncedSearch.trim() || undefined,- limit: CANDIDATE_LIMIT- },+ { actorType: AgentVaultMemberType.User, search: debouncedSearch.trim() || undefined },isOpen);// Only the ?requesterEmail= deep link needs the whole roster: it resolves an address the candidate@@ -168,27 +162,33 @@ export const InviteMembersDialog = ({ isOpen, onOpenChange }: Props) => {</DialogHeader><Field>- <FieldLabel>Users</FieldLabel>+ <FieldLabel htmlFor="agent-vault-invite-users">Users</FieldLabel><FieldContent>- <FilterableSelect- isMulti- value={selected}- onChange={(value) => setSelected((value ?? []) as TCandidate[])}+ <Combobox+ id="agent-vault-invite-users"+ multipleoptions={candidates}- placeholder="Search by name or email..."- getOptionLabel={(option) => option.label}- getOptionValue={(option) => option.value}- isLoading={isCandidatesFetching || search !== debouncedSearch}- onInputChange={(value, actionMeta) => {- if (actionMeta.action === "input-change") setSearch(value);- }}+ value={selected}// The server already matched the term, against fields the label does not show.- filterOption={() => true}- noOptionsMessage={() =>- search+ shouldFilter={false}+ isLoading={isCandidatesFetching}+ // Without this a chip already picked vanishes when the next search returns a page it is not on.+ includeMissingSelectedOptions+ onInputValueChange={setSearch}+ getOptionValue={(option) => option.value}+ getOptionLabel={(option) => option.label}+ getOptionKeywords={(option) => [option.email]}+ placeholder="Pick users"+ searchPlaceholder="Search by name or email..."+ searchAriaLabel="Search users"+ emptyMessage={(inputValue) =>+ inputValue? "No one matches who is not already a member": "Everyone in the organization is already a member"}+ clearAriaLabel="Clear all users"+ modal+ onValueChange={(next) => setSelected([...next])}/>{isCandidateListTruncated && (<FieldDescription>