Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | import { useState, useEffect } from 'react'
import { Route, X, CheckCircle, XCircle, Loader2, Database } from 'lucide-react'
function RoutingViewerModal({ isOpen, onClose, routing, title }) {
const [loading, setLoading] = useState(true)
const [routingData, setRoutingData] = useState(null)
useEffect(() => {
if (!isOpen) return
const handleEscape = (e) => {
if (e.key === 'Escape') onClose()
}
window.addEventListener('keydown', handleEscape)
return () => window.removeEventListener('keydown', handleEscape)
}, [isOpen, onClose])
useEffect(() => {
if (!isOpen || !routing?.url) {
setLoading(false)
return
}
setLoading(true)
setRoutingData(null)
fetch(routing.url)
.then(res => res.json())
.then(data => {
setRoutingData(data)
setLoading(false)
})
.catch(err => {
console.error('Failed to fetch routing data:', err)
setLoading(false)
})
}, [isOpen, routing])
if (!isOpen || !routing) return null
const routes = routingData?.results?.routes || []
const kbStats = {}
routes.forEach(r => {
if (!kbStats[r.knowledgeBaseId]) {
kbStats[r.knowledgeBaseId] = {
name: r.knowledgeBaseName || r.knowledgeBaseId,
success: 0,
failed: 0,
errors: []
}
}
if (r.success) {
kbStats[r.knowledgeBaseId].success++
} else {
kbStats[r.knowledgeBaseId].failed++
if (r.error) {
kbStats[r.knowledgeBaseId].errors.push(r.error)
}
}
})
const { routed = 0, failed = 0, skipped = false, reason } = routing.metadata || {}
return (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4">
<div className="bg-white rounded-xl shadow-2xl max-w-2xl w-full max-h-[85vh] overflow-hidden flex flex-col">
<div className="flex items-center justify-between p-4 border-b">
<div className="flex items-center gap-3">
<Route className="w-5 h-5 text-gray-600" />
<div>
<h3 className="text-lg font-semibold text-gray-900">Routage vers les bases de connaissances</h3>
<p className="text-sm text-gray-500">{title}</p>
</div>
</div>
<button
onClick={onClose}
className="p-2 hover:bg-gray-100 rounded-full transition-colors"
>
<X className="w-5 h-5 text-gray-500" />
</button>
</div>
{loading ? (
<div className="flex-1 flex items-center justify-center p-8">
<Loader2 className="w-8 h-8 animate-spin text-gray-400" />
</div>
) : (
<>
<div className="p-4 bg-gray-50 border-b">
<h4 className="text-sm font-medium text-gray-700 mb-3">Résumé</h4>
<div className="grid grid-cols-3 gap-4">
<div className="bg-white rounded-lg p-3 border">
<div className="text-2xl font-bold text-green-600">{routed}</div>
<div className="text-sm text-gray-500">Faits routés</div>
</div>
<div className="bg-white rounded-lg p-3 border">
<div className="text-2xl font-bold text-red-600">{failed}</div>
<div className="text-sm text-gray-500">Échecs</div>
</div>
<div className="bg-white rounded-lg p-3 border">
<div className="text-2xl font-bold text-gray-600">{Object.keys(kbStats).length}</div>
<div className="text-sm text-gray-500">Bases ciblées</div>
</div>
</div>
{skipped && (
<p className="mt-2 text-xs text-gray-500 italic">
Routage ignoré: {reason || 'raison non spécifiée'}
</p>
)}
</div>
{Object.keys(kbStats).length > 0 && (
<div className="flex-1 overflow-auto p-4">
<h4 className="text-sm font-medium text-gray-700 mb-3">Statistiques par base de connaissances</h4>
<div className="space-y-3">
{Object.entries(kbStats).map(([kbId, stats]) => (
<div key={kbId} className="bg-white rounded-lg p-4 border">
<div className="flex items-center justify-between mb-2">
<div className="flex items-center gap-2">
<Database className="w-4 h-4 text-gray-400" />
<span className="font-medium text-gray-900">{stats.name}</span>
</div>
<div className="flex items-center gap-3 text-sm">
{stats.success > 0 && (
<span className="flex items-center gap-1 text-green-600">
<CheckCircle className="w-4 h-4" />
{stats.success} réussi{stats.success > 1 ? 's' : ''}
</span>
)}
{stats.failed > 0 && (
<span className="flex items-center gap-1 text-red-600">
<XCircle className="w-4 h-4" />
{stats.failed} échoué{stats.failed > 1 ? 's' : ''}
</span>
)}
</div>
</div>
{stats.errors.length > 0 && (
<div className="mt-2 text-xs text-red-600 bg-red-50 rounded p-2">
{stats.errors[0]}
{stats.errors.length > 1 && ` (+${stats.errors.length - 1} autres erreurs)`}
</div>
)}
</div>
))}
</div>
</div>
)}
</>
)}
<div className="p-3 bg-gray-50 border-t text-center text-sm text-gray-500">
Appuyez sur Echap pour fermer
</div>
</div>
</div>
)
}
export default RoutingViewerModal
|