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
feat: add pagination on projects card
adilson2735508b745e
diff --git a/frontend/src/hooks/api/secretInsights/queries.tsx b/frontend/src/hooks/api/secretInsights/queries.tsxindex 1bb66bc559..26e0654fac 100644--- a/frontend/src/hooks/api/secretInsights/queries.tsx+++ b/frontend/src/hooks/api/secretInsights/queries.tsx@@ -1,4 +1,4 @@-import { useQuery, UseQueryOptions } from "@tanstack/react-query";+import { useInfiniteQuery, useQuery, UseQueryOptions } from "@tanstack/react-query";import { apiRequest } from "@app/config/request";@@ -264,18 +264,25 @@ export const useGetOrgSecretsSummary = (orgId: string) => {};export const useGetOrgSecretsProjects = (orgId: string, params: TGetOrgSecretsProjectsDTO = {}) => {- return useQuery({+ return useInfiniteQuery({queryKey: secretInsightsKeys.orgSecretsProjects(orgId, params),- queryFn: async () => {+ initialPageParam: 0,+ queryFn: async ({ pageParam }) => {const { data } = await apiRequest.get<{ projectWarnings: TOrgProjectsInsights }>("/api/v1/insights/secrets/projects",- { params }+ { params: { ...params, offset: pageParam } });return data.projectWarnings;},+ // Rows are ordered severityScore desc, so the first `projectsWithIssues` rows are+ // exactly the problem projects; there is nothing worth fetching past that boundary.+ getNextPageParam: (lastPage) => {+ if (lastPage.projects.length === 0) return undefined;+ const nextOffset = lastPage.offset + lastPage.projects.length;+ return nextOffset < lastPage.projectsWithIssues ? nextOffset : undefined;+ },enabled: Boolean(orgId),- staleTime: INSIGHTS_STALE_TIME,- placeholderData: (prev) => prev+ staleTime: INSIGHTS_STALE_TIME});};diff --git a/frontend/src/hooks/api/secretInsights/types.ts b/frontend/src/hooks/api/secretInsights/types.tsindex fcdae7bd0e..f5ef1ab4c4 100644--- a/frontend/src/hooks/api/secretInsights/types.ts+++ b/frontend/src/hooks/api/secretInsights/types.ts@@ -203,7 +203,6 @@ export type TOrgProjectsInsights = {};export type TGetOrgSecretsProjectsDTO = {- offset?: number;limit?: number;};diff --git a/frontend/src/pages/organization/SecretInsightsPage/SecretInsightsPage.tsx b/frontend/src/pages/organization/SecretInsightsPage/SecretInsightsPage.tsxindex 7bf61d50d9..d450f0732f 100644--- a/frontend/src/pages/organization/SecretInsightsPage/SecretInsightsPage.tsx+++ b/frontend/src/pages/organization/SecretInsightsPage/SecretInsightsPage.tsx@@ -1,4 +1,4 @@-import { Fragment, ReactNode } from "react";+import { Fragment, ReactNode, useMemo } from "react";import { Helmet } from "react-helmet";import { format } from "date-fns";import { BoxIcon, FileTextIcon, KeyIcon, LayersIcon, PlusIcon, RefreshCwIcon } from "lucide-react";@@ -46,12 +46,36 @@ export const SecretInsightsPage = withPermission(const { currentOrg } = useOrganization();const { data: summary, isPending: isSummaryPending } = useGetOrgSecretsSummary(currentOrg.id);- // limit 100 is the endpoint maximum; orgs with more projects need real pagination later- // TODO: add pagination- const { data: projectsInsights, isPending: isProjectsPending } = useGetOrgSecretsProjects(- currentOrg.id,- { limit: 100 }- );+ // Paginated: pages of 100 (the endpoint maximum); NeedsAttentionCard fetches further+ // pages on demand while more problem projects remain on the server.+ const {+ data: projectsPages,+ isPending: isProjectsPending,+ hasNextPage: hasMoreProjects,+ fetchNextPage: fetchMoreProjects,+ isFetchingNextPage: isFetchingMoreProjects+ } = useGetOrgSecretsProjects(currentOrg.id, { limit: 1 });++ const projectsInsights = useMemo(() => {+ if (!projectsPages) return undefined;+ const lastPage = projectsPages.pages[projectsPages.pages.length - 1];+ // Dedupe across pages: rows can shift between fetches while the server cache refreshes+ const seen = new Set<string>();+ const projects = projectsPages.pages+ .flatMap((page) => page.projects)+ .filter((project) => {+ if (seen.has(project.projectId)) return false;+ seen.add(project.projectId);+ return true;+ });+ return {+ projects,+ totalProjects: lastPage.totalProjects,+ projectsWithIssues: lastPage.projectsWithIssues,+ offset: lastPage.offset,+ limit: lastPage.limit+ };+ }, [projectsPages]);const { data: authMethodUsage, isPending: isAuthMethodsPending } =useGetOrgAuthMethodDistribution(currentOrg.id);const { data: staticSecretUsage, isPending: isStaticSecretsPending } =@@ -187,7 +211,12 @@ export const SecretInsightsPage = withPermission({!isSummaryPending && summary && <SummaryCard summary={summary} />}{isProjectsPending && <Skeleton className="h-[320px]" />}{!isProjectsPending && projectsInsights && (- <NeedsAttentionCard data={projectsInsights} />+ <NeedsAttentionCard+ data={projectsInsights}+ hasMore={hasMoreProjects}+ onLoadMore={fetchMoreProjects}+ isLoadingMore={isFetchingMoreProjects}+ />)}<divclassName={diff --git a/frontend/src/pages/organization/SecretInsightsPage/components/NeedsAttentionCard.tsx b/frontend/src/pages/organization/SecretInsightsPage/components/NeedsAttentionCard.tsxindex 7da1bf0457..09a1df7e5f 100644--- a/frontend/src/pages/organization/SecretInsightsPage/components/NeedsAttentionCard.tsx+++ b/frontend/src/pages/organization/SecretInsightsPage/components/NeedsAttentionCard.tsx@@ -73,7 +73,17 @@ const WarningBadges = ({ warnings }: { warnings: TOrgProjectInsightWarnings }) =const hasIssues = (warnings: TOrgProjectInsightWarnings) =>WARNING_CHIPS.some(({ key }) => (warnings[key] ?? 0) > 0);-export const NeedsAttentionCard = ({ data }: { data: TOrgProjectsInsights }) => {+export const NeedsAttentionCard = ({+ data,+ hasMore,+ onLoadMore,+ isLoadingMore+}: {+ data: TOrgProjectsInsights;+ hasMore: boolean;+ onLoadMore: () => void;+ isLoadingMore: boolean;+}) => {const navigate = useNavigate();const { currentOrg } = useOrganization();const [search, setSearch] = useState("");@@ -188,7 +198,21 @@ export const NeedsAttentionCard = ({ data }: { data: TOrgProjectsInsights }) =>{cleanCount.toLocaleString()} {cleanCount === 1 ? "project has" : "projects have"} nooutstanding issues</span>- {!isSearching && filtered.length > COLLAPSED_ROW_COUNT && (+ {!isSearching && hasMore && (+ <Button+ variant="ghost"+ size="xs"+ isPending={isLoadingMore}+ onClick={() => {+ setShowAll(true);+ onLoadMore();+ }}+ >+ Show More Projects+ <ChevronDownIcon />+ </Button>+ )}+ {!isSearching && !hasMore && filtered.length > COLLAPSED_ROW_COUNT && (<Button variant="ghost" size="xs" onClick={() => setShowAll((prev) => !prev)}>{showAll ? "Show Fewer Projects" : "Show All Projects"}{showAll ? <ChevronUpIcon /> : <ChevronDownIcon />}