Skip to content

Commit

Permalink
update after running prepublish
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehu committed Jul 18, 2018
1 parent be4a3e6 commit e70fd0d
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 30 deletions.
40 changes: 35 additions & 5 deletions lib/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,36 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
*/


var styles = {
error: {
color: "rgb(244, 67, 54)",
fontSize: "12px",
lineHeight: "12px"
},
checkbox: {
marginTop: "14px",
marginBottom: "0px",
height: "72px"
}
};

var Checkbox2 = function (_React$Component) {
_inherits(Checkbox2, _React$Component);

function Checkbox2() {
function Checkbox2(props) {
_classCallCheck(this, Checkbox2);

return _possibleConstructorReturn(this, (Checkbox2.__proto__ || Object.getPrototypeOf(Checkbox2)).apply(this, arguments));
var _this = _possibleConstructorReturn(this, (Checkbox2.__proto__ || Object.getPrototypeOf(Checkbox2)).call(this, props));

var _this$props = _this.props,
model = _this$props.model,
form = _this$props.form;
var key = form.key;
//If a boolean is stored, use it; if not, if a boolean is defined as schema's default, use it.

var value = _.isBoolean(_this.props.value) ? _this.props.value : _.isBoolean(form.schema.default) ? form.schema.default : undefined;
_this.props.setDefault(key, model, form, value);
return _this;
}

_createClass(Checkbox2, [{
Expand All @@ -45,17 +68,22 @@ var Checkbox2 = function (_React$Component) {

return _react2.default.createElement(
'div',
{ className: this.props.form.className },
{ className: this.props.form.className, style: styles.checkbox },
_react2.default.createElement(_Checkbox2.default, {
name: this.props.form.key.slice(-1)[0],
value: this.props.form.key.slice(-1)[0],
checked: this.props.value || false,
checked: this.props.value,
label: this.props.form.title,
disabled: this.props.form.readonly,
onCheck: function onCheck(e, checked) {
_this2.props.onChangeValidate(e);
}
})
}),
_react2.default.createElement(
'span',
{ style: styles.error },
this.props.errorText
)
);
}
}]);
Expand All @@ -73,6 +101,8 @@ var _temp = function () {
return;
}

__REACT_HOT_LOADER__.register(styles, 'styles', 'src/Checkbox.js');

__REACT_HOT_LOADER__.register(Checkbox2, 'Checkbox2', 'src/Checkbox.js');

