/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useEffect, useState } from 'react';
import {
Layout,
Card,
Tag,
Grid,
Typography,
Progress,
Spin,
Empty,
} from '@/components/ui';
import { Iconbolt, IconActivity } from '@/components/ui/icons';
import { useTranslation } from 'react-i18next';
import { API, showError } from '../../helpers';
import { formatPercent } from '../../helpers/safeDisplay';
const { Content } = Layout;
const { Text, Title } = Typography;
const { Row, Col } = Grid;
const Status = () => {
const { t } = useTranslation();
const [loading, setLoading] = useState(true);
const [data, setData] = useState([]);
useEffect(() => {
const fetchData = async () => {
try {
const res = await API.get('/api/channels/status');
const { success, message, data } = res.data;
if (success) {
setData(data);
} else {
showError(message);
}
} catch (error) {
showError(error);
} finally {
setLoading(false);
}
};
fetchData();
}, []);
const renderScore = (uptime) => {
let percent = Math.round(uptime * 100);
let color = 'success';
if (percent < 80) color = 'warning';
if (percent < 50) color = 'danger';
// Segmented bar simulation using multiple small bars or just a styled progress
// Requirement: "Segmented energy bar"
// We can simulate this with a customized progress bar or just standard one for now.
// For "smooth high level line", a high uptime bar looks like a high line.
return (
);
};
const renderStatus = (status, responseTime) => {
// status: 1=up, 2=maintenance, 0=down
let text = t('Available');
if (status === 2) {
text = t('Maintenance');
} else if (status === 0) {
text = t('Unavailable');
}
return (
{text}
{/* Fast Indicator */}
{status === 1 && responseTime > 0 && responseTime < 1000 && (
}>
{t('Fast')}
)}
);
};
return (
{t('System Status Monitor')}
{t('Real-time monitoring of all available services')}
{loading ? (
) : data.length === 0 ? (
}
description={t('No data available')}
/>
) : (
data.map((group, gIndex) => (
{group.monitors.map((item, mIndex) => (
{item.name}
{/* Optional: Add latency text if needed */}
{renderStatus(item.status, item.response_time)}
{/* Energy Bar / Uptime Bar */}
{renderScore(item.uptime)}
{item.response_time > 0 && (
{t('Response')}: {item.response_time}ms
)}
))}
))
)}
);
};
export default Status;