2026-03-28 13:57:13 +01:00
|
|
|
import { useState, useMemo, useCallback } from 'react';
|
|
|
|
|
import { useParams } from 'react-router';
|
|
|
|
|
import { useGlobalFilters } from '@cameleer/design-system';
|
2026-03-28 14:22:34 +01:00
|
|
|
import { useExecutionDetail } from '../../api/queries/executions';
|
2026-03-28 13:57:13 +01:00
|
|
|
import { useDiagramByRoute } from '../../api/queries/diagrams';
|
|
|
|
|
import { useRouteCatalog } from '../../api/queries/catalog';
|
|
|
|
|
import { ExchangeHeader } from './ExchangeHeader';
|
|
|
|
|
import { ExecutionDiagram } from '../../components/ExecutionDiagram/ExecutionDiagram';
|
|
|
|
|
import { ProcessDiagram } from '../../components/ProcessDiagram';
|
|
|
|
|
import styles from './ExchangesPage.module.css';
|
|
|
|
|
|
2026-03-28 14:22:34 +01:00
|
|
|
// The full-width Dashboard table — used at every scope level
|
2026-03-28 13:57:13 +01:00
|
|
|
import Dashboard from '../Dashboard/Dashboard';
|
|
|
|
|
|
|
|
|
|
export default function ExchangesPage() {
|
|
|
|
|
const { appId, routeId, exchangeId } = useParams<{
|
|
|
|
|
appId?: string; routeId?: string; exchangeId?: string;
|
|
|
|
|
}>();
|
|
|
|
|
|
2026-03-28 14:22:34 +01:00
|
|
|
// No route scoped: full-width Dashboard
|
2026-03-28 13:57:13 +01:00
|
|
|
if (!routeId) {
|
|
|
|
|
return <Dashboard />;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-28 14:22:34 +01:00
|
|
|
// Route scoped: 50:50 split — Dashboard table on left, diagram on right
|
2026-03-28 13:57:13 +01:00
|
|
|
return (
|
2026-03-28 14:22:34 +01:00
|
|
|
<div className={styles.splitView}>
|
|
|
|
|
<div className={styles.leftPanel}>
|
|
|
|
|
<Dashboard />
|
|
|
|
|
</div>
|
|
|
|
|
<div className={styles.rightPanel}>
|
|
|
|
|
<DiagramPanel appId={appId!} routeId={routeId} exchangeId={exchangeId} />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-03-28 13:57:13 +01:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-28 14:22:34 +01:00
|
|
|
// ─── Right panel: diagram + optional execution overlay ──────────────────────
|
2026-03-28 13:57:13 +01:00
|
|
|
|
2026-03-28 14:22:34 +01:00
|
|
|
interface DiagramPanelProps {
|
2026-03-28 13:57:13 +01:00
|
|
|
appId: string;
|
|
|
|
|
routeId: string;
|
2026-03-28 14:22:34 +01:00
|
|
|
exchangeId?: string;
|
2026-03-28 13:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
2026-03-28 14:22:34 +01:00
|
|
|
function DiagramPanel({ appId, routeId, exchangeId }: DiagramPanelProps) {
|
2026-03-28 13:57:13 +01:00
|
|
|
const { timeRange } = useGlobalFilters();
|
|
|
|
|
const timeFrom = timeRange.start.toISOString();
|
|
|
|
|
const timeTo = timeRange.end.toISOString();
|
|
|
|
|
|
2026-03-28 14:22:34 +01:00
|
|
|
// Fetch execution detail if an exchange is selected
|
|
|
|
|
const { data: detail } = useExecutionDetail(exchangeId ?? null);
|
2026-03-28 13:57:13 +01:00
|
|
|
|
2026-03-28 14:22:34 +01:00
|
|
|
// Fetch diagram for topology-only view
|
2026-03-28 13:57:13 +01:00
|
|
|
const diagramQuery = useDiagramByRoute(appId, routeId);
|
|
|
|
|
|
2026-03-28 14:22:34 +01:00
|
|
|
// Known route IDs for drill-down
|
2026-03-28 13:57:13 +01:00
|
|
|
const { data: catalog } = useRouteCatalog(timeFrom, timeTo);
|
|
|
|
|
const knownRouteIds = useMemo(() => {
|
|
|
|
|
const ids = new Set<string>();
|
|
|
|
|
if (catalog) {
|
|
|
|
|
for (const app of catalog as any[]) {
|
|
|
|
|
for (const r of app.routes || []) {
|
|
|
|
|
ids.add(r.routeId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ids;
|
|
|
|
|
}, [catalog]);
|
|
|
|
|
|
2026-03-28 14:22:34 +01:00
|
|
|
// If exchange selected: show header + ExecutionDiagram
|
|
|
|
|
if (exchangeId && detail) {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<ExchangeHeader detail={detail} />
|
|
|
|
|
<ExecutionDiagram
|
|
|
|
|
executionId={exchangeId}
|
|
|
|
|
executionDetail={detail}
|
|
|
|
|
knownRouteIds={knownRouteIds}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-03-28 13:57:13 +01:00
|
|
|
|
2026-03-28 14:22:34 +01:00
|
|
|
// No exchange: show topology-only ProcessDiagram
|
|
|
|
|
if (diagramQuery.data) {
|
|
|
|
|
return (
|
|
|
|
|
<ProcessDiagram
|
|
|
|
|
application={appId}
|
|
|
|
|
routeId={routeId}
|
|
|
|
|
diagramLayout={diagramQuery.data}
|
|
|
|
|
knownRouteIds={knownRouteIds}
|
2026-03-28 13:57:13 +01:00
|
|
|
/>
|
2026-03-28 14:22:34 +01:00
|
|
|
);
|
|
|
|
|
}
|
2026-03-28 13:57:13 +01:00
|
|
|
|
2026-03-28 14:22:34 +01:00
|
|
|
return (
|
|
|
|
|
<div className={styles.emptyRight}>
|
|
|
|
|
Loading diagram...
|
2026-03-28 13:57:13 +01:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|