fix: refresh buttons use "now" as to-date for queries
Instead of calling refetch() with stale time params, the refresh buttons now set a toOverride state to new Date().toISOString(). This flows into the query key, triggering a fresh fetch with the current time as the upper bound. Both useApplicationLogs and useAgentEvents hooks accept an optional toOverride parameter. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -19,15 +19,16 @@ export function useAgents(status?: string, application?: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export function useAgentEvents(appId?: string, agentId?: string, limit = 50) {
|
||||
export function useAgentEvents(appId?: string, agentId?: string, limit = 50, toOverride?: string) {
|
||||
const refetchInterval = useRefreshInterval(15_000);
|
||||
return useQuery({
|
||||
queryKey: ['agents', 'events', appId, agentId, limit],
|
||||
queryKey: ['agents', 'events', appId, agentId, limit, toOverride],
|
||||
queryFn: async () => {
|
||||
const token = useAuthStore.getState().accessToken;
|
||||
const params = new URLSearchParams();
|
||||
if (appId) params.set('appId', appId);
|
||||
if (agentId) params.set('agentId', agentId);
|
||||
if (toOverride) params.set('to', toOverride);
|
||||
params.set('limit', String(limit));
|
||||
const res = await fetch(`${config.apiBaseUrl}/agents/events-log?${params}`, {
|
||||
headers: {
|
||||
|
||||
@@ -16,20 +16,21 @@ export interface LogEntryResponse {
|
||||
export function useApplicationLogs(
|
||||
application?: string,
|
||||
agentId?: string,
|
||||
options?: { limit?: number },
|
||||
options?: { limit?: number; toOverride?: string },
|
||||
) {
|
||||
const refetchInterval = useRefreshInterval(15_000);
|
||||
const { timeRange } = useGlobalFilters();
|
||||
const to = options?.toOverride ?? timeRange.end.toISOString();
|
||||
|
||||
return useQuery({
|
||||
queryKey: ['logs', application, agentId, timeRange.start.toISOString(), timeRange.end.toISOString(), options?.limit],
|
||||
queryKey: ['logs', application, agentId, timeRange.start.toISOString(), to, options?.limit],
|
||||
queryFn: async () => {
|
||||
const token = useAuthStore.getState().accessToken;
|
||||
const params = new URLSearchParams();
|
||||
params.set('application', application!);
|
||||
if (agentId) params.set('agentId', agentId);
|
||||
params.set('from', timeRange.start.toISOString());
|
||||
params.set('to', timeRange.end.toISOString());
|
||||
params.set('to', to);
|
||||
if (options?.limit) params.set('limit', String(options.limit));
|
||||
const res = await fetch(`${config.apiBaseUrl}/logs?${params}`, {
|
||||
headers: {
|
||||
|
||||
Reference in New Issue
Block a user