@@ -11,10 +11,12 @@ import {
11
11
ListItemText ,
12
12
Typography ,
13
13
} from "@mui/material" ;
14
+ import A from "next/link" ;
15
+ import { useRouter } from "next/router" ;
14
16
15
17
import { ModalWrapper } from "../../components/modals/ModalWrapper" ;
16
18
import { useDMAuthorizationStatus } from "../../hooks/useIsAuthorized" ;
17
- import { NavLink } from "./NavLink " ;
19
+ import { NAV_LINKS , NAV_PARAMS_TO_STRIP , type NavLinkData } from "./navigationConstants " ;
18
20
import { OUPContext } from "./OUPContext" ;
19
21
import { UserMenuContent } from "./UserMenuContent" ;
20
22
@@ -27,6 +29,7 @@ import { UserMenuContent } from "./UserMenuContent";
27
29
export const MobileNavMenu = ( ) => {
28
30
const [ open , setOpen ] = useState ( false ) ;
29
31
const isDMAuthorized = useDMAuthorizationStatus ( ) ;
32
+ const router = useRouter ( ) ;
30
33
31
34
return (
32
35
< >
@@ -43,34 +46,23 @@ export const MobileNavMenu = () => {
43
46
Links
44
47
</ Typography >
45
48
< List aria-label = "main-mobile-navigation" component = "nav" >
46
- < NavLink stripQueryParameters = { [ "taskId" , "instanceId" , "path" ] } title = "Datasets" >
47
- { ( { active } ) => (
48
- < ListItemButton component = "a" selected = { active } >
49
- < ListItemText primary = "Datasets" />
50
- </ ListItemButton >
51
- ) }
52
- </ NavLink >
53
- < NavLink stripQueryParameters = { [ "taskId" , "instanceId" , "path" ] } title = "Project" >
54
- { ( { active } ) => (
55
- < ListItemButton component = "a" selected = { active } >
56
- < ListItemText primary = "Project" />
57
- </ ListItemButton >
58
- ) }
59
- </ NavLink >
60
- < NavLink stripQueryParameters = { [ "taskId" , "instanceId" , "path" ] } title = "Run" >
61
- { ( { active } ) => (
62
- < ListItemButton component = "a" selected = { active } >
63
- < ListItemText primary = "Apps/Jobs" />
64
- </ ListItemButton >
65
- ) }
66
- </ NavLink >
67
- < NavLink stripQueryParameters = { [ "taskId" , "instanceId" , "path" ] } title = "Results" >
68
- { ( { active } ) => (
69
- < ListItemButton component = "a" selected = { active } >
70
- < ListItemText primary = "Results" />
49
+ { NAV_LINKS . map ( ( { title, path, text } : NavLinkData ) => {
50
+ const active = router . pathname . startsWith ( path ) ;
51
+ const query = { ...router . query } ;
52
+ NAV_PARAMS_TO_STRIP . forEach ( ( param : string ) => delete query [ param ] ) ;
53
+ const href = { query, pathname : path } ;
54
+
55
+ return (
56
+ < ListItemButton
57
+ component = { A }
58
+ href = { href }
59
+ key = { title }
60
+ selected = { active }
61
+ >
62
+ < ListItemText primary = { text } />
71
63
</ ListItemButton >
72
- ) }
73
- </ NavLink >
64
+ ) ;
65
+ } ) }
74
66
</ List >
75
67
</ Grid >
76
68
< Grid
0 commit comments