Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal : Redesign the website's heading #23

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 35 additions & 118 deletions frontend/src/components/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,12 @@ import {
CircularProgress,
} from "@mui/material";
import RefreshIcon from "@mui/icons-material/Refresh";

import StatCard from "./Charts/StatCard";
import JobStatusPieChart from "./Charts/JobStatusPieChart";
import QueueResourcesBarChart from "./Charts/QueueResourcesBarChart";

const Dashboard = () => {
const [dashboardData, setDashboardData] = useState({
jobs: [],
queues: [],
pods: [],
});
const [dashboardData, setDashboardData] = useState({ jobs: [], queues: [], pods: [] });
const [isLoading, setIsLoading] = useState(true);
const [refreshing, setRefreshing] = useState(false);
const [error, setError] = useState(null);
Expand Down Expand Up @@ -50,164 +45,86 @@ const Dashboard = () => {
pods: podsData.items || [],
});
} catch (error) {
console.error("Error fetching dashboard data:", error);
setError(error.message);
} finally {
setRefreshing(false);
setIsLoading(false);
}
};

const handleRefresh = () => {
fetchAllData();
};

useEffect(() => {
fetchAllData();
}, []);

return (
<Box
sx={{
height: "100vh",
display: "flex",
flexDirection: "column",
p: 3,
}}
>
<Box sx={{ height: "100vh", p: 3, bgcolor: "#f4f6f8" }}>
{error && (
<Paper
sx={{
p: 2,
mb: 2,
bgcolor: "error.light",
color: "error.contrastText",
}}
>
<Paper sx={{ p: 2, mb: 2, bgcolor: "error.light", color: "error.contrastText" }}>
<Typography>{error}</Typography>
</Paper>
)}

<Box
sx={{
display: "flex",
justifyContent: "space-between",
alignItems: "center",
mb: 3,
}}
>
<Typography variant="h4">Volcano Dashboard</Typography>
<Box sx={{ display: "flex", justifyContent: "space-between", alignItems: "center", mb: 3 }}>
<Typography
variant="h4"
sx={{
fontWeight: "bold",
background: "linear-gradient(45deg, #ff9800, #ff5722)",
WebkitBackgroundClip: "text",
color: "transparent",
}}
>
Volcano Dashboard
</Typography>
<Tooltip title="Refresh Data">
<IconButton onClick={handleRefresh} disabled={refreshing}>
<RefreshIcon />
<IconButton onClick={fetchAllData} disabled={refreshing}>
<RefreshIcon sx={{ color: "#ff9800", transition: "0.3s", '&:hover': { color: "#ff5722" } }} />
</IconButton>
</Tooltip>
</Box>

<Grid container spacing={3} sx={{ mb: 3 }}>
<Grid container spacing={3}>
<Grid item xs={12} sm={6} md={3}>
<StatCard title="Total Jobs" value={dashboardData.jobs?.length || 0} />
</Grid>
<Grid item xs={12} sm={6} md={3}>
<StatCard
title="Active Queues"
value={
dashboardData.queues?.filter((q) => q.status?.state === "Open")
?.length || 0
}
/>
<StatCard title="Active Queues" value={dashboardData.queues?.filter(q => q.status?.state === "Open")?.length || 0} />
</Grid>
<Grid item xs={12} sm={6} md={3}>
<StatCard
title="Running Pods"
value={
dashboardData.pods?.filter((p) => p.status?.phase === "Running")
?.length || 0
}
/>
<StatCard title="Running Pods" value={dashboardData.pods?.filter(p => p.status?.phase === "Running")?.length || 0} />
</Grid>
<Grid item xs={12} sm={6} md={3}>
<StatCard
title="Complete Rate"
value={`${calculateSuccessRate(dashboardData.jobs)}%`}
/>
<StatCard title="Complete Rate" value={`${calculateSuccessRate(dashboardData.jobs)}%`} />
</Grid>
</Grid>

<Grid container spacing={3} sx={{ flex: 1, minHeight: 0, mb: 3 }}>
<Grid container spacing={3} sx={{ mt: 3 }}>
<Grid item xs={12} md={6}>
<Paper
sx={{
height: "calc(100vh - 250px)",
display: "flex",
flexDirection: "column",
p: 2,
}}
>
{isLoading ? (
<Box
sx={{
display: "flex",
justifyContent: "center",
alignItems: "center",
flex: 1,
}}
>
<CircularProgress />
</Box>
) : (
<Box sx={{ height: "100%" }}>
<JobStatusPieChart data={dashboardData.jobs} />
</Box>
)}
<Paper sx={{ height: "400px", p: 2, boxShadow: 3, borderRadius: 2 }}>
{isLoading ? <LoadingIndicator /> : <JobStatusPieChart data={dashboardData.jobs} />}
</Paper>
</Grid>

<Grid item xs={12} md={6}>
<Paper
sx={{
height: "calc(100vh - 250px)",
display: "flex",
flexDirection: "column",
p: 2,
}}
>
{isLoading ? (
<Box
sx={{
display: "flex",
justifyContent: "center",
alignItems: "center",
flex: 1,
}}
>
<CircularProgress />
</Box>
) : (
<Box sx={{ height: "100%" }}>
<QueueResourcesBarChart data={dashboardData.queues} />
</Box>
)}
<Paper sx={{ height: "400px", p: 2, boxShadow: 3, borderRadius: 2 }}>
{isLoading ? <LoadingIndicator /> : <QueueResourcesBarChart data={dashboardData.queues} />}
</Paper>
</Grid>
</Grid>
</Box>
);
};

const LoadingIndicator = () => (
<Box sx={{ display: "flex", justifyContent: "center", alignItems: "center", height: "100%" }}>
<CircularProgress />
</Box>
);

const calculateSuccessRate = (jobs) => {
if (!jobs || jobs.length === 0) return 0;
const completed = jobs.filter(
(job) => job.status?.succeeded || job.status?.state?.phase === "Completed"
).length;
const finished = jobs.filter(
(job) =>
job.status?.succeeded ||
job.status?.failed ||
job.status?.state?.phase === "Completed" ||
job.status?.state?.phase === "Failed"
).length;
const completed = jobs.filter(job => job.status?.succeeded || job.status?.state?.phase === "Completed").length;
const finished = jobs.filter(job => job.status?.succeeded || job.status?.failed || job.status?.state?.phase === "Completed" || job.status?.state?.phase === "Failed").length;
return finished === 0 ? 0 : Math.round((completed / finished) * 100);
};

export default Dashboard;
export default Dashboard;