|
| 1 | +import React, {PropTypes, Component} from 'react' |
| 2 | +import {Button, Col, Panel, Glyphicon, Form, FormGroup, ControlLabel, FormControl} from 'react-bootstrap' |
| 3 | + |
| 4 | +import {getMessage, getComponentMessages} from '../../common/util/config' |
| 5 | +import {UPDATER_FIELDS} from '../util/deployment' |
| 6 | + |
| 7 | +export default class Updater extends Component { |
| 8 | + static propTypes = { |
| 9 | + onChange: PropTypes.func, |
| 10 | + onRemove: PropTypes.func, |
| 11 | + updater: PropTypes.object |
| 12 | + } |
| 13 | + |
| 14 | + _onChange = (evt) => this.props.onChange(evt, this.props.index) |
| 15 | + |
| 16 | + // _onChangeNumber = (evt) => this.props.onChange(this.props.index, {[evt.target.name]: evt.target.value}) |
| 17 | + |
| 18 | + _onRemove = () => this.props.onRemove(this.props.index) |
| 19 | + |
| 20 | + render () { |
| 21 | + const messages = getComponentMessages('ProjectSettings') |
| 22 | + const {updater} = this.props |
| 23 | + return ( |
| 24 | + <Panel |
| 25 | + header={`${updater.type || '[type]'} - ${updater.url || '[url]'}`} |
| 26 | + defaultExpanded={!updater.type} |
| 27 | + collapsible> |
| 28 | + <Form> |
| 29 | + <Button |
| 30 | + bsSize='xsmall' |
| 31 | + bsStyle='danger' |
| 32 | + className='pull-right' |
| 33 | + onClick={this._onRemove}> |
| 34 | + Remove <Glyphicon glyph='remove' /> |
| 35 | + </Button> |
| 36 | + {UPDATER_FIELDS.map((f, i) => { |
| 37 | + const fieldName = f.name.split('.').slice(-1)[0] |
| 38 | + return ( |
| 39 | + <Col key={i} xs={f.width || 6}> |
| 40 | + <FormGroup> |
| 41 | + <ControlLabel>{getMessage(messages, `deployment.${f.name}`)}</ControlLabel> |
| 42 | + <FormControl |
| 43 | + value={updater[fieldName]} |
| 44 | + {...f} |
| 45 | + name={f.name} |
| 46 | + children={f.children |
| 47 | + ? f.children.sort((a, b) => { |
| 48 | + if (a.value < b.value) return -1 |
| 49 | + if (a.value > b.value) return 1 |
| 50 | + return 0 |
| 51 | + }).map((o, i) => ( |
| 52 | + <option key={i} {...o} /> |
| 53 | + )) |
| 54 | + : undefined |
| 55 | + } |
| 56 | + onChange={this._onChange} /> |
| 57 | + </FormGroup> |
| 58 | + </Col> |
| 59 | + ) |
| 60 | + })} |
| 61 | + </Form> |
| 62 | + </Panel> |
| 63 | + ) |
| 64 | + } |
| 65 | +} |
0 commit comments