From f21de3dd1c8f851562c6ae1da2e561519db84e02 Mon Sep 17 00:00:00 2001 From: kwingram25 Date: Mon, 1 Jul 2019 18:00:26 +0100 Subject: [PATCH] ActionItem component for responding to proposals (#1351) * ActionItem * rearrange --- packages/app-democracy/src/Overview/Item.tsx | 73 --------------- .../app-democracy/src/Overview/Proposal.tsx | 21 +++-- .../app-democracy/src/Overview/Referendum.tsx | 15 +-- .../app-treasury/src/Overview/Proposal.tsx | 21 ++--- packages/ui-app/src/ActionItem.tsx | 91 +++++++++++++++++++ packages/ui-app/src/Column.tsx | 7 +- packages/ui-app/src/index.tsx | 1 + 7 files changed, 122 insertions(+), 107 deletions(-) delete mode 100644 packages/app-democracy/src/Overview/Item.tsx create mode 100644 packages/ui-app/src/ActionItem.tsx diff --git a/packages/app-democracy/src/Overview/Item.tsx b/packages/app-democracy/src/Overview/Item.tsx deleted file mode 100644 index 78ae8224fa..0000000000 --- a/packages/app-democracy/src/Overview/Item.tsx +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2017-2019 @polkadot/app-democracy authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import { I18nProps } from '@polkadot/ui-app/types'; -import { Method, Proposal } from '@polkadot/types'; - -import BN from 'bn.js'; -import React from 'react'; -import styled from 'styled-components'; -import { Call, Card } from '@polkadot/ui-app'; -import { formatNumber } from '@polkadot/util'; -import { styles as rowStyles } from '@polkadot/ui-app/Row'; - -import translate from '../translate'; - -type Props = I18nProps & { - children?: React.ReactNode, - proposal: Proposal, - proposalExtra?: React.ReactNode, - idNumber: BN | number -}; - -class Item extends React.PureComponent { - render () { - const { children, className, idNumber, proposal, proposalExtra } = this.props; - const { meta, method, section } = Method.findFunction(proposal.callIndex); - - return ( - -
-
-
-

#{formatNumber(idNumber)}: {section}.{method}

- {meta && meta.documentation && ( -
- {meta.documentation.join(' ')} -
- )} -
- {children} -
- - {proposalExtra} - -
-
- ); - } -} - -export default translate(styled(Item as React.ComponentClass)` - ${rowStyles} - - .democracy--Item-extrinsic { - margin-top: 1rem; - - .ui--Params-Content { - padding-left: 0; - } - } - - .democracy--Item-header { - margin-bottom: 1rem; - } - - .ui--Row-details.democracy--Item-header{ - min-width: 0; - } -`); diff --git a/packages/app-democracy/src/Overview/Proposal.tsx b/packages/app-democracy/src/Overview/Proposal.tsx index 9931417dfe..e08bff76d6 100644 --- a/packages/app-democracy/src/Overview/Proposal.tsx +++ b/packages/app-democracy/src/Overview/Proposal.tsx @@ -7,12 +7,11 @@ import { I18nProps } from '@polkadot/ui-app/types'; import BN from 'bn.js'; import React from 'react'; import { AccountId, Balance, Option, Proposal, Tuple, Vector } from '@polkadot/types'; -import { InputAddress, Labelled, Static } from '@polkadot/ui-app'; +import { ActionItem, InputAddress, Labelled, Static } from '@polkadot/ui-app'; import { withCalls, withMulti } from '@polkadot/ui-api'; import { formatBalance } from '@polkadot/util'; import translate from '../translate'; -import Item from './Item'; import Seconding from './Seconding'; type Props = I18nProps & { @@ -29,21 +28,23 @@ class ProposalDisplay extends React.PureComponent { : []; return ( - + } > - - + {this.renderInfo()} + ); } - private renderExtra () { + private renderInfo () { const { democracy_depositOf, t } = this.props; if (!democracy_depositOf) { diff --git a/packages/app-democracy/src/Overview/Referendum.tsx b/packages/app-democracy/src/Overview/Referendum.tsx index de19796bb1..c390f835c7 100644 --- a/packages/app-democracy/src/Overview/Referendum.tsx +++ b/packages/app-democracy/src/Overview/Referendum.tsx @@ -10,13 +10,12 @@ import { RawParam } from '@polkadot/ui-params/types'; import BN from 'bn.js'; import React from 'react'; import styled from 'styled-components'; -import { Chart, Static } from '@polkadot/ui-app'; +import { ActionItem, Chart, Static } from '@polkadot/ui-app'; import { formatBalance, formatNumber } from '@polkadot/util'; import settings from '@polkadot/ui-settings'; import VoteThreshold from '@polkadot/ui-params/Param/VoteThreshold'; import { withCalls, withMulti } from '@polkadot/ui-api'; -import Item from './Item'; import translate from '../translate'; import Voting from './Voting'; @@ -96,18 +95,20 @@ class Referendum extends React.PureComponent { } return ( - + } > - - + {this.renderInfo()} + ); } - private renderExtra () { + private renderInfo () { const { chain_bestNumber, democracy_publicDelay, t, value: { end, threshold } } = this.props; if (!chain_bestNumber) { diff --git a/packages/app-treasury/src/Overview/Proposal.tsx b/packages/app-treasury/src/Overview/Proposal.tsx index bf9e6bf2db..9123d14aa0 100644 --- a/packages/app-treasury/src/Overview/Proposal.tsx +++ b/packages/app-treasury/src/Overview/Proposal.tsx @@ -7,13 +7,12 @@ import { SubjectInfo } from '@polkadot/ui-keyring/observable/types'; import React from 'react'; import { Option, TreasuryProposal } from '@polkadot/types'; -import { Button, Icon, InputAddress, Labelled, Static } from '@polkadot/ui-app'; +import { ActionItem, Button, Icon, InputAddress, Labelled, Static } from '@polkadot/ui-app'; import { withCalls, withMulti, withObservable } from '@polkadot/ui-api'; import keyring from '@polkadot/ui-keyring'; import { formatBalance } from '@polkadot/util'; import translate from '../translate'; -import Item from './Item'; import Approve from './Approve'; type Props = I18nProps & { @@ -33,21 +32,19 @@ class ProposalDisplay extends React.PureComponent { }; render () { - const { isApproved, proposal, proposalId } = this.props; + const { proposal, proposalId } = this.props; if (!proposal) { return null; } return ( - - {this.renderAccessory()} - + {this.renderInfo()} + ); } @@ -85,14 +82,14 @@ class ProposalDisplay extends React.PureComponent { ); } - private renderExtra () { + private renderInfo () { const { isApproved, proposal, t } = this.props; if (!proposal) { diff --git a/packages/ui-app/src/ActionItem.tsx b/packages/ui-app/src/ActionItem.tsx new file mode 100644 index 0000000000..cbfdea35b8 --- /dev/null +++ b/packages/ui-app/src/ActionItem.tsx @@ -0,0 +1,91 @@ +// Copyright 2017-2019 @polkadot/app-democracy authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +import { Method, Proposal } from '@polkadot/types'; + +import BN from 'bn.js'; +import React from 'react'; +import styled from 'styled-components'; +import { formatNumber } from '@polkadot/util'; + +import Call from './Call'; +import Card from './Card'; +import { styles as rowStyles } from './Row'; + +type Props = { + className?: string, + children?: React.ReactNode, + accessory?: React.ReactNode, + proposal?: Proposal, + idNumber: BN | number | string +}; + +export const styles = ` + ${rowStyles} + + .ui--ActionItem-extrinsic { + margin-top: 1rem; + + .ui--Params-Content { + padding-left: 0; + } + } + + .ui--ActionItem-header { + margin-bottom: 1rem; + } + + .ui--ActionItem-buttons { + + } +`; + +class ActionItem extends React.PureComponent { + render () { + const { className, children, accessory, proposal } = this.props; + + const idNumber = typeof this.props.idNumber === 'string' + ? this.props.idNumber + : formatNumber(this.props.idNumber); + + return ( + +
+
+
+ { + proposal ? + (() => { + const { meta, method, section } = Method.findFunction(proposal.callIndex); + + return ( + <> +

#{idNumber}: {section}.{method}

+ {meta && meta.documentation && ( +
+ {meta.documentation.join(' ')} +
+ )} + + + ); + })() : + ( +

#{idNumber}

+ ) + } +
+ {accessory} +
+ {children} +
+
+ ); + } +} + +export default styled(ActionItem as React.ComponentClass)`${styles}`; diff --git a/packages/ui-app/src/Column.tsx b/packages/ui-app/src/Column.tsx index d76518df92..84e822c8f4 100644 --- a/packages/ui-app/src/Column.tsx +++ b/packages/ui-app/src/Column.tsx @@ -31,11 +31,8 @@ class Column extends Collection { renderCollection () { const { children } = this.props; - return ( -
- {children} -
- ); + + return children; } // renderEmpty () { diff --git a/packages/ui-app/src/index.tsx b/packages/ui-app/src/index.tsx index 1d050cee0f..508c9b68f3 100644 --- a/packages/ui-app/src/index.tsx +++ b/packages/ui-app/src/index.tsx @@ -2,6 +2,7 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +export { default as ActionItem } from './ActionItem'; export { default as AddressCard } from './AddressCard'; export { default as AddressInfo } from './AddressInfo'; export { default as AddressMini } from './AddressMini';