@pareto-engineering/design-system 4.9.2 → 4.10.0
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.
- package/dist/cjs/a/AreaChart/AreaChart.js +176 -0
- package/dist/cjs/a/AreaChart/index.js +13 -0
- package/dist/cjs/a/AreaChart/styles.scss +89 -0
- package/dist/cjs/a/XMLEditor/XMLEditor.js +1 -1
- package/dist/cjs/a/index.js +8 -1
- package/dist/cjs/b/Button/styles.scss +1 -0
- package/dist/cjs/g/FormBuilder/FormBuilder.js +3 -3
- package/dist/cjs/g/FormBuilder/common/Renderer/Renderer.js +38 -38
- package/dist/cjs/g/FormBuilder/common/Renderer/common/Section/Section.js +34 -8
- package/dist/es/a/AreaChart/AreaChart.js +163 -0
- package/dist/es/a/AreaChart/index.js +1 -0
- package/dist/es/a/AreaChart/styles.scss +89 -0
- package/dist/es/a/XMLEditor/XMLEditor.js +2 -2
- package/dist/es/a/index.js +2 -1
- package/dist/es/b/Button/styles.scss +1 -0
- package/dist/es/g/FormBuilder/FormBuilder.js +3 -3
- package/dist/es/g/FormBuilder/common/Renderer/Renderer.js +39 -39
- package/dist/es/g/FormBuilder/common/Renderer/common/Section/Section.js +35 -9
- package/package.json +4 -3
- package/src/stories/a/AreaChart.stories.jsx +118 -0
- package/src/ui/a/AreaChart/AreaChart.jsx +185 -0
- package/src/ui/a/AreaChart/index.js +1 -0
- package/src/ui/a/AreaChart/styles.scss +89 -0
- package/src/ui/a/XMLEditor/XMLEditor.jsx +4 -1
- package/src/ui/a/index.js +1 -0
- package/src/ui/b/Button/styles.scss +1 -0
- package/src/ui/g/FormBuilder/FormBuilder.jsx +2 -2
- package/src/ui/g/FormBuilder/common/Renderer/Renderer.jsx +40 -39
- package/src/ui/g/FormBuilder/common/Renderer/common/Section/Section.jsx +41 -10
- package/tests/__snapshots__/Storyshots.test.js.snap +501 -1
- package/tests/test-setup.js +11 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
var _recharts = require("recharts");
|
|
10
|
+
var _exports = _interopRequireDefault(require("@pareto-engineering/bem/exports"));
|
|
11
|
+
require("./styles.scss");
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
14
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
15
|
+
// front/packages/design-system/src/ui/a/AreaChart/AreaChart.jsx
|
|
16
|
+
|
|
17
|
+
// Local Definitions
|
|
18
|
+
|
|
19
|
+
const baseClassName = _exports.default.base;
|
|
20
|
+
const componentClassName = 'area-chart';
|
|
21
|
+
const AreaChart = _ref => {
|
|
22
|
+
let {
|
|
23
|
+
id,
|
|
24
|
+
className: userClassName,
|
|
25
|
+
data,
|
|
26
|
+
title,
|
|
27
|
+
xKey,
|
|
28
|
+
yKeys,
|
|
29
|
+
xLabel,
|
|
30
|
+
yLabel,
|
|
31
|
+
colors,
|
|
32
|
+
filled,
|
|
33
|
+
height,
|
|
34
|
+
width
|
|
35
|
+
// ...otherProps
|
|
36
|
+
} = _ref;
|
|
37
|
+
const processedData = data.map(item => {
|
|
38
|
+
const yValues = yKeys.map(key => item[key]);
|
|
39
|
+
const lowerBound = Math.min(...yValues);
|
|
40
|
+
const upperBound = Math.max(...yValues);
|
|
41
|
+
const margin = (upperBound - lowerBound) * 0.1;
|
|
42
|
+
return {
|
|
43
|
+
...item,
|
|
44
|
+
bounds: [lowerBound - margin, upperBound + margin]
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
const yAxisBounds = () => {
|
|
48
|
+
const yValues = data.map(item => yKeys.map(key => item[key]));
|
|
49
|
+
const min = Math.min(...yValues.flat());
|
|
50
|
+
const max = Math.max(...yValues.flat());
|
|
51
|
+
const margin = (max - min) * 0.1;
|
|
52
|
+
return [min - margin, max + margin];
|
|
53
|
+
};
|
|
54
|
+
const CustomTooltipContent = _ref2 => {
|
|
55
|
+
let {
|
|
56
|
+
active,
|
|
57
|
+
payload,
|
|
58
|
+
label
|
|
59
|
+
} = _ref2;
|
|
60
|
+
if (active && payload && payload.length) {
|
|
61
|
+
const newPayload = payload.filter(item => item.name !== 'bounds');
|
|
62
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
63
|
+
className: "custom-tooltip"
|
|
64
|
+
}, /*#__PURE__*/React.createElement("p", {
|
|
65
|
+
className: "label"
|
|
66
|
+
}, `${xLabel}: ${label}`), newPayload.map(entry => /*#__PURE__*/React.createElement("p", {
|
|
67
|
+
className: "label",
|
|
68
|
+
key: `${entry.name}`,
|
|
69
|
+
style: {
|
|
70
|
+
color: entry.color
|
|
71
|
+
}
|
|
72
|
+
}, `${entry.name}: ${entry.value}`)));
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
};
|
|
76
|
+
const CustomLegend = _ref3 => {
|
|
77
|
+
let {
|
|
78
|
+
colorsArray,
|
|
79
|
+
yKeysArray
|
|
80
|
+
} = _ref3;
|
|
81
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
82
|
+
className: "custom-legend"
|
|
83
|
+
}, yKeysArray.map((key, index) => /*#__PURE__*/React.createElement("div", {
|
|
84
|
+
key: key,
|
|
85
|
+
className: "item"
|
|
86
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
87
|
+
className: "line",
|
|
88
|
+
style: {
|
|
89
|
+
backgroundColor: colorsArray[index]
|
|
90
|
+
}
|
|
91
|
+
}), /*#__PURE__*/React.createElement("span", {
|
|
92
|
+
className: "text"
|
|
93
|
+
}, key))));
|
|
94
|
+
};
|
|
95
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
96
|
+
id: id,
|
|
97
|
+
className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' ')
|
|
98
|
+
}, /*#__PURE__*/React.createElement("h3", null, title), /*#__PURE__*/React.createElement(CustomLegend, {
|
|
99
|
+
colorsArray: colors,
|
|
100
|
+
yKeysArray: yKeys
|
|
101
|
+
}), /*#__PURE__*/React.createElement(_recharts.ResponsiveContainer, {
|
|
102
|
+
width: width,
|
|
103
|
+
height: height
|
|
104
|
+
}, /*#__PURE__*/React.createElement(_recharts.AreaChart, {
|
|
105
|
+
data: processedData
|
|
106
|
+
}, /*#__PURE__*/React.createElement(_recharts.CartesianGrid, {
|
|
107
|
+
strokeDasharray: "3 3"
|
|
108
|
+
}), /*#__PURE__*/React.createElement(_recharts.XAxis, {
|
|
109
|
+
dataKey: xKey,
|
|
110
|
+
label: {
|
|
111
|
+
value: xLabel,
|
|
112
|
+
position: 'insideBottom',
|
|
113
|
+
offset: -5
|
|
114
|
+
} // Adjusted offset for padding
|
|
115
|
+
,
|
|
116
|
+
axisLine: false,
|
|
117
|
+
tickLine: false,
|
|
118
|
+
tickCount: 3
|
|
119
|
+
}), /*#__PURE__*/React.createElement(_recharts.YAxis, {
|
|
120
|
+
domain: yAxisBounds,
|
|
121
|
+
label: {
|
|
122
|
+
value: yLabel,
|
|
123
|
+
angle: -90,
|
|
124
|
+
position: 'insideLeft',
|
|
125
|
+
offset: 15
|
|
126
|
+
},
|
|
127
|
+
axisLine: false,
|
|
128
|
+
tickLine: false,
|
|
129
|
+
tickFormatter: value => value.toFixed(2)
|
|
130
|
+
}), /*#__PURE__*/React.createElement(_recharts.Tooltip, {
|
|
131
|
+
content: /*#__PURE__*/React.createElement(CustomTooltipContent, null)
|
|
132
|
+
}), filled && /*#__PURE__*/React.createElement(_recharts.Area, {
|
|
133
|
+
id: "bounds",
|
|
134
|
+
type: "linear",
|
|
135
|
+
dataKey: "bounds",
|
|
136
|
+
stroke: "none",
|
|
137
|
+
fill: "var(--hard-ui-main-2)",
|
|
138
|
+
fillOpacity: 0.4,
|
|
139
|
+
activeDot: false,
|
|
140
|
+
dot: false,
|
|
141
|
+
label: false,
|
|
142
|
+
isAnimationActive: false
|
|
143
|
+
}), yKeys.map((key, index) => /*#__PURE__*/React.createElement(_recharts.Area, {
|
|
144
|
+
id: key,
|
|
145
|
+
key: key,
|
|
146
|
+
type: "linear",
|
|
147
|
+
dataKey: key,
|
|
148
|
+
stroke: colors[index],
|
|
149
|
+
fill: "none",
|
|
150
|
+
connectNulls: true,
|
|
151
|
+
dot: false,
|
|
152
|
+
activeDot: {
|
|
153
|
+
r: 4
|
|
154
|
+
},
|
|
155
|
+
isAnimationActive: false
|
|
156
|
+
})))));
|
|
157
|
+
};
|
|
158
|
+
AreaChart.propTypes = {
|
|
159
|
+
// eslint-disable-next-line react/forbid-prop-types
|
|
160
|
+
data: _propTypes.default.arrayOf(_propTypes.default.object).isRequired,
|
|
161
|
+
title: _propTypes.default.string.isRequired,
|
|
162
|
+
xKey: _propTypes.default.string.isRequired,
|
|
163
|
+
yKeys: _propTypes.default.arrayOf(_propTypes.default.string).isRequired,
|
|
164
|
+
xLabel: _propTypes.default.string,
|
|
165
|
+
yLabel: _propTypes.default.string,
|
|
166
|
+
colors: _propTypes.default.arrayOf(_propTypes.default.string).isRequired,
|
|
167
|
+
filled: _propTypes.default.bool,
|
|
168
|
+
height: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
169
|
+
width: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number])
|
|
170
|
+
};
|
|
171
|
+
AreaChart.defaultProps = {
|
|
172
|
+
filled: false,
|
|
173
|
+
width: '100%',
|
|
174
|
+
height: 300
|
|
175
|
+
};
|
|
176
|
+
var _default = exports.default = AreaChart;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "AreaChart", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _AreaChart.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _AreaChart = _interopRequireDefault(require("./AreaChart"));
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
@use "@pareto-engineering/bem";
|
|
2
|
+
|
|
3
|
+
$default-margin: 1rem;
|
|
4
|
+
$default-padding: 1rem;
|
|
5
|
+
$default-box-shadow: 0 .25rem .75rem var(--ui-lines);
|
|
6
|
+
$default-text-font-size: calc(var(--s-1) * 1rem);
|
|
7
|
+
$default-border-radius: .25rem;
|
|
8
|
+
$default-legend-gap: .625rem;
|
|
9
|
+
$default-legend-padding: calc($default-padding * .125) calc($default-padding * .625);
|
|
10
|
+
$default-legend-line-width: 1.25rem;
|
|
11
|
+
$default-legend-line-height: .125rem;
|
|
12
|
+
$default-legend-line-margin-right: .3125rem;
|
|
13
|
+
$default-border-line-width: .0625rem;
|
|
14
|
+
|
|
15
|
+
.#{bem.$base} {
|
|
16
|
+
&.area-chart {
|
|
17
|
+
background-color: var(--background-far);
|
|
18
|
+
border-radius: var(--theme-default-border-radius);
|
|
19
|
+
box-shadow: $default-box-shadow;
|
|
20
|
+
margin: $default-margin 0;
|
|
21
|
+
padding: $default-padding;
|
|
22
|
+
|
|
23
|
+
h3 {
|
|
24
|
+
color: var(--subtitle);
|
|
25
|
+
margin: calc($default-margin / 5);
|
|
26
|
+
text-align: left;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.custom-legend {
|
|
30
|
+
display: flex;
|
|
31
|
+
gap: $default-legend-gap;
|
|
32
|
+
justify-content: flex-end;
|
|
33
|
+
padding-bottom: $default-padding;
|
|
34
|
+
padding-right: calc($default-padding * .25);
|
|
35
|
+
|
|
36
|
+
.item {
|
|
37
|
+
align-items: center;
|
|
38
|
+
border: $default-border-line-width solid var(--ui-lines);
|
|
39
|
+
border-radius: $default-border-radius;
|
|
40
|
+
display: flex;
|
|
41
|
+
padding: $default-legend-padding;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.line {
|
|
45
|
+
display: inline-block;
|
|
46
|
+
height: $default-legend-line-height;
|
|
47
|
+
margin-right: $default-legend-line-margin-right;
|
|
48
|
+
width: $default-legend-line-width;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.text {
|
|
52
|
+
color: var(--paragraph);
|
|
53
|
+
font-size: calc($default-text-font-size * .75);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.custom-tooltip {
|
|
58
|
+
background-color: var(--background-far);
|
|
59
|
+
border: $default-border-line-width solid var(--ui-lines);
|
|
60
|
+
border-radius: $default-border-radius;
|
|
61
|
+
padding: calc($default-padding * .25);
|
|
62
|
+
|
|
63
|
+
.label {
|
|
64
|
+
color: var(--hard-paragraph);
|
|
65
|
+
font-size: $default-text-font-size;
|
|
66
|
+
margin: calc($default-margin * .25);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* stylelint-disable selector-max-compound-selectors -- nested elements */
|
|
71
|
+
.recharts-wrapper {
|
|
72
|
+
.recharts-surface {
|
|
73
|
+
.recharts-cartesian-grid line {
|
|
74
|
+
stroke: var(--ui-lines);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.recharts-text {
|
|
78
|
+
fill: var(--soft-paragraph);
|
|
79
|
+
font-size: calc($default-text-font-size * .75);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.recharts-text.recharts-label {
|
|
83
|
+
fill: var(--paragraph);
|
|
84
|
+
font-size: $default-text-font-size;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -44,7 +44,7 @@ const XMLEditor = _ref => {
|
|
|
44
44
|
(0, _react.useEffect)(() => {
|
|
45
45
|
const startState = _state.EditorState.create({
|
|
46
46
|
doc: config,
|
|
47
|
-
extensions: [_view.keymap.of([_commands.defaultKeymap, _commands.indentWithTab]), (0, _language.indentOnInput)(), (0, _view.lineNumbers)(), (0, _language.bracketMatching)(), (0, _language.foldGutter)(), (0, _view.drawSelection)(), (0, _view.highlightActiveLine)(), (0, _view.highlightActiveLineGutter)(), (0, _view.highlightSpecialChars)(), (0, _view.dropCursor)(), (0, _view.rectangularSelection)(), (0, _view.crosshairCursor)(), (0, _langXml.xml)(), _common.theme, _state.EditorState.readOnly.of(readOnly), _view.EditorView.updateListener.of(view => {
|
|
47
|
+
extensions: [_view.keymap.of([_commands.defaultKeymap, _commands.indentWithTab, ..._commands.historyKeymap]), (0, _language.indentOnInput)(), (0, _view.lineNumbers)(), (0, _language.bracketMatching)(), (0, _language.foldGutter)(), (0, _view.drawSelection)(), (0, _view.highlightActiveLine)(), (0, _view.highlightActiveLineGutter)(), (0, _view.highlightSpecialChars)(), (0, _view.dropCursor)(), (0, _view.rectangularSelection)(), (0, _view.crosshairCursor)(), (0, _langXml.xml)(), (0, _commands.history)(), _common.theme, _state.EditorState.readOnly.of(readOnly), _view.EditorView.updateListener.of(view => {
|
|
48
48
|
onChange(view);
|
|
49
49
|
// view.state.doc.toString() to receive the current content in the editor.
|
|
50
50
|
}), _view.EditorView.focusChangeEffect.of((state, focused) => {
|
package/dist/cjs/a/index.js
CHANGED
|
@@ -27,6 +27,12 @@ Object.defineProperty(exports, "AppContextProvider", {
|
|
|
27
27
|
return _AppContext.AppContextProvider;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
|
+
Object.defineProperty(exports, "AreaChart", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _AreaChart.AreaChart;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
30
36
|
Object.defineProperty(exports, "BlurOverlay", {
|
|
31
37
|
enumerable: true,
|
|
32
38
|
get: function () {
|
|
@@ -230,4 +236,5 @@ var _Removable = require("./Removable");
|
|
|
230
236
|
var _ToggleSwitch = require("./ToggleSwitch");
|
|
231
237
|
var _XMLEditor = require("./XMLEditor");
|
|
232
238
|
var _DatePicker = require("./DatePicker");
|
|
233
|
-
var _Tooltip = require("./Tooltip");
|
|
239
|
+
var _Tooltip = require("./Tooltip");
|
|
240
|
+
var _AreaChart = require("./AreaChart");
|
|
@@ -34,8 +34,8 @@ const FormBuilder = _ref => {
|
|
|
34
34
|
formBuilderId,
|
|
35
35
|
onBuilderFormSave,
|
|
36
36
|
onBuilderError,
|
|
37
|
-
onRendererError,
|
|
38
37
|
onRendererFormSave,
|
|
38
|
+
onFileUpload,
|
|
39
39
|
onBuilderValidate,
|
|
40
40
|
initialBuilderValues,
|
|
41
41
|
fileUploadStatus,
|
|
@@ -62,9 +62,9 @@ const FormBuilder = _ref => {
|
|
|
62
62
|
onSave: onRendererFormSave,
|
|
63
63
|
readOnly: readOnly,
|
|
64
64
|
shouldSubmit: shouldSubmit,
|
|
65
|
-
onError: onRendererError,
|
|
66
65
|
fileUploadStatus: fileUploadStatus,
|
|
67
|
-
handleFileDelete: handleFileDelete
|
|
66
|
+
handleFileDelete: handleFileDelete,
|
|
67
|
+
onFileUpload: onFileUpload
|
|
68
68
|
}));
|
|
69
69
|
};
|
|
70
70
|
FormBuilder.propTypes = {
|
|
@@ -18,28 +18,6 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
18
18
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } /* @pareto-engineering/generator-front 1.1.1-alpha.2 */ // Local Definitions
|
|
19
19
|
const baseClassName = _exports.default.base;
|
|
20
20
|
const componentClassName = 'renderer';
|
|
21
|
-
const reconstructFormDataWithValues = (formData, values) => {
|
|
22
|
-
const valuesMap = {};
|
|
23
|
-
Object.keys(values).forEach(async key => {
|
|
24
|
-
if (key.includes('files')) {
|
|
25
|
-
const files = values[key].map(file => file instanceof File ? URL.createObjectURL(file) : file);
|
|
26
|
-
valuesMap[key] = files;
|
|
27
|
-
} else {
|
|
28
|
-
valuesMap[key] = values[key];
|
|
29
|
-
}
|
|
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] !== undefined ? valuesMap[input.name] : input.value
|
|
38
|
-
}))
|
|
39
|
-
}))
|
|
40
|
-
};
|
|
41
|
-
return newData;
|
|
42
|
-
};
|
|
43
21
|
const validate = (currentSectionIndex, formData, values) => {
|
|
44
22
|
const errors = {};
|
|
45
23
|
const hasAtLeastOneValue = Object.keys(values).some(valueKey => {
|
|
@@ -58,6 +36,25 @@ const validate = (currentSectionIndex, formData, values) => {
|
|
|
58
36
|
});
|
|
59
37
|
return errors;
|
|
60
38
|
};
|
|
39
|
+
const reconstructFormDataWithValues = (formData, values) => {
|
|
40
|
+
const valuesMap = {};
|
|
41
|
+
Object.keys(values).forEach(async key => {
|
|
42
|
+
if (!key.includes('files')) {
|
|
43
|
+
valuesMap[key] = values[key];
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
const newData = {
|
|
47
|
+
...formData,
|
|
48
|
+
sections: formData.sections.map(section => ({
|
|
49
|
+
...section,
|
|
50
|
+
inputs: section.inputs.map(input => ({
|
|
51
|
+
...input,
|
|
52
|
+
value: valuesMap[input.name] !== undefined ? valuesMap[input.name] : input.value
|
|
53
|
+
}))
|
|
54
|
+
}))
|
|
55
|
+
};
|
|
56
|
+
return newData;
|
|
57
|
+
};
|
|
61
58
|
|
|
62
59
|
/**
|
|
63
60
|
* This is the component description.
|
|
@@ -70,15 +67,18 @@ const Renderer = _ref => {
|
|
|
70
67
|
formData,
|
|
71
68
|
readOnly,
|
|
72
69
|
onSave,
|
|
73
|
-
onError,
|
|
74
70
|
shouldSubmit,
|
|
75
71
|
fileUploadStatus,
|
|
76
|
-
handleFileDelete
|
|
72
|
+
handleFileDelete,
|
|
73
|
+
onFileUpload,
|
|
74
|
+
shouldUpdateInputStateInRealTime = true
|
|
77
75
|
// ...otherProps
|
|
78
76
|
} = _ref;
|
|
79
77
|
const [currentSectionIndex, setCurrentSectionIndex] = (0, _react.useState)(0);
|
|
80
78
|
const [sectionHistory, setSectionHistory] = (0, _react.useState)([]);
|
|
81
|
-
const [updatedFormData, setUpdatedFormData] = (0, _react.useState)(
|
|
79
|
+
const [updatedFormData, setUpdatedFormData] = (0, _react.useState)({
|
|
80
|
+
...formData
|
|
81
|
+
});
|
|
82
82
|
(0, _react.useEffect)(() => {
|
|
83
83
|
setUpdatedFormData(formData);
|
|
84
84
|
}, [formData]);
|
|
@@ -118,6 +118,9 @@ const Renderer = _ref => {
|
|
|
118
118
|
}
|
|
119
119
|
};
|
|
120
120
|
const isSubmit = currentSectionIndex === updatedFormData.sections.length - 1 || updatedFormData.sections[currentSectionIndex].navigation.nextSection === 'submit';
|
|
121
|
+
const ref = (0, _react.useRef)(null);
|
|
122
|
+
const currentSectionInputs = updatedFormData.sections[currentSectionIndex].inputs;
|
|
123
|
+
const hasErrorsOnInitialRender = currentSectionInputs.some(input => input.required && !ref.current?.values[input.name] || ref.current?.errors[input.name]);
|
|
121
124
|
return /*#__PURE__*/React.createElement("div", {
|
|
122
125
|
id: id,
|
|
123
126
|
className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' '),
|
|
@@ -125,31 +128,28 @@ const Renderer = _ref => {
|
|
|
125
128
|
}, /*#__PURE__*/React.createElement(_formik.Formik, {
|
|
126
129
|
initialValues: initialValues,
|
|
127
130
|
onSubmit: handleSubmit,
|
|
128
|
-
validate: values => validate(currentSectionIndex,
|
|
131
|
+
validate: values => validate(currentSectionIndex, updatedFormData, values),
|
|
132
|
+
innerRef: ref
|
|
129
133
|
}, _ref2 => {
|
|
130
134
|
let {
|
|
131
135
|
values,
|
|
132
136
|
errors
|
|
133
137
|
} = _ref2;
|
|
134
138
|
(0, _react.useEffect)(() => {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
139
|
+
if (shouldUpdateInputStateInRealTime) {
|
|
140
|
+
const formDataWithValues = reconstructFormDataWithValues(updatedFormData, values);
|
|
141
|
+
onSave?.(formDataWithValues);
|
|
142
|
+
}
|
|
138
143
|
}, [values]);
|
|
139
|
-
(0, _react.useEffect)(() => {
|
|
140
|
-
onError?.({
|
|
141
|
-
errors,
|
|
142
|
-
values
|
|
143
|
-
});
|
|
144
|
-
}, [errors, values]);
|
|
145
144
|
const hasErrors = Object.keys(errors).length > 0;
|
|
146
145
|
return /*#__PURE__*/React.createElement(_formik.Form, null, updatedFormData.sections.map((section, sectionIndex) => sectionIndex === currentSectionIndex && /*#__PURE__*/React.createElement(_common.Section, _extends({
|
|
147
146
|
key: `${section.title}`
|
|
148
147
|
}, section, {
|
|
149
148
|
readOnly: readOnly,
|
|
150
|
-
setUpdatedFormData: setUpdatedFormData,
|
|
151
149
|
fileUploadStatus: fileUploadStatus,
|
|
152
|
-
handleFileDelete: handleFileDelete
|
|
150
|
+
handleFileDelete: handleFileDelete,
|
|
151
|
+
onFileUpload: onFileUpload,
|
|
152
|
+
sectionIndex: sectionIndex
|
|
153
153
|
}))), /*#__PURE__*/React.createElement("div", {
|
|
154
154
|
className: "navigator-container"
|
|
155
155
|
}, updatedFormData.sections.length > 1 && /*#__PURE__*/React.createElement(_b.Button, {
|
|
@@ -164,7 +164,7 @@ const Renderer = _ref => {
|
|
|
164
164
|
color: "interactive",
|
|
165
165
|
isGradient: true,
|
|
166
166
|
type: "submit",
|
|
167
|
-
disabled: hasErrors
|
|
167
|
+
disabled: hasErrors || hasErrorsOnInitialRender
|
|
168
168
|
}, isSubmit ? 'Submit' : 'Next')));
|
|
169
169
|
}));
|
|
170
170
|
};
|
|
@@ -15,6 +15,14 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
15
15
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } /* eslint-disable no-alert */ /* @pareto-engineering/generator-front 1.1.1-alpha.2 */ // Local Definitions
|
|
16
16
|
const baseClassName = _exports.default.base;
|
|
17
17
|
const componentClassName = 'section';
|
|
18
|
+
const fileTypeMapper = {
|
|
19
|
+
VID: 'Video',
|
|
20
|
+
TXT: 'Text',
|
|
21
|
+
IMG: 'Image',
|
|
22
|
+
PDF: 'PDF',
|
|
23
|
+
AUD: 'Audio',
|
|
24
|
+
FILE: 'Generic'
|
|
25
|
+
};
|
|
18
26
|
|
|
19
27
|
/**
|
|
20
28
|
* This is the component description.
|
|
@@ -29,7 +37,9 @@ const Section = _ref => {
|
|
|
29
37
|
inputs,
|
|
30
38
|
readOnly,
|
|
31
39
|
fileUploadStatus,
|
|
32
|
-
handleFileDelete
|
|
40
|
+
handleFileDelete,
|
|
41
|
+
onFileUpload,
|
|
42
|
+
sectionIndex
|
|
33
43
|
// ...otherProps
|
|
34
44
|
} = _ref;
|
|
35
45
|
return /*#__PURE__*/React.createElement("div", {
|
|
@@ -41,13 +51,29 @@ const Section = _ref => {
|
|
|
41
51
|
}, title), /*#__PURE__*/React.createElement(_.ExpandableLexicalPreview, {
|
|
42
52
|
nodes: description,
|
|
43
53
|
name: "instructions"
|
|
44
|
-
}), inputs?.map(input =>
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
54
|
+
}), inputs?.map((input, inputIndex) => {
|
|
55
|
+
const isFileInput = input.type === 'file';
|
|
56
|
+
return /*#__PURE__*/React.createElement(_f.FormInput, _extends({
|
|
57
|
+
key: input.name
|
|
58
|
+
}, input, {
|
|
59
|
+
disabled: readOnly
|
|
60
|
+
}, isFileInput && {
|
|
61
|
+
uploadStatus: fileUploadStatus,
|
|
62
|
+
handleFileDelete,
|
|
63
|
+
onChange: files => {
|
|
64
|
+
const filesToUpload = files?.filter(file => file instanceof File).map(file => ({
|
|
65
|
+
file,
|
|
66
|
+
name: file.name,
|
|
67
|
+
mimeType: file.type,
|
|
68
|
+
type: fileTypeMapper[(0, _f.getFileType)(file)] || 'Generic',
|
|
69
|
+
title: file.name,
|
|
70
|
+
sectionIndex,
|
|
71
|
+
inputIndex
|
|
72
|
+
}));
|
|
73
|
+
onFileUpload(filesToUpload);
|
|
74
|
+
}
|
|
75
|
+
}));
|
|
76
|
+
}));
|
|
51
77
|
};
|
|
52
78
|
Section.propTypes = {
|
|
53
79
|
/**
|