import { useState } from 'react' import { useMutation, useQueryClient } from '@tanstack/react-query' import { Loader2 } from 'lucide-react' import { api } from '@/lib/api' import { QK } from '@/lib/queryKeys' export function ExtendHistoryPanel({ caps, isRunning, earliestDate, onStart }: { caps: { label: string; capabilities: Record } | undefined isRunning: boolean earliestDate: string | null onStart: () => void }) { const qc = useQueryClient() const [value, setValue] = useState(6) const [unit, setUnit] = useState<'month' | 'year'>('month') const hasBatchCap = !!caps?.capabilities?.['kline.daily.batch'] const extend = useMutation({ mutationFn: () => api.extendHistory(value, unit), onSuccess: () => { onStart() qc.invalidateQueries({ queryKey: QK.pipelineJobs }) }, }) const offsetDays = unit === 'month' ? value * 30 : value * 365 const estimate = earliestDate ? (() => { const d = new Date(earliestDate) d.setDate(d.getDate() - offsetDays) return d.toISOString().slice(0, 10) })() : null return (
向前扩展历史数据
{value}
{(['month', 'year'] as const).map(u => ( ))}
{estimate && (
预计扩展至 {estimate} {earliestDate && (当前最早: {earliestDate})}
)} {!hasBatchCap && ( 需 Pro+ 权限 )}
) }