diff --git a/frontend/src/app/data/page.tsx b/frontend/src/app/data/page.tsx index 44feb217..baa0612c 100644 --- a/frontend/src/app/data/page.tsx +++ b/frontend/src/app/data/page.tsx @@ -3,7 +3,6 @@ import React, { useEffect, useState } from "react"; import DatePicker from 'react-datepicker'; import 'react-datepicker/dist/react-datepicker.css'; -import { string } from "zod"; import ApplicationChart from "../../components/ApplicationChart"; interface DataModel { @@ -35,9 +34,11 @@ const DataFetcher: React.FC = () => { const [startDate, setStartDate] = useState(null); const [endDate, setEndDate] = useState(null); const [sortConfig, setSortConfig] = useState<{ key: keyof DataModel | null, direction: 'ascending' | 'descending' }>({ key: 'id', direction: 'descending' }); - const [itemsPerPage, setItemsPerPage] = useState(5); + const [itemsPerPage, setItemsPerPage] = useState(25); const [currentPage, setCurrentPage] = useState(1); - const [showChart, setShowChart] = useState(false); + const [interval, setIntervalTime] = useState(10); // Default interval 10 seconds + const [reloadInterval, setReloadInterval] = useState(null); + useEffect(() => { const fetchData = async () => { @@ -117,9 +118,59 @@ const DataFetcher: React.FC = () => { const paginatedData = sortedData.slice((currentPage - 1) * itemsPerPage, currentPage * itemsPerPage); + useEffect(() => { + const storedInterval = localStorage.getItem('reloadInterval'); + if (storedInterval) { + setIntervalTime(Number(storedInterval)); + } + }, []); + + + useEffect(() => { + if (interval <= 10) { + const newInterval = setInterval(() => { + window.location.reload(); + }, 10000); + + + return () => clearInterval(newInterval); + } else { + const newInterval = setInterval(() => { + window.location.reload(); + }, interval * 1000); + } + + }, [interval]); + + + useEffect(() => { + if (interval > 0) { + localStorage.setItem('reloadInterval', interval.toString()); + } else { + localStorage.removeItem('reloadInterval'); + } + }, [interval]); + if (loading) return

Loading...

; if (error) return

Error: {error}

; + var installingCounts: number = 0; + var failedCounts: number = 0; + var doneCounts: number = 0 + var unknownCounts: number = 0; + data.forEach((item) => { + if (item.status === "installing") { + installingCounts += 1; + } else if (item.status === "failed") { + failedCounts += 1; + } + else if (item.status === "done") { + doneCounts += 1; + } + else { + unknownCounts += 1; + } + }); return (
@@ -160,10 +211,24 @@ const DataFetcher: React.FC = () => { />
+ +
+
+ setIntervalTime(Number(e.target.value))} + className="p-2 border" + placeholder="Interval (seconds)" + /> + +
+

{filteredData.length} results found

+

Status Legend: 🔄 installing {installingCounts} | ✔️ completetd {doneCounts} | ❌ failed {failedCounts} | ❓ unknown {unknownCounts}