2026-03-28 15:00:45 +01:00
|
|
|
import { useNavigate } from 'react-router';
|
2026-03-28 13:55:13 +01:00
|
|
|
import { StatusDot, MonoText, Badge } from '@cameleer/design-system';
|
|
|
|
|
import { useCorrelationChain } from '../../api/queries/correlation';
|
|
|
|
|
import type { ExecutionDetail } from '../../components/ExecutionDiagram/types';
|
2026-03-28 14:49:45 +01:00
|
|
|
import styles from './ExchangeHeader.module.css';
|
2026-03-28 13:55:13 +01:00
|
|
|
|
|
|
|
|
interface ExchangeHeaderProps {
|
|
|
|
|
detail: ExecutionDetail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type StatusVariant = 'success' | 'error' | 'running' | 'warning';
|
|
|
|
|
|
|
|
|
|
function statusVariant(s: string): StatusVariant {
|
|
|
|
|
switch (s) {
|
|
|
|
|
case 'COMPLETED': return 'success';
|
|
|
|
|
case 'FAILED': return 'error';
|
|
|
|
|
case 'RUNNING': return 'running';
|
|
|
|
|
default: return 'warning';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-28 15:00:45 +01:00
|
|
|
function statusLabel(s: string): string {
|
|
|
|
|
switch (s) {
|
|
|
|
|
case 'COMPLETED': return 'OK';
|
|
|
|
|
case 'FAILED': return 'ERR';
|
|
|
|
|
case 'RUNNING': return 'RUN';
|
|
|
|
|
default: return s;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-28 13:55:13 +01:00
|
|
|
function formatDuration(ms: number): string {
|
|
|
|
|
if (ms >= 60_000) return `${(ms / 1000).toFixed(0)}s`;
|
|
|
|
|
if (ms >= 1000) return `${(ms / 1000).toFixed(2)}s`;
|
|
|
|
|
return `${ms}ms`;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-28 15:00:45 +01:00
|
|
|
export function ExchangeHeader({ detail }: ExchangeHeaderProps) {
|
|
|
|
|
const navigate = useNavigate();
|
2026-03-28 13:55:13 +01:00
|
|
|
const { data: chainResult } = useCorrelationChain(detail.correlationId ?? null);
|
|
|
|
|
const chain = chainResult?.data;
|
|
|
|
|
const showChain = chain && chain.length > 1;
|
2026-03-28 15:07:23 +01:00
|
|
|
const attrs = Object.entries(detail.attributes ?? {});
|
2026-03-28 13:55:13 +01:00
|
|
|
|
|
|
|
|
return (
|
2026-03-28 14:49:45 +01:00
|
|
|
<div className={styles.header}>
|
2026-03-28 15:00:45 +01:00
|
|
|
{/* Exchange info — always shown */}
|
|
|
|
|
<div className={styles.info}>
|
|
|
|
|
<StatusDot variant={statusVariant(detail.status)} />
|
|
|
|
|
<Badge label={statusLabel(detail.status)} color={statusVariant(detail.status)} />
|
2026-03-28 15:07:23 +01:00
|
|
|
{attrs.length > 0 && (
|
|
|
|
|
<>
|
|
|
|
|
<span className={styles.separator} />
|
|
|
|
|
{attrs.map(([k, v]) => (
|
|
|
|
|
<Badge key={k} label={`${k}: ${v}`} color="auto" />
|
|
|
|
|
))}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
<span className={styles.separator} />
|
2026-03-28 15:02:52 +01:00
|
|
|
<MonoText size="xs">{detail.exchangeId || detail.executionId}</MonoText>
|
2026-03-28 15:00:45 +01:00
|
|
|
<span className={styles.separator} />
|
|
|
|
|
<span className={styles.route}>{detail.routeId}</span>
|
|
|
|
|
<span className={styles.app}>{detail.applicationName}</span>
|
|
|
|
|
<span className={styles.duration}>{formatDuration(detail.durationMs)}</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Correlation chain — only when multiple correlated exchanges exist */}
|
2026-03-28 13:55:13 +01:00
|
|
|
{showChain && (
|
2026-03-28 14:49:45 +01:00
|
|
|
<div className={styles.chain}>
|
2026-03-28 15:00:45 +01:00
|
|
|
<span className={styles.chainLabel}>Correlated</span>
|
|
|
|
|
{chain.map((ce: any, i: number) => {
|
2026-03-28 14:49:45 +01:00
|
|
|
const isCurrent = ce.executionId === detail.executionId;
|
|
|
|
|
const variant = statusVariant(ce.status);
|
|
|
|
|
const statusCls =
|
|
|
|
|
variant === 'success' ? styles.chainNodeSuccess
|
|
|
|
|
: variant === 'error' ? styles.chainNodeError
|
|
|
|
|
: variant === 'running' ? styles.chainNodeRunning
|
|
|
|
|
: styles.chainNodeWarning;
|
|
|
|
|
return (
|
2026-03-28 15:00:45 +01:00
|
|
|
<span key={ce.executionId} className={styles.chainEntry}>
|
|
|
|
|
{i > 0 && <span className={styles.chainArrow}>→</span>}
|
|
|
|
|
<button
|
|
|
|
|
className={`${styles.chainNode} ${statusCls} ${isCurrent ? styles.chainNodeCurrent : ''}`}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
if (!isCurrent) {
|
|
|
|
|
navigate(`/exchanges/${ce.applicationName ?? detail.applicationName}/${ce.routeId}/${ce.executionId}`);
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
title={`${ce.executionId}\n${ce.routeId} \u2014 ${formatDuration(ce.durationMs)}`}
|
|
|
|
|
>
|
|
|
|
|
<StatusDot variant={variant} />
|
|
|
|
|
<span className={styles.chainRoute}>{ce.routeId}</span>
|
|
|
|
|
<span className={styles.chainDuration}>{formatDuration(ce.durationMs)}</span>
|
|
|
|
|
</button>
|
|
|
|
|
</span>
|
2026-03-28 14:49:45 +01:00
|
|
|
);
|
|
|
|
|
})}
|
2026-03-28 13:55:13 +01:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|