Skip to content

Commit 4cb897a

Browse files
authored
Merge pull request #61 from Wavelop/release/0.3.4
Release/0.3.4
2 parents 56ca294 + bd824f4 commit 4cb897a

File tree

11 files changed

+87
-22
lines changed

11 files changed

+87
-22
lines changed

README.md

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@
4949
- [👶 Prerequisites](#-prerequisites)
5050
- [💻 Installation](#-installation)
5151
- [🚲 Usage](#-usage)
52-
- [📚Documentation](#documentation)
52+
- [📚 Documentation](#-documentation)
53+
- [🥇 Add your values](#-add-your-values)
5354
- [🏘 Using existing components](#-using-existing-components)
5455
- [🧱 Build your custom components](#-build-your-custom-components)
55-
- [🧱 Repeater components](#-repeater-components)
56+
- [💫 Repeater components](#-repeater-components)
5657
- [✈️ Roadmap](#️-roadmap)
5758
- [🚑 Contributing](#-contributing)
5859
- [💰 License](#-license)
@@ -110,6 +111,7 @@ export default [
110111
helperText: "Write your email",
111112
tag: Input,
112113
type: "email",
114+
defaultValue: "info@wavelop.com",
113115
validations: [
114116
{
115117
kind: required,
@@ -186,10 +188,29 @@ export default withDynamicForm()(Example);
186188

187189
_For more examples, please refer to the [Example folder](https://github.com/Wavelop/dynamic-form/tree/master/example)_.
188190

189-
## 📚Documentation
191+
## 📚 Documentation
190192

191193
Check out our [documentation website](https://dynamic-form-wavelop.firebaseapp.com/).
192194

195+
## 🥇 Add your values
196+
197+
Use the `deafultValue` option to add an initial value to a field.
198+
199+
```javascript
200+
// config.js
201+
...
202+
fields: [
203+
{
204+
name: "field1_row2",
205+
label: "field1_row2",
206+
helperText: "field1_row2",
207+
tag: "notRow",
208+
defaultValue: "hello",
209+
}
210+
]
211+
...
212+
```
213+
193214
## 🏘 Using existing components
194215

195216
Core functionalities can be used with exinsing components, as with the one of the package `@wavelop/dynamic-form-base-components` or you can create your custom components to inject inside the configuration.
@@ -198,13 +219,14 @@ Core functionalities can be used with exinsing components, as with the one of th
198219

199220
WIP.
200221

201-
### 🧱 Repeater components
222+
### 💫 Repeater components
202223

203224
There are more way to create repeater components:
204225

205226
1. Update your configuration dinamically adding new piece of configuration. To group state results you should use `rowOptions`, both on row container and field.
206227

207-
Example:
228+
<details>
229+
<summary>Example point 1</summary>
208230

209231
In the configuration create the initial configuration:
210232
```js
@@ -473,7 +495,11 @@ console.log(groupByRowsGroupIn);
473495
**/
474496
```
475497

476-
2. (WIP) Create a custom component that implement the repeater logic and it update the form values.
498+
</details>
499+
500+
501+
<br/>
502+
1. (WIP) Create a custom component that implement the repeater logic and it update the form values.
477503

478504
<!-- ROADMAP -->
479505
## ✈️ Roadmap

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dynamic-form/wavelop",
3-
"version": "0.3.3",
3+
"version": "0.3.4",
44
"description": "Dynamic form from configuration with React",
55
"author": "Wavelop",
66
"license": "MIT",

packages/base-components/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@wavelop/dynamic-form-base-components",
3-
"version": "0.3.3",
3+
"version": "0.3.4",
44
"description": "Dynamic Form: basic components",
55
"author": "Wavelop",
66
"license": "MIT",

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@wavelop/dynamic-form",
3-
"version": "0.3.3",
3+
"version": "0.3.4",
44
"description": "Dynamic Form: core functionalities",
55
"author": "Wavelop",
66
"license": "MIT",

packages/core/src/components/DynamicForm/index.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const DynamicForm = forwardRef((props, ref) => {
2626
const helpers = useDynamicForm();
2727
const { idStateModel, idStateError } = helpers;
2828

29+
// Save config only at the beniginning
2930
useMemo(() => {
3031
!internal && saveConfig(idStateModel, id, config, internal);
3132
}, [config, internal]);
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
export const dataCoverterHandler = (data, config) => {
1+
export const dataCoverterHandler = (data, {dataManipulatorIn} = {}) => {
22
let dataConverted = data;
33

44
if (
5-
config.dataManipulatorIn &&
6-
typeof config.dataManipulatorIn === "function" &&
5+
dataManipulatorIn &&
6+
typeof dataManipulatorIn === "function" &&
77
data !== ""
88
) {
9-
dataConverted = config.dataManipulatorIn(data);
9+
dataConverted = dataManipulatorIn(data);
1010
}
1111
return dataConverted;
1212
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { dataCoverterHandler } from "./dataCoverterHandler";
2+
3+
4+
describe("Components", () => {
5+
describe("FactoryComponent", () => {
6+
describe("utils", () => {
7+
describe("dataCoverterHandler", () => {
8+
9+
it("given a data without a dataManipulatorIn, data is not converted", () => {
10+
expect(dataCoverterHandler("10")).toEqual("10");
11+
});
12+
13+
it("given a data with a dataManipulatorIn, data is converted", () => {
14+
expect(dataCoverterHandler("10", {dataManipulatorIn: (data) => { return parseInt(data); }})).toEqual(10);
15+
});
16+
17+
});
18+
});
19+
});
20+
});

packages/core/src/components/DynamicForm/utils/htmlToRender.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ export const htmlToRender = ({
3737
onChange={handleChange(dispatchModel, "UPDATE_MODEL")}
3838
config={configObj}
3939
data={
40-
stateFromService && stateFromService[configObj.name]
41-
? tag === "hidden"
42-
? model[name]
43-
: stateFromService[configObj.name]
40+
stateFromService !== undefined && stateFromService[configObj.name] !== null
41+
? stateFromService[configObj.name]
4442
: configObj.defaultValue !== undefined &&
4543
configObj.defaultValue !== null
4644
? configObj.defaultValue
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
export const dataCoverterHandler = (data, config) => {
1+
export const dataCoverterHandler = (data, {dataManipulatorIn} = {}) => {
22
let dataConverted = data;
33

44
if (
5-
config.dataManipulatorIn &&
6-
typeof config.dataManipulatorIn === "function" &&
5+
dataManipulatorIn &&
6+
typeof dataManipulatorIn === "function" &&
77
data !== ""
88
) {
9-
dataConverted = config.dataManipulatorIn(data);
9+
dataConverted = dataManipulatorIn(data);
1010
}
1111
return dataConverted;
1212
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { dataCoverterHandler } from "./dataCoverterHandler";
2+
3+
4+
describe("Components", () => {
5+
describe("FactoryComponent", () => {
6+
describe("utils", () => {
7+
describe("dataCoverterHandler", () => {
8+
9+
it("given a data without a dataManipulatorIn, data is not converted", () => {
10+
expect(dataCoverterHandler("10")).toEqual("10");
11+
});
12+
13+
it("given a data with a dataManipulatorIn, data is converted", () => {
14+
expect(dataCoverterHandler("10", {dataManipulatorIn: (data) => { return parseInt(data); }})).toEqual(10);
15+
});
16+
17+
});
18+
});
19+
});
20+
});

0 commit comments

Comments
 (0)