1616"use client" ;
1717
1818import { useEffect , useMemo , useRef , useState } from "react" ;
19+ import { useRouter , useSearchParams } from "next/navigation" ;
1920import { AlertCircle , ChevronDown , Clock , ExternalLink , MessageSquare , Search , Zap } from "lucide-react" ;
2021import Link from "next/link" ;
2122import { toast } from "sonner" ;
@@ -82,6 +83,8 @@ export function GlobalGroupHealthPanel({
8283 initialWindow,
8384 onWindowChange,
8485} : GlobalGroupHealthPanelProps ) {
86+ const router = useRouter ( ) ;
87+ const searchParams = useSearchParams ( ) ;
8588 const [ internalOpen , setInternalOpen ] = useState ( true ) ;
8689 const [ localSummary , setLocalSummary ] = useState ( summary ) ;
8790 const [ loadingWindow , setLoadingWindow ] = useState < GlobalGroupHealthWindow | null > ( null ) ;
@@ -95,6 +98,15 @@ export function GlobalGroupHealthPanel({
9598 const activeSummary = localSummary ?? summary ;
9699 const available = activeSummary ?. available === true ;
97100
101+ // Sync selectedWindow with URL changes
102+ useEffect ( ( ) => {
103+ const windowParam = searchParams . get ( "window" ) ;
104+ const isValidWindow = [ "1h" , "6h" , "12h" , "24h" , "7d" , "15d" , "30d" ] . includes ( windowParam ?? "" ) ;
105+ if ( windowParam && isValidWindow ) {
106+ setSelectedWindow ( windowParam as GlobalGroupHealthWindow ) ;
107+ }
108+ } , [ searchParams ] ) ;
109+
98110 useEffect ( ( ) => {
99111 if ( ! activeSummary || ! initialWindow || initialWindow === activeSummary . defaultWindow ) {
100112 return ;
@@ -176,6 +188,16 @@ export function GlobalGroupHealthPanel({
176188 const handleWindowChange = async ( window : GlobalGroupHealthWindow ) => {
177189 setSelectedWindow ( window ) ;
178190 onWindowChange ?.( window ) ;
191+ // Push window to URL for /group/global page
192+ const params = new URLSearchParams ( searchParams . toString ( ) ) ;
193+ if ( window === "24h" ) {
194+ params . delete ( "window" ) ;
195+ } else {
196+ params . set ( "window" , window ) ;
197+ }
198+ router . replace ( `/group/global${ params . toString ( ) ? `?${ params . toString ( ) } ` : "" } ` , {
199+ scroll : false ,
200+ } ) ;
179201 const hasWindowData = ( activeSummary . itemsByWindow [ window ] ?? [ ] ) . length > 0 ;
180202 if ( hasWindowData || loadingWindow === window ) {
181203 return ;
0 commit comments