29650ca512
Move to openspec/changes/archive/2026-07-09-per-instance-hook-scoping/ (R100 renames preserved). 9 artifacts. Canonical openspec/specs/ service-instance-scoping/ remains. Resolves multi-instance wrong-data bug (hooks now scope by instance.id; instance switcher re-scopes). Carry-overs: fetchBackupDashboard untouched (design decision 5); subquery scoping for runs/alerts (schema asymmetry).
76 lines
1.6 KiB
TypeScript
76 lines
1.6 KiB
TypeScript
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import {
|
|
acknowledgeBackupAlert,
|
|
fetchBackupAlerts,
|
|
fetchBackupDashboard,
|
|
fetchBackupJob,
|
|
fetchBackupJobs,
|
|
fetchBackupRuns,
|
|
} from "../api/backups";
|
|
|
|
export function useBackupJobs(serviceId?: string) {
|
|
return useQuery({
|
|
queryKey: ["backups", "jobs", serviceId ?? ""],
|
|
queryFn: () => fetchBackupJobs(serviceId),
|
|
refetchInterval: 30_000,
|
|
});
|
|
}
|
|
|
|
export function useBackupJob(jobId: string) {
|
|
return useQuery({
|
|
queryKey: ["backups", "jobs", jobId],
|
|
queryFn: () => fetchBackupJob(jobId),
|
|
enabled: !!jobId,
|
|
});
|
|
}
|
|
|
|
export function useBackupRuns(
|
|
jobId?: string,
|
|
status?: string,
|
|
serviceId?: string,
|
|
) {
|
|
return useQuery({
|
|
queryKey: ["backups", "runs", jobId, status, serviceId ?? ""],
|
|
queryFn: () => fetchBackupRuns(jobId, status, serviceId),
|
|
refetchInterval: 15_000,
|
|
});
|
|
}
|
|
|
|
export function useBackupAlerts(
|
|
jobId?: string,
|
|
acknowledged?: boolean,
|
|
severity?: string,
|
|
serviceId?: string,
|
|
) {
|
|
return useQuery({
|
|
queryKey: [
|
|
"backups",
|
|
"alerts",
|
|
jobId,
|
|
acknowledged,
|
|
severity,
|
|
serviceId ?? "",
|
|
],
|
|
queryFn: () => fetchBackupAlerts(jobId, acknowledged, severity, serviceId),
|
|
refetchInterval: 30_000,
|
|
});
|
|
}
|
|
|
|
export function useAcknowledgeAlert() {
|
|
const queryClient = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: acknowledgeBackupAlert,
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ["backups", "alerts"] });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useBackupDashboard() {
|
|
return useQuery({
|
|
queryKey: ["dashboard", "backups"],
|
|
queryFn: fetchBackupDashboard,
|
|
refetchInterval: 30_000,
|
|
});
|
|
}
|