view data fixes

This commit is contained in:
2026-01-24 00:52:27 +01:00
parent 62e8b768ce
commit ae59df61eb
321 changed files with 1157 additions and 2234 deletions

View File

@@ -1,80 +1,44 @@
/**
* Health View Data Builder
*
* Transforms health DTO data into UI-ready view models.
* This layer isolates the UI from API churn by providing a stable interface
* between the API layer and the presentation layer.
*/
'use client';
import type { HealthDTO } from '@/lib/types/generated/HealthDTO';
import type { HealthViewData, HealthStatus, HealthMetrics, HealthComponent, HealthAlert } from '@/lib/view-data/HealthViewData';
import { HealthStatusDisplay } from '@/lib/display-objects/HealthStatusDisplay';
import { HealthMetricDisplay } from '@/lib/display-objects/HealthMetricDisplay';
import { HealthComponentDisplay } from '@/lib/display-objects/HealthComponentDisplay';
import { HealthAlertDisplay } from '@/lib/display-objects/HealthAlertDisplay';
import type { ViewDataBuilder } from '@/lib/contracts/builders/ViewDataBuilder';
export interface HealthDTO {
status: 'ok' | 'degraded' | 'error' | 'unknown';
timestamp: string;
uptime?: number;
responseTime?: number;
errorRate?: number;
lastCheck?: string;
checksPassed?: number;
checksFailed?: number;
components?: Array<{
name: string;
status: 'ok' | 'degraded' | 'error' | 'unknown';
lastCheck?: string;
responseTime?: number;
errorRate?: number;
}>;
alerts?: Array<{
id: string;
type: 'critical' | 'warning' | 'info';
title: string;
message: string;
timestamp: string;
}>;
}
import { ViewDataBuilder } from "../../contracts/builders/ViewDataBuilder";
export class HealthViewDataBuilder implements ViewDataBuilder<any, any> {
build(input: any): any {
return HealthViewDataBuilder.build(input);
}
static build(
static build(dto: HealthDTO): HealthViewData {
export class HealthViewDataBuilder {
public static build(apiDto: HealthDTO): HealthViewData {
const now = new Date();
const lastUpdated = dto.timestamp || now.toISOString();
const lastUpdated = apiDto.timestamp || now.toISOString();
// Build overall status
const overallStatus: HealthStatus = {
status: dto.status,
timestamp: dto.timestamp,
formattedTimestamp: HealthStatusDisplay.formatTimestamp(dto.timestamp),
relativeTime: HealthStatusDisplay.formatRelativeTime(dto.timestamp),
statusLabel: HealthStatusDisplay.formatStatusLabel(dto.status),
statusColor: HealthStatusDisplay.formatStatusColor(dto.status),
statusIcon: HealthStatusDisplay.formatStatusIcon(dto.status),
status: apiDto.status,
timestamp: apiDto.timestamp,
formattedTimestamp: HealthStatusDisplay.formatTimestamp(apiDto.timestamp),
relativeTime: HealthStatusDisplay.formatRelativeTime(apiDto.timestamp),
statusLabel: HealthStatusDisplay.formatStatusLabel(apiDto.status),
statusColor: HealthStatusDisplay.formatStatusColor(apiDto.status),
statusIcon: HealthStatusDisplay.formatStatusIcon(apiDto.status),
};
// Build metrics
const metrics: HealthMetrics = {
uptime: HealthMetricDisplay.formatUptime(dto.uptime),
responseTime: HealthMetricDisplay.formatResponseTime(dto.responseTime),
errorRate: HealthMetricDisplay.formatErrorRate(dto.errorRate),
lastCheck: dto.lastCheck || lastUpdated,
formattedLastCheck: HealthMetricDisplay.formatTimestamp(dto.lastCheck || lastUpdated),
checksPassed: dto.checksPassed || 0,
checksFailed: dto.checksFailed || 0,
totalChecks: (dto.checksPassed || 0) + (dto.checksFailed || 0),
successRate: HealthMetricDisplay.formatSuccessRate(dto.checksPassed, dto.checksFailed),
uptime: HealthMetricDisplay.formatUptime(apiDto.uptime),
responseTime: HealthMetricDisplay.formatResponseTime(apiDto.responseTime),
errorRate: HealthMetricDisplay.formatErrorRate(apiDto.errorRate),
lastCheck: apiDto.lastCheck || lastUpdated,
formattedLastCheck: HealthMetricDisplay.formatTimestamp(apiDto.lastCheck || lastUpdated),
checksPassed: apiDto.checksPassed || 0,
checksFailed: apiDto.checksFailed || 0,
totalChecks: (apiDto.checksPassed || 0) + (apiDto.checksFailed || 0),
successRate: HealthMetricDisplay.formatSuccessRate(apiDto.checksPassed, apiDto.checksFailed),
};
// Build components
const components: HealthComponent[] = (dto.components || []).map((component) => ({
const components: HealthComponent[] = (apiDto.components || []).map((component) => ({
name: component.name,
status: component.status,
statusLabel: HealthComponentDisplay.formatStatusLabel(component.status),
@@ -87,7 +51,7 @@ export class HealthViewDataBuilder implements ViewDataBuilder<any, any> {
}));
// Build alerts
const alerts: HealthAlert[] = (dto.alerts || []).map((alert) => ({
const alerts: HealthAlert[] = (apiDto.alerts || []).map((alert) => ({
id: alert.id,
type: alert.type,
title: alert.title,
@@ -117,3 +81,5 @@ export class HealthViewDataBuilder implements ViewDataBuilder<any, any> {
};
}
}
HealthViewDataBuilder satisfies ViewDataBuilder<HealthDTO, HealthViewData>;