From 2a19aa0ed30c9c26608ebef882a3bc0a1af7f82a Mon Sep 17 00:00:00 2001 From: Reinier van der Leer Date: Thu, 4 Sep 2025 07:43:19 +0100 Subject: [PATCH] fix(frontend/library): Show total runs count above runs list (#10832) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Resolves #10831 ### Changes 🏗️ - Show number of total runs instead of currently loaded runs - Show loading spinner instead of zero while loading ### Checklist 📋 #### For code changes: - [x] I have clearly listed my changes in the PR description - [x] I have made a test plan - [x] I have tested my changes according to the test plan: - [x] Counter shows number of total runs, even if it exceeds number of currently loaded items --- .../components/agent-runs-selector-list.tsx | 7 +++-- .../OldAgentLibraryView/use-agent-runs.ts | 27 ++++++++++++++----- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/OldAgentLibraryView/components/agent-runs-selector-list.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/OldAgentLibraryView/components/agent-runs-selector-list.tsx index c2066e63d4..31aa286fd4 100644 --- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/OldAgentLibraryView/components/agent-runs-selector-list.tsx +++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/OldAgentLibraryView/components/agent-runs-selector-list.tsx @@ -15,7 +15,7 @@ import { cn } from "@/lib/utils"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/atoms/Button/Button"; -import LoadingBox from "@/components/ui/loading"; +import LoadingBox, { LoadingSpinner } from "@/components/ui/loading"; import { PlusIcon } from "@phosphor-icons/react"; import { Separator } from "@/components/ui/separator"; import { ScrollArea } from "@/components/ui/scroll-area"; @@ -49,6 +49,7 @@ export function AgentRunsSelectorList({ agent, agentRunsQuery: { agentRuns, + agentRunCount, agentRunsLoading, hasMoreRuns, fetchMoreRuns, @@ -113,7 +114,9 @@ export function AgentRunsSelectorList({ onClick={() => setActiveListTab("runs")} > Runs - {agentRuns.length} + + {agentRunCount ?? } + { return response.executions; }) ?? []; - const agentRunCount = queryResults?.pages[-1] - ? (queryResults.pages[-1].data as GraphExecutionsPaginated).pagination - .total_items - : 0; + const agentRunCount = ( + queryResults?.pages.at(-1)?.data as GraphExecutionsPaginated | undefined + )?.pagination.total_items; const upsertAgentRun = (newAgentRun: GraphExecutionMeta) => { queryClient.setQueryData( queryKey, (currentQueryData: typeof queryResults) => { - if (!currentQueryData?.pages) return currentQueryData; + if (!currentQueryData?.pages || agentRunCount === undefined) + return currentQueryData; const exists = currentQueryData.pages.some((page) => { if (page.status !== 200) return false; @@ -147,7 +147,22 @@ export const useAgentRunsInfinite = (graphID?: GraphID) => { const updatedPages = [updatedPage, ...currentQueryData.pages.slice(1)]; return { ...currentQueryData, - pages: updatedPages, + pages: updatedPages.map( + // Increment the total runs count in the pagination info of all pages + (page) => + page.status === 200 + ? { + ...page, + data: { + ...page.data, + pagination: { + ...page.data.pagination, + total_items: agentRunCount + 1, + }, + }, + } + : page, + ), }; }, );