Skip to content

Commit

Permalink
Fix enum and boolean handling issue (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbrott committed Dec 18, 2018
1 parent 17effc7 commit 93c75b6
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 32 deletions.
4 changes: 2 additions & 2 deletions FtcDashboard/dash/config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"HOST": "192.168.49.1",
"HOST": "192.168.1.20",
"PORT": 8000
}
}
13 changes: 10 additions & 3 deletions FtcDashboard/dash/src/components/inputs/BooleanInput.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import React from 'react';
import PropTypes from 'prop-types';

const BooleanInput = ({ value, onChange }) => (
<input type="checkbox" checked={value} onChange={evt => onChange(evt.target.checked, true)} />
const BooleanInput = ({ value, onChange, onSave }) => (
<span>
<input type="checkbox" checked={value} onChange={evt => onChange({
value: evt.target.checked,
valid: true
})} />
<button onClick={onSave}>Save</button>
</span>
);

BooleanInput.propTypes = {
value: PropTypes.bool.isRequired,
onChange: PropTypes.func.isRequired
onChange: PropTypes.func.isRequired,
onSave: PropTypes.func.isRequired
};

export default BooleanInput;
27 changes: 17 additions & 10 deletions FtcDashboard/dash/src/components/inputs/EnumInput.jsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
import React from 'react';
import PropTypes from 'prop-types';

const EnumInput = ({ value, values, onChange }) => (
<select
className="valid"
value={value}
onChange={evt => onChange(evt.target.value, true)}>
{
values.map(v => (<option key={v} value={v}>{v}</option>))
}
</select>
const EnumInput = ({ value, values, onChange, onSave }) => (
<span>
<select
className="valid"
value={value}
onChange={evt => onChange({
value: evt.target.value,
valid: true
})}>
{
values.map(v => (<option key={v} value={v}>{v}</option>))
}
</select>
<button onClick={onSave}>Save</button>
</span>
);

EnumInput.propTypes = {
value: PropTypes.string.isRequired,
values: PropTypes.arrayOf(PropTypes.string).isRequired,
onChange: PropTypes.func.isRequired
onChange: PropTypes.func.isRequired,
onSave: PropTypes.func.isRequired
};

export default EnumInput;
4 changes: 2 additions & 2 deletions FtcDashboard/dash/src/components/inputs/TextInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class TextInput extends React.Component {

handleKeyDown(evt) {
if (evt.keyCode === 13) {
this.props.onEnter();
this.props.onSave();
}
}

Expand All @@ -41,7 +41,7 @@ TextInput.propTypes = {
valid: PropTypes.bool.isRequired,
validate: PropTypes.func.isRequired,
onChange: PropTypes.func.isRequired,
onEnter: PropTypes.func.isRequired
onSave: PropTypes.func.isRequired
};

export default TextInput;
20 changes: 13 additions & 7 deletions FtcDashboard/dash/src/containers/BasicOption.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class BasicOption extends React.Component {

const type = OptionType.getFromSchema(schema);

const onEnter = () => {
const optionOnSave = () => {
if (valid && modified) {
onSave(value);
}
Expand All @@ -22,27 +22,33 @@ class BasicOption extends React.Component {

switch (type) {
case OptionType.INT:
input = <TextInput value={value} valid={valid} validate={validateInt} onChange={onChange} onEnter={onEnter} />;
input = <TextInput value={value} valid={valid} validate={validateInt} onChange={onChange} onSave={optionOnSave} />;
break;
case OptionType.DOUBLE:
input = <TextInput value={value} valid={valid} validate={validateDouble} onChange={onChange} onEnter={onEnter} />;
input = <TextInput value={value} valid={valid} validate={validateDouble} onChange={onChange} onSave={optionOnSave} />;
break;
case OptionType.STRING:
input = <TextInput value={value} valid={valid} validate={validateString} onChange={onChange} onEnter={onEnter} />;
input = <TextInput value={value} valid={valid} validate={validateString} onChange={onChange} onSave={optionOnSave} />;
break;
case OptionType.BOOLEAN:
input = <BooleanInput value={value} onChange={onChange} />;
input = <BooleanInput value={value} onChange={onChange} onSave={optionOnSave} />;
break;
case OptionType.ENUM:
input = <EnumInput value={value} values={schema.values} onChange={onChange} />;
input = <EnumInput value={value} values={schema.values} onChange={onChange} onSave={optionOnSave} />;
break;
default:
input = <p>Unknown option type: {type}</p>;
}

return (
<tr>
<td>{modified ? '*' : ''}{name}</td>
<td><span style={ modified ? {
userSelect: 'auto',
opacity: 1.0
} : {
userSelect: 'none',
opacity: 0.0
}}>*</span>{name}</td>
<td>{input}</td>
</tr>
);
Expand Down
7 changes: 0 additions & 7 deletions FtcDashboard/dash/src/containers/CustomOption.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import PropTypes from 'prop-types';
import { isEqual } from 'lodash';
import Heading from '../components/Heading';
import Icon from '../components/Icon';
import BasicOption from './BasicOption';
Expand Down Expand Up @@ -30,12 +29,6 @@ class CustomOption extends React.Component {
.filter((key) => key in schema)
.sort();

// TODO: hack to reverse sort PID coefficients
if (isEqual(optionKeys, ['d', 'i', 'p'])) {
optionKeys[0] = 'p';
optionKeys[2] = 'd';
}

const options = optionKeys.map((key) => {
const onChange = (value) => {
this.props.onChange({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* WebSocket connection to a dashboard client.
*/
public class DashboardWebSocket extends NanoWSD.WebSocket {
public static final boolean DEBUG = true;
public static final boolean DEBUG = false;

private static final Gson GSON = new GsonBuilder()
.registerTypeAdapter(Message.class, new MessageDeserializer())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.firstinspires.ftc.teamcode;

import com.acmerobotics.dashboard.config.Config;
import com.qualcomm.robotcore.hardware.DcMotorSimple;

/*
* Some additional constants for testing.
*/
@Config
public class SampleConstants {
public static DcMotorSimple.Direction DIR = DcMotorSimple.Direction.FORWARD;
public static boolean FF_ENABLED = false;
}

0 comments on commit 93c75b6

Please sign in to comment.