Merge pull request #3555 from ethcore/ng-fast-ui

Faster UI - React Tweaks
This commit is contained in:
Gav Wood 2016-11-22 17:05:23 +01:00 committed by GitHub
commit 490b39cc85
11 changed files with 317 additions and 119 deletions

View File

@ -102,6 +102,7 @@
"postcss-nested": "^1.0.0", "postcss-nested": "^1.0.0",
"postcss-simple-vars": "^3.0.0", "postcss-simple-vars": "^3.0.0",
"raw-loader": "^0.5.1", "raw-loader": "^0.5.1",
"react-addons-perf": "~15.3.2",
"react-addons-test-utils": "~15.3.2", "react-addons-test-utils": "~15.3.2",
"react-copy-to-clipboard": "^4.2.3", "react-copy-to-clipboard": "^4.2.3",
"react-dom": "~15.3.2", "react-dom": "~15.3.2",

View File

@ -46,6 +46,12 @@ import './index.html';
injectTapEventPlugin(); injectTapEventPlugin();
if (process.env.NODE_ENV === 'development') {
// Expose the React Performance Tools on the`window` object
const Perf = require('react-addons-perf');
window.Perf = Perf;
}
const AUTH_HASH = '#/auth?'; const AUTH_HASH = '#/auth?';
const parityUrl = process.env.PARITY_URL || const parityUrl = process.env.PARITY_URL ||
( (

View File

@ -16,26 +16,17 @@
import React, { Component, PropTypes } from 'react'; import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
class ParityBackground extends Component { class ParityBackground extends Component {
static contextTypes = {
muiTheme: PropTypes.object.isRequired
}
static propTypes = { static propTypes = {
style: PropTypes.object.isRequired,
children: PropTypes.node, children: PropTypes.node,
className: PropTypes.string, className: PropTypes.string,
gradient: PropTypes.string,
seed: PropTypes.any,
settings: PropTypes.object.isRequired,
onClick: PropTypes.func onClick: PropTypes.func
} };
render () { render () {
const { muiTheme } = this.context; const { children, className, style, onClick } = this.props;
const { children, className, gradient, seed, settings, onClick } = this.props;
const style = muiTheme.parity.getBackgroundStyle(gradient, seed || settings.backgroundSeed);
return ( return (
<div <div
@ -48,17 +39,29 @@ class ParityBackground extends Component {
} }
} }
function mapStateToProps (state) { function mapStateToProps (_, initProps) {
const { settings } = state; const { gradient, seed, muiTheme } = initProps;
return { settings }; let _seed = seed;
let _props = { style: muiTheme.parity.getBackgroundStyle(gradient, seed) };
return (state, props) => {
const { backgroundSeed } = state.settings;
const { seed } = props;
const newSeed = seed || backgroundSeed;
if (newSeed === _seed) {
return _props;
} }
function mapDispatchToProps (dispatch) { _seed = newSeed;
return bindActionCreators({}, dispatch); _props = { style: muiTheme.parity.getBackgroundStyle(gradient, newSeed) };
return _props;
};
} }
export default connect( export default connect(
mapStateToProps, mapStateToProps
mapDispatchToProps
)(ParityBackground); )(ParityBackground);

View File

@ -16,6 +16,7 @@
import React, { Component, PropTypes } from 'react'; import React, { Component, PropTypes } from 'react';
import { Link } from 'react-router'; import { Link } from 'react-router';
import { isEqual } from 'lodash';
import { Balance, Container, ContainerTitle, IdentityIcon, IdentityName, Tags, Input } from '../../../ui'; import { Balance, Container, ContainerTitle, IdentityIcon, IdentityName, Tags, Input } from '../../../ui';
@ -30,7 +31,6 @@ export default class Summary extends Component {
link: PropTypes.string, link: PropTypes.string,
name: PropTypes.string, name: PropTypes.string,
noLink: PropTypes.bool, noLink: PropTypes.bool,
children: PropTypes.node,
handleAddSearchToken: PropTypes.func handleAddSearchToken: PropTypes.func
}; };
@ -42,8 +42,42 @@ export default class Summary extends Component {
name: 'Unnamed' name: 'Unnamed'
}; };
shouldComponentUpdate (nextProps) {
const prev = {
link: this.props.link, name: this.props.name,
noLink: this.props.noLink,
meta: this.props.account.meta, address: this.props.account.address
};
const next = {
link: nextProps.link, name: nextProps.name,
noLink: nextProps.noLink,
meta: nextProps.account.meta, address: nextProps.account.address
};
if (!isEqual(next, prev)) {
return true;
}
const prevTokens = this.props.balance.tokens || [];
const nextTokens = nextProps.balance.tokens || [];
if (prevTokens.length !== nextTokens.length) {
return true;
}
const prevValues = prevTokens.map((t) => t.value.toNumber());
const nextValues = nextTokens.map((t) => t.value.toNumber());
if (!isEqual(prevValues, nextValues)) {
return true;
}
return false;
}
render () { render () {
const { account, children, handleAddSearchToken } = this.props; const { account, handleAddSearchToken } = this.props;
const { tags } = account.meta; const { tags } = account.meta;
if (!account) { if (!account) {
@ -71,7 +105,6 @@ export default class Summary extends Component {
byline={ addressComponent } /> byline={ addressComponent } />
{ this.renderBalance() } { this.renderBalance() }
{ children }
</Container> </Container>
); );
} }

View File

@ -30,3 +30,25 @@
right: 1em; right: 1em;
top: 4em; top: 4em;
} }
.loadings {
display: flex;
flex-wrap: wrap;
.loading {
flex: 0 1 50%;
width: 50%;
height: 150px;
display: flex;
padding: 0.25em;
box-sizing: border-box;
> div {
display: flex;
flex: 1;
align-items: center;
justify-content: center;
background-color: rgba(0, 0, 0, 0.8);
}
}
}

View File

@ -42,17 +42,48 @@ class Accounts extends Component {
newDialog: false, newDialog: false,
sortOrder: '', sortOrder: '',
searchValues: [], searchValues: [],
searchTokens: [] searchTokens: [],
show: false
}
componentWillMount () {
window.setTimeout(() => {
this.setState({ show: true });
}, 100);
} }
render () { render () {
const { accounts, hasAccounts, balances } = this.props;
const { searchValues, sortOrder } = this.state;
return ( return (
<div className={ styles.accounts }> <div className={ styles.accounts }>
{ this.renderNewDialog() } { this.renderNewDialog() }
{ this.renderActionbar() } { this.renderActionbar() }
{ this.state.show ? this.renderAccounts() : this.renderLoading() }
</div>
);
}
renderLoading () {
const { accounts } = this.props;
const loadings = ((accounts && Object.keys(accounts)) || []).map((_, idx) => (
<div key={ idx } className={ styles.loading }>
<div></div>
</div>
));
return (
<div className={ styles.loadings }>
{ loadings }
</div>
);
}
renderAccounts () {
const { accounts, hasAccounts, balances } = this.props;
const { searchValues, sortOrder } = this.state;
return (
<Page> <Page>
<List <List
search={ searchValues } search={ searchValues }
@ -65,7 +96,6 @@ class Accounts extends Component {
className={ styles.accountTooltip } className={ styles.accountTooltip }
text='your accounts are visible for easy access, allowing you to edit the meta information, make transfers, view transactions and fund the account' /> text='your accounts are visible for easy access, allowing you to edit the meta information, make transfers, view transactions and fund the account' />
</Page> </Page>
</div>
); );
} }

View File

@ -22,6 +22,10 @@ import { Errors, ParityBackground, Tooltips } from '../../../ui';
import styles from '../application.css'; import styles from '../application.css';
export default class Container extends Component { export default class Container extends Component {
static contextTypes = {
muiTheme: PropTypes.object.isRequired
};
static propTypes = { static propTypes = {
children: PropTypes.node.isRequired, children: PropTypes.node.isRequired,
showFirstRun: PropTypes.bool, showFirstRun: PropTypes.bool,
@ -30,9 +34,10 @@ export default class Container extends Component {
render () { render () {
const { children, showFirstRun, onCloseFirstRun } = this.props; const { children, showFirstRun, onCloseFirstRun } = this.props;
const { muiTheme } = this.context;
return ( return (
<ParityBackground className={ styles.container }> <ParityBackground className={ styles.container } muiTheme={ muiTheme }>
<FirstRun <FirstRun
visible={ showFirstRun } visible={ showFirstRun }
onClose={ onCloseFirstRun } /> onClose={ onCloseFirstRun } />

View File

@ -23,6 +23,11 @@
.tabs { .tabs {
width: 100%; width: 100%;
position: relative; position: relative;
display: flex;
& > * {
flex: 1;
}
} }
.tabs button, .tabs button,
@ -38,6 +43,7 @@
button.tabactive, button.tabactive,
button.tabactive:hover { button.tabactive:hover {
color: white !important;
background: rgba(0, 0, 0, 0.25) !important; background: rgba(0, 0, 0, 0.25) !important;
border-radius: 4px 4px 0 0; border-radius: 4px 4px 0 0;
} }

View File

@ -18,7 +18,7 @@ import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { bindActionCreators } from 'redux'; import { bindActionCreators } from 'redux';
import { Toolbar, ToolbarGroup } from 'material-ui/Toolbar'; import { Toolbar, ToolbarGroup } from 'material-ui/Toolbar';
import { Tabs, Tab } from 'material-ui/Tabs'; import { Tab as MUITab } from 'material-ui/Tabs';
import { Badge, Tooltip } from '../../../ui'; import { Badge, Tooltip } from '../../../ui';
@ -33,20 +33,138 @@ const TABMAP = {
deploy: 'contract' deploy: 'contract'
}; };
class Tab extends Component {
static propTypes = {
active: PropTypes.bool,
view: PropTypes.object,
children: PropTypes.node,
pendings: PropTypes.number,
onChange: PropTypes.func
};
shouldComponentUpdate (nextProps) {
return nextProps.active !== this.props.active ||
(nextProps.view.id === 'signer' && nextProps.pendings !== this.props.pendings);
}
render () {
const { active, view, children } = this.props;
const label = this.getLabel(view);
return (
<MUITab
className={ active ? styles.tabactive : '' }
selected={ active }
icon={ view.icon }
label={ label }
onClick={ this.handleClick }
>
{ children }
</MUITab>
);
}
getLabel (view) {
const { label } = view;
if (view.id === 'signer') {
return this.renderSignerLabel(label);
}
if (view.id === 'status') {
return this.renderStatusLabel(label);
}
return this.renderLabel(label);
}
renderLabel (name, bubble) {
return (
<div className={ styles.label }>
{ name }
{ bubble }
</div>
);
}
renderSignerLabel (label) {
const { pendings } = this.props;
if (pendings) {
const bubble = (
<Badge
color='red'
className={ styles.labelBubble }
value={ pendings } />
);
return this.renderLabel(label, bubble);
}
return this.renderLabel(label);
}
renderStatusLabel (label) {
// const { isTest, netChain } = this.props;
// const bubble = (
// <Badge
// color={ isTest ? 'red' : 'default' }
// className={ styles.labelBubble }
// value={ isTest ? 'TEST' : netChain } />
// );
return this.renderLabel(label, null);
}
handleClick = () => {
const { onChange, view } = this.props;
onChange(view);
}
}
class TabBar extends Component { class TabBar extends Component {
static contextTypes = { static contextTypes = {
router: PropTypes.object.isRequired router: PropTypes.object.isRequired
} };
static propTypes = { static propTypes = {
views: PropTypes.array.isRequired,
hash: PropTypes.string.isRequired,
pending: PropTypes.array, pending: PropTypes.array,
isTest: PropTypes.bool, isTest: PropTypes.bool,
netChain: PropTypes.string, netChain: PropTypes.string
settings: PropTypes.object.isRequired };
}
static defaultProps = {
pending: []
};
state = { state = {
activeRoute: '/accounts' activeViewId: ''
};
setActiveView (props = this.props) {
const { hash, views } = props;
const view = views.find((view) => view.value === hash);
this.setState({ activeViewId: view.id });
}
componentWillMount () {
this.setActiveView();
}
componentWillReceiveProps (nextProps) {
if (nextProps.hash !== this.props.hash) {
this.setActiveView(nextProps);
}
}
shouldComponentUpdate (nextProps, nextState) {
return (nextProps.hash !== this.props.hash) ||
(nextProps.pending.length !== this.props.pending.length) ||
(nextState.activeViewId !== this.state.activeViewId);
} }
render () { render () {
@ -81,100 +199,64 @@ class TabBar extends Component {
} }
renderTabs () { renderTabs () {
const { settings } = this.props; const { views, pending } = this.props;
const windowHash = (window.location.hash || '').split('?')[0].split('/')[1]; const { activeViewId } = this.state;
const hash = TABMAP[windowHash] || windowHash;
const items = Object.keys(settings.views) const items = views
.filter((id) => settings.views[id].fixed || settings.views[id].active) .map((view, index) => {
.map((id) => { const body = (view.id === 'accounts')
const view = settings.views[id]; ? (
let label = this.renderLabel(view.label);
let body = null;
if (id === 'accounts') {
body = (
<Tooltip className={ styles.tabbarTooltip } text='navigate between the different parts and views of the application, switching between an account view, token view and distributed application view' /> <Tooltip className={ styles.tabbarTooltip } text='navigate between the different parts and views of the application, switching between an account view, token view and distributed application view' />
); )
} else if (id === 'signer') { : null;
label = this.renderSignerLabel(label);
} else if (id === 'status') { const active = activeViewId === view.id;
label = this.renderStatusLabel(label);
}
return ( return (
<Tab <Tab
className={ hash === view.value ? styles.tabactive : '' } active={ active }
value={ view.value } view={ view }
icon={ view.icon } onChange={ this.onChange }
key={ id } key={ index }
label={ label } pendings={ pending.length }
onActive={ this.onActivate(view.route) }> >
{ body } { body }
</Tab> </Tab>
); );
}); });
return ( return (
<Tabs <div
className={ styles.tabs } className={ styles.tabs }
value={ hash }> onChange={ this.onChange }>
{ items } { items }
</Tabs>
);
}
renderLabel = (name, bubble) => {
return (
<div className={ styles.label }>
{ name }
{ bubble }
</div> </div>
); );
} }
renderSignerLabel = (label) => { onChange = (view) => {
const { pending } = this.props;
let bubble = null;
if (pending && pending.length) {
bubble = (
<Badge
color='red'
className={ styles.labelBubble }
value={ pending.length } />
);
}
return this.renderLabel(label, bubble);
}
renderStatusLabel = (label) => {
// const { isTest, netChain } = this.props;
// const bubble = (
// <Badge
// color={ isTest ? 'red' : 'default' }
// className={ styles.labelBubble }
// value={ isTest ? 'TEST' : netChain } />
// );
return this.renderLabel(label, null);
}
onActivate = (activeRoute) => {
const { router } = this.context; const { router } = this.context;
return (event) => { router.push(view.route);
router.push(activeRoute); this.setState({ activeViewId: view.id });
this.setState({ activeRoute });
};
} }
} }
function mapStateToProps (state) { function mapStateToProps (state) {
const { settings } = state; const { views } = state.settings;
return { settings }; const filteredViews = Object
.keys(views)
.filter((id) => views[id].fixed || views[id].active)
.map((id) => ({
...views[id],
id
}));
const windowHash = (window.location.hash || '').split('?')[0].split('/')[1];
const hash = TABMAP[windowHash] || windowHash;
return { views: filteredViews, hash };
} }
function mapDispatchToProps (dispatch) { function mapDispatchToProps (dispatch) {

View File

@ -28,6 +28,10 @@ import imagesEthcoreBlock from '../../../assets/images/parity-logo-white-no-text
import styles from './parityBar.css'; import styles from './parityBar.css';
class ParityBar extends Component { class ParityBar extends Component {
static contextTypes = {
muiTheme: PropTypes.object.isRequired
};
static propTypes = { static propTypes = {
pending: PropTypes.array, pending: PropTypes.array,
dapp: PropTypes.bool dapp: PropTypes.bool
@ -62,6 +66,7 @@ class ParityBar extends Component {
renderBar () { renderBar () {
const { dapp } = this.props; const { dapp } = this.props;
const { muiTheme } = this.context;
if (!dapp) { if (!dapp) {
return null; return null;
@ -75,7 +80,7 @@ class ParityBar extends Component {
return ( return (
<div className={ styles.bar }> <div className={ styles.bar }>
<ParityBackground className={ styles.corner }> <ParityBackground className={ styles.corner } muiTheme={ muiTheme }>
<div className={ styles.cornercolor }> <div className={ styles.cornercolor }>
<Link to='/apps'> <Link to='/apps'>
<Button <Button
@ -95,9 +100,11 @@ class ParityBar extends Component {
} }
renderExpanded () { renderExpanded () {
const { muiTheme } = this.context;
return ( return (
<div className={ styles.overlay }> <div className={ styles.overlay }>
<ParityBackground className={ styles.expanded }> <ParityBackground className={ styles.expanded } muiTheme={ muiTheme }>
<div className={ styles.header }> <div className={ styles.header }>
<div className={ styles.title }> <div className={ styles.title }>
<ContainerTitle title='Parity Signer: Pending' /> <ContainerTitle title='Parity Signer: Pending' />

View File

@ -81,6 +81,7 @@ class Background extends Component {
renderBackgrounds () { renderBackgrounds () {
const { settings } = this.props; const { settings } = this.props;
const { seeds } = this.state; const { seeds } = this.state;
const { muiTheme } = this.context;
return seeds.map((seed, index) => { return seeds.map((seed, index) => {
return ( return (
@ -89,7 +90,9 @@ class Background extends Component {
<ParityBackground <ParityBackground
className={ settings.backgroundSeed === seed ? styles.seedactive : styles.seed } className={ settings.backgroundSeed === seed ? styles.seedactive : styles.seed }
seed={ seed } seed={ seed }
onClick={ this.onSelect(seed) } /> onClick={ this.onSelect(seed) }
muiTheme={ muiTheme }
/>
</div> </div>
</div> </div>
); );