import { useEffect, useState } from 'react'; import { NavLink, Outlet } from 'react-router-dom'; import { getSelectedStoreId, setSelectedStoreId } from '../config'; import { getHealth } from '../api/client'; const navItems = [ { to: '/', label: 'Dashboard', end: true }, { to: '/heatmap', label: 'Heatmap' }, { to: '/funnel', label: 'Funnel' }, { to: '/anomalies', label: 'Anomalies' }, { to: '/health', label: 'System Health' }, ] as const; export function Layout() { const [currentStore, setCurrentStore] = useState(getSelectedStoreId()); const [availableStores, setAvailableStores] = useState(['ST1008', 'ST_STORE2']); useEffect(() => { getHealth() .then((data) => { if (data && data.stores) { const ids = data.stores.map((s) => s.store_id); if (ids.length > 0) { setAvailableStores(ids); } } }) .catch((err) => { console.warn('Failed to load active stores list from health endpoint, using defaults:', err); }); }, []); const handleStoreChange = (storeId: string) => { setSelectedStoreId(storeId); setCurrentStore(storeId); // Reload the page to reset websockets and fetch new metrics window.location.reload(); }; return (
); }