2026-03-28 14:29:19 +01:00
|
|
|
import { useState, useMemo, useCallback, useRef } from 'react';
|
2026-03-28 14:37:58 +01:00
|
|
|
import { useParams, useNavigate } from 'react-router';
|
2026-03-28 13:57:13 +01:00
|
|
|
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';
|
2026-03-28 14:37:58 +01:00
|
|
|
import type { NodeAction } from '../../components/ProcessDiagram/types';
|
2026-03-28 13:57:13 +01:00
|
|
|
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:29:19 +01:00
|
|
|
// Route scoped: resizable split — Dashboard table on left, diagram on right
|
|
|
|
|
return <SplitExchangeView appId={appId!} routeId={routeId} exchangeId={exchangeId} />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Resizable split view ───────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
interface SplitExchangeViewProps {
|
|
|
|
|
appId: string;
|
|
|
|
|
routeId: string;
|
|
|
|
|
exchangeId?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function SplitExchangeView({ appId, routeId, exchangeId }: SplitExchangeViewProps) {
|
|
|
|
|
const [splitPercent, setSplitPercent] = useState(50);
|
|
|
|
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
|
|
|
|
|
const handleSplitterDown = useCallback((e: React.PointerEvent) => {
|
|
|
|
|
e.currentTarget.setPointerCapture(e.pointerId);
|
|
|
|
|
const container = containerRef.current;
|
|
|
|
|
if (!container) return;
|
|
|
|
|
const onMove = (me: PointerEvent) => {
|
|
|
|
|
const rect = container.getBoundingClientRect();
|
|
|
|
|
const x = me.clientX - rect.left;
|
|
|
|
|
const pct = Math.min(80, Math.max(20, (x / rect.width) * 100));
|
|
|
|
|
setSplitPercent(pct);
|
|
|
|
|
};
|
|
|
|
|
const onUp = () => {
|
|
|
|
|
document.removeEventListener('pointermove', onMove);
|
|
|
|
|
document.removeEventListener('pointerup', onUp);
|
|
|
|
|
};
|
|
|
|
|
document.addEventListener('pointermove', onMove);
|
|
|
|
|
document.addEventListener('pointerup', onUp);
|
|
|
|
|
}, []);
|
|
|
|
|
|
2026-03-28 13:57:13 +01:00
|
|
|
return (
|
2026-03-28 14:29:19 +01:00
|
|
|
<div ref={containerRef} className={styles.splitView}>
|
|
|
|
|
<div className={styles.leftPanel} style={{ width: `${splitPercent}%` }}>
|
2026-03-28 14:22:34 +01:00
|
|
|
<Dashboard />
|
|
|
|
|
</div>
|
2026-03-28 14:29:19 +01:00
|
|
|
<div className={styles.splitter} onPointerDown={handleSplitterDown} />
|
|
|
|
|
<div className={styles.rightPanel} style={{ width: `${100 - splitPercent}%` }}>
|
|
|
|
|
<DiagramPanel appId={appId} routeId={routeId} exchangeId={exchangeId} />
|
2026-03-28 14:22:34 +01:00
|
|
|
</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 14:37:58 +01:00
|
|
|
const navigate = useNavigate();
|
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
|
|
|
const { data: detail } = useExecutionDetail(exchangeId ?? null);
|
2026-03-28 13:57:13 +01:00
|
|
|
const diagramQuery = useDiagramByRoute(appId, routeId);
|
|
|
|
|
|
|
|
|
|
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:37:58 +01:00
|
|
|
const handleNodeAction = useCallback((nodeId: string, action: NodeAction) => {
|
|
|
|
|
if (action === 'configure-tap') {
|
|
|
|
|
navigate(`/admin/appconfig?app=${encodeURIComponent(appId)}&processor=${encodeURIComponent(nodeId)}`);
|
|
|
|
|
}
|
|
|
|
|
}, [appId, navigate]);
|
|
|
|
|
|
2026-03-28 14:22:34 +01:00
|
|
|
if (exchangeId && detail) {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<ExchangeHeader detail={detail} />
|
|
|
|
|
<ExecutionDiagram
|
|
|
|
|
executionId={exchangeId}
|
|
|
|
|
executionDetail={detail}
|
|
|
|
|
knownRouteIds={knownRouteIds}
|
2026-03-28 14:37:58 +01:00
|
|
|
onNodeAction={handleNodeAction}
|
2026-03-28 14:22:34 +01:00
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-03-28 13:57:13 +01:00
|
|
|
|
2026-03-28 14:22:34 +01:00
|
|
|
if (diagramQuery.data) {
|
|
|
|
|
return (
|
|
|
|
|
<ProcessDiagram
|
|
|
|
|
application={appId}
|
|
|
|
|
routeId={routeId}
|
|
|
|
|
diagramLayout={diagramQuery.data}
|
|
|
|
|
knownRouteIds={knownRouteIds}
|
2026-03-28 14:37:58 +01:00
|
|
|
onNodeAction={handleNodeAction}
|
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>
|
|
|
|
|
);
|
|
|
|
|
}
|