1da67f38c7
PR 3 of 4 for the runtime service registry change. - Add service + new-shape widget TypeScript types; widgets carry service_id + widget_kind (service-bound) or null (built-in). - Add services API client + TanStack Query hooks; reconcile the widget API client/hooks to the new endpoints (remove sources/types; add builtin kinds). - Add closed frontend service registry (integrations/registry.ts) mirroring the backend, with resolveWidget(widget, services) mapping a widget to its component + refresh interval. - Add ServicePage at /services/:serviceType/:serviceId with config view, empty-on-edit secret inputs + 'set' badges, enable toggle, delete, and the service's widget-kind list. - Register /services/:serviceType/:serviceId in App.tsx. - Reconcile the six widget components to refreshIntervalMs + description props; rewrite WidgetConfigDialog around a service -> widget-kind picker. - Update Dashboard test; add integrations/registry.test.ts. Verification: frontend lint 0 errors, build success, 70 tests passed; backend ruff clean, 222 tests passed.
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import {
|
|
createServiceInstance,
|
|
deleteServiceInstance,
|
|
fetchServiceInstances,
|
|
fetchServiceTypes,
|
|
updateServiceInstance,
|
|
} from "../api/services";
|
|
import type { ServiceInstanceInput } from "../types";
|
|
|
|
export function useServiceTypes() {
|
|
return useQuery({
|
|
queryKey: ["services", "types"],
|
|
queryFn: fetchServiceTypes,
|
|
staleTime: 5 * 60 * 1000,
|
|
});
|
|
}
|
|
|
|
export function useServiceInstances(serviceType?: string) {
|
|
return useQuery({
|
|
queryKey: ["services", "instances", serviceType ?? "all"],
|
|
queryFn: () => fetchServiceInstances(serviceType),
|
|
refetchInterval: 60_000,
|
|
});
|
|
}
|
|
|
|
export function useSaveServiceInstance() {
|
|
const queryClient = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (input: ServiceInstanceInput) =>
|
|
input.id ? updateServiceInstance(input) : createServiceInstance(input),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ["services", "instances"] });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useDeleteServiceInstance() {
|
|
const queryClient = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (serviceId: string) => deleteServiceInstance(serviceId),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ["services", "instances"] });
|
|
queryClient.invalidateQueries({ queryKey: ["widgets", "instances"] });
|
|
},
|
|
});
|
|
}
|