__REACT_HOT_LOADER__.register(_default, 'default', 'src/Checkbox.js');
Expand Down
2 changes: 1 addition & 1 deletion lib/ComposedComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var _default = function _default(ComposedComponent) {
_this.state = {
value: value,
valid: !!(validationResult.valid || !value),
error: !validationResult.valid && value ? validationResult.error.message : null
error: !validationResult.valid && (value ? validationResult.error.message : null) || _this.props.errorText
};
return _this;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Number.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ var Number = function (_React$Component) {
type: this.props.form.type,
floatingLabelText: this.props.form.title,
hintText: this.props.form.placeholder,
errorText: this.props.error,
errorText: this.props.error || this.props.errorText,
onChange: this.preValidationCheck,
value: this.state.lastSuccessfulValue,
ref: 'numberField',
Expand Down
48 changes: 38 additions & 10 deletions lib/SchemaForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,44 +92,72 @@ var SchemaForm = function (_React$Component) {
'fieldset': _FieldSet2.default
};

_this.onChange = _this.onChange.bind(_this);
_this.setDefault = function () {
return _this.__setDefault__REACT_HOT_LOADER__.apply(_this, arguments);
};

return _this;
}

// Assign default values and save it to the model


_createClass(SchemaForm, [{
key: 'onChange',
value: function onChange(key, val, type) {
//console.log('SchemaForm.onChange', key, val);
this.props.onModelChange(key, val, type);
key: '__setDefault__REACT_HOT_LOADER__',
value: function __setDefault__REACT_HOT_LOADER__() {
return this.__setDefault__REACT_HOT_LOADER__.apply(this, arguments);
}
}, {
key: '__setDefault__REACT_HOT_LOADER__',
value: function __setDefault__REACT_HOT_LOADER__(key, model, form, value) {
var currentValue = _utils2.default.selectOrSet(key, model);

// If current value is not setted and exist a default, apply the default over the model
if (_lodash2.default.isNil(currentValue) && !_lodash2.default.isNil(value)) this.props.onModelChange(key, value, form.type, form);
}
}, {
key: 'builder',
value: function builder(form, model, index, onChange, mapper) {
var type = form.type;
var Field = this.mapper[type];
value: function builder(form, model, index, mapper) {
var Field = this.mapper[form.type];
if (!Field) {
console.log('Invalid field: \"' + form.key[0] + '\"!');
return null;
}

// Apply conditionals to review if this field must be rendered
if (form.condition && _utils2.default.safeEval(form.condition, { model: model }) === false) {
return null;
}

var key = form.key && form.key.join(".") || index;
return _react2.default.createElement(Field, { model: model, form: form, key: key, onChange: onChange, mapper: mapper, builder: this.builder });

var errors = this.props.errors;

var error = key in errors ? errors[key] : null;

return _react2.default.createElement(Field, {
model: model,
form: form,
key: key,
onChange: this.props.onModelChange,
setDefault: this.setDefault,
mapper: mapper,
builder: this.builder,
errorText: error
});
}
}, {
key: 'render',
value: function render() {
var merged = _utils2.default.merge(this.props.schema, this.props.form, this.props.ignore, this.props.option);

//console.log('SchemaForm merged = ', JSON.stringify(merged, undefined, 2));
var mapper = this.mapper;
if (this.props.mapper) {
mapper = _lodash2.default.merge(this.mapper, this.props.mapper);
}
var forms = merged.map(function (form, index) {
return this.builder(form, this.props.model, index, this.onChange, mapper);
return this.builder(form, this.props.model, index, mapper);
}.bind(this));

return _react2.default.createElement(
Expand Down
19 changes: 17 additions & 2 deletions lib/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ var _SelectField = require('material-ui/SelectField');

var _SelectField2 = _interopRequireDefault(_SelectField);

var _lodash = require('lodash');

var _lodash2 = _interopRequireDefault(_lodash);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
Expand All @@ -42,9 +46,20 @@ var Select = function (_React$Component) {
var _this = _possibleConstructorReturn(this, (Select.__proto__ || Object.getPrototypeOf(Select)).call(this, props));

_this.onSelected = _this.onSelected.bind(_this);
var possibleValue = _this.getModelKey(_this.props.model, _this.props.form.key);

var _this$props = _this.props,
model = _this$props.model,
form = _this$props.form;
var key = form.key;


var storedValue = model && _this.getModelKey(model, key) || false;
var defaultValue = form.schema.default || false;
var value = !_lodash2.default.isEmpty(storedValue) && storedValue || defaultValue;

_this.props.setDefault(key, model, form, value);
_this.state = {
currentValue: _this.props.model !== undefined && possibleValue ? possibleValue : _this.props.form.titleMap != null ? _this.props.form.titleMap[0].value : ''
currentValue: value
};
return _this;
}
Expand Down
18 changes: 14 additions & 4 deletions lib/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,34 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
var Text = function (_React$Component) {
_inherits(Text, _React$Component);

function Text() {
function Text(props) {
_classCallCheck(this, Text);

return _possibleConstructorReturn(this, (Text.__proto__ || Object.getPrototypeOf(Text)).apply(this, arguments));
var _this = _possibleConstructorReturn(this, (Text.__proto__ || Object.getPrototypeOf(Text)).call(this, props));

var _this$props = _this.props,
model = _this$props.model,
form = _this$props.form,
value = _this$props.value;
var key = form.key;


_this.props.setDefault(key, model, form, value);
return _this;
}

_createClass(Text, [{
key: 'render',
value: function render() {
//console.log('Text props', this.props.form.readonly);
//console.log('Text props', this.props);
return _react2.default.createElement(
'div',
{ className: this.props.form.htmlClass },
_react2.default.createElement(_TextField2.default, {
type: this.props.form.type,
floatingLabelText: this.props.form.title,
hintText: this.props.form.placeholder,
errorText: this.props.error,
errorText: this.props.error || this.props.errorText,
onChange: this.props.onChangeValidate,
defaultValue: this.props.value,
disabled: this.props.form.readonly,
Expand Down
2 changes: 1 addition & 1 deletion lib/TextArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var TextArea = function (_React$Component) {
floatingLabelText: this.props.form.title,
hintText: this.props.form.placeholder,
onChange: this.props.onChangeValidate,
errorText: this.props.error,
errorText: this.props.error || this.props.errorText,
defaultValue: this.props.value,
multiLine: true,
rows: this.props.form.rows,
Expand Down
10 changes: 6 additions & 4 deletions lib/TextSuggest.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ var TextSuggest = function (_React$Component) {
var key = this.props.form.key;
var type = this.props.form.schema.type;

return this.props.onChange(key, newValue[dataSourceConfig['value']], type);
return this.props.onChange(key, newValue[dataSourceConfig['value']], type, this.props.form);
}
}, {
key: '__handleInit__REACT_HOT_LOADER__',
Expand All @@ -85,9 +85,9 @@ var TextSuggest = function (_React$Component) {
var names = this.props.form.schema.enumNames || this.props.form.schema.enum;
var values = this.props.form.schema.enum;

console.log(names, values);
console.log("indexOf", values.indexOf(init_value));
console.log("names[values.indexOf(init_value)]", names[values.indexOf(init_value)]);
// console.log(names, values);
// console.log("indexOf", values.indexOf(init_value));
// console.log("names[values.indexOf(init_value)]", names[values.indexOf(init_value)]);
var init_value_name = names[values.indexOf(init_value)];

// this.handleUpdate({[dataSourceConfig['value']]: init_value, [dataSourceConfig['text']]: init_value_name})
Expand All @@ -110,6 +110,8 @@ var TextSuggest = function (_React$Component) {
}
}(this.props.form.filter);

// console.log("TEXTSUG", this.props);

var value = this.props.value && this.handleInit(this.props.value);

return _react2.default.createElement(
Expand Down
4 changes: 2 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,9 @@ function merge(schema, form, ignore, options, readonly) {
}
}

//If it has a titleMap make sure it's a list
//If it has a titleMap make sure to update it with latest enum and names
if (obj.titleMap) {
obj.titleMap = canonicalTitleMap(obj.titleMap);
obj.titleMap = canonicalTitleMap(obj.schema.enumNames, obj.schema.enum);
}

//
Expand Down

0 comments on commit e70fd0d

Please sign in to comment.