diff --git a/ui/src/pages/Exchanges/ExchangesPage.tsx b/ui/src/pages/Exchanges/ExchangesPage.tsx index e4f70187..9d6f702f 100644 --- a/ui/src/pages/Exchanges/ExchangesPage.tsx +++ b/ui/src/pages/Exchanges/ExchangesPage.tsx @@ -1,5 +1,5 @@ -import { useState, useMemo, useCallback, useRef } from 'react'; -import { useNavigate } from 'react-router'; +import { useState, useMemo, useCallback, useRef, useEffect } from 'react'; +import { useNavigate, useLocation } from 'react-router'; import { useGlobalFilters } from '@cameleer/design-system'; import { useExecutionDetail } from '../../api/queries/executions'; import { useDiagramByRoute } from '../../api/queries/diagrams'; @@ -14,20 +14,42 @@ import Dashboard from '../Dashboard/Dashboard'; import type { SelectedExchange } from '../Dashboard/Dashboard'; export default function ExchangesPage() { - const [selected, setSelected] = useState(null); + const navigate = useNavigate(); + const location = useLocation(); + + // Restore selection from browser history state (enables Back/Forward) + const stateSelected = (location.state as any)?.selectedExchange as SelectedExchange | undefined; + const [selected, setSelectedInternal] = useState(stateSelected ?? null); + + // Sync from history state when the user navigates Back/Forward + useEffect(() => { + const restored = (location.state as any)?.selectedExchange as SelectedExchange | undefined; + setSelectedInternal(restored ?? null); + }, [location.state]); + const [splitPercent, setSplitPercent] = useState(50); const containerRef = useRef(null); + // Select an exchange: push a history entry so Back restores the previous state const handleExchangeSelect = useCallback((exchange: SelectedExchange) => { - setSelected(exchange); - }, []); + setSelectedInternal(exchange); + navigate(location.pathname + location.search, { + state: { ...location.state, selectedExchange: exchange }, + }); + }, [navigate, location.pathname, location.search, location.state]); + // Select a correlated exchange: push another history entry const handleCorrelatedSelect = useCallback((executionId: string, applicationName: string, routeId: string) => { - setSelected({ executionId, applicationName, routeId }); - }, []); + const exchange = { executionId, applicationName, routeId }; + setSelectedInternal(exchange); + navigate(location.pathname + location.search, { + state: { ...location.state, selectedExchange: exchange }, + }); + }, [navigate, location.pathname, location.search, location.state]); + // Clear selection: push a history entry without selection (so Back returns to selected state) const handleClearSelection = useCallback(() => { - setSelected(null); + setSelectedInternal(null); }, []); const handleSplitterDown = useCallback((e: React.PointerEvent) => {