Browse Source

Merge pull request #127 from loeck/master

Improved performance for TransactionsList, remove Defer on Chart in D…
master
Meriadec Pillet 7 years ago
committed by GitHub
parent
commit
beb58dc1c8
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      src/components/DashboardPage/AccountCard.js
  2. 60
      src/components/DashboardPage/index.js
  3. 65
      src/components/TransactionsList/index.js

21
src/components/DashboardPage/AccountCard.js

@ -9,7 +9,6 @@ import IconCurrencyBitcoin from 'icons/currencies/Bitcoin'
import { AreaChart } from 'components/base/Chart' import { AreaChart } from 'components/base/Chart'
import Bar from 'components/base/Bar' import Bar from 'components/base/Bar'
import Box, { Card } from 'components/base/Box' import Box, { Card } from 'components/base/Box'
import Defer from 'components/base/Defer'
import FormattedVal from 'components/base/FormattedVal' import FormattedVal from 'components/base/FormattedVal'
const AccountCard = ({ const AccountCard = ({
@ -47,17 +46,15 @@ const AccountCard = ({
/> />
)} )}
</Box> </Box>
<Defer> <AreaChart
<AreaChart tiny
tiny id={`account-chart-${account.id}`}
id={`account-chart-${account.id}`} color="#fcb653"
color="#fcb653" height={52}
height={52} data={data}
data={data} strokeWidth={1}
strokeWidth={1} linearGradient={[[5, 0.4], [80, 0]]}
linearGradient={[[5, 0.4], [80, 0]]} />
/>
</Defer>
</Card> </Card>
) )

60
src/components/DashboardPage/index.js

@ -25,7 +25,6 @@ import { saveSettings } from 'actions/settings'
import { AreaChart } from 'components/base/Chart' import { AreaChart } from 'components/base/Chart'
import Box, { Card } from 'components/base/Box' import Box, { Card } from 'components/base/Box'
import Pills from 'components/base/Pills' import Pills from 'components/base/Pills'
import Defer from 'components/base/Defer'
import Text from 'components/base/Text' import Text from 'components/base/Text'
import TransactionsList from 'components/TransactionsList' import TransactionsList from 'components/TransactionsList'
@ -56,6 +55,7 @@ type State = {
} }
const ACCOUNTS_BY_LINE = 3 const ACCOUNTS_BY_LINE = 3
const ALL_TRANSACTIONS_LIMIT = 10
const TIMEOUT_REFRESH_DATAS = 5e3 const TIMEOUT_REFRESH_DATAS = 5e3
const itemsTimes = [ const itemsTimes = [
@ -92,7 +92,9 @@ const getAllTransactions = accounts => {
return result return result
}, []) }, [])
return sortBy(allTransactions, t => t.received_at).reverse() return sortBy(allTransactions, t => t.received_at)
.reverse()
.slice(0, ALL_TRANSACTIONS_LIMIT)
} }
const getAccountsChunk = accounts => { const getAccountsChunk = accounts => {
@ -123,7 +125,7 @@ class DashboardPage extends PureComponent<Props, State> {
}) })
} }
if (nextProps.accounts.length !== this.props.accounts.length) { if (nextProps.accounts !== this.props.accounts) {
this.setState({ this.setState({
accountsChunk: getAccountsChunk(nextProps.accounts), accountsChunk: getAccountsChunk(nextProps.accounts),
allTransactions: getAllTransactions(nextProps.accounts), allTransactions: getAllTransactions(nextProps.accounts),
@ -192,33 +194,31 @@ class DashboardPage extends PureComponent<Props, State> {
<Box px={6}> <Box px={6}>
<BalanceInfos since={selectedTime} /> <BalanceInfos since={selectedTime} />
</Box> </Box>
<Defer> <Box ff="Open Sans" fontSize={4} color="warmGrey">
<Box ff="Open Sans" fontSize={4} color="warmGrey"> <AreaChart
<AreaChart id="dashboard-chart"
id="dashboard-chart" margin={{
margin={{ top: space[6],
top: space[6], bottom: 0,
bottom: 0, left: space[6] - 10,
left: space[6] - 10, right: space[6],
right: space[6], }}
}} color="#5286f7"
color="#5286f7" height={250}
height={250} data={takeRight(
data={takeRight( fakeDatas.reduce((res, data) => {
fakeDatas.reduce((res, data) => { data.forEach((d, i) => {
data.forEach((d, i) => { res[i] = {
res[i] = { name: d.name,
name: d.name, value: (res[i] ? res[i].value : 0) + d.value,
value: (res[i] ? res[i].value : 0) + d.value, }
} })
}) return res
return res }, []),
}, []), 25,
25, )}
)} />
/> </Box>
</Box>
</Defer>
</Card> </Card>
<Box flow={4}> <Box flow={4}>
<Box horizontal align="flex-end"> <Box horizontal align="flex-end">

65
src/components/TransactionsList/index.js

@ -1,9 +1,10 @@
// @flow // @flow
import React from 'react' import React, { Component } from 'react'
import styled from 'styled-components' import styled from 'styled-components'
import moment from 'moment' import moment from 'moment'
import get from 'lodash/get' import get from 'lodash/get'
import isEqual from 'lodash/isEqual'
import type { Transaction as TransactionType } from 'types/common' import type { Transaction as TransactionType } from 'types/common'
@ -118,28 +119,48 @@ type Props = {
withAccounts?: boolean, withAccounts?: boolean,
} }
const TransactionsList = ({ transactions, withAccounts }: Props) => ( class TransactionsList extends Component<Props> {
<Box flow={1}> static defaultProps = {
<Box horizontal pt={4}> withAccounts: false,
<HeaderCol size={DATE_COL_SIZE}>{'Date'}</HeaderCol> }
{withAccounts && <HeaderCol size={ACCOUNT_COL_SIZE}>{'Account'}</HeaderCol>}
<HeaderCol grow>{'Address'}</HeaderCol> componentWillReceiveProps(nextProps: Props) {
<HeaderCol size={AMOUNT_COL_SIZE} justify="flex-end"> if (nextProps.transactions !== this.props.transactions) {
{'Amount'} this._hashCache = this.getHashCache(nextProps.transactions)
</HeaderCol> }
</Box> }
<Defer>
<Box> shouldComponentUpdate(nextProps: Props) {
{transactions.map(t => ( return !isEqual(this._hashCache, this.getHashCache(nextProps.transactions))
<Transaction key={`{${t.hash}-${t.account ? t.account.id : ''}`} tx={t} /> }
))}
</Box>
</Defer>
</Box>
)
TransactionsList.defaultProps = { getHashCache = (transactions: Array<TransactionType>) => transactions.map(t => t.hash)
withAccounts: false,
_hashCache = this.getHashCache(this.props.transactions)
render() {
const { transactions, withAccounts } = this.props
return (
<Box flow={1}>
<Box horizontal pt={4}>
<HeaderCol size={DATE_COL_SIZE}>{'Date'}</HeaderCol>
{withAccounts && <HeaderCol size={ACCOUNT_COL_SIZE}>{'Account'}</HeaderCol>}
<HeaderCol grow>{'Address'}</HeaderCol>
<HeaderCol size={AMOUNT_COL_SIZE} justify="flex-end">
{'Amount'}
</HeaderCol>
</Box>
<Defer>
<Box>
{transactions.map(t => (
<Transaction key={`{${t.hash}-${t.account ? t.account.id : ''}`} tx={t} />
))}
</Box>
</Defer>
</Box>
)
}
} }
export default TransactionsList export default TransactionsList

Loading…
Cancel
Save