Skip to content

Commit

Permalink
Merge pull request #880 from smartcontractkit/chores/key-value-list
Browse files Browse the repository at this point in the history
Extract KeyValueList and allow configuration for Transactions#Show
  • Loading branch information
rupurt authored Jan 10, 2019
2 parents 7453797 + 4925ea6 commit 275165b
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 103 deletions.
32 changes: 32 additions & 0 deletions gui/__tests__/components/KeyValueList.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react'
import { render } from 'enzyme'
import KeyValueList from 'components/KeyValueList'

describe('components/KeyValueList', () => {
it('can display a title', () => {
let withTitle = render(<KeyValueList entries={[]} title='My Title' />)
expect(withTitle.text()).toContain('My Title')
})

it('can display header columns', () => {
let withHead = render(<KeyValueList entries={[]} showHead />)
expect(withHead.text()).toContain('Key')
expect(withHead.text()).toContain('Value')

let withoutHead = render(<KeyValueList entries={[]} />)
expect(withoutHead.text()).not.toContain('Key')
expect(withoutHead.text()).not.toContain('Value')
})

it('renders entry pairs', () => {
const entries = [
['CHAINLINK_DEV', 'true'],
['DATABASE_TIMEOUT', 1000]
]
let wrapper = render(<KeyValueList entries={entries} />)
expect(wrapper.text()).toContain('CHAINLINK_DEV')
expect(wrapper.text()).toContain('true')
expect(wrapper.text()).toContain('DATABASE_TIMEOUT')
expect(wrapper.text()).toContain('1000')
})
})
9 changes: 2 additions & 7 deletions gui/src/components/Cards/SimpleList.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@ import React from 'react'
import Table from '@material-ui/core/Table'
import TableBody from '@material-ui/core/TableBody'
import Card from '@material-ui/core/Card'
import CardContent from '@material-ui/core/CardContent'
import Typography from '@material-ui/core/Typography'
import CardTitle from 'components/Cards/Title'

const SimpleList = ({children, title}) => {
return (
<Card>
<CardContent>
<Typography variant='h5' color='secondary'>
{title}
</Typography>
</CardContent>
<CardTitle>{title}</CardTitle>

<Table>
<TableBody>
Expand Down
25 changes: 25 additions & 0 deletions gui/src/components/Cards/Title.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react'
import PropTypes from 'prop-types'
import CardContent from '@material-ui/core/CardContent'
import Divider from '@material-ui/core/Divider'
import Typography from '@material-ui/core/Typography'

const Title = ({children, divider}) => (
<React.Fragment>
<CardContent>
<Typography variant='h5' color='secondary'>{children}</Typography>
</CardContent>

{divider && <Divider />}
</React.Fragment>
)

Title.propTypes = {
divider: PropTypes.bool.isRequired
}

Title.defaultProps = {
divider: false
}

export default Title
81 changes: 0 additions & 81 deletions gui/src/components/ConfigList.js

This file was deleted.

85 changes: 85 additions & 0 deletions gui/src/components/KeyValueList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import React from 'react'
import PropTypes from 'prop-types'
import Card from '@material-ui/core/Card'
import Table from '@material-ui/core/Table'
import TableBody from '@material-ui/core/TableBody'
import TableCell from '@material-ui/core/TableCell'
import TableHead from '@material-ui/core/TableHead'
import TableRow from '@material-ui/core/TableRow'
import Typography from '@material-ui/core/Typography'
import CardTitle from 'components/Cards/Title'

const renderEntries = entries => (
entries.map(([k, v]) => (
<TableRow key={k}>
<Col>{k}</Col>
<Col>{v}</Col>
</TableRow>
))
)

const renderBody = (entries, error) => {
if (error) {
return <ErrorRow>{error}</ErrorRow>
} else if (entries.length === 0) {
return <FetchingRow />
} else {
return renderEntries(entries)
}
}

const SpanRow = ({children}) => (
<TableRow>
<TableCell component='th' scope='row' colSpan={3}>{children}</TableCell>
</TableRow>
)

const FetchingRow = () => <SpanRow>...</SpanRow>

const ErrorRow = ({children}) => <SpanRow>{children}</SpanRow>

const Col = ({children}) => (
<TableCell>
<Typography variant='body1'>{children}</Typography>
</TableCell>
)

const HeadCol = ({children}) => (
<TableCell>
<Typography variant='body1' color='textSecondary'>
{children}
</Typography>
</TableCell>
)

const KeyValueList = ({entries, error, showHead, title}) => (
<Card>
{title && <CardTitle divider>{title}</CardTitle>}

<Table>
{showHead &&
<TableHead>
<TableRow>
<HeadCol>Key</HeadCol>
<HeadCol>Value</HeadCol>
</TableRow>
</TableHead>}
<TableBody>
{renderBody(entries, error)}
</TableBody>
</Table>
</Card>
)

KeyValueList.propTypes = {
showHead: PropTypes.bool.isRequired,
entries: PropTypes.array.isRequired,
title: PropTypes.string,
error: PropTypes.string
}

KeyValueList.defaultProps = {
showHead: false
}

export default KeyValueList
22 changes: 7 additions & 15 deletions gui/src/containers/Configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import { connect } from 'react-redux'
import { withRouteData } from 'react-static'
import Grid from '@material-ui/core/Grid'
import Typography from '@material-ui/core/Typography'
import Card from '@material-ui/core/Card'
import CardContent from '@material-ui/core/CardContent'
import Divider from '@material-ui/core/Divider'
import PaddedCard from 'components/PaddedCard'
import ConfigList from 'components/ConfigList'
import KeyValueList from 'components/KeyValueList'
import Content from 'components/Content'
import DeleteJobRuns from 'containers/Configuration/DeleteJobRuns'
import { fetchConfiguration } from 'actions'
Expand All @@ -23,17 +20,12 @@ export const Configuration = useHooks(props => {
<Content>
<Grid container spacing={40}>
<Grid item sm={12} md={8}>
<Card>
<CardContent>
<Typography variant='h5' color='secondary'>
Configuration
</Typography>
</CardContent>

<Divider />

<ConfigList configs={props.configs} error={props.error} />
</Card>
<KeyValueList
title='Configuration'
entries={props.configs}
error={props.error}
showHead
/>
</Grid>
<Grid item sm={12} md={4}>
<Grid container spacing={40}>
Expand Down

0 comments on commit 275165b

Please sign in to comment.