Files
cameleer-server/ui/src/hooks/useScope.ts
hsiegeln 670e458376
All checks were successful
CI / cleanup-branch (push) Has been skipped
CI / build (push) Successful in 1m23s
CI / docker (push) Successful in 1m29s
CI / deploy-feature (push) Has been skipped
CI / deploy (push) Successful in 50s
fix: update ITs to use consolidated init.sql, remove dead code
- All 7 ClickHouse integration tests now load init.sql via shared
  ClickHouseTestHelper instead of deleted V1-V11 migration files
- Remove unused useScope exports (setApp, setRoute, setExchange, clearScope)
- Remove unused CSS classes (monoCell, punchcardStack)
- Update ui/README.md DS version to v0.1.28

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 17:03:54 +02:00

41 lines
1.2 KiB
TypeScript

// ui/src/hooks/useScope.ts
import { useParams, useNavigate, useLocation } from 'react-router';
import { useCallback } from 'react';
export type TabKey = 'exchanges' | 'dashboard' | 'runtime' | 'logs';
const VALID_TABS = new Set<TabKey>(['exchanges', 'dashboard', 'runtime', 'logs']);
export interface Scope {
tab: TabKey;
appId?: string;
routeId?: string;
exchangeId?: string;
}
export function useScope() {
const params = useParams<{ tab?: string; appId?: string; routeId?: string; exchangeId?: string }>();
const navigate = useNavigate();
const location = useLocation();
// Derive tab from first URL segment — fallback to 'exchanges'
const rawTab = location.pathname.split('/').filter(Boolean)[0] ?? 'exchanges';
const tab: TabKey = VALID_TABS.has(rawTab as TabKey) ? (rawTab as TabKey) : 'exchanges';
const scope: Scope = {
tab,
appId: params.appId,
routeId: params.routeId,
exchangeId: params.exchangeId,
};
const setTab = useCallback((newTab: TabKey) => {
const parts = ['', newTab];
if (scope.appId) parts.push(scope.appId);
if (scope.routeId) parts.push(scope.routeId);
navigate(parts.join('/'));
}, [navigate, scope.appId, scope.routeId]);
return { scope, setTab };
}