1
- import React from 'react' ;
1
+ import React , { useState } from 'react' ;
2
2
import './header.scss' ;
3
3
import { connect } from 'react-redux' ;
4
- import { Link , useHistory } from 'react-router-dom' ;
4
+ import { Link , useLocation } from 'react-router-dom' ;
5
5
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' ;
6
- import { faChevronRight , faChevronLeft } from '@fortawesome/free-solid-svg-icons' ;
6
+ import { faChevronRight , faChevronLeft , faCaretDown } from '@fortawesome/free-solid-svg-icons' ;
7
+ import { getCurrentExperimentDetails } from 'src/model/selectors/experiment' ;
7
8
import { getSelectedExperiment } from '../../model/selectors/projects' ;
8
9
import { onUserLogoutAction } from '../../model/actions/users' ;
9
10
import { RootState } from '../../model/types' ;
@@ -14,13 +15,28 @@ type Props = StateProps & DispatchProps;
14
15
15
16
export const Header : React . FC < Props > = ( props ) => {
16
17
const isSwitchVisible = props . selectedExperimentID ? 'active' : '' ;
17
- let history = useHistory ( ) ;
18
- const currentView = history . location . pathname ;
18
+ const { experimentDetails } = props ;
19
+ let location = useLocation ( ) ;
20
+
21
+ const currentView = location . pathname ;
19
22
const linkTo = currentView === '/' ? `/experiment/${ props . selectedExperimentID } ` : '/' ;
23
+
20
24
const logoutUser = ( ) => {
21
25
props . userLogout ( ) ;
22
26
window . location . href = '/' ;
23
27
} ;
28
+
29
+ const [ isInfoOpen , toggleInfo ] = useState ( false ) ;
30
+ const activeClass = isInfoOpen ? 'active' : '' ;
31
+
32
+ window . addEventListener ( 'click' , ( evt : any ) => {
33
+ if ( currentView === '/' ) {
34
+ return null ;
35
+ }
36
+ const dropdown = document . querySelector ( '.exp-info' ) ;
37
+ dropdown && ! dropdown . contains ( evt . target ) && toggleInfo ( false ) ;
38
+ } ) ;
39
+
24
40
return (
25
41
< header id = "header" className = "main-header" >
26
42
< div className = "header-container" >
@@ -30,6 +46,37 @@ export const Header: React.FC<Props> = (props) => {
30
46
< Link to = { linkTo } className = { `page-switch-btn ${ isSwitchVisible } ` } >
31
47
< FontAwesomeIcon icon = { currentView === '/' ? faChevronRight : faChevronLeft } />
32
48
</ Link >
49
+ { currentView !== '/' && (
50
+ < div className = "exp-info" onClick = { ( ) => toggleInfo ( ! isInfoOpen ) } >
51
+ < ul >
52
+ < li className = { activeClass } >
53
+ Details
54
+ < span >
55
+ < FontAwesomeIcon icon = { faCaretDown } />
56
+ </ span >
57
+ < ul >
58
+ < li >
59
+ < span > Pipeline:</ span >
60
+ < span > { experimentDetails . pipeline } </ span >
61
+ </ li >
62
+ < li >
63
+ < span > Dataset:</ span >
64
+ < span > { experimentDetails . dataset } </ span >
65
+ </ li >
66
+ < li >
67
+ < span > By:</ span >
68
+ < span > { experimentDetails . created_by || 'Unknown' } </ span >
69
+ </ li >
70
+ < li >
71
+ < span > Project:</ span >
72
+ < span > { experimentDetails . project } </ span >
73
+ </ li >
74
+ </ ul >
75
+ </ li >
76
+ </ ul >
77
+ </ div >
78
+ ) }
79
+
33
80
< ul className = "user-opts" >
34
81
< li >
35
82
< button type = "button" onClick = { logoutUser } className = "logout-button" >
@@ -44,6 +91,7 @@ export const Header: React.FC<Props> = (props) => {
44
91
45
92
const mapState = ( state : RootState ) => ( {
46
93
selectedExperimentID : getSelectedExperiment ( state ) ,
94
+ experimentDetails : getCurrentExperimentDetails ( state ) ,
47
95
} ) ;
48
96
49
97
const mapDispatch = ( dispatch : Function ) => ( {
0 commit comments