Skip to content

Commit d8077e3

Browse files
author
Murtaza Nsair
committed
Improve activity log pagination UI - move buttons to top right, add Load All button
1 parent b459ddd commit d8077e3

File tree

4 files changed

+76
-41
lines changed

4 files changed

+76
-41
lines changed

maestro_frontend/src/components/mission/AgentActivityLog.tsx

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ interface AgentActivityLogProps {
5151
missionId?: string;
5252
hasMore?: boolean;
5353
onLoadMore?: () => void;
54+
onLoadAll?: () => void;
5455
isLoadingMore?: boolean;
5556
totalLogs?: number;
5657
}
@@ -62,6 +63,7 @@ export const AgentActivityLog: React.FC<AgentActivityLogProps> = ({
6263
missionId,
6364
hasMore = false,
6465
onLoadMore,
66+
onLoadAll,
6567
isLoadingMore = false,
6668
totalLogs = 0
6769
}) => {
@@ -126,18 +128,37 @@ export const AgentActivityLog: React.FC<AgentActivityLogProps> = ({
126128

127129
return (
128130
<div className="flex flex-col h-full max-h-full overflow-hidden space-y-2">
129-
<div className="flex items-center space-x-2 flex-shrink-0">
130-
<Bot className="h-4 w-4 text-primary" />
131-
<h3 className="text-base font-semibold text-foreground">Agent Activity Log</h3>
132-
{logs.length > 0 && (
133-
<div className="flex items-center gap-2">
131+
<div className="flex items-center justify-between flex-shrink-0">
132+
<div className="flex items-center space-x-2">
133+
<Bot className="h-4 w-4 text-primary" />
134+
<h3 className="text-base font-semibold text-foreground">Agent Activity Log</h3>
135+
{logs.length > 0 && (
134136
<span className="text-xs text-muted-foreground bg-secondary px-2 py-1 rounded">
135-
{logs.length} entries
137+
{logs.length} entries{totalLogs > 0 && totalLogs > logs.length ? ` of ${totalLogs} total` : ''}
136138
</span>
137-
{totalLogs > 0 && totalLogs > logs.length && (
138-
<span className="text-xs text-muted-foreground">
139-
of {totalLogs} total
140-
</span>
139+
)}
140+
</div>
141+
{(hasMore || (totalLogs > 0 && logs.length < totalLogs)) && onLoadMore && (
142+
<div className="flex gap-2">
143+
<Button
144+
onClick={onLoadMore}
145+
disabled={isLoadingMore || (!hasMore && logs.length >= totalLogs)}
146+
variant="outline"
147+
size="sm"
148+
className="text-xs h-7"
149+
>
150+
{isLoadingMore ? 'Loading...' : 'Load More'}
151+
</Button>
152+
{hasMore && onLoadAll && (
153+
<Button
154+
onClick={onLoadAll}
155+
disabled={isLoadingMore}
156+
variant="outline"
157+
size="sm"
158+
className="text-xs h-7"
159+
>
160+
Load All
161+
</Button>
141162
)}
142163
</div>
143164
)}
@@ -167,37 +188,6 @@ export const AgentActivityLog: React.FC<AgentActivityLogProps> = ({
167188
)}
168189

169190
{logs.map((log, index) => renderLogEntry(log, index))}
170-
171-
{(hasMore || (totalLogs > 0 && logs.length < totalLogs)) && onLoadMore && (
172-
<div className="p-4 border-t space-y-3">
173-
<div className="flex items-center justify-between text-xs text-muted-foreground">
174-
<span>
175-
Showing {logs.length} of {totalLogs || logs.length} logs
176-
</span>
177-
</div>
178-
<div className="flex justify-center">
179-
<Button
180-
onClick={onLoadMore}
181-
disabled={isLoadingMore || (!hasMore && logs.length >= totalLogs)}
182-
variant="outline"
183-
size="sm"
184-
className="flex items-center gap-2"
185-
>
186-
{isLoadingMore ? (
187-
<>
188-
<Activity className="h-4 w-4 animate-spin" />
189-
Loading more...
190-
</>
191-
) : (
192-
<>
193-
<ChevronDown className="h-4 w-4" />
194-
Load More
195-
</>
196-
)}
197-
</Button>
198-
</div>
199-
</div>
200-
)}
201191
</CardContent>
202192
</Card>
203193
</div>

maestro_frontend/src/features/mission/components/AgentsTab.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface AgentsTabProps {
1111
missionId: string;
1212
hasMoreLogs?: boolean;
1313
onLoadMoreLogs?: () => void;
14+
onLoadAllLogs?: () => void;
1415
isLoadingMoreLogs?: boolean;
1516
totalLogsCount?: number;
1617
}
@@ -19,6 +20,7 @@ export const AgentsTab: React.FC<AgentsTabProps> = ({
1920
missionId,
2021
hasMoreLogs,
2122
onLoadMoreLogs,
23+
onLoadAllLogs,
2224
isLoadingMoreLogs,
2325
totalLogsCount
2426
}) => {
@@ -71,6 +73,7 @@ export const AgentsTab: React.FC<AgentsTabProps> = ({
7173
missionId={missionId}
7274
hasMore={hasMoreLogs}
7375
onLoadMore={onLoadMoreLogs}
76+
onLoadAll={onLoadAllLogs}
7477
isLoadingMore={isLoadingMoreLogs}
7578
totalLogs={totalLogsCount}
7679
/>

maestro_frontend/src/features/mission/components/ResearchPanel.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,44 @@ export const ResearchPanel: React.FC = () => {
110110
}
111111
}, [activeChat?.missionId, hasMoreLogs, isLoadingMoreLogs, missionLogs, appendMissionLogs, addToast])
112112

113+
// Load all logs function
114+
const loadAllLogs = useCallback(async () => {
115+
if (!activeChat?.missionId || !hasMoreLogs || isLoadingMoreLogs) {
116+
return
117+
}
118+
119+
setIsLoadingMoreLogs(true)
120+
try {
121+
// Fetch all remaining logs in one request
122+
const response = await apiClient.get(`/api/missions/${activeChat.missionId}/logs?skip=0&limit=10000`)
123+
if (response.data && response.data.logs) {
124+
const allLogs = response.data.logs.map((log: any) => ({
125+
...log,
126+
timestamp: ensureDate(log.timestamp),
127+
}))
128+
129+
// Sort all logs by timestamp
130+
const sortedAllLogs = allLogs.sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime())
131+
132+
// Replace existing logs with all logs
133+
setMissionLogs(activeChat.missionId, sortedAllLogs)
134+
135+
// Update pagination state
136+
setHasMoreLogs(false)
137+
setTotalLogsCount(response.data.total || sortedAllLogs.length)
138+
}
139+
} catch (error) {
140+
console.error('Failed to load all logs:', error)
141+
addToast({
142+
type: 'error',
143+
title: 'Failed to load all logs',
144+
message: 'Please try again'
145+
})
146+
} finally {
147+
setIsLoadingMoreLogs(false)
148+
}
149+
}, [activeChat?.missionId, hasMoreLogs, isLoadingMoreLogs, setMissionLogs, addToast])
150+
113151
// Set up single WebSocket connection for ALL research updates
114152
const { isConnected, subscribeMission, unsubscribeMission } = useResearchWebSocket()
115153

@@ -403,6 +441,7 @@ export const ResearchPanel: React.FC = () => {
403441
isWebSocketConnected={isConnected}
404442
hasMoreLogs={hasMoreLogs}
405443
onLoadMoreLogs={loadMoreLogs}
444+
onLoadAllLogs={loadAllLogs}
406445
isLoadingMoreLogs={isLoadingMoreLogs}
407446
totalLogsCount={totalLogsCount}
408447
/>

maestro_frontend/src/features/mission/components/ResearchTabs.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ interface ResearchTabsProps {
1616
isWebSocketConnected?: boolean
1717
hasMoreLogs?: boolean
1818
onLoadMoreLogs?: () => void
19+
onLoadAllLogs?: () => void
1920
isLoadingMoreLogs?: boolean
2021
totalLogsCount?: number
2122
}
@@ -24,6 +25,7 @@ export const ResearchTabs: React.FC<ResearchTabsProps> = ({
2425
missionId,
2526
hasMoreLogs,
2627
onLoadMoreLogs,
28+
onLoadAllLogs,
2729
isLoadingMoreLogs,
2830
totalLogsCount
2931
}) => {
@@ -97,6 +99,7 @@ export const ResearchTabs: React.FC<ResearchTabsProps> = ({
9799
missionId={missionId}
98100
hasMoreLogs={hasMoreLogs}
99101
onLoadMoreLogs={onLoadMoreLogs}
102+
onLoadAllLogs={onLoadAllLogs}
100103
isLoadingMoreLogs={isLoadingMoreLogs}
101104
totalLogsCount={totalLogsCount}
102105
/>

0 commit comments

Comments
 (0)