1515const BundlePlots = require ( './components/BundlePlots' ) ;
1616const BundleRunForm = require ( './components/BundleRunForm' ) ;
1717const React = require ( 'react' ) ;
18+ const WelcomeMessage = require ( './components/WelcomeMessage' ) ;
1819
1920const handleAPIError = require ( '../utils/handleAPIError' ) ;
2021
@@ -29,21 +30,29 @@ import {message, Row, Col, Card, Tag, Icon} from 'antd';
2930import type { BundleOptions } from 'metro/src/shared/types.flow.js' ;
3031
3132type State = {
32- metroHistory : MetroHistory ,
33- selectedBundleHash ?: ?string ,
34- showLoadingIndicator : boolean ,
33+ metroHistory : ?MetroHistory ,
34+ selectedBundleHash : ?string ,
35+ isLoadingData : boolean ,
36+ isBundling : boolean ,
3537} ;
3638
3739class DashboardApp extends React . Component < mixed , State > {
40+ state = {
41+ metroHistory : undefined ,
42+ selectedBundleHash : undefined ,
43+ isLoadingData : false ,
44+ isBundling : false ,
45+ } ;
46+
3847 componentDidMount ( ) {
3948 this . fetchBundles ( ) ;
4049 }
4150
4251 fetchBundles ( ) {
43- this . setState ( { showLoadingIndicator : true } ) ;
52+ this . setState ( { isLoadingData : true } ) ;
4453 fetch ( '/visualizer/bundles' )
4554 . then ( res => {
46- this . setState ( { showLoadingIndicator : false } ) ;
55+ this . setState ( { isLoadingData : false } ) ;
4756 return handleAPIError ( res ) ;
4857 } )
4958 . then ( response => response . json ( ) )
@@ -53,50 +62,60 @@ class DashboardApp extends React.Component<mixed, State> {
5362 . catch ( error => message . error ( error . message ) ) ;
5463 }
5564
65+ _handleReload = ( ) => {
66+ this . fetchBundles ( ) ;
67+ } ;
68+
5669 render ( ) {
70+ const { metroHistory , isLoadingData , isBundling } = this . state ;
71+ const loadedEmptyHistory =
72+ ! isLoadingData && metroHistory && Object . keys ( metroHistory ) . length === 0 ;
5773 return (
58- this . state && (
59- < div >
60- < Row type = "flex" justify = "center" >
61- < img
62- src = { 'https://facebook.github.io/metro/img/metro.svg' }
63- className = { logo }
64- alt = "logo"
74+ < div >
75+ < Row type = "flex" justify = "center" >
76+ < img
77+ src = { 'https://facebook.github.io/metro/img/metro.svg' }
78+ className = { logo }
79+ alt = "logo"
80+ />
81+ </ Row >
82+
83+ < Row type = "flex" justify = "center" >
84+ < Col span = { 16 } >
85+ < BundleRunForm
86+ handleStartedBundling = { ( ) => this . setState ( { isBundling : true } ) }
87+ handleFinishedBundling = { ( ) => {
88+ this . fetchBundles ( ) ;
89+ this . setState ( { isBundling : false } ) ;
90+ } }
6591 />
66- </ Row >
67-
68- < Row type = "flex" justify = "center" >
69- < Col span = { 16 } >
70- < BundleRunForm
71- handleStartedBundling = { ( ) =>
72- this . setState ( { showLoadingIndicator : true } )
73- }
74- handleFinishedBundling = { ( ) => this . fetchBundles ( ) }
75- />
76- </ Col >
77- </ Row >
78-
79- < Row type = "flex" justify = "center" >
80- < Col span = { 16 } >
81- { this . state . metroHistory &&
82- Object . keys ( this . state . metroHistory ) . map ( bundleHash => (
83- < Link to = { `/graph/${ bundleHash } ` } key = { bundleHash } >
84- < BundleCard
85- onClick = { ( ) =>
86- this . setState ( { selectedBundleHash : bundleHash } )
87- }
88- bundleInfo = { this . state . metroHistory [ bundleHash ] }
89- />
90- </ Link >
91- ) ) }
92- </ Col >
93- </ Row >
94-
95- { this . state . showLoadingIndicator && (
96- < Icon type = "loading" className = { loadingIndicator } />
97- ) }
98- </ div >
99- )
92+ </ Col >
93+ </ Row >
94+
95+ { loadedEmptyHistory && ! isBundling ? (
96+ < WelcomeMessage onReload = { this . _handleReload } />
97+ ) : null }
98+
99+ < Row type = "flex" justify = "center" >
100+ < Col span = { 16 } >
101+ { metroHistory &&
102+ Object . keys ( metroHistory ) . map ( bundleHash => (
103+ < Link to = { `/graph/${ bundleHash } ` } key = { bundleHash } >
104+ < BundleCard
105+ onClick = { ( ) =>
106+ this . setState ( { selectedBundleHash : bundleHash } )
107+ }
108+ bundleInfo = { metroHistory [ bundleHash ] }
109+ />
110+ </ Link >
111+ ) ) }
112+ </ Col >
113+ </ Row >
114+
115+ { ( isLoadingData || isBundling ) && (
116+ < Icon type = "loading" className = { loadingIndicator } />
117+ ) }
118+ </ div >
100119 ) ;
101120 }
102121}
0 commit comments