openreplay/frontend/app/components/Header/HealthStatus/getHealth.ts
Andrey Babushkin fd5c0c9747
Add lokalisation (#3092)
* applied eslint

* add locales and lint the project

* removed error boundary

* updated locales

* fix min files

* fix locales
2025-03-06 17:43:15 +01:00

52 lines
1.6 KiB
TypeScript

import { healthService } from 'App/services';
import {
categoryKeyNames,
lastAskedKey,
healthResponseKey,
} from 'Components/Header/HealthStatus/const';
import { IServiceStats } from 'Components/Header/HealthStatus/HealthStatus';
function mapResponse(resp: Record<string, any>) {
const services = Object.keys(resp);
const healthMap: Record<string, IServiceStats> = {};
services.forEach((service) => {
if (service === 'details') return;
if (service === 'ssl') {
healthMap[service] = {
name: categoryKeyNames[service],
healthOk: resp[service].health,
serviceName: service,
// @ts-ignore
subservices: { ssl: resp[service] },
};
return;
}
healthMap[service] = {
// @ts-ignore
name: categoryKeyNames[service],
healthOk: true,
subservices: resp[service],
serviceName: service,
};
Object.values(healthMap[service].subservices).forEach(
(subservice: Record<string, any>) => {
if (!subservice?.health) healthMap[service].healthOk = false;
},
);
});
const overallHealth = Object.values(healthMap).every(
(service: Record<string, any>) => service.healthOk,
);
return { overallHealth, healthMap, details: resp.details };
}
export async function getHealthRequest(isPublic?: boolean) {
const r = await healthService.fetchStatus(isPublic);
const healthMap = mapResponse(r);
const asked = new Date().getTime();
localStorage.setItem(healthResponseKey, JSON.stringify(healthMap));
localStorage.setItem(lastAskedKey, asked.toString());
return { healthMap, asked };
}