Skip to content

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

Applications search endpoint improvements

Carlos Monastyrskif1d6684d0ff4
diff --git a/backend/src/server/routes/v1/pki-application-router.ts b/backend/src/server/routes/v1/pki-application-router.ts
index 355fbc7370..eb9b4bd483 100644
--- a/backend/src/server/routes/v1/pki-application-router.ts
+++ b/backend/src/server/routes/v1/pki-application-router.ts
@@ -96,7 +96,18 @@ export const registerPkiApplicationRouter = async (server: FastifyZodProvider) =
querystring: z.object({
search: z.string().optional(),
limit: z.coerce.number().int().min(1).max(100).default(20),
- offset: z.coerce.number().int().min(0).default(0)
+ offset: z.coerce.number().int().min(0).default(0),
+ applicationIds: z
+ .string()
+ .optional()
+ .transform((val) =>
+ val
+ ? val
+ .split(",")
+ .map((id) => id.trim())
+ .filter(Boolean)
+ : undefined
+ )
}),
response: {
200: z.object({
@@ -115,7 +126,8 @@ export const registerPkiApplicationRouter = async (server: FastifyZodProvider) =
projectId: req.internalCertManagerProjectId,
search: req.query.search,
limit: req.query.limit,
- offset: req.query.offset
+ offset: req.query.offset,
+ applicationIds: req.query.applicationIds
});
await server.services.auditLog.createAuditLog({
diff --git a/backend/src/services/pki-application/pki-application-service.ts b/backend/src/services/pki-application/pki-application-service.ts
index f30242a05d..02444df3d3 100644
--- a/backend/src/services/pki-application/pki-application-service.ts
+++ b/backend/src/services/pki-application/pki-application-service.ts
@@ -249,6 +249,7 @@ export const pkiApplicationServiceFactory = ({
search,
limit,
offset,
+ applicationIds,
projectId,
actor,
actorId,
@@ -269,8 +270,8 @@ export const pkiApplicationServiceFactory = ({
if (hasRole(ProjectMembershipRole.Admin)) {
const [applications, total] = await Promise.all([
- pkiApplicationDAL.findByProjectId(projectId, { search, limit, offset }),
- pkiApplicationDAL.countByProjectId(projectId, search)
+ pkiApplicationDAL.findByProjectId(projectId, { search, limit, offset, applicationIds }),
+ pkiApplicationDAL.countByProjectId(projectId, search, undefined, applicationIds)
]);
return { applications, total };
}
@@ -286,7 +287,9 @@ export const pkiApplicationServiceFactory = ({
new Set(memberships.map((m) => m.scopeResourceId).filter((id): id is string => Boolean(id)))
);
- if (allowedIds.length === 0) {
+ const scopedIds = applicationIds ? allowedIds.filter((id) => applicationIds.includes(id)) : allowedIds;
+
+ if (scopedIds.length === 0) {
return { applications: [], total: 0 };
}
@@ -295,9 +298,9 @@ export const pkiApplicationServiceFactory = ({
search,
limit,
offset,
- applicationIds: allowedIds
+ applicationIds: scopedIds
}),
- pkiApplicationDAL.countByProjectId(projectId, search, undefined, allowedIds)
+ pkiApplicationDAL.countByProjectId(projectId, search, undefined, scopedIds)
]);
return { applications, total };
};
diff --git a/backend/src/services/pki-application/pki-application-types.ts b/backend/src/services/pki-application/pki-application-types.ts
index 8914249a78..1823e097d7 100644
--- a/backend/src/services/pki-application/pki-application-types.ts
+++ b/backend/src/services/pki-application/pki-application-types.ts
@@ -49,6 +49,7 @@ export type TListPkiApplicationsDTO = {
search?: string;
limit?: number;
offset?: number;
+ applicationIds?: string[];
} & TProjectPermission;
export type TDeletePkiApplicationDTO = {
diff --git a/frontend/src/hooks/api/pkiApplications/queries.ts b/frontend/src/hooks/api/pkiApplications/queries.ts
index a747c69b83..4c3100985c 100644
--- a/frontend/src/hooks/api/pkiApplications/queries.ts
+++ b/frontend/src/hooks/api/pkiApplications/queries.ts
@@ -49,8 +49,12 @@ export const useListPkiApplications = (
useQuery({
queryKey: pkiApplicationKeys.list(params),
queryFn: async () => {
+ const { applicationIds, ...rest } = params ?? {};
const { data } = await apiRequest.get<TListPkiApplicationsResponse>(BASE_URL, {
- params
+ params: {
+ ...rest,
+ ...(applicationIds?.length ? { applicationIds: applicationIds.join(",") } : {})
+ }
});
return data;
},
diff --git a/frontend/src/hooks/api/pkiApplications/types.ts b/frontend/src/hooks/api/pkiApplications/types.ts
index a695374971..b9632b8821 100644
--- a/frontend/src/hooks/api/pkiApplications/types.ts
+++ b/frontend/src/hooks/api/pkiApplications/types.ts
@@ -171,6 +171,7 @@ export type TListPkiApplicationsParams = {
search?: string;
limit?: number;
offset?: number;
+ applicationIds?: string[];
};
export type TListPkiApplicationsResponse = {
diff --git a/frontend/src/layouts/ProjectLayout/components/ProjectSelect/ApplicationSelect.tsx b/frontend/src/layouts/ProjectLayout/components/ProjectSelect/ApplicationSelect.tsx
index a6546c1b67..8055f3b57b 100644
--- a/frontend/src/layouts/ProjectLayout/components/ProjectSelect/ApplicationSelect.tsx
+++ b/frontend/src/layouts/ProjectLayout/components/ProjectSelect/ApplicationSelect.tsx
@@ -18,6 +18,7 @@ import {
ResourceIcon
} from "@app/components/v3";
import { useListPkiApplications } from "@app/hooks/api/pkiApplications";
+import { useDebounce } from "@app/hooks/useDebounce";
const ApplicationSelectInner = ({
applicationName,
@@ -29,12 +30,13 @@ const ApplicationSelectInner = ({
orgId: string;
}) => {
const [open, setOpen] = useState(false);
+ const [search, setSearch] = useState("");
+ const [debouncedSearch] = useDebounce(search);
const navigate = useNavigate();
- const { data } = useListPkiApplications({ limit: 100 });
+ const { data } = useListPkiApplications({ search: debouncedSearch || undefined, limit: 20 });
const applications = data?.applications ?? [];
- const current = applications.find((a) => a.name === applicationName);
- const displayName = current?.name ?? applicationName;
+ const displayName = applicationName;
const handleSelect = (nextName: string) => {
setOpen(false);
@@ -67,8 +69,12 @@ const ApplicationSelectInner = ({
</IconButton>
</PopoverTrigger>
<PopoverContent align="start" sideOffset={20} className="w-96 p-0">
- <Command>
- <CommandInput placeholder="Search applications..." />
+ <Command shouldFilter={false}>
+ <CommandInput
+ placeholder="Search applications..."
+ value={search}
+ onValueChange={setSearch}
+ />
<CommandList>
<CommandEmpty>No applications found.</CommandEmpty>
<CommandGroup heading="Applications">
diff --git a/frontend/src/pages/cert-manager/CertificatesPage/components/AssignCertificateToApplicationModal.tsx b/frontend/src/pages/cert-manager/CertificatesPage/components/AssignCertificateToApplicationModal.tsx
index 8b35fce013..a830b67ac2 100644
--- a/frontend/src/pages/cert-manager/CertificatesPage/components/AssignCertificateToApplicationModal.tsx
+++ b/frontend/src/pages/cert-manager/CertificatesPage/components/AssignCertificateToApplicationModal.tsx
@@ -1,8 +1,15 @@
import { useEffect, useState } from "react";
+import { Check, ChevronsUpDown } from "lucide-react";
import { createNotification } from "@app/components/notifications";
import {
Button,
+ Command,
+ CommandEmpty,
+ CommandGroup,
+ CommandInput,
+ CommandItem,
+ CommandList,
Dialog,
DialogContent,
DialogDescription,
@@ -12,14 +19,13 @@ import {
Field,
FieldContent,
FieldLabel,
- Select,
- SelectContent,
- SelectItem,
- SelectTrigger,
- SelectValue
+ Popover,
+ PopoverContent,
+ PopoverTrigger
} from "@app/components/v3";
import { useAssignCertificateToApplication } from "@app/hooks/api/certificates";
import { useListPkiApplications } from "@app/hooks/api/pkiApplications";
+import { useDebounce } from "@app/hooks/useDebounce";
type Props = {
isOpen: boolean;
@@ -28,9 +34,15 @@ type Props = {
};
export const AssignCertificateToApplicationModal = ({ isOpen, onClose, certificateId }: Props) => {
- const [selectedApplicationId, setSelectedApplicationId] = useState<string>("");
+ const [selectedApplication, setSelectedApplication] = useState<{
+ id: string;
+ name: string;
+ } | null>(null);
+ const [popoverOpen, setPopoverOpen] = useState(false);
+ const [search, setSearch] = useState("");
+ const [debouncedSearch] = useDebounce(search);
const { data, isPending } = useListPkiApplications(
- { limit: 100 },
+ { search: debouncedSearch || undefined, limit: 20 },
{
enabled: isOpen
}
@@ -39,13 +51,16 @@ export const AssignCertificateToApplicationModal = ({ isOpen, onClose, certifica
const assign = useAssignCertificateToApplication();
useEffect(() => {
- if (!isOpen) setSelectedApplicationId("");
+ if (!isOpen) {
+ setSelectedApplication(null);
+ setSearch("");
+ }
}, [isOpen]);
const handleSubmit = async () => {
- if (!selectedApplicationId) return;
+ if (!selectedApplication) return;
try {
- await assign.mutateAsync({ certificateId, applicationId: selectedApplicationId });
+ await assign.mutateAsync({ certificateId, applicationId: selectedApplication.id });
createNotification({ type: "success", text: "Certificate assigned to Application" });
onClose();
} catch (err) {
@@ -68,28 +83,55 @@ export const AssignCertificateToApplicationModal = ({ isOpen, onClose, certifica
<Field>
<FieldLabel>Application</FieldLabel>
<FieldContent>
- <Select
- value={selectedApplicationId}
- onValueChange={setSelectedApplicationId}
- disabled={isPending || applications.length === 0}
- >
- <SelectTrigger className="w-full">
- <SelectValue
- placeholder={
- applications.length === 0
- ? "No applications available"
- : "Select an application"
- }
- />
- </SelectTrigger>
- <SelectContent>
- {applications.map((app) => (
- <SelectItem key={app.id} value={app.id}>
- {app.name}
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
+ <Popover open={popoverOpen} onOpenChange={setPopoverOpen} modal>
+ <PopoverTrigger asChild>
+ <Button
+ type="button"
+ variant="outline"
+ role="combobox"
+ className="w-full justify-between font-normal"
+ >
+ <span className={selectedApplication ? "" : "text-muted"}>
+ {selectedApplication ? selectedApplication.name : "Select an application"}
+ </span>
+ <ChevronsUpDown className="size-4 shrink-0 opacity-50" />
+ </Button>
+ </PopoverTrigger>
+ <PopoverContent align="start" className="w-[var(--radix-popover-trigger-width)] p-0">
+ <Command shouldFilter={false}>
+ <CommandInput
+ placeholder="Search applications..."
+ value={search}
+ onValueChange={setSearch}
+ />
+ <CommandList>
+ <CommandEmpty>
+ {isPending ? "Loading applications..." : "No applications found."}
+ </CommandEmpty>
+ <CommandGroup>
+ {applications.map((app) => (
+ <CommandItem
+ key={app.id}
+ value={app.id}
+ onSelect={() => {
+ setSelectedApplication({ id: app.id, name: app.name });
+ setPopoverOpen(false);
+ }}
+ className="gap-2"
+ >
+ <Check
+ className={
+ selectedApplication?.id === app.id ? "opacity-100" : "opacity-0"
+ }
+ />
+ <span className="truncate">{app.name}</span>
+ </CommandItem>
+ ))}
+ </CommandGroup>
+ </CommandList>
+ </Command>
+ </PopoverContent>
+ </Popover>
</FieldContent>
</Field>
@@ -101,7 +143,7 @@ export const AssignCertificateToApplicationModal = ({ isOpen, onClose, certifica
type="button"
variant="project"
isPending={assign.isPending}
- isDisabled={!selectedApplicationId || assign.isPending}
+ isDisabled={!selectedApplication || assign.isPending}
onClick={handleSubmit}
>
Assign
diff --git a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificatesTable.tsx b/frontend/src/pages/cert-manager/CertificatesPage/components/CertificatesTable.tsx
index ddaffbf647..039df07650 100644
--- a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificatesTable.tsx
+++ b/frontend/src/pages/cert-manager/CertificatesPage/components/CertificatesTable.tsx
@@ -88,6 +88,7 @@ import {
PkiApplicationResourceSub
} from "@app/hooks/api/pkiApplications/types";
import { useListWorkspaceCertificates } from "@app/hooks/api/projects";
+import { useDebounce } from "@app/hooks/useDebounce";
import { UsePopUpState } from "@app/hooks/usePopUp";
import { ActiveFilterChips } from "./ActiveFilterChips";
@@ -296,13 +297,43 @@ export const CertificatesTable = ({
applicationId
});
- const { data: applicationsResponse } = useListPkiApplications(
- { limit: 100 },
+ const [applicationFilterSearch, setApplicationFilterSearch] = useState("");
+ const [debouncedApplicationFilterSearch] = useDebounce(applicationFilterSearch);
+ const { data: applicationOptionsResponse } = useListPkiApplications(
+ { search: debouncedApplicationFilterSearch || undefined, limit: 20 },
+ { enabled: !applicationId }
+ );
+
+ const selectedApplicationIds = useMemo(() => {
+ const ids = new Set<string>();
+ [...appliedFilters, ...pendingFilters].forEach((rule) => {
+ if (rule.field === "applicationId" && Array.isArray(rule.value)) {
+ rule.value.forEach((v) => {
+ if (typeof v === "string") ids.add(v);
+ });
+ }
+ });
+ return Array.from(ids);
+ }, [appliedFilters, pendingFilters]);
+
+ const { data: selectedApplicationsResponse } = useListPkiApplications(
{
- enabled: !applicationId
- }
+ applicationIds: selectedApplicationIds,
+ limit: Math.min(Math.max(selectedApplicationIds.length, 1), 100)
+ },
+ { enabled: !applicationId && selectedApplicationIds.length > 0 }
);
- const applicationsData = applicationsResponse?.applications;
+
+ const applicationOptions = useMemo(() => {
+ const byId = new Map<string, { value: string; label: string }>();
+ (applicationOptionsResponse?.applications ?? []).forEach((app) => {
+ byId.set(app.id, { value: app.id, label: app.name });
+ });
+ (selectedApplicationsResponse?.applications ?? []).forEach((app) => {
+ byId.set(app.id, { value: app.id, label: app.name });
+ });
+ return Array.from(byId.values());
+ }, [applicationOptionsResponse, selectedApplicationsResponse]);
const { data: caData } = useListCasByProjectId();
const { data: viewsData } = useListCertificateInventoryViews(applicationId);
@@ -334,14 +365,11 @@ export const CertificatesTable = ({
label: p.slug
}));
}
- if (applicationsData) {
- options.applicationId = applicationsData.map((app) => ({
- value: app.id,
- label: app.name
- }));
+ if (applicationOptions.length) {
+ options.applicationId = applicationOptions;
}
return options;
- }, [caData, profilesData, applicationsData]);
+ }, [caData, profilesData, applicationOptions]);
const filterSearchParams = useMemo(() => filtersToSearchParams(appliedFilters), [appliedFilters]);
@@ -747,6 +775,7 @@ export const CertificatesTable = ({
}}
onSaveView={canCreateViews ? () => setIsSaveViewOpen(true) : undefined}
dynamicFieldOptions={dynamicFieldOptions}
+ onDynamicFieldSearch={{ applicationId: setApplicationFilterSearch }}
hiddenFieldKeys={applicationId ? ["applicationId"] : undefined}
/>
</PopoverContent>
diff --git a/frontend/src/pages/cert-manager/CertificatesPage/components/FilterBuilder.tsx b/frontend/src/pages/cert-manager/CertificatesPage/components/FilterBuilder.tsx
index 0138000f15..3c2e337a5b 100644
--- a/frontend/src/pages/cert-manager/CertificatesPage/components/FilterBuilder.tsx
+++ b/frontend/src/pages/cert-manager/CertificatesPage/components/FilterBuilder.tsx
@@ -27,6 +27,7 @@ type Props = {
onClearAll: () => void;
onSaveView?: () => void;
dynamicFieldOptions?: Record<string, { value: string; label: string }[]>;
+ onDynamicFieldSearch?: Record<string, (query: string) => void>;
hiddenFieldKeys?: string[];
};
@@ -103,12 +104,14 @@ const FilterRow = ({
onUpdate,
onRemove,
dynamicFieldOptions: dynOpts,
+ onDynamicFieldSearch,
availableFields
}: {
rule: FilterRule;
onUpdate: (updated: FilterRule) => void;
onRemove: () => void;
dynamicFieldOptions?: Record<string, { value: string; label: string }[]>;
+ onDynamicFieldSearch?: Record<string, (query: string) => void>;
availableFields: FilterFieldDefinition[];
}) => {
const fieldDef = getFieldDef(rule.field, dynOpts);
@@ -155,6 +158,8 @@ const FilterRow = ({
})
.filter(Boolean) as { value: string; label: string }[];
+ const serverSearch = onDynamicFieldSearch?.[rule.field];
+
return (
<FilterableSelect
isMulti
@@ -169,6 +174,15 @@ const FilterRow = ({
maxMenuHeight={160}
menuPortalTarget={document.body}
menuPosition="fixed"
+ {...(serverSearch
+ ? {
+ filterOption: () => true,
+ onInputChange: (value, { action }) => {
+ if (action === "input-change") serverSearch(value);
+ },
+ onMenuClose: () => serverSearch("")
+ }
+ : {})}
/>
);
}
@@ -277,6 +291,7 @@ export const FilterBuilder = ({
onClearAll,
onSaveView,
dynamicFieldOptions,
+ onDynamicFieldSearch,
hiddenFieldKeys
}: Props) => {
const availableFields = hiddenFieldKeys?.length
@@ -344,6 +359,7 @@ export const FilterBuilder = ({
onUpdate={(updated) => handleUpdateRule(index, updated)}
onRemove={() => handleRemoveRule(index)}
dynamicFieldOptions={dynamicFieldOptions}
+ onDynamicFieldSearch={onDynamicFieldSearch}
availableFields={availableFields}
/>
</div>
diff --git a/frontend/src/pages/cert-manager/RequestsPage/RequestsPage.tsx b/frontend/src/pages/cert-manager/RequestsPage/RequestsPage.tsx
index 3a625f8487..d136f1ab25 100644
--- a/frontend/src/pages/cert-manager/RequestsPage/RequestsPage.tsx
+++ b/frontend/src/pages/cert-manager/RequestsPage/RequestsPage.tsx
@@ -161,13 +161,28 @@ export const RequestsPage = () => {
})
);
- const { data: appsResponse } = useListPkiApplications({ limit: 100 });
- const apps = appsResponse?.applications ?? [];
+ // resolve names only for the applications actually referenced by the visible
+ // requests, rather than loading the project's entire application list
+ const referencedAppIds = useMemo(() => {
+ const ids = new Set<string>();
+ (requests as TApprovalRequest[]).forEach((r) => {
+ if (r.scopeType === ApprovalPolicyScope.PkiApplication && r.scopeId) ids.add(r.scopeId);
+ });
+ return Array.from(ids);
+ }, [requests]);
+
+ const { data: appsResponse } = useListPkiApplications(
+ {
+ applicationIds: referencedAppIds,
+ limit: Math.min(Math.max(referencedAppIds.length, 1), 100)
+ },
+ { enabled: referencedAppIds.length > 0 }
+ );
const appById = useMemo(() => {
const map = new Map<string, { id: string; name: string }>();
- apps.forEach((a) => map.set(a.id, { id: a.id, name: a.name }));
+ (appsResponse?.applications ?? []).forEach((a) => map.set(a.id, { id: a.id, name: a.name }));
return map;
- }, [apps]);
+ }, [appsResponse]);
const filtered = useMemo(() => {
const norm = debouncedSearch.trim().toLowerCase();