Skip to content

Commit 2a19aa0

Browse files
authored
fix(frontend/library): Show total runs count above runs list (#10832)
- 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
1 parent 6d39dfe commit 2a19aa0

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

โ€Žautogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/OldAgentLibraryView/components/agent-runs-selector-list.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { cn } from "@/lib/utils";
1515

1616
import { Badge } from "@/components/ui/badge";
1717
import { Button } from "@/components/atoms/Button/Button";
18-
import LoadingBox from "@/components/ui/loading";
18+
import LoadingBox, { LoadingSpinner } from "@/components/ui/loading";
1919
import { PlusIcon } from "@phosphor-icons/react";
2020
import { Separator } from "@/components/ui/separator";
2121
import { ScrollArea } from "@/components/ui/scroll-area";
@@ -49,6 +49,7 @@ export function AgentRunsSelectorList({
4949
agent,
5050
agentRunsQuery: {
5151
agentRuns,
52+
agentRunCount,
5253
agentRunsLoading,
5354
hasMoreRuns,
5455
fetchMoreRuns,
@@ -113,7 +114,9 @@ export function AgentRunsSelectorList({
113114
onClick={() => setActiveListTab("runs")}
114115
>
115116
<span>Runs</span>
116-
<span className="text-neutral-600">{agentRuns.length}</span>
117+
<span className="text-neutral-600">
118+
{agentRunCount ?? <LoadingSpinner className="size-4" />}
119+
</span>
117120
</Badge>
118121

119122
<Badge

โ€Žautogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/OldAgentLibraryView/use-agent-runs.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,16 @@ export const useAgentRunsInfinite = (graphID?: GraphID) => {
8686
return response.executions;
8787
}) ?? [];
8888

89-
const agentRunCount = queryResults?.pages[-1]
90-
? (queryResults.pages[-1].data as GraphExecutionsPaginated).pagination
91-
.total_items
92-
: 0;
89+
const agentRunCount = (
90+
queryResults?.pages.at(-1)?.data as GraphExecutionsPaginated | undefined
91+
)?.pagination.total_items;
9392

9493
const upsertAgentRun = (newAgentRun: GraphExecutionMeta) => {
9594
queryClient.setQueryData(
9695
queryKey,
9796
(currentQueryData: typeof queryResults) => {
98-
if (!currentQueryData?.pages) return currentQueryData;
97+
if (!currentQueryData?.pages || agentRunCount === undefined)
98+
return currentQueryData;
9999

100100
const exists = currentQueryData.pages.some((page) => {
101101
if (page.status !== 200) return false;
@@ -147,7 +147,22 @@ export const useAgentRunsInfinite = (graphID?: GraphID) => {
147147
const updatedPages = [updatedPage, ...currentQueryData.pages.slice(1)];
148148
return {
149149
...currentQueryData,
150-
pages: updatedPages,
150+
pages: updatedPages.map(
151+
// Increment the total runs count in the pagination info of all pages
152+
(page) =>
153+
page.status === 200
154+
? {
155+
...page,
156+
data: {
157+
...page.data,
158+
pagination: {
159+
...page.data.pagination,
160+
total_items: agentRunCount + 1,
161+
},
162+
},
163+
}
164+
: page,
165+
),
151166
};
152167
},
153168
);

0 commit comments

Comments
ย (0)