cabana/src/components/EditMessageModal.js

124 lines
3.7 KiB
JavaScript
Raw Normal View History

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import Modal from './Modals/baseModal';
export default class EditMessageModal extends Component {
2017-12-12 19:27:20 -07:00
static propTypes = {
handleClose: PropTypes.func.isRequired,
handleSave: PropTypes.func.isRequired,
message: PropTypes.object.isRequired
};
constructor(props) {
super(props);
2017-12-12 19:27:20 -07:00
this.state = {
messageFrame: props.message.frame.copy()
};
this.handleSave = this.handleSave.bind(this);
this.editTransmitter = this.editTransmitter.bind(this);
this.addTransmitter = this.addTransmitter.bind(this);
this.renderActions = this.renderActions.bind(this);
}
2017-12-12 19:27:20 -07:00
handleSave() {
this.props.handleSave(this.state.messageFrame);
}
2017-12-12 19:27:20 -07:00
addTransmitter() {
const { messageFrame } = this.state;
messageFrame.addTransmitter();
this.setState({ messageFrame });
}
editTransmitter(transmitter) {}
2017-06-21 23:57:35 -06:00
2017-12-12 19:27:20 -07:00
renderActions() {
return (
<div>
<button className="button--inverted" onClick={this.props.handleClose}>
Cancel
</button>
<button className="button--primary" onClick={this.handleSave}>
Save Message
</button>
</div>
);
}
2017-06-21 23:57:35 -06:00
2017-12-12 19:27:20 -07:00
render() {
return (
<Modal
title={`Edit Message: (${this.props.message.id})`}
subtitle="Make changes and update defaults of this message"
handleClose={this.props.handleClose}
handleSave={this.handleSave}
actions={this.renderActions()}
>
<div className="form-field">
<label htmlFor="message_name">
<span>Name</span>
<sup>Customize the name of this message</sup>
</label>
<input
type="text"
id="message_name"
value={this.state.messageFrame.name}
onChange={(e) => {
2017-12-12 19:27:20 -07:00
const { messageFrame } = this.state;
messageFrame.name = e.target.value;
this.setState({ messageFrame });
}}
/>
</div>
2017-12-12 19:27:20 -07:00
<div className="form-field">
<label htmlFor="message_size">
<span>Size</span>
<sup>Add a size parameter to this message</sup>
</label>
<input
type="number"
id="message_size"
value={this.state.messageFrame.size}
onChange={(e) => {
2017-12-12 19:27:20 -07:00
const { messageFrame } = this.state;
messageFrame.size = parseInt(e.target.value, 10);
this.setState({ messageFrame });
}}
/>
</div>
<div className="form-field u-hidden">
<label htmlFor="message_transmitters">
<span>Transmitters</span>
<sup>
Add the physical ECU units that this message is coming from.
</sup>
</label>
<div className="form-field-inset">
<ul className="form-field-inset-list">
{this.state.messageFrame.transmitters.map((transmitter) => (
<li className="form-field-inset-list-item" key={transmitter}>
<div className="form-field-inset-list-item-title">
<span>{transmitter}</span>
</div>
<div className="form-field-inset-list-item-action">
<button className="button--tiny button--alpha">Edit</button>
</div>
</li>
))}
2017-12-12 19:27:20 -07:00
<button className="button--tiny button--alpha">
<span>
<i className="fa fa-plus" />
{' '}
Add Transmitter
2017-12-12 19:27:20 -07:00
</span>
</button>
</ul>
</div>
</div>
</Modal>
);
}
2017-06-20 17:46:07 -06:00
}