Skip to content

Commit c0da20f

Browse files
motiz88facebook-github-bot
authored andcommitted
Add basic welcome message to visualizer
Reviewed By: mjesun Differential Revision: D13093802 fbshipit-source-id: 93d190c19c2e8ffd7de0ae2fde6d772e0e729687
1 parent cb1ae79 commit c0da20f

File tree

2 files changed

+116
-46
lines changed

2 files changed

+116
-46
lines changed

packages/metro-visualizer/src/app/dashboard/DashboardApp.js

Lines changed: 65 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
const BundlePlots = require('./components/BundlePlots');
1616
const BundleRunForm = require('./components/BundleRunForm');
1717
const React = require('react');
18+
const WelcomeMessage = require('./components/WelcomeMessage');
1819

1920
const handleAPIError = require('../utils/handleAPIError');
2021

@@ -29,21 +30,29 @@ import {message, Row, Col, Card, Tag, Icon} from 'antd';
2930
import type {BundleOptions} from 'metro/src/shared/types.flow.js';
3031

3132
type State = {
32-
metroHistory: MetroHistory,
33-
selectedBundleHash?: ?string,
34-
showLoadingIndicator: boolean,
33+
metroHistory: ?MetroHistory,
34+
selectedBundleHash: ?string,
35+
isLoadingData: boolean,
36+
isBundling: boolean,
3537
};
3638

3739
class 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
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
* @format
9+
*/
10+
11+
/* eslint-env browser */
12+
13+
'use strict';
14+
15+
const React = require('react');
16+
17+
const {css} = require('emotion');
18+
const message = css`
19+
text-align: center;
20+
margin-top: 8px;
21+
margin-bottom: 16px;
22+
`;
23+
24+
import {Row, Col} from 'antd';
25+
26+
type Props = {|
27+
onReload: () => void,
28+
|};
29+
30+
class WelcomeMessage extends React.Component<Props> {
31+
_onReloadClick = e => {
32+
e.preventDefault();
33+
this.props.onReload();
34+
};
35+
36+
render() {
37+
return (
38+
<Row type="flex" justify="center">
39+
<Col span={16} className={message}>
40+
I don't see any bundles here. If you've started a build externally,{' '}
41+
<a href="#" onClick={this._onReloadClick}>
42+
reload this page
43+
</a>{' '}
44+
to see it.
45+
</Col>
46+
</Row>
47+
);
48+
}
49+
}
50+
51+
module.exports = WelcomeMessage;

0 commit comments

Comments
 (0)