diff --git a/frontend-modern/src/components/Alerts/ThresholdsTable.tsx b/frontend-modern/src/components/Alerts/ThresholdsTable.tsx index 7e3d1a650..1f625642a 100644 --- a/frontend-modern/src/components/Alerts/ThresholdsTable.tsx +++ b/frontend-modern/src/components/Alerts/ThresholdsTable.tsx @@ -1,4 +1,5 @@ -import { createSignal, createMemo, Show, For, onMount, onCleanup } from 'solid-js'; +import { createSignal, createMemo, Show, For, onMount, onCleanup, createEffect } from 'solid-js'; +import { useNavigate, useLocation } from '@solidjs/router'; // Workaround for eslint false-positive when `For` is used only in JSX const __ensureForUsage = For; @@ -192,6 +193,9 @@ interface ThresholdsTableProps { } export function ThresholdsTable(props: ThresholdsTableProps) { + const navigate = useNavigate(); + const location = useLocation(); + const [searchTerm, setSearchTerm] = createSignal(''); const [editingId, setEditingId] = createSignal(null); const [editingThresholds, setEditingThresholds] = createSignal< @@ -200,6 +204,38 @@ export function ThresholdsTable(props: ThresholdsTableProps) { const [activeTab, setActiveTab] = createSignal<'proxmox' | 'pmg' | 'docker'>('proxmox'); let searchInputRef: HTMLInputElement | undefined; + // Determine active tab from URL + const getActiveTabFromRoute = (): 'proxmox' | 'pmg' | 'docker' => { + const path = location.pathname; + if (path.includes('/thresholds/docker')) return 'docker'; + if (path.includes('/thresholds/mail-gateway')) return 'pmg'; + return 'proxmox'; // default + }; + + // Sync active tab with route on mount and route changes + createEffect(() => { + const tabFromRoute = getActiveTabFromRoute(); + if (activeTab() !== tabFromRoute) { + setActiveTab(tabFromRoute); + } + }); + + // Handle default redirect - if at /alerts/thresholds exactly, redirect to /alerts/thresholds/proxmox + createEffect(() => { + if (location.pathname === '/alerts/thresholds') { + navigate('/alerts/thresholds/proxmox', { replace: true }); + } + }); + + const handleTabClick = (tab: 'proxmox' | 'pmg' | 'docker') => { + const tabRoutes = { + proxmox: '/alerts/thresholds/proxmox', + pmg: '/alerts/thresholds/mail-gateway', + docker: '/alerts/thresholds/docker', + }; + navigate(tabRoutes[tab]); + }; + // Set up keyboard shortcuts onMount(() => { const isEditableElement = (el: HTMLElement | null | undefined): boolean => { @@ -1635,8 +1671,8 @@ const dockerContainersGroupedByHost = createMemo>((pr