Skip to content

Data types feature#67

Merged
rvsia merged 3 commits into
masterfrom
data-types-feature
Aug 5, 2019
Merged

Data types feature#67
rvsia merged 3 commits into
masterfrom
data-types-feature

Conversation

@Hyperkid123

@Hyperkid123 Hyperkid123 commented Aug 2, 2019

Copy link
Copy Markdown
Member

closes: #65

Adds data types casting to form fields (both default and custom)

  • enhances FieldProvider onChange function with type casting if the dataType prop has been given
  • supported data types
    • integer
    • float
    • number
    • boolean
    • string

@Hyperkid123 Hyperkid123 added enhancement New feature or request renderer React form renderer PR labels Aug 2, 2019
@Hyperkid123

Copy link
Copy Markdown
Member Author

cc @Fryguy, @slemrmartin, @gmcculloug

FLOAT: 'float',
NUMBER: 'number',
BOOLEAN: 'boolean',
STRING: 'stirng',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where?

@codecov-io

codecov-io commented Aug 2, 2019

Copy link
Copy Markdown

Codecov Report

Merging #67 into master will increase coverage by 0.29%.
The diff coverage is 93.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #67      +/-   ##
==========================================
+ Coverage   82.76%   83.06%   +0.29%     
==========================================
  Files          79       80       +1     
  Lines        1271     1299      +28     
  Branches      302      310       +8     
==========================================
+ Hits         1052     1079      +27     
- Misses        188      189       +1     
  Partials       31       31
Impacted Files Coverage Δ
packages/react-form-renderer/src/index.js 100% <ø> (+100%) ⬆️
...act-form-renderer/src/form-renderer/render-form.js 100% <ø> (ø) ⬆️
...ckages/react-form-renderer/src/validators/index.js 89.02% <0%> (-1.1%) ⬇️
...m-renderer/src/parsers/default-schema-validator.js 98.36% <100%> (+0.21%) ⬆️
...-form-renderer/src/form-renderer/field-provider.js 100% <100%> (ø) ⬆️
...ackages/react-form-renderer/src/constants/index.js 100% <100%> (ø) ⬆️
...m-renderer/src/form-renderer/enhanced-on-change.js 87.5% <87.5%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0986487...755f93c. Read the comment docs.

* Pick a value from event object and returns it
* @param {Object|Any} event event value returned from form field
*/
const sanytyzeValue = event =>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sanitize

pattern: /^\d*[.]{0,1}\d*$/, message: 'Values mut be number', ...options,
}),
float: options => pattern({
pattern: /^\d*[.]{0,1}\d*$/, message: 'Values mut be number', ...options,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mut > must be a number

## Introduction

You can specify a type of a component by providing `dataType`, which will automatically validates the component value.
Becuse almost everyting in html inputs is outputed as a string, adding the `dataType` props will also cast the value to given type.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because.. everything

You can specify a type of a component by providing `dataType`, which will automatically validates the component value.
Becuse almost everyting in html inputs is outputed as a string, adding the `dataType` props will also cast the value to given type.

### Avaiable dataTypes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Available

@rvsia

rvsia commented Aug 2, 2019

Copy link
Copy Markdown
Contributor

Code looks solid! 👍 Just a few typos.. Need to test in UI. I like it, however, are we really make this feature as a default behavior? (To be honest, I haven't seen DataTypes used anywhere yet [except our demo schemas], but it can theoretically break some stuff if somebody uses it.)

@Hyperkid123

Copy link
Copy Markdown
Member Author

@rvsia it theoretically could break something but if yo are using data types and actually not expecting that data type in the output i don't thin it should be used at all. They can always remove it and just use validator.

### Available dataTypes

```jsx
['integer', 'float', 'number', 'bool', 'string']

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boolean

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we will make this bool because Mozilla parser returns bool (i know we won't be using it). Let me fix it in the mapper.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about to allow both?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nvm it is actually boolean

@rvsia rvsia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add dataType validator to renderer, otherwise, it works perfectly! 👍 📈

@martinpovolny

Copy link
Copy Markdown
Contributor

Looks good!

@Hyperkid123 Hyperkid123 force-pushed the data-types-feature branch 3 times, most recently from 2d12716 to 5c8dc51 Compare August 5, 2019 13:04
@rvsia rvsia merged commit 7c638c7 into master Aug 5, 2019
@Hyperkid123 Hyperkid123 deleted the data-types-feature branch August 6, 2019 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request renderer React form renderer PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Data type conversion

4 participants