diff --git a/src/pages/ServerHistory/ServerHistory.jsx b/src/pages/ServerHistory/ServerHistory.jsx
index ed8d237..0c1b2aa 100644
--- a/src/pages/ServerHistory/ServerHistory.jsx
+++ b/src/pages/ServerHistory/ServerHistory.jsx
@@ -1,25 +1,25 @@
import { useEffect, useState, useRef } from 'react';
-import { useParams, useNavigate, useLocation } from 'react-router-dom';
+import { useParams, useNavigate } from 'react-router-dom';
import styles from './ServerHistory.module.scss';
import serviiApi from "../../service/api.tsx";
import Loading from '../Loading/loading.jsx';
import PropTypes from "prop-types";
-const ServerHistory = ({ user }) => {
+const ServerHistory = () => {
const navigate = useNavigate();
const { serverName } = useParams();
const [loading, setLoading] = useState(false);
const [error, setError] = useState(null);
- const [history, setHistory] = useState('');
- const location = useLocation();
- const status = location.state?.status;
+ const [history, setHistory] = useState([]);
+ const [filter, setFilter] = useState({
+ ServerCreate: true,
+ ServerRun: true,
+ Command: true,
+ UpdateProperties: true
+ });
const historyEndRef = useRef(null);
- const scrollToBottom = () => {
- historyEndRef.current?.scrollIntoView({ behavior: "smooth" });
- };
-
const fetchServerHistory = async () => {
setError(null);
setLoading(true);
@@ -28,16 +28,43 @@ const ServerHistory = ({ user }) => {
const response = await serviiApi.fetchHistory(serverName);
if (response.return_code === 200) {
let historyString = response.message;
- historyString = historyString.slice(1, -1);
+ historyString = historyString.slice(1, -1);
historyString = historyString.replace(/\\n/g, '\n');
- historyString = historyString.replace(/\\\"/g, '"');
- historyString = historyString.replace(/, ?/g, '');
- historyString = historyString.replace(/"{2,}/g, '');
+ historyString = historyString.replace(/\\"/g, '"');
+ historyString = historyString.replace(/, ?/g, '');
+ historyString = historyString.replace(/"{2,}/g, '');
historyString = historyString.replace(/'{2,}/g, '');
historyString = historyString.trim();
- setHistory(historyString);
+
+ console.log("History string after parsing:", historyString);
+
+ historyString = historyString.replace(/(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})(type": ")/g, '$1", "$2');
+ historyString = historyString.replace(/(type": "ServerCreate|ServerRun|Command|UpdateProperties)(details": )/g, '$1", "$2');
+
+ const historyArray = historyString.split('\n').map(entry => {
+ const timestampMatch = entry.match(/"timestamp": "(.*?)"/);
+ const typeMatch = entry.match(/"type": "(.*?)"/);
+ const detailsMatch = entry.match(/"details": "(.*?)"/);
+
+ const parsedEntry = {
+ timestamp: timestampMatch ? timestampMatch[1] : "Unknown",
+ type: typeMatch ? typeMatch[1] : "Unknown",
+ details: detailsMatch ? detailsMatch[1] : null
+ };
+
+ console.log("Parsed entry:", parsedEntry);
+
+ return parsedEntry;
+ });
+
+ console.log("Final history array:", historyArray);
+
+ setHistory(historyArray);
+ } else {
+ console.error("Failed to fetch history, response:", response);
}
} catch (err) {
+ console.error("Error fetching history:", err);
setError(`Erreur: ${err.message}`);
} finally {
setLoading(false);
@@ -48,9 +75,17 @@ const ServerHistory = ({ user }) => {
fetchServerHistory();
}, [serverName]);
- useEffect(() => {
- scrollToBottom();
- }, [history]);
+
+
+ const handleFilterChange = (event) => {
+ const { name, checked } = event.target;
+ setFilter(prevFilter => ({
+ ...prevFilter,
+ [name]: checked
+ }));
+ };
+
+ const filteredHistory = history.filter(item => filter[item.type]);
if (loading) {
return
- {history} -+