From f606af49a54a4f324f7e51dd2deac08bbcc21c08 Mon Sep 17 00:00:00 2001 From: Anastasia Poupeney Date: Fri, 1 Jun 2018 16:10:13 +0200 Subject: [PATCH] adding pagination for operation details --- src/components/AccountPage/index.js | 2 +- src/components/OperationsList/index.js | 47 +++++++++++-------- .../modals/AccountSettingRenderBody.js | 10 ++-- 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/components/AccountPage/index.js b/src/components/AccountPage/index.js index 7bd5c134..ac2965c7 100644 --- a/src/components/AccountPage/index.js +++ b/src/components/AccountPage/index.js @@ -178,7 +178,7 @@ class AccountPage extends PureComponent { )} /> - + ) : ( diff --git a/src/components/OperationsList/index.js b/src/components/OperationsList/index.js index f81f5c78..34f2334f 100644 --- a/src/components/OperationsList/index.js +++ b/src/components/OperationsList/index.js @@ -66,31 +66,39 @@ type Props = { openModal: Function, t: T, withAccount?: boolean, - nbToShow: number, title?: string, } -export class OperationsList extends PureComponent { +type State = { + nbToShow: number, +} + +const initialState = { + nbToShow: 20, +} +export class OperationsList extends PureComponent { static defaultProps = { onAccountClick: noop, withAccount: false, canShowMore: false, - nbToShow: 20, } + state = initialState + handleClickOperation = (data: Object) => this.props.openModal(MODAL_OPERATION_DETAILS, data) + // TODO: convert of async/await if fetching with the api + fetchMoreOperations = () => { + this.setState({ nbToShow: this.state.nbToShow + 20 }) + } + render() { - const { - account, - accounts, - canShowMore, - nbToShow, - onAccountClick, - t, - title, - withAccount, - } = this.props + const { account, accounts, canShowMore, onAccountClick, t, title, withAccount } = this.props + const { nbToShow } = this.state + + const totalOperations = accounts + ? accounts.reduce((a, b) => +a + +b.operations.length, 0) + : account.operations.length if (!account && !accounts) { console.warn('Preventing render OperationsList because not received account or accounts') // eslint-disable-line no-console @@ -139,12 +147,13 @@ export class OperationsList extends PureComponent { ) })} - {canShowMore && ( - - {t('operationsList:showMore')} - - - )} + {canShowMore && + totalOperations > nbToShow && ( + + {t('operationsList:showMore')} + + + )} ) diff --git a/src/components/modals/AccountSettingRenderBody.js b/src/components/modals/AccountSettingRenderBody.js index ab04d3c8..7da86ae3 100644 --- a/src/components/modals/AccountSettingRenderBody.js +++ b/src/components/modals/AccountSettingRenderBody.js @@ -37,10 +37,6 @@ type Props = { data: any, } -function onClickSelectAll(e) { - e.target.select() -} - const mapDispatchToProps = { setDataModal, updateAccount, @@ -173,14 +169,16 @@ class HelperComp extends PureComponent {