import { useState, useEffect } from "react";
import { useQuery } from "@tanstack/react-query";
import { Card, CardContent } from "@/components/ui/card";
import { Loader2 } from "lucide-react";
import {
LineChart,
Line,
BarChart,
Bar,
XAxis,
YAxis,
CartesianGrid,
Tooltip,
ResponsiveContainer,
Legend,
} from "recharts";
interface DnsUpdateChartProps {
timeframe?: string;
domainId?: number;
}
export function DnsUpdateChart({
timeframe = "day",
domainId
}: DnsUpdateChartProps) {
// This would be a real API query in a production app
// For this MVP, we'll generate sample data
// Create a query key that includes the timeframe and domainId
const queryKey = ["/api/metrics/dns-updates", timeframe, domainId];
// In a real app, this would fetch data from the API
const { data: chartData, isLoading } = useQuery({
queryKey,
queryFn: async () => generateSampleData(timeframe),
// Keep data fresh for 5 minutes
staleTime: 5 * 60 * 1000,
});
// Generate sample data based on timeframe
// In a real application, this would come from the API
const generateSampleData = (timeframe: string) => {
const data = [];
if (timeframe === "day") {
// Generate hourly data for a day
for (let i = 0; i < 24; i++) {
const hour = i.toString().padStart(2, "0") + ":00";
const updateCount = Math.floor(Math.random() * 10) + 1;
data.push({
time: hour,
updates: updateCount,
});
}
} else if (timeframe === "week") {
// Generate daily data for a week
const days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
for (let i = 0; i < 7; i++) {
const updateCount = Math.floor(Math.random() * 50) + 10;
data.push({
time: days[i],
updates: updateCount,
});
}
} else if (timeframe === "month") {
// Generate weekly data for a month
for (let i = 1; i <= 4; i++) {
const updateCount = Math.floor(Math.random() * 200) + 50;
data.push({
time: `Week ${i}`,
updates: updateCount,
});
}
}
return data;
};
if (isLoading) {
return (