removed unnecessary components #2
test-org/trust-module-frontend/pipeline/pr-rc This commit looks good
Details
test-org/trust-module-frontend/pipeline/pr-rc This commit looks good
Details
parent
f38c8825fe
commit
54cf5504a4
|
|
@ -4,7 +4,7 @@ import Dashboard from "./Components/Layout/Dashboard";
|
|||
import LoginModal from "./Components/UI/LoginModal";
|
||||
import { lightTheme, darkTheme } from "./Style/theme";
|
||||
import Logo from './assets/images/logo.svg?react';
|
||||
import { checkAuth } from "./Components/UI/auth"; // Убедитесь, что путь правильный
|
||||
import { checkAuth } from "./Components/UI/auth";
|
||||
|
||||
function App() {
|
||||
const [authState, setAuthState] = useState({
|
||||
|
|
|
|||
|
|
@ -1,85 +0,0 @@
|
|||
// src/services/StatusService.js
|
||||
import { statusManager1, statusManager2 } from "../TreeChart/dataUtils";
|
||||
|
||||
class StatusService {
|
||||
constructor() {
|
||||
this.statusData = null;
|
||||
this.subscribers = new Set();
|
||||
this.pollingInterval = null;
|
||||
}
|
||||
|
||||
// Подписка на обновления статусов
|
||||
subscribe(callback) {
|
||||
this.subscribers.add(callback);
|
||||
return () => this.unsubscribe(callback);
|
||||
}
|
||||
|
||||
unsubscribe(callback) {
|
||||
this.subscribers.delete(callback);
|
||||
}
|
||||
|
||||
// Запуск периодического обновления статусов
|
||||
startPolling(interval = 30000) {
|
||||
this.fetchStatuses(); // Первый запрос сразу
|
||||
this.pollingInterval = setInterval(() => this.fetchStatuses(), interval);
|
||||
}
|
||||
|
||||
stopPolling() {
|
||||
if (this.pollingInterval) {
|
||||
clearInterval(this.pollingInterval);
|
||||
this.pollingInterval = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Запрос статусов с бэкенда
|
||||
async fetchStatuses() {
|
||||
try {
|
||||
const response = await fetch('/api/metrics/all-values');
|
||||
const data = await response.json();
|
||||
|
||||
// Преобразуем данные в нужную структуру
|
||||
const transformedData = this.transformData(data);
|
||||
|
||||
// Обновляем статусы с помощью менеджера
|
||||
statusManager1.updateStatuses(transformedData);
|
||||
|
||||
// Сохраняем данные
|
||||
this.statusData = transformedData;
|
||||
|
||||
// Оповещаем подписчиков
|
||||
this.notifySubscribers();
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error fetching statuses:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Преобразование данных от бэкенда в древовидную структуру
|
||||
transformData(apiData) {
|
||||
// Здесь реализуйте преобразование под вашу структуру
|
||||
// Пример:
|
||||
return {
|
||||
name: "Root System",
|
||||
status: "0",
|
||||
items: apiData.map(item => ({
|
||||
id: item.metric.__name__,
|
||||
title: item.metric.__name__,
|
||||
status: item.data[0]?.status || "0",
|
||||
items: [] // Могут быть вложенные элементы
|
||||
}))
|
||||
};
|
||||
}
|
||||
|
||||
// Получение текущих данных
|
||||
getStatusData() {
|
||||
return this.statusData;
|
||||
}
|
||||
|
||||
// Оповещение подписчиков
|
||||
notifySubscribers() {
|
||||
this.subscribers.forEach(callback => callback(this.statusData));
|
||||
}
|
||||
}
|
||||
|
||||
// Экспортируем singleton экземпляр сервиса
|
||||
export const statusService = new StatusService();
|
||||
Loading…
Reference in New Issue