fix(xod-client, xod-core): fix errors caused by pulse type

This commit is contained in:
Kirill Shumilov
2016-12-30 18:15:08 +03:00
parent 8c1fd7d0cd
commit 2124cb3cab
4 changed files with 11 additions and 11 deletions

View File

@@ -7,7 +7,7 @@ function BoolWidget(props) {
'is-disabled': props.disabled,
});
const onChange = (event) => {
props.onChange(event.target.value);
props.onChange(event.target.checked);
};
return (
<div className={cls}>
@@ -16,10 +16,7 @@ function BoolWidget(props) {
type="checkbox"
value="1"
checked={props.value}
autoFocus={props.focused}
disabled={props.disabled}
onFocus={props.onFocus}
onBlur={props.onBlur}
onChange={onChange}
/>
<label

View File

@@ -25,6 +25,7 @@ export default function composeWidget(Component, widgetProps) {
constructor(props) {
super(props);
this.type = widgetProps.type;
this.commitOnChange = widgetProps.commitOnChange;
const val = this.parseValue(props.value);
this.state = {
@@ -87,13 +88,15 @@ export default function composeWidget(Component, widgetProps) {
updateValue(value) {
const newValue = this.parseValue(value);
const commitCallback = (this.commitOnChange) ? this.commit.bind(this) : noop;
this.setState({
value: newValue,
});
}, commitCallback);
}
commit() {
if (this.state.value !== this.props.value && this.props.injected) {
if (this.parseValue(this.state.value) !== this.parseValue(this.props.value)) {
this.props.onPropUpdate(
this.props.entityId,
this.props.kind,

View File

@@ -56,10 +56,10 @@ export const WIDGET_MAPPING = {
props: { type: 'string' },
},
[WIDGET_TYPE.PULSE]: {
component: PulseWidget,
component: BoolWidget,
props: {
type: 'pulse',
keyDownHandlers: widgetNumberKeysDownHandlers,
type: 'bool',
commitOnChange: true,
},
},
[WIDGET_TYPE.IO_LABEL]: {

View File

@@ -49,7 +49,7 @@ export const PROPERTY_DEFAULT_VALUE = {
BOOL: false,
NUMBER: 0,
STRING: '',
PULSE: 'once',
PULSE: false,
};
export const PROPERTY_TYPE_PARSE = {
@@ -60,7 +60,7 @@ export const PROPERTY_TYPE_PARSE = {
return isNaN(newValue) ? '' : newValue;
},
[PROPERTY_TYPE.STRING]: v => String(v),
[PROPERTY_TYPE.PULSE]: v => (v !== null ? String(v) : PROPERTY_DEFAULT_VALUE.PULSE),
[PROPERTY_TYPE.PULSE]: v => !!v,
};
export const SIZE = {