Skip to content

Commit

Permalink
fix(RodEditor): Add cell/layer selection
Browse files Browse the repository at this point in the history
  • Loading branch information
floryst committed Apr 30, 2018
1 parent d0af4b0 commit 5f9a8a9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
37 changes: 31 additions & 6 deletions src/simput/RodEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,24 @@ export default class RodEditor extends React.Component {
super(props);
this.state = {};

this.onCellChange = this.onCellChange.bind(this);
this.onLengthChange = this.onLengthChange.bind(this);
this.addLayer = this.addLayer.bind(this);
this.delLayer = this.delLayer.bind(this);
}

onCellChange(layer, value) {
const data = this.props.data;
const cells = this.props.ui.domain;
if (data.value && data.value.length) {
const stack = data.value[0].stack;
if (value in cells) {
stack[layer.key].label = value;
this.props.onChange(data);
}
}
}

onLengthChange(layer, value) {
const data = this.props.data;
if (data.value && data.value.length) {
Expand All @@ -34,12 +47,13 @@ export default class RodEditor extends React.Component {

addLayer(idx) {
const data = this.props.data;
if (data.value && data.value.length) {
const cells = Object.keys(this.props.ui.domain);
if (data.value && data.value.length && cells.length) {
const stack = data.value[0].stack;
const afterIdx = idx + 1;
stack.splice(afterIdx, 0, {
color: 'blue',
type: 'gap',
label: cells[0],
length: 0,
});

Expand All @@ -58,16 +72,27 @@ export default class RodEditor extends React.Component {
}

render() {
const cells = Object.keys(this.props.ui.domain);

const columns = [
{
key: 'color',
dataKey: 'color',
label: 'Color',
},
{
key: 'type',
dataKey: 'label',
label: 'Layer Type',
key: 'cell',
dataKey: 'cell',
label: 'Cell/Layer Type',
classes: style.centeredCell,
render: (cellName, layer) => (
<select
className={style.cellSelect}
onChange={(e) => this.onCellChange(layer, e.target.value)}
>
{cells.map((name) => <option key={name}>{name}</option>)}
</select>
),
},
{
key: 'length',
Expand Down Expand Up @@ -115,7 +140,7 @@ RodEditor.propTypes = {
// name: PropTypes.string,
onChange: PropTypes.func.isRequired,
// show: PropTypes.func.isRequired,
// ui: PropTypes.object.isRequired,
ui: PropTypes.object.isRequired,
viewData: PropTypes.object.isRequired,
};

Expand Down
4 changes: 4 additions & 0 deletions src/simput/RodEditor.mcss
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.centeredCell {
text-align: center;
}

.cellSelect {
width: 100%;
}

0 comments on commit 5f9a8a9

Please sign in to comment.