Add dedicated request/response DTOs for all controllers, replacing raw JsonNode parameters with validated types. Move OpenAPI path-prefix stripping and ProcessorNode children injection into OpenApiCustomizer beans so the spec served at /api/v1/api-docs is already clean — eliminating the need for the ui/scripts/process-openapi.mjs post-processing script. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
98 lines
2.7 KiB
TypeScript
98 lines
2.7 KiB
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
import { api } from '../client';
|
|
import type { SearchRequest } from '../types';
|
|
|
|
export function useExecutionStats(timeFrom: string | undefined, timeTo: string | undefined) {
|
|
return useQuery({
|
|
queryKey: ['executions', 'stats', timeFrom, timeTo],
|
|
queryFn: async () => {
|
|
const { data, error } = await api.GET('/search/stats', {
|
|
params: {
|
|
query: {
|
|
from: timeFrom!,
|
|
to: timeTo || undefined,
|
|
},
|
|
},
|
|
});
|
|
if (error) throw new Error('Failed to load stats');
|
|
return data!;
|
|
},
|
|
enabled: !!timeFrom,
|
|
placeholderData: (prev) => prev,
|
|
refetchInterval: 10_000,
|
|
});
|
|
}
|
|
|
|
export function useSearchExecutions(filters: SearchRequest, live = false) {
|
|
return useQuery({
|
|
queryKey: ['executions', 'search', filters],
|
|
queryFn: async () => {
|
|
const { data, error } = await api.POST('/search/executions', {
|
|
body: filters,
|
|
});
|
|
if (error) throw new Error('Search failed');
|
|
return data!;
|
|
},
|
|
placeholderData: (prev) => prev,
|
|
refetchInterval: live ? 5_000 : false,
|
|
});
|
|
}
|
|
|
|
export function useStatsTimeseries(timeFrom: string | undefined, timeTo: string | undefined) {
|
|
return useQuery({
|
|
queryKey: ['executions', 'timeseries', timeFrom, timeTo],
|
|
queryFn: async () => {
|
|
const { data, error } = await api.GET('/search/stats/timeseries', {
|
|
params: {
|
|
query: {
|
|
from: timeFrom!,
|
|
to: timeTo || undefined,
|
|
buckets: 24,
|
|
},
|
|
},
|
|
});
|
|
if (error) throw new Error('Failed to load timeseries');
|
|
return data!;
|
|
},
|
|
enabled: !!timeFrom,
|
|
placeholderData: (prev) => prev,
|
|
refetchInterval: 30_000,
|
|
});
|
|
}
|
|
|
|
export function useExecutionDetail(executionId: string | null) {
|
|
return useQuery({
|
|
queryKey: ['executions', 'detail', executionId],
|
|
queryFn: async () => {
|
|
const { data, error } = await api.GET('/executions/{executionId}', {
|
|
params: { path: { executionId: executionId! } },
|
|
});
|
|
if (error) throw new Error('Failed to load execution detail');
|
|
return data!;
|
|
},
|
|
enabled: !!executionId,
|
|
});
|
|
}
|
|
|
|
export function useProcessorSnapshot(
|
|
executionId: string | null,
|
|
index: number | null,
|
|
) {
|
|
return useQuery({
|
|
queryKey: ['executions', 'snapshot', executionId, index],
|
|
queryFn: async () => {
|
|
const { data, error } = await api.GET(
|
|
'/executions/{executionId}/processors/{index}/snapshot',
|
|
{
|
|
params: {
|
|
path: { executionId: executionId!, index: index! },
|
|
},
|
|
},
|
|
);
|
|
if (error) throw new Error('Failed to load snapshot');
|
|
return data!;
|
|
},
|
|
enabled: !!executionId && index !== null,
|
|
});
|
|
}
|