Initial commit

This commit is contained in:
Orionis312050 committed 2026-04-16 14:18:56 +02:00
commit e6e07dc5c2
30 files changed
+5948

No files matched your search

+125
View File
@@ -0,0 +1,125 @@
import React, { useState, useEffect } from 'react';
import { useNavigate, useParams } from 'react-router-dom';
import { ArrowLeft, Server, HardDrive, Trash2 } from 'lucide-react';
import type { LogService } from '../types';
import LogTerminal from '../components/LogTerminal';
function DeleteWithConfirmation({ onDelete, serviceName }: { onDelete: () => void, serviceName: string }) {
const [showConfirm, setShowConfirm] = useState(false);
if (showConfirm) {
return (
<div className="delete-confirm-box">
<span>Supprimer {serviceName} ?</span>
<button className="btn btn-danger btn-sm" onClick={onDelete}>Oui</button>
<button className="btn btn-sm" onClick={() => setShowConfirm(false)}>Non</button>
</div>
);
}
return (
<button className="btn btn-danger-outline btn-sm" onClick={() => setShowConfirm(true)}>
<Trash2 size={16} />
<span>Supprimer</span>
</button>
);
}
export default function ServiceView() {
const { id } = useParams<{ id: string }>();
const navigate = useNavigate();
const [service, setService] = useState<LogService | null>(null);
const [initialLogs, setInitialLogs] = useState<{ id: string, line: string, isError: boolean }[]>([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
const fetchServiceAndLogs = async () => {
try {
const [svcRes, logsRes] = await Promise.all([
fetch(`http://localhost:3001/api/services`, {
credentials: 'include'
}),
fetch(`http://localhost:3001/api/services/${id}/logs`, {
credentials: 'include'
})
]);
const allServices = await svcRes.json();
const logs = await logsRes.json();
const found = allServices.find((s: LogService) => s.id === Number(id));
if (found) {
setService(found);
setInitialLogs(logs);
updateRecentHistory(Number(id));
} else {
navigate('/');
}
} catch (e) {
console.error(e);
} finally {
setLoading(false);
}
};
fetchServiceAndLogs();
}, [id]);
const updateRecentHistory = (id: number) => {
const recents: number[] = JSON.parse(localStorage.getItem('recentServiceIds') || '[]');
// Filtrer si déjà présent et mettre au début
const filtered = recents.filter(rid => rid !== id);
const updated = [id, ...filtered].slice(0, 5); // Garder les 5 derniers
localStorage.setItem('recentServiceIds', JSON.stringify(updated));
};
const handleDelete = async () => {
try {
await fetch(`http://localhost:3001/api/services/${id}`, {
method: 'DELETE',
credentials: 'include'
});
navigate('/');
} catch (err) {
console.error(err);
}
};
if (loading) return <div className="loading-state">Chargement du service...</div>;
if (!service) return <div className="loading-state">Service introuvable.</div>;
return (
<div className="service-view fade-in">
<button className="btn btn-back" onClick={() => navigate('/')}>
<ArrowLeft size={18} />
Retour à l'accueil
</button>
<div className="glass-panel service-view-container" style={{ marginTop: '1rem', padding: 0, overflow: 'hidden' }}>
<div className="service-view-header">
<div className="service-info-main">
<div className="service-icon-wrapper">
{service.type === 'docker' ? <Server size={24} /> : <HardDrive size={24} />}
</div>
<div>
<h3 className="service-title">{service.name}</h3>
<span className="service-subtitle">{service.pathOrContainerId}</span>
</div>
</div>
<div className="service-actions">
<DeleteWithConfirmation
onDelete={handleDelete}
serviceName={service.name}
/>
</div>
</div>
<div style={{ padding: '1rem' }}>
<LogTerminal service={service} initialLogs={initialLogs} />
</div>
</div>
</div>
);
}