Skip to content

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

misc: add frontend support for filtering by type

Sheen Capadngane63226d2329a
diff --git a/backend/src/ee/routes/v1/pam-routers/pam-account-router.ts b/backend/src/ee/routes/v1/pam-routers/pam-account-router.ts
index 089c08f2b7..9c3808028d 100644
--- a/backend/src/ee/routes/v1/pam-routers/pam-account-router.ts
+++ b/backend/src/ee/routes/v1/pam-routers/pam-account-router.ts
@@ -350,7 +350,8 @@ export const registerPamAccountRouter = async (server: FastifyZodProvider) => {
querystring: z.object({
folderId: z.string().uuid().optional().describe("Filter accounts by folder ID"),
templateId: z.string().uuid().optional().describe("Filter accounts by template ID"),
- search: z.string().optional().describe("Filter accounts by name")
+ accountType: z.nativeEnum(PamAccountType).optional().describe("Filter accounts by platform type"),
+ search: z.string().trim().optional().describe("Filter accounts by name")
}),
response: {
200: z.object({ accounts: z.array(PamAccountListItemSchema) })
@@ -363,6 +364,7 @@ export const registerPamAccountRouter = async (server: FastifyZodProvider) => {
projectId: req.internalPamProjectId,
folderId: req.query.folderId,
templateId: req.query.templateId,
+ accountType: req.query.accountType,
search: req.query.search,
actorId: req.permission.id,
actor: req.permission.type,
diff --git a/backend/src/ee/services/pam-account/pam-account-service.ts b/backend/src/ee/services/pam-account/pam-account-service.ts
index 2d6c9a76ef..dc54daca50 100644
--- a/backend/src/ee/services/pam-account/pam-account-service.ts
+++ b/backend/src/ee/services/pam-account/pam-account-service.ts
@@ -183,7 +183,14 @@ export const pamAccountServiceFactory = (deps: TPamAccountServiceFactoryDep) =>
const checkFolder = (folderId: string, projectId: string, ctx: TActorContext) =>
checkFolderPermission(permissionService, folderId, projectId, ctx);
- const list = async ({ projectId, folderId, templateId, search, ...ctx }: TListPamAccountsDTO & TActorContext) => {
+ const list = async ({
+ projectId,
+ folderId,
+ templateId,
+ accountType,
+ search,
+ ...ctx
+ }: TListPamAccountsDTO & TActorContext) => {
await verifyMembership(projectId, ctx);
const { folderIds, accountIds } = await getResourceIdsWithActions(
@@ -198,6 +205,7 @@ export const pamAccountServiceFactory = (deps: TPamAccountServiceFactoryDep) =>
const { accounts } = await pamAccountDAL.findAccessible(projectId, folderIds, accountIds, {
folderId,
templateId,
+ accountType,
search
});
diff --git a/backend/src/ee/services/pam-account/pam-account-types.ts b/backend/src/ee/services/pam-account/pam-account-types.ts
index c3a3a5e660..7cd932b30b 100644
--- a/backend/src/ee/services/pam-account/pam-account-types.ts
+++ b/backend/src/ee/services/pam-account/pam-account-types.ts
@@ -47,6 +47,7 @@ export type TListPamAccountsDTO = {
projectId: string;
folderId?: string;
templateId?: string;
+ accountType?: string;
search?: string;
};
diff --git a/frontend/src/hooks/api/pam/queries.tsx b/frontend/src/hooks/api/pam/queries.tsx
index c086fc9354..bc6fc2f645 100644
--- a/frontend/src/hooks/api/pam/queries.tsx
+++ b/frontend/src/hooks/api/pam/queries.tsx
@@ -180,6 +180,7 @@ export type TAccessiblePamFolder = {
type TListPamAccountsParams = {
folderId?: string;
templateId?: string;
+ accountType?: string;
search?: string;
};
diff --git a/frontend/src/pages/pam/PamAccountsPage/PamAccountsPage.tsx b/frontend/src/pages/pam/PamAccountsPage/PamAccountsPage.tsx
index eb52838d35..0d896400a3 100644
--- a/frontend/src/pages/pam/PamAccountsPage/PamAccountsPage.tsx
+++ b/frontend/src/pages/pam/PamAccountsPage/PamAccountsPage.tsx
@@ -1,4 +1,4 @@
-import { useCallback, useEffect, useState } from "react";
+import { useCallback, useMemo, useState } from "react";
import { Helmet } from "react-helmet";
import { useTranslation } from "react-i18next";
import { ChevronDown, FolderOpen, FolderPlus, Layers, Plus, Search } from "lucide-react";
@@ -47,9 +47,11 @@ import {
PamAccountType,
PamResourcePermissionActions,
TAccessiblePamAccount,
+ TPamAccountListItem,
useDeletePamAccount,
useDeletePamFolder,
useGetPamAccessCapabilities,
+ useListPamAccounts,
useListPamAccountTypes,
useListPamFolders
} from "@app/hooks/api/pam";
@@ -76,7 +78,6 @@ export const PamAccountsPage = () => {
const [selectedFolderId, setSelectedFolderId] = useState<string>("");
const [selectedAccountType, setSelectedAccountType] = useState<string>("");
const [expandedFolders, setExpandedFolders] = useState<Set<string>>(new Set());
- const [resultCounts, setResultCounts] = useState<Record<string, number>>({});
// Every role sees the same folder/account structure; permissions only disable actions on a row,
// never hide it. Capabilities just drive the create affordances and the empty-state copy.
@@ -114,10 +115,30 @@ export const PamAccountsPage = () => {
const [launchAccount, setLaunchAccount] = useState<TAccessiblePamAccount | null>(null);
const query = searchInput.trim();
- // Active filters force-open every folder so matches surface; otherwise folders load lazily on open
const filterActive = Boolean(query || selectedAccountType);
const hasActiveFilters = Boolean(query || selectedFolderId || selectedAccountType);
+ // Filtering is done server-side in a single request across every folder the caller can read, so
+ // searching doesn't have to open (and fetch) each folder just to filter its rows in the client.
+ const { data: matches = [], isLoading: isLoadingMatches } = useListPamAccounts(
+ {
+ search: query || undefined,
+ accountType: selectedAccountType || undefined,
+ folderId: selectedFolderId || undefined
+ },
+ { enabled: filterActive }
+ );
+
+ // Group the flat match list back under its folder so the tree layout is unchanged while filtering.
+ const matchesByFolder = useMemo(() => {
+ const grouped: Record<string, TPamAccountListItem[]> = {};
+ matches.forEach((account) => {
+ if (!account.folderId) return;
+ grouped[account.folderId] = [...(grouped[account.folderId] ?? []), account];
+ });
+ return grouped;
+ }, [matches]);
+
const toggleFolder = useCallback((folderId: string) => {
setExpandedFolders((prev) => {
const next = new Set(prev);
@@ -127,27 +148,20 @@ export const PamAccountsPage = () => {
});
}, []);
- const handleResultCount = useCallback((folderId: string, count: number) => {
- setResultCounts((prev) => (prev[folderId] === count ? prev : { ...prev, [folderId]: count }));
- }, []);
-
- // Reset result counts when filters change so folder groups recompute counts for new filter
- useEffect(() => {
- setResultCounts({});
- }, [query, selectedAccountType]);
-
- const visibleFolders = selectedFolderId
+ const allFolders = selectedFolderId
? folders.filter((folder) => folder.id === selectedFolderId)
: folders;
+ // While filtering, only folders with matches are worth rendering.
+ const visibleFolders = filterActive
+ ? allFolders.filter((folder) => (matchesByFolder[folder.id]?.length ?? 0) > 0)
+ : allFolders;
const folderDropdownOptions = folders;
const isFolderOpen = (folderId: string) =>
filterActive || folderId === selectedFolderId || expandedFolders.has(folderId);
- const filterSettled = visibleFolders.every((f) => resultCounts[f.id] !== undefined);
- const filterHasMatches = visibleFolders.some((f) => (resultCounts[f.id] ?? 0) > 0);
- const showNoMatches = filterActive && filterSettled && !filterHasMatches;
- const showEmpty = !isLoadingFolders && (visibleFolders.length === 0 || showNoMatches);
+ const showEmpty =
+ !isLoadingFolders && !(filterActive && isLoadingMatches) && visibleFolders.length === 0;
// Compute empty state messages to avoid nested ternaries
let emptyTitle: string;
@@ -371,8 +385,7 @@ export const PamAccountsPage = () => {
isOpen={isFolderOpen(folder.id)}
onToggle={() => toggleFolder(folder.id)}
search={searchInput}
- accountType={selectedAccountType}
- filterActive={filterActive}
+ accounts={filterActive ? (matchesByFolder[folder.id] ?? []) : undefined}
onOpenAccount={(id, tab) => accountSheet.openSheet(id, tab)}
onLaunchAccount={setLaunchAccount}
onRequestAccess={setRequestAccount}
@@ -390,7 +403,6 @@ export const PamAccountsPage = () => {
accountCount: folder.accountCount
})
}
- onResultCount={handleResultCount}
/>
))}
</TableBody>
diff --git a/frontend/src/pages/pam/PamAccountsPage/components/FolderAccountRows.tsx b/frontend/src/pages/pam/PamAccountsPage/components/FolderAccountRows.tsx
index 9ac6c553a1..8b85919f3d 100644
--- a/frontend/src/pages/pam/PamAccountsPage/components/FolderAccountRows.tsx
+++ b/frontend/src/pages/pam/PamAccountsPage/components/FolderAccountRows.tsx
@@ -1,4 +1,3 @@
-import { useEffect, useMemo } from "react";
import { ChevronRight, Folder, FolderOpen } from "lucide-react";
import { TableCell, TableRow } from "@app/components/v3";
@@ -6,6 +5,7 @@ import { Skeleton } from "@app/components/v3/generic/Skeleton";
import {
PamAccountType,
TAccessiblePamAccount,
+ TPamAccountListItem,
TPamFolderWithCount,
useListPamAccounts
} from "@app/hooks/api/pam";
@@ -19,8 +19,11 @@ type Props = {
isOpen: boolean;
onToggle: () => void;
search: string;
- accountType: string;
- filterActive: boolean;
+ /**
+ * Pre-filtered accounts for this folder, supplied by the page's single server-side filter query.
+ * When omitted (no active filter) the folder fetches its own accounts lazily on open.
+ */
+ accounts?: TPamAccountListItem[];
onOpenAccount: (accountId: string, tab?: PamSheetTab) => void;
onLaunchAccount: (account: TAccessiblePamAccount) => void;
onRequestAccess: (account: TAccessiblePamAccount) => void;
@@ -28,7 +31,6 @@ type Props = {
onOpenFolder: (tab?: PamSheetTab) => void;
onFolderAddAccount: () => void;
onFolderDelete: () => void;
- onResultCount: (folderId: string, count: number) => void;
};
export const FolderAccountRows = ({
@@ -36,45 +38,28 @@ export const FolderAccountRows = ({
isOpen,
onToggle,
search,
- accountType,
- filterActive,
+ accounts: providedAccounts,
onOpenAccount,
onLaunchAccount,
onRequestAccess,
onDeleteAccount,
onOpenFolder,
onFolderAddAccount,
- onFolderDelete,
- onResultCount
+ onFolderDelete
}: Props) => {
- // Only fetch this folder's accounts once it's open (lazy load per folder)
- const { data, isLoading } = useListPamAccounts({ folderId: folder.id }, { enabled: isOpen });
- const accounts = data ?? [];
+ const isFiltering = providedAccounts !== undefined;
- const q = search.trim().toLowerCase();
- const hasQuery = q.length > 0;
-
- // Client-side filtering keeps search/type instant once a folder's accounts are loaded
- const accountsToShow = useMemo(() => {
- let list = accounts;
- if (accountType) list = list.filter((a) => a.accountType === accountType);
- if (hasQuery) {
- list = list.filter((a) => `${a.name} ${a.description ?? ""}`.toLowerCase().includes(q));
- }
- return list;
- }, [accounts, accountType, q, hasQuery]);
-
- useEffect(() => {
- if (isOpen && !isLoading) onResultCount(folder.id, accountsToShow.length);
- }, [isOpen, isLoading, accountsToShow.length, folder.id, onResultCount]);
+ // Only fetch this folder's accounts once it's open (lazy load per folder), and never while the
+ // page is filtering — the matches already arrived in the page's single filtered request.
+ const { data, isLoading: isFetching } = useListPamAccounts(
+ { folderId: folder.id },
+ { enabled: isOpen && !isFiltering }
+ );
- // While filtering, hide folders with no matching accounts
- if (filterActive && isOpen && !isLoading && accountsToShow.length === 0) {
- return null;
- }
+ const accountsToShow = providedAccounts ?? data ?? [];
+ const isLoading = !isFiltering && isFetching;
- let count = folder.accountCount;
- if (isOpen && !isLoading) count = filterActive ? accountsToShow.length : accounts.length;
+ const count = isOpen && !isLoading ? accountsToShow.length : folder.accountCount;
return (
<>