File size: 2,392 Bytes
0a7c6ee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { useEffect, useState } from 'react';
import { api } from '../api';

export default function SimulationList({ refreshTrigger, onSelect }) {
    const [simulations, setSimulations] = useState([]);
    const [error, setError] = useState(null);

    useEffect(() => {
        loadSimulations();
    }, [refreshTrigger]);

    const loadSimulations = async () => {
        try {
            const data = await api.getSimulations();
            console.log('Simulations loaded:', data);
            setSimulations(data);
            setError(null);
        } catch (err) {
            console.error('Error loading simulations:', err);
            setError(err.message);
        }
    };

    const getStatusClass = (status) => {
        switch (status) {
            case 'completed': return 'status-completed';
            case 'running': return 'status-running';
            case 'failed': return 'status-failed';
            default: return 'status-pending';
        }
    };

    return (
        <div className="simulation-list">
            <h2>Simulations récentes</h2>
            {error && <div className="error">Erreur: {error}</div>}
            {simulations.length === 0 && !error && <p>Aucune simulation pour le moment.</p>}
            <table>
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>Nom</th>
                        <th>Status</th>
                        <th>Créée</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    {simulations.map(sim => (
                        <tr key={sim.id} onClick={() => onSelect(sim)}>
                            <td>#{sim.id}</td>
                            <td>{sim.name}</td>
                            <td>
                                <span className={`status ${getStatusClass(sim.status)}`}>
                                    {sim.status}
                                </span>
                            </td>
                            <td>{new Date(sim.created_at).toLocaleString()}</td>
                            <td>
                                {sim.status === 'completed' && 'Voir résultats'}
                            </td>
                        </tr>
                    ))}
                </tbody>
            </table>
        </div>
    );
}