@pareto-engineering/design-system 4.3.2 → 4.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -92,6 +92,9 @@ const InputBuilder = _ref => {
92
92
  }, {
93
93
  value: 'text',
94
94
  label: 'Basic input'
95
+ }, {
96
+ value: 'number',
97
+ label: 'Number input'
95
98
  }, {
96
99
  value: 'textarea',
97
100
  label: 'Long paragraph'
@@ -19,18 +19,25 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
19
19
  const baseClassName = _exports.default.base;
20
20
  const componentClassName = 'renderer';
21
21
  const reconstructFormDataWithValues = (formData, values) => {
22
- const newData = {
23
- ...formData
24
- };
22
+ const valuesMap = {};
25
23
  Object.keys(values).forEach(async key => {
26
- const [sectionIdx, inputIdx] = key.match(/\d+/g).map(Number);
27
24
  if (key.includes('files')) {
28
25
  const files = values[key].map(file => URL.createObjectURL(file));
29
- newData.sections[sectionIdx].inputs[inputIdx].files = files;
26
+ valuesMap[key] = files;
30
27
  } else {
31
- newData.sections[sectionIdx].inputs[inputIdx].value = values[key];
28
+ valuesMap[key] = values[key];
32
29
  }
33
30
  });
31
+ const newData = {
32
+ ...formData,
33
+ sections: formData.sections.map(section => ({
34
+ ...section,
35
+ inputs: section.inputs.map(input => ({
36
+ ...input,
37
+ value: valuesMap[input.name] || input.value
38
+ }))
39
+ }))
40
+ };
34
41
  return newData;
35
42
  };
36
43
  const validate = values => {
@@ -68,10 +75,9 @@ const Renderer = _ref => {
68
75
  (0, _react.useEffect)(() => {
69
76
  setUpdatedFormData(formData);
70
77
  }, [formData]);
71
- const initialValues = formData.sections.reduce((acc, section, sectionIndex) => {
72
- section.inputs.forEach((input, inputIndex) => {
73
- const inputName = `section_${sectionIndex}_input_${inputIndex}`;
74
- acc[inputName] = input.value || '';
78
+ const initialValues = formData.sections.reduce((acc, section) => {
79
+ section.inputs.forEach(input => {
80
+ acc[input.name] = input.value || '';
75
81
  });
76
82
  return acc;
77
83
  }, {});
@@ -82,6 +82,9 @@ const InputBuilder = ({
82
82
  }, {
83
83
  value: 'text',
84
84
  label: 'Basic input'
85
+ }, {
86
+ value: 'number',
87
+ label: 'Number input'
85
88
  }, {
86
89
  value: 'textarea',
87
90
  label: 'Long paragraph'
@@ -14,18 +14,25 @@ import { Section } from "./common";
14
14
  const baseClassName = styleNames.base;
15
15
  const componentClassName = 'renderer';
16
16
  const reconstructFormDataWithValues = (formData, values) => {
17
- const newData = {
18
- ...formData
19
- };
17
+ const valuesMap = {};
20
18
  Object.keys(values).forEach(async key => {
21
- const [sectionIdx, inputIdx] = key.match(/\d+/g).map(Number);
22
19
  if (key.includes('files')) {
23
20
  const files = values[key].map(file => URL.createObjectURL(file));
24
- newData.sections[sectionIdx].inputs[inputIdx].files = files;
21
+ valuesMap[key] = files;
25
22
  } else {
26
- newData.sections[sectionIdx].inputs[inputIdx].value = values[key];
23
+ valuesMap[key] = values[key];
27
24
  }
28
25
  });
26
+ const newData = {
27
+ ...formData,
28
+ sections: formData.sections.map(section => ({
29
+ ...section,
30
+ inputs: section.inputs.map(input => ({
31
+ ...input,
32
+ value: valuesMap[input.name] || input.value
33
+ }))
34
+ }))
35
+ };
29
36
  return newData;
30
37
  };
31
38
  const validate = values => {
@@ -62,10 +69,9 @@ const Renderer = ({
62
69
  useEffect(() => {
63
70
  setUpdatedFormData(formData);
64
71
  }, [formData]);
65
- const initialValues = formData.sections.reduce((acc, section, sectionIndex) => {
66
- section.inputs.forEach((input, inputIndex) => {
67
- const inputName = `section_${sectionIndex}_input_${inputIndex}`;
68
- acc[inputName] = input.value || '';
72
+ const initialValues = formData.sections.reduce((acc, section) => {
73
+ section.inputs.forEach(input => {
74
+ acc[input.name] = input.value || '';
69
75
  });
70
76
  return acc;
71
77
  }, {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pareto-engineering/design-system",
3
- "version": "4.3.2",
3
+ "version": "4.3.5",
4
4
  "description": "",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/es/index.js",
@@ -82,5 +82,5 @@
82
82
  "relay-test-utils": "^15.0.0"
83
83
  },
84
84
  "browserslist": "> 2%",
85
- "gitHead": "6e334c8fc47b8d7fc8448c25a587a5b059085a32"
85
+ "gitHead": "67b9225b149d2028cb22c5a1698eafc435d6c072"
86
86
  }
@@ -110,6 +110,10 @@ const InputBuilder = ({
110
110
  value:'text',
111
111
  label:'Basic input',
112
112
  },
113
+ {
114
+ value:'number',
115
+ label:'Number input',
116
+ },
113
117
  {
114
118
  value:'textarea',
115
119
  label:'Long paragraph',
@@ -22,16 +22,25 @@ const baseClassName = styleNames.base
22
22
  const componentClassName = 'renderer'
23
23
 
24
24
  const reconstructFormDataWithValues = (formData, values) => {
25
- const newData = { ...formData }
25
+ const valuesMap = {}
26
26
  Object.keys(values).forEach(async (key) => {
27
- const [sectionIdx, inputIdx] = key.match(/\d+/g).map(Number)
28
27
  if (key.includes('files')) {
29
28
  const files = values[key].map((file) => URL.createObjectURL(file))
30
- newData.sections[sectionIdx].inputs[inputIdx].files = files
29
+ valuesMap[key] = files
31
30
  } else {
32
- newData.sections[sectionIdx].inputs[inputIdx].value = values[key]
31
+ valuesMap[key] = values[key]
33
32
  }
34
33
  })
34
+ const newData = {
35
+ ...formData,
36
+ sections:formData.sections.map((section) => ({
37
+ ...section,
38
+ inputs:section.inputs.map((input) => ({
39
+ ...input,
40
+ value:valuesMap[input.name] || input.value,
41
+ })),
42
+ })),
43
+ }
35
44
  return newData
36
45
  }
37
46
 
@@ -74,10 +83,9 @@ const Renderer = ({
74
83
  setUpdatedFormData(formData)
75
84
  }, [formData])
76
85
 
77
- const initialValues = formData.sections.reduce((acc, section, sectionIndex) => {
78
- section.inputs.forEach((input, inputIndex) => {
79
- const inputName = `section_${sectionIndex}_input_${inputIndex}`
80
- acc[inputName] = input.value || ''
86
+ const initialValues = formData.sections.reduce((acc, section) => {
87
+ section.inputs.forEach((input) => {
88
+ acc[input.name] = input.value || ''
81
89
  })
82
90
  return acc
83
91
  }, {})