Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 2x 2x 2x 2x 2x 2x 4x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 22x 22x 22x 22x 22x 24x 1x 1x 1x 1x 1x 24x 1x 1x 1x 1x 1x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 4x 4x 4x 4x 4x 4x 4x 2x 2x 4x 4x 4x 4x 4x 4x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 24x 24x 24x 24x 24x 24x 1x 1x 1x 1x 1x 1x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 1x 1x | 'use client';
import React from 'react';
import { Sparklines, SparklinesLine, SparklinesReferenceLine } from 'react-sparklines';
import type { SLOResult } from '@/lib/observability/slo';
/**
* Sparkline data point
*/
export interface SparklinePoint {
value: number;
}
/**
* Trend indicator
*/
export interface TrendIndicator {
direction: 'up' | 'down' | 'stable';
change: number;
}
export interface SLOCardProps {
/** SLO name */
name: string;
/** Current value as percentage */
current: number;
/** Target value as percentage */
target: number;
/** Budget consumed percentage */
budgetConsumed: number;
/** SLO status */
status: SLOResult['status'];
/** Time window display text */
window: string;
/** Status color */
statusColor: string;
/** Status text */
statusText: string;
/** Optional sparkline data (recent values) */
sparklineData?: number[];
/** Optional trend indicator */
trendIndicator?: TrendIndicator | null;
/** Link to view full history */
historyLink?: string;
}
/**
* Get trend icon
*/
function TrendIcon({ direction }: { direction: 'up' | 'down' | 'stable' }) {
if (direction === 'up') {
return (
<svg className="w-4 h-4 text-green-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M7 11l5-5m0 0l5 5m-5-5v12" />
</svg>
);
}
if (direction === 'down') {
return (
<svg className="w-4 h-4 text-red-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M17 13l-5 5m0 0l-5-5m5 5V6" />
</svg>
);
}
return (
<svg className="w-4 h-4 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 12h14" />
</svg>
);
}
/**
* SLOCard Component
*
* Displays a single Service Level Objective with its current status,
* progress towards target, and error budget consumption.
*/
export function SLOCard({
name,
current,
target,
budgetConsumed,
// status is part of props but we use statusColor/statusText for display
status: _status,
window,
statusColor,
statusText,
sparklineData,
trendIndicator,
historyLink,
}: SLOCardProps) {
void _status; // Acknowledge unused prop that's part of the interface
const getStatusClasses = () => {
switch (statusColor) {
case 'green':
return {
badge: 'bg-green-100 dark:bg-green-900/30 text-green-800 dark:text-green-300',
progress: 'bg-green-500',
border: 'border-green-500',
};
case 'yellow':
return {
badge: 'bg-yellow-100 dark:bg-yellow-900/30 text-yellow-800 dark:text-yellow-300',
progress: 'bg-yellow-500',
border: 'border-yellow-500',
};
case 'red':
return {
badge: 'bg-red-100 dark:bg-red-900/30 text-red-800 dark:text-red-300',
progress: 'bg-red-500',
border: 'border-red-500',
};
default:
return {
badge: 'bg-gray-100 dark:bg-gray-700 text-gray-800 dark:text-gray-300',
progress: 'bg-gray-500',
border: 'border-gray-500',
};
}
};
const classes = getStatusClasses();
const progressWidth = Math.min(100, Math.max(0, (current / target) * 100));
return (
<div
className={`bg-white dark:bg-gray-800 rounded-lg shadow p-4 border-l-4 ${classes.border}`}
data-testid="slo-card"
>
<div className="flex justify-between items-start mb-2">
<h4 className="font-medium text-gray-900 dark:text-white text-sm">{name}</h4>
<span
className={`px-2 py-0.5 text-xs font-medium rounded ${classes.badge}`}
data-testid="slo-status-badge"
>
{statusText}
</span>
</div>
<div className="mb-3">
<div className="flex justify-between items-baseline mb-1">
<div className="flex items-center gap-2">
<span className="text-2xl font-bold text-gray-900 dark:text-white">
{current.toFixed(2)}%
</span>
{trendIndicator && (
<div className="flex items-center gap-1" data-testid="trend-indicator">
<TrendIcon direction={trendIndicator.direction} />
<span
className={`text-xs ${
trendIndicator.direction === 'up'
? 'text-green-500'
: trendIndicator.direction === 'down'
? 'text-red-500'
: 'text-gray-400'
}`}
>
{trendIndicator.change > 0 ? '+' : ''}
{trendIndicator.change.toFixed(2)}%
</span>
</div>
)}
</div>
<span className="text-sm text-gray-500 dark:text-gray-400">
Target: {target}%
</span>
</div>
{/* Progress bar */}
<div className="w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2">
<div
className={`h-2 rounded-full transition-all duration-300 ${classes.progress}`}
style={{ width: `${progressWidth}%` }}
role="progressbar"
aria-valuenow={current}
aria-valuemin={0}
aria-valuemax={target}
/>
</div>
</div>
{/* Sparkline */}
{sparklineData && sparklineData.length > 0 && (
<div className="mb-3" data-testid="sparkline">
<Sparklines data={sparklineData} height={30} margin={2}>
<SparklinesLine
color={statusColor === 'green' ? '#22c55e' : statusColor === 'yellow' ? '#eab308' : '#ef4444'}
style={{ strokeWidth: 1.5, fill: 'none' }}
/>
<SparklinesReferenceLine
type="custom"
value={target}
style={{ stroke: '#ef4444', strokeDasharray: '2 2', strokeOpacity: 0.5 }}
/>
</Sparklines>
</div>
)}
<div className="flex justify-between items-center text-xs">
<div className="flex items-center gap-2">
<span className="text-gray-500 dark:text-gray-400">{window}</span>
{historyLink && (
<a
href={historyLink}
className="text-blue-500 hover:text-blue-600 dark:text-blue-400 dark:hover:text-blue-300"
>
View History
</a>
)}
</div>
<span
className={`${budgetConsumed > 80 ? 'text-red-600 dark:text-red-400' : 'text-gray-500 dark:text-gray-400'}`}
>
Error budget: {(100 - budgetConsumed).toFixed(1)}% remaining
</span>
</div>
</div>
);
}
export default SLOCard;
|