Add table to Safe owner list

This commit is contained in:
Germán Martínez 2019-05-24 21:14:58 +02:00
parent ca729f1707
commit a21dc1cf62
5 changed files with 133 additions and 42 deletions

View File

@ -21,6 +21,7 @@ type Props<K> = {
children: Function, children: Function,
size: number, size: number,
defaultFixed?: boolean, defaultFixed?: boolean,
noBorder: boolean,
} }
type State = { type State = {
@ -30,6 +31,7 @@ type State = {
orderProp: boolean, orderProp: boolean,
rowsPerPage: number, rowsPerPage: number,
fixed?: boolean, fixed?: boolean,
noBorder: boolean,
} }
const styles = { const styles = {
@ -99,7 +101,7 @@ class GnoTable<K> extends React.Component<Props<K>, State> {
render() { render() {
const { const {
data, label, columns, classes, children, size, defaultOrderBy, defaultFixed, data, label, columns, classes, children, size, defaultOrderBy, defaultFixed, noBorder,
} = this.props } = this.props
const { const {
order, orderBy, page, orderProp, rowsPerPage, fixed, order, orderBy, page, orderProp, rowsPerPage, fixed,
@ -117,7 +119,7 @@ class GnoTable<K> extends React.Component<Props<K>, State> {
const paginationClasses = { const paginationClasses = {
selectRoot: classes.selectRoot, selectRoot: classes.selectRoot,
root: classes.paginationRoot, root: !noBorder && classes.paginationRoot,
input: classes.white, input: classes.white,
} }
@ -132,13 +134,13 @@ class GnoTable<K> extends React.Component<Props<K>, State> {
return ( return (
<React.Fragment> <React.Fragment>
{!isEmpty && ( {!isEmpty && (
<Table aria-labelledby={label} className={classes.root}> <Table aria-labelledby={label} className={!noBorder && classes.root}>
<TableHead columns={columns} order={order} orderBy={orderByParam} onSort={this.onSort} /> <TableHead columns={columns} order={order} orderBy={orderByParam} onSort={this.onSort} />
<TableBody>{children(sortedData)}</TableBody> <TableBody>{children(sortedData)}</TableBody>
</Table> </Table>
)} )}
{isEmpty && ( {isEmpty && (
<Row className={classNames(classes.loader, classes.root)} style={this.getEmptyStyle(emptyRows + 1)}> <Row className={classNames(classes.loader, !noBorder && classes.root)} style={this.getEmptyStyle(emptyRows + 1)}>
<CircularProgress size={60} /> <CircularProgress size={60} />
</Row> </Row>
)} )}

View File

@ -0,0 +1,21 @@
// @flow
import * as React from 'react'
import Block from '~/components/layout/Block'
import Paragraph from '~/components/layout/Paragraph'
import Identicon from '~/components/Identicon'
type Props = {
address: string,
}
const OwnerAddressTableCell = (props: Props) => {
const { address } = props
return (
<Block align="left">
<Identicon address={address} diameter={32} />
<Paragraph style={{ marginLeft: 10 }}>{address}</Paragraph>
</Block>
)
}
export default OwnerAddressTableCell

View File

@ -0,0 +1,55 @@
// @flow
import { List } from 'immutable'
import type { Owner } from '~/routes/safe/store/models/owner'
import { type SortRow } from '~/components/Table/sorting'
import { type Column } from '~/components/Table/TableHead'
export const OWNERS_TABLE_NAME_ID = 'name'
export const OWNERS_TABLE_ADDRESS_ID = 'address'
export const OWNERS_TABLE_ACTIONS_ID = 'actions'
type OwnerData = {
name: string,
address: string,
}
export type OwnerRow = SortRow<OwnerData>
export const getOwnerData = (owners: List<Owner>): List<OwnerRow> => {
const rows = owners.map((owner: Owner) => ({
[OWNERS_TABLE_NAME_ID]: owner.get('name'),
[OWNERS_TABLE_ADDRESS_ID]: owner.get('address'),
}))
return rows
}
export const generateColumns = () => {
const nameColumn: Column = {
id: OWNERS_TABLE_NAME_ID,
order: false,
disablePadding: false,
label: 'Name',
width: 150,
align: 'left',
}
const addressColumn: Column = {
id: OWNERS_TABLE_ADDRESS_ID,
order: false,
disablePadding: false,
label: 'Address',
width: 350,
align: 'left',
}
const actionsColumn: Column = {
id: OWNERS_TABLE_ACTIONS_ID,
order: false,
disablePadding: false,
label: '',
custom: true,
}
return List([nameColumn, addressColumn, actionsColumn])
}

View File

@ -1,6 +1,7 @@
// @flow // @flow
import React from 'react' import React from 'react'
import classNames from 'classnames' import classNames from 'classnames'
import { List } from 'immutable'
import { withStyles } from '@material-ui/core/styles' import { withStyles } from '@material-ui/core/styles'
import Identicon from '~/components/Identicon' import Identicon from '~/components/Identicon'
import Block from '~/components/layout/Block' import Block from '~/components/layout/Block'
@ -9,12 +10,19 @@ import Field from '~/components/forms/Field'
import { import {
composeValidators, required, minMaxLength, composeValidators, required, minMaxLength,
} from '~/components/forms/validator' } from '~/components/forms/validator'
import Table from '~/components/Table'
import { type Column, cellWidth } from '~/components/Table/TableHead'
import TableRow from '@material-ui/core/TableRow'
import TableCell from '@material-ui/core/TableCell'
import TextField from '~/components/forms/TextField' import TextField from '~/components/forms/TextField'
import Row from '~/components/layout/Row' import Row from '~/components/layout/Row'
import Paragraph from '~/components/layout/Paragraph' import Paragraph from '~/components/layout/Paragraph'
import Hairline from '~/components/layout/Hairline' import Hairline from '~/components/layout/Hairline'
import Button from '~/components/layout/Button' import Button from '~/components/layout/Button'
import AddOwnerModal from './AddOwnerModal' import AddOwnerModal from './AddOwnerModal'
import OwnerAddressTableCell from './OwnerAddressTableCell'
import type { Owner } from '~/routes/safe/store/models/owner'
import { getOwnerData, generateColumns, OWNERS_TABLE_ADDRESS_ID, type OwnerRow, } from './dataFetcher'
import { sm, boldFont } from '~/theme/variables' import { sm, boldFont } from '~/theme/variables'
import { styles } from './style' import { styles } from './style'
@ -38,7 +46,7 @@ type Props = {
createTransaction: Function, createTransaction: Function,
} }
type Action = 'AddOwner' type Action = 'AddOwner' | 'EditOwner' | 'ReplaceOwner' | 'RemoveOwner'
class ManageOwners extends React.Component<Props, State> { class ManageOwners extends React.Component<Props, State> {
state = { state = {
@ -66,45 +74,53 @@ class ManageOwners extends React.Component<Props, State> {
} = this.props } = this.props
const { showAddOwner } = this.state const { showAddOwner } = this.state
const columns = generateColumns()
const ownerData = getOwnerData(owners)
return ( return (
<React.Fragment> <React.Fragment>
<Block className={classes.formContainer}> <Block className={classes.formContainer}>
<Paragraph noMargin className={classes.title} size="lg" weight="bolder"> <Paragraph noMargin className={classes.title} size="lg" weight="bolder">
Manage Safe Owners Manage Safe Owners
</Paragraph> </Paragraph>
<Row className={classes.header}>
<Col xs={3}>NAME</Col> <Table
<Col xs={9}>ADDRESS</Col> label="owners"
</Row> columns={columns}
<Hairline /> data={ownerData}
<Block> size={ownerData.size}
{owners.map(owner => ( defaultFixed
<React.Fragment key={owner.get('address')}> noBorder
<Row className={classes.owner}> >
<Col xs={3}> {(sortedData: Array<OwnerRow>) => sortedData.map((row: any, index: number) => (
<Paragraph size="lg" noMargin> <TableRow tabIndex={-1} key={index} className={classes.hide}>
{owner.get('name')} {columns.map((column: Column) => (
</Paragraph> <TableCell key={column.id} style={cellWidth(column.width)} align={column.align} component="td">
</Col> {column.id === OWNERS_TABLE_ADDRESS_ID ? <OwnerAddressTableCell address={row[column.id]} /> : row[column.id]}
<Col xs={1} align="right"> </TableCell>
<Block className={classNames(classes.name, classes.userName)}> ))}
<Identicon address={owner.get('address')} diameter={32} /> <TableCell component="td">
</Block> <Row align="end" className={classes.actions}>
</Col> <Button
<Col xs={8}> onClick={this.onShow('EditOwner')}
<Block className={classNames(classes.name, classes.userName)}> >
<Block align="center" className={classes.user}> Edit
<Paragraph size="md" color="disabled" noMargin> </Button>
{owner.get('address')} <Button
</Paragraph> onClick={this.onShow('ReplaceOwner')}
</Block> >
</Block> Replace
</Col> </Button>
</Row> <Button
<Hairline /> onClick={this.onShow('RemoveOwner')}
</React.Fragment> >
Remove
</Button>
</Row>
</TableCell>
</TableRow>
))} ))}
</Block> </Table>
</Block> </Block>
<Hairline /> <Hairline />
<Row style={controlsStyle} align="end" grow> <Row style={controlsStyle} align="end" grow>

View File

@ -1,6 +1,6 @@
// @flow // @flow
import { import {
sm, xs, lg, border, sm, xs, md, lg, border,
} from '~/theme/variables' } from '~/theme/variables'
export const styles = () => ({ export const styles = () => ({
@ -11,9 +11,6 @@ export const styles = () => ({
formContainer: { formContainer: {
minHeight: '369px', minHeight: '369px',
}, },
header: {
padding: `${sm} ${lg}`,
},
owners: { owners: {
padding: lg, padding: lg,
}, },
@ -25,7 +22,7 @@ export const styles = () => ({
whiteSpace: 'nowrap', whiteSpace: 'nowrap',
}, },
owner: { owner: {
padding: sm, padding: md,
paddingLeft: lg, paddingLeft: lg,
alignItems: 'center', alignItems: 'center',
}, },