@@ -4,7 +4,7 @@ import * as React from 'react';
4
4
import { Redirect , Route , RouteComponentProps , Router , Switch } from 'react-router' ;
5
5
6
6
import { uiUrl } from './shared/base' ;
7
- import { Layout } from './shared/components' ;
7
+ import { Layout , NotificationInfo , Notifications , NotificationsManager , Popup , PopupManager , PopupProps } from './shared/components' ;
8
8
import { AppContext } from './shared/context' ;
9
9
10
10
export const history = createHistory ( ) ;
@@ -30,28 +30,56 @@ const navItems = [{
30
30
iconClassName : 'argo-icon-docs' ,
31
31
} ] ;
32
32
33
- export const App = ( ) => (
34
- < div >
35
- < Router history = { history } >
36
- < Switch >
37
- < Redirect exact = { true } path = { uiUrl ( '' ) } to = { workflowsUrl } />
38
- < Route path = { timelineUrl } component = { class ToWorkflows extends React . Component {
39
- public static contextTypes = { router : PropTypes . object } ;
40
- public render ( ) { return < div /> ; }
41
-
42
- public componentWillMount ( ) {
43
- const router = ( this . context as AppContext ) . router ;
44
- router . history . push ( router . route . location . pathname . replace ( timelineUrl , workflowsUrl ) ) ;
45
- }
46
- } } />
47
- < Layout navItems = { navItems } >
48
- { /* <NotificationsContainer /> */ }
49
- { Object . keys ( routes ) . map ( ( path ) => {
50
- const route = routes [ path ] ;
51
- return < Route key = { path } path = { path } component = { route . component } /> ;
52
- } ) }
53
- </ Layout >
54
- </ Switch >
55
- </ Router >
56
- </ div >
57
- ) ;
33
+ export class App extends React . Component < { } , { notifications : NotificationInfo [ ] , popupProps : PopupProps } > {
34
+ public static childContextTypes = {
35
+ history : PropTypes . object ,
36
+ apis : PropTypes . object ,
37
+ } ;
38
+
39
+ private popupManager : PopupManager ;
40
+ private notificationsManager : NotificationsManager ;
41
+
42
+ constructor ( props : { } ) {
43
+ super ( props ) ;
44
+ this . state = { notifications : [ ] , popupProps : null } ;
45
+ this . popupManager = new PopupManager ( ) ;
46
+ this . notificationsManager = new NotificationsManager ( ) ;
47
+ }
48
+
49
+ public componentDidMount ( ) {
50
+ this . popupManager . popupProps . subscribe ( ( popupProps ) => this . setState ( { popupProps } ) ) ;
51
+ this . notificationsManager . notifications . subscribe ( ( notifications ) => this . setState ( { notifications } ) ) ;
52
+ }
53
+
54
+ public render ( ) {
55
+ return (
56
+ < div >
57
+ { this . state . popupProps && < Popup { ...this . state . popupProps } /> }
58
+ < Router history = { history } >
59
+ < Switch >
60
+ < Redirect exact = { true } path = { uiUrl ( '' ) } to = { workflowsUrl } />
61
+ < Route path = { timelineUrl } component = { class ToWorkflows extends React . Component {
62
+ public static contextTypes = { router : PropTypes . object } ;
63
+ public render ( ) { return < div /> ; }
64
+ public componentWillMount ( ) {
65
+ const router = ( this . context as AppContext ) . router ;
66
+ router . history . push ( router . route . location . pathname . replace ( timelineUrl , workflowsUrl ) ) ;
67
+ }
68
+ } } />
69
+ < Layout navItems = { navItems } >
70
+ < Notifications leftOffset = { 60 } closeNotification = { ( item ) => this . notificationsManager . close ( item ) } notifications = { this . state . notifications } />
71
+ { Object . keys ( routes ) . map ( ( path ) => {
72
+ const route = routes [ path ] ;
73
+ return < Route key = { path } path = { path } component = { route . component } /> ;
74
+ } ) }
75
+ </ Layout >
76
+ </ Switch >
77
+ </ Router >
78
+ </ div >
79
+ ) ;
80
+ }
81
+
82
+ public getChildContext ( ) {
83
+ return { history, apis : { popup : this . popupManager , notifications : this . notificationsManager } } ;
84
+ }
85
+ }
0 commit comments