File tree Expand file tree Collapse file tree 3 files changed +23
-10
lines changed
Expand file tree Collapse file tree 3 files changed +23
-10
lines changed Original file line number Diff line number Diff line change @@ -20,14 +20,9 @@ export default class extends Controller {
2020 setLeftNavToLocation ( ) {
2121 this . removeAllActive ( ) ;
2222
23- // Get the first 3 parts of the pathname to match the left nav href
24- let path = window . location . pathname . split ( "/" ) . slice ( 0 , 3 ) . join ( "/" ) ;
25- let tag = 'a[href="' + path + '"]' ;
26-
27- let element = this . element . querySelector ( tag ) ;
28-
29- if ( element ) {
30- element . classList . add ( "active" ) ;
23+ let tab = this . findTab ( ) ;
24+ if ( tab ) {
25+ tab . classList . add ( "active" ) ;
3126 }
3227 }
3328
@@ -38,6 +33,24 @@ export default class extends Controller {
3833 }
3934 }
4035
36+ // Recursive function to find the tab that matches the current window
37+ findTab ( level = 1 , tag = "a[href='/']" ) {
38+ let element = this . element . querySelectorAll ( tag ) ;
39+ if ( element . length == 1 ) {
40+ return element [ 0 ] ;
41+ } else {
42+ let path_vec = window . location . pathname . split ( "/" ) ;
43+ if ( level > path_vec . length ) {
44+ return ;
45+ }
46+
47+ let path = path_vec . slice ( 0 , level ) . join ( "/" ) ;
48+ let tag = 'a[href="' + path + '"]' ;
49+
50+ return this . findTab ( level + 1 , tag )
51+ }
52+ }
53+
4154 // Remove event listener when controller is disconnected
4255 disconnect ( ) {
4356 document . removeEventListener ( "turbo:load" , this . callback ) ;
Original file line number Diff line number Diff line change 1- < nav data-controller ="left-nav-menu ">
1+ < nav data-controller ="left-nav-menu " class =" overflow-hidden " >
22 < ul class ="nav flex-column justify-content-end ">
33 < % for link in nav.links { %>
44 < % if !link.hide_for_lg_screens { %>
Original file line number Diff line number Diff line change @@ -100,7 +100,7 @@ async fn main() {
100100 site_search_copy. build ( ) . await . expect ( "Error building site search" ) ;
101101 } ) ;
102102
103- pgml_dashboard:: migrate ( guards:: Cluster :: default ( None ) . pool ( ) )
103+ pgml_dashboard:: migrate ( guards:: Cluster :: default ( ) . pool ( ) )
104104 . await
105105 . unwrap ( ) ;
106106
You can’t perform that action at this time.
0 commit comments