@@ -7,8 +7,11 @@ import { DBConnection, Project } from '../../data/models'
77import { useAppDispatch , useAppSelector } from '../../redux/hooks'
88import { selectIsShowingSidebar , setIsShowingSidebar } from '../../redux/configSlice'
99import { selectProjects } from '../../redux/projectsSlice'
10- import { selectDBConnection } from '../../redux/dbConnectionSlice'
10+ import { selectAllDBConnections } from '../../redux/allDBConnectionsSlice'
11+ import { selectDBConnection , getDBDataModels , resetDBDataModels } from '../../redux/dbConnectionSlice'
1112import utils from '../../lib/utils'
13+ import { Tooltip } from 'react-tooltip'
14+ import 'react-tooltip/dist/react-tooltip.css'
1215
1316const Header = ( ) => {
1417
@@ -19,17 +22,15 @@ const Header = () => {
1922 const dispatch = useAppDispatch ( )
2023
2124 const projects : Project [ ] = useAppSelector ( selectProjects )
25+ const dbConnections : DBConnection [ ] = useAppSelector ( selectAllDBConnections )
2226 const currentDBConnection : DBConnection | undefined = useAppSelector ( selectDBConnection )
2327 const isShowingSidebar : boolean = useAppSelector ( selectIsShowingSidebar )
2428
2529
2630 const [ isShowingDropDown , setIsShowingDropDown ] = useState ( false )
2731 const [ isShowingNavDropDown , setIsShowingNavDropDown ] = useState ( false )
32+ const [ isShowingDBDropDown , setIsShowingDBDropdown ] = useState ( false )
2833
29- const options = [
30- { value : 'home' , label : 'Home' , path : Constants . APP_PATHS . HOME . path } ,
31- ...projects . map ( ( x : Project ) => ( { value : x . id , label : x . name , path : Constants . APP_PATHS . PROJECT . path . replace ( '[id]' , x . id ) } ) )
32- ]
3334
3435 const onNavigate = ( option : {
3536 value : string ;
@@ -44,54 +45,114 @@ const Header = () => {
4445 dispatch ( setIsShowingSidebar ( ! isShowingSidebar ) )
4546 }
4647
47- let currentOption = 'home'
48+ let currentProjectOption : String | undefined = undefined ;
49+ let currentDBOption : string | undefined = undefined ;
4850 if ( location . pathname . startsWith ( '/project' ) )
49- currentOption = String ( params . id )
51+ currentProjectOption = String ( params . id )
5052 else if ( location . pathname . startsWith ( '/db' ) ) {
5153 if ( currentDBConnection )
52- currentOption = currentDBConnection ?. projectId
54+ currentProjectOption = currentDBConnection ?. projectId
55+ currentDBOption = currentDBConnection ?. id
56+ }
57+
58+ const projectOptions = [
59+
60+ ...projects . map ( ( x : Project ) => ( { value : x . id , label : x . name , path : Constants . APP_PATHS . PROJECT . path . replace ( '[id]' , x . id ) } ) )
61+ ]
62+ const dbOptions = [
63+ ...dbConnections . filter ( ( x : DBConnection ) => ( x . projectId === currentProjectOption ) ) . map ( ( x : DBConnection ) => ( { value : x . id , label : x . name , path : Constants . APP_PATHS . DB . path . replace ( '[id]' , x . id ) } ) )
64+ ]
65+
66+ const refreshDataModels = ( ) => {
67+ dispatch ( resetDBDataModels ( ) )
68+ dispatch ( getDBDataModels ( { dbConnId : currentDBConnection ! . id } ) )
5369 }
5470
5571 return (
5672 < header className = { styles . header } >
5773 < div className = { styles . leftBtns } >
58- { ! isShowingSidebar && < button className = { "button is-dark " + [ styles . btn ] . join ( ' ' ) } onClick = { toggleSidebar } >
74+ { ! isShowingSidebar ? ( < button className = { "button is-dark " + [ styles . btn ] . join ( ' ' ) } onClick = { toggleSidebar } >
75+ < i className = "fas fa-bars" />
76+ </ button > ) : ( < button className = { "button is-dark " + [ styles . btn ] . join ( ' ' ) } onClick = { toggleSidebar } >
5977 < i className = "fas fa-bars" />
60- </ button > }
78+ </ button > ) }
6179 < Link to = { Constants . APP_PATHS . HOME . path } >
62- < button className = { " button is-dark " + [ styles . btn ] . join ( ' ' ) } >
80+ < button className = { ` button is-dark ` + [ styles . btn , currentProjectOption !== undefined ? styles . home : '' ] . join ( ' ' ) } >
6381 < span className = "icon" >
6482 < i className = { `fas fa-home` } />
6583 </ span >
6684 </ button >
6785 </ Link >
68- </ div >
69- < div className = { styles . headerCenter } >
70- < div className = { `dropdown${ isShowingNavDropDown ? ' is-active' : '' } ` } >
71- < div className = "dropdown-trigger" >
72- < button className = { "button is-dark " + styles . btn } aria-haspopup = "true" aria-controls = "dropdown-menu" onClick = { ( ) => { setIsShowingNavDropDown ( ! isShowingNavDropDown ) } } >
73- < span > { options . find ( x => x . value === currentOption ) ?. label } </ span >
74- < span className = "icon is-small" >
75- < i className = "fas fa-angle-down" aria-hidden = "true" > </ i >
76- </ span >
77- </ button >
78- </ div >
79- < OutsideClickHandler onOutsideClick = { ( ) => { setIsShowingNavDropDown ( false ) } } >
80- < div className = "dropdown-menu" id = "dropdown-menu" role = "menu" >
81- < div className = "dropdown-content" >
82- { options . map ( ( x ) => {
83- return (
84- < React . Fragment key = { x . value } >
85- < a onClick = { ( ) => { onNavigate ( x ) } } className = { `dropdown-item${ x . value === currentOption ? ' is-active' : '' } ` } >
86- { x . label }
87- </ a >
88- { x . value === 'home' && < hr className = "dropdown-divider" /> }
89- </ React . Fragment >
90- )
91- } ) }
86+ < div className = { styles . headerCenter } >
87+ { currentProjectOption !== undefined && < div className = { `dropdown${ isShowingNavDropDown ? ' is-active' : '' } ` } >
88+ < div className = { `dropdown-trigger` } >
89+ < button className = { "button is-dark " + [ styles . btn , styles . bread , currentDBOption === undefined ? styles . breadEnds : '' ] . join ( ' ' ) } aria-haspopup = "true" aria-controls = "dropdown-menu" onClick = { ( ) => { setIsShowingNavDropDown ( ! isShowingNavDropDown ) } } >
90+ < span className = 'icon' >
91+ < i className = "fas fa-folder" aria-hidden = "true" > </ i >
92+ </ span >
93+ < span > { projectOptions . find ( x => x . value === currentProjectOption ) ?. label } </ span >
94+ < span className = "icon" >
95+ < i className = "fas fa-angle-down" aria-hidden = "true" > </ i >
96+ </ span >
97+ </ button >
98+ </ div >
99+ < OutsideClickHandler onOutsideClick = { ( ) => { setIsShowingNavDropDown ( false ) } } >
100+ < div className = "dropdown-menu" id = "dropdown-menu" role = "menu" >
101+ < div className = "dropdown-content" >
102+ { projectOptions . map ( ( x ) => {
103+ return (
104+ < React . Fragment key = { x . value } >
105+ < a onClick = { ( ) => { onNavigate ( x ) } } className = { `dropdown-item${ x . value === currentProjectOption ? ' is-active' : '' } ` } >
106+ { x . label }
107+ </ a >
108+ { x . value === 'home' && < hr className = "dropdown-divider" /> }
109+ </ React . Fragment >
110+ )
111+ } ) }
112+ </ div >
92113 </ div >
114+ </ OutsideClickHandler >
115+ </ div > }
116+ { currentProjectOption !== undefined && currentDBOption !== undefined && < div className = { `dropdown${ isShowingDBDropDown ? ' is-active' : '' } ` } >
117+ < div className = { `dropdown-trigger` } >
118+ < button className = { "button is-dark " + [ styles . btn , styles . bread , styles . dbBread , styles . breadEnds ] . join ( ' ' ) } aria-haspopup = "true" aria-controls = "dropdown-menu" onClick = { ( ) => { setIsShowingDBDropdown ( ! isShowingDBDropDown ) } } >
119+ < span className = 'icon' >
120+ < i className = "fas fa-database" aria-hidden = "true" > </ i >
121+ </ span >
122+ < span > { dbOptions . find ( x => x . value === currentDBOption ) ?. label } </ span >
123+ < span className = "icon" >
124+ < i className = "fas fa-angle-down" aria-hidden = "true" > </ i >
125+ </ span >
126+ </ button >
93127 </ div >
94- </ OutsideClickHandler >
128+ < OutsideClickHandler onOutsideClick = { ( ) => { setIsShowingDBDropdown ( false ) } } >
129+ < div className = "dropdown-menu" id = "dropdown-menu" role = "menu" >
130+ < div className = "dropdown-content" >
131+ { dbOptions . map ( ( x ) => {
132+ return (
133+ < React . Fragment key = { x . value } >
134+ < a onClick = { ( ) => { onNavigate ( x ) } } className = { `dropdown-item${ x . value === currentDBOption ? ' is-active' : '' } ` } >
135+ { x . label }
136+ </ a >
137+ { x . value === 'home' && < hr className = "dropdown-divider" /> }
138+ </ React . Fragment >
139+ )
140+ } ) }
141+ </ div >
142+ </ div >
143+ </ OutsideClickHandler >
144+ { currentDBOption !== undefined &&
145+ < div >
146+ < button id = "refreshBtn" data-tooltip-content = "Refresh data models" className = { " button is-dark is-small" + [ styles . btn ] . join ( ' ' ) } onClick = { refreshDataModels } >
147+ < span className = "icon is-small" >
148+ < i className = "fas fa-sync" />
149+ </ span >
150+ </ button >
151+ < Tooltip anchorId = "refreshBtn" />
152+ </ div >
153+ }
154+ </ div >
155+ }
95156 </ div >
96157 </ div >
97158 < div className = { styles . headerMenu } >
0 commit comments