@arquimedes.co/eureka-forms 1.9.94-test → 1.9.96-test
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/App.d.ts +0 -10
- package/dist/App.js +29 -64
- package/dist/FormComponents/Form/ColumnForm/ColumnForm.js +1 -1
- package/dist/FormComponents/Section/Section.d.ts +1 -1
- package/dist/FormComponents/Step/@Construction/CBRElementStep/CBRElementStep.js +2 -15
- package/dist/FormComponents/Step/@Construction/CBRIncidentsStep/MaterialCBRIncidentsStep/MaterialCBRIncidentsStep.js +7 -6
- package/dist/FormComponents/Step/AYFStepMapper.js +1 -11
- package/dist/FormComponents/Step/EntityValueStep/MaterialEntityValuePickerStep/MaterialEntityValuePickerStep.js +46 -36
- package/dist/FormComponents/Step/MapperStep/MaterialMapperStep/MaterialMapperStep.js +18 -4
- package/dist/FormComponents/Step/SmartSelectStep/MaterialSmartSelectStep/MaterialSmartSelectStep.d.ts +1 -1
- package/dist/FormComponents/Step/SmartSelectStep/MaterialSmartSelectStep/MaterialSmartSelectStep.js +57 -31
- package/dist/FormComponents/Step/SmartSelectStep/SmartSelectStep.d.ts +0 -2
- package/package.json +1 -1
package/dist/App.d.ts
CHANGED
|
@@ -49,14 +49,4 @@ export interface CustomStep {
|
|
|
49
49
|
}
|
|
50
50
|
declare function App({ apiKey, domain, preview, partial, formData, postview, editable, isWidget, internal, valuesData, customSend, customSteps, classifiers, handleConfirmed, customStepProps, ...others }: AppProps): JSX.Element;
|
|
51
51
|
export default App;
|
|
52
|
-
export declare enum SIZES {
|
|
53
|
-
SMALL = "SMALL",
|
|
54
|
-
MEDIUM = "MEDIUM",
|
|
55
|
-
LARGE = "LARGE"
|
|
56
|
-
}
|
|
57
|
-
export declare const SizesToNum: {
|
|
58
|
-
LARGE: number;
|
|
59
|
-
MEDIUM: number;
|
|
60
|
-
SMALL: number;
|
|
61
|
-
};
|
|
62
52
|
export declare const mapOriginalValue: (step: FormStep, value: any, form?: Form) => any;
|
package/dist/App.js
CHANGED
|
@@ -56,7 +56,6 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
56
56
|
}
|
|
57
57
|
return t;
|
|
58
58
|
};
|
|
59
|
-
var _a;
|
|
60
59
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
61
60
|
import { useEffect, useRef, useState } from 'react';
|
|
62
61
|
import Loader from './shared/Loader/Loader';
|
|
@@ -65,7 +64,6 @@ import FormComponent from './FormComponents/Form/Form';
|
|
|
65
64
|
import StepTypes from './constants/FormStepTypes';
|
|
66
65
|
import axiosInstance from './AxiosAPI';
|
|
67
66
|
import widgetInstance from './AxiosWidget';
|
|
68
|
-
import InternalFormStyle from './constants/InternalFormStyle';
|
|
69
67
|
import { calcCbrForm } from './utils/CbrFunctions';
|
|
70
68
|
import CBRStepTypes from './constants/CBRFormStepTypes';
|
|
71
69
|
import { nanoid } from 'nanoid';
|
|
@@ -275,62 +273,13 @@ function App(_a) {
|
|
|
275
273
|
}
|
|
276
274
|
}
|
|
277
275
|
export default App;
|
|
278
|
-
//THIS IS TEMP
|
|
279
|
-
export var SIZES;
|
|
280
|
-
(function (SIZES) {
|
|
281
|
-
SIZES["SMALL"] = "SMALL";
|
|
282
|
-
SIZES["MEDIUM"] = "MEDIUM";
|
|
283
|
-
SIZES["LARGE"] = "LARGE";
|
|
284
|
-
})(SIZES || (SIZES = {}));
|
|
285
|
-
export var SizesToNum = (_a = {},
|
|
286
|
-
_a[SIZES.LARGE] = 4,
|
|
287
|
-
_a[SIZES.MEDIUM] = 2,
|
|
288
|
-
_a[SIZES.SMALL] = 1,
|
|
289
|
-
_a);
|
|
290
276
|
var migrateForm = function (form, classifiers) {
|
|
291
|
-
var steps =
|
|
277
|
+
var steps = {};
|
|
292
278
|
for (var _i = 0, _a = Object.keys(form.steps); _i < _a.length; _i++) {
|
|
293
279
|
var idStep = _a[_i];
|
|
294
|
-
|
|
295
|
-
if (step.size && isNaN(step.size)) {
|
|
296
|
-
step.size = getStaticWidth(step);
|
|
297
|
-
}
|
|
298
|
-
if (step.type === CBRStepTypes.CBR_EMAIL) {
|
|
299
|
-
step.validation = {
|
|
300
|
-
value: /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
|
|
301
|
-
.source,
|
|
302
|
-
message: 'El correo no es válido',
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
else if (step.type === CBRStepTypes.CBR_PHONE ||
|
|
306
|
-
step.type === CBRStepTypes.CBR_CEL) {
|
|
307
|
-
step.validation = {
|
|
308
|
-
value: /^(\+[0-9])|([0-9])$/.source,
|
|
309
|
-
message: 'El teléfono no es válido',
|
|
310
|
-
};
|
|
311
|
-
}
|
|
312
|
-
steps[idStep] = step;
|
|
280
|
+
steps[idStep] = migrateStep(form.steps, form.steps[idStep]);
|
|
313
281
|
}
|
|
314
282
|
var newForm = __assign(__assign({}, form), { steps: steps });
|
|
315
|
-
if (form.size === undefined) {
|
|
316
|
-
if (form.spacingSize) {
|
|
317
|
-
newForm.size = {
|
|
318
|
-
spacingSize: form.spacingSize,
|
|
319
|
-
blockNum: form.blockNum,
|
|
320
|
-
blockSize: form.blockSize,
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
else {
|
|
324
|
-
newForm.size = {
|
|
325
|
-
spacingSize: 20,
|
|
326
|
-
blockNum: 4,
|
|
327
|
-
blockSize: 210,
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
if (form.style === undefined) {
|
|
332
|
-
newForm.style = InternalFormStyle;
|
|
333
|
-
}
|
|
334
283
|
if (form.classifiers) {
|
|
335
284
|
var mappedClassifiers = {};
|
|
336
285
|
for (var _b = 0, _c = Object.keys(form.classifiers); _b < _c.length; _b++) {
|
|
@@ -360,17 +309,33 @@ var migrateForm = function (form, classifiers) {
|
|
|
360
309
|
}
|
|
361
310
|
return newForm;
|
|
362
311
|
};
|
|
363
|
-
function
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
312
|
+
var migrateStep = function (steps, pStep) {
|
|
313
|
+
var step = __assign({}, pStep);
|
|
314
|
+
if (step.type === StepTypes.MAPPER) {
|
|
315
|
+
var newSteps = {};
|
|
316
|
+
for (var _i = 0, _a = Object.keys(step.steps); _i < _a.length; _i++) {
|
|
317
|
+
var idStep = _a[_i];
|
|
318
|
+
newSteps[idStep] = migrateStep(__assign(__assign({}, steps), step.steps), step.steps[idStep]);
|
|
319
|
+
}
|
|
320
|
+
step.steps = newSteps;
|
|
372
321
|
}
|
|
373
|
-
|
|
322
|
+
//TODO: Pasar esto al back
|
|
323
|
+
if (step.type === CBRStepTypes.CBR_EMAIL) {
|
|
324
|
+
step.validation = {
|
|
325
|
+
value: /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
|
|
326
|
+
.source,
|
|
327
|
+
message: 'El correo no es válido',
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
else if (step.type === CBRStepTypes.CBR_PHONE ||
|
|
331
|
+
step.type === CBRStepTypes.CBR_CEL) {
|
|
332
|
+
step.validation = {
|
|
333
|
+
value: /^(\+[0-9])|([0-9])$/.source,
|
|
334
|
+
message: 'El teléfono no es válido',
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
return step;
|
|
338
|
+
};
|
|
374
339
|
var mapOriginalValues = function (originalValues, form) {
|
|
375
340
|
var _a;
|
|
376
341
|
var newValues = {};
|
|
@@ -422,7 +387,7 @@ var mapOriginalValues = function (originalValues, form) {
|
|
|
422
387
|
var addInitialMappers = function (newValues, steps) {
|
|
423
388
|
for (var _i = 0, _a = Object.values(steps); _i < _a.length; _i++) {
|
|
424
389
|
var step = _a[_i];
|
|
425
|
-
if (step.type !== StepTypes.MAPPER)
|
|
390
|
+
if (step.type !== StepTypes.MAPPER || newValues[step.id])
|
|
426
391
|
continue;
|
|
427
392
|
var idElement = nanoid();
|
|
428
393
|
var newElement = {
|
|
@@ -328,7 +328,7 @@ function calcDependencies(steps, originalValues, customSteps, allSteps, dependen
|
|
|
328
328
|
var idDep = _e[_d];
|
|
329
329
|
var depStep = allSteps[idDep];
|
|
330
330
|
if (depStep && dependencies[idDep] === undefined) {
|
|
331
|
-
dependencies[idDep] = calcStepDependencyValue(depStep,
|
|
331
|
+
dependencies[idDep] = calcStepDependencyValue(depStep, originalValues, customSteps);
|
|
332
332
|
}
|
|
333
333
|
else if (dependencies[idDep] === undefined) {
|
|
334
334
|
dependencies[idDep] = originalValues[idDep];
|
|
@@ -25,7 +25,7 @@ export interface RecursiveData {
|
|
|
25
25
|
/** Function to call on postview to fetch the download url of a file */
|
|
26
26
|
fetchDownloadUrl?: (S3Key: string, fileName: string) => Promise<string>;
|
|
27
27
|
dependencyStore: Record<string, any>;
|
|
28
|
-
setDependencyStore:
|
|
28
|
+
setDependencyStore: React.Dispatch<React.SetStateAction<Record<string, any>>>;
|
|
29
29
|
setFocus: (id: string) => void;
|
|
30
30
|
}
|
|
31
31
|
export interface SectionComponentProps extends RecursiveData {
|
|
@@ -53,7 +53,7 @@ import InputIcon from '../../../../shared/InputIcon/InputIcon';
|
|
|
53
53
|
function CBRElementStepComponent(props) {
|
|
54
54
|
return (_jsx(SmartSelectStep, __assign({}, props, { step: props.step, icon: _jsx(InputIcon, { icon: 'LEAK' }), getOptions: getElementOptions, getOptionSelected: function (option, value) {
|
|
55
55
|
return option.id === value.id;
|
|
56
|
-
}, getValueString: function (value) { return value === null || value === void 0 ? void 0 : value.id; }, calcDepError: calcDepError,
|
|
56
|
+
}, getValueString: function (value) { return value === null || value === void 0 ? void 0 : value.id; }, calcDepError: calcDepError, valueOverwrite: function (value) {
|
|
57
57
|
if (value) {
|
|
58
58
|
return __assign(__assign({}, value), { subStep: props.step.subStep });
|
|
59
59
|
}
|
|
@@ -73,7 +73,7 @@ function ElementSubStepRenderer(_a) {
|
|
|
73
73
|
if ((subStep === null || subStep === void 0 ? void 0 : subStep.type) !== CBRFormStepTypes.CBR_LOCATIVAS) {
|
|
74
74
|
return _jsx("div", {});
|
|
75
75
|
}
|
|
76
|
-
return (_jsx(SmartSelectStep, __assign({}, stepProps, { step: subStep, level: stepProps.level + 1, icon: _jsx(InputIcon, { icon: 'LEAK' }),
|
|
76
|
+
return (_jsx(SmartSelectStep, __assign({}, stepProps, { step: subStep, level: stepProps.level + 1, icon: _jsx(InputIcon, { icon: 'LEAK' }), getOptions: getElementOptions, calcDepError: calcDepError, getOptionSelected: function (option, value) {
|
|
77
77
|
return option.id === value.id;
|
|
78
78
|
}, getValueString: function (value) { return value === null || value === void 0 ? void 0 : value.id; } }, { children: _jsx(ElementSubStepRenderer, {}) })));
|
|
79
79
|
}
|
|
@@ -111,19 +111,6 @@ var getElementOptions = function (_a, step, dependencyStore) {
|
|
|
111
111
|
});
|
|
112
112
|
});
|
|
113
113
|
};
|
|
114
|
-
var calcInvalidDependencies = function (step, dependencyStore) {
|
|
115
|
-
var _a;
|
|
116
|
-
var deps = [];
|
|
117
|
-
if (step.dependencies) {
|
|
118
|
-
for (var _i = 0, _b = step.dependencies; _i < _b.length; _i++) {
|
|
119
|
-
var idDep = _b[_i];
|
|
120
|
-
if (((_a = dependencyStore[idDep]) === null || _a === void 0 ? void 0 : _a.id) === undefined) {
|
|
121
|
-
deps.push(idDep);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return deps;
|
|
126
|
-
};
|
|
127
114
|
var calcDepError = function (steps) {
|
|
128
115
|
for (var _i = 0, steps_1 = steps; _i < steps_1.length; _i++) {
|
|
129
116
|
var step = steps_1[_i];
|
|
@@ -52,7 +52,6 @@ function Incidents(_a) {
|
|
|
52
52
|
}
|
|
53
53
|
}, [firstRender]);
|
|
54
54
|
var handleAddIncident = function () {
|
|
55
|
-
var _a, _b;
|
|
56
55
|
var current = incidents.filter(function (incident) { return !incident.deleted; });
|
|
57
56
|
var newIncident = {
|
|
58
57
|
idSpaceStep: CBRFormStepTypes.CBR_TIPO_ESPACIO + '-' + nanoid(),
|
|
@@ -63,11 +62,13 @@ function Incidents(_a) {
|
|
|
63
62
|
var newSteps = __assign({}, localForm.steps);
|
|
64
63
|
newSteps[newIncident.idSpaceStep] = __assign(__assign({}, step.spaceStep), { id: newIncident.idSpaceStep, type: CBRFormStepTypes.CBR_TIPO_ESPACIO, dependencies: step.dependencies });
|
|
65
64
|
newSteps[newIncident.idCommentStep] = __assign(__assign({}, step.commentStep), { id: newIncident.idCommentStep, type: CBRFormStepTypes.CBR_COMENTARIO });
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
setDependencyStore(function (dependencies) {
|
|
66
|
+
var _a, _b;
|
|
67
|
+
var deps = __assign({}, dependencies);
|
|
68
|
+
addRecursiveElementStep(newIncident.idElementStep, step.elementStep, null, newSteps, deps, (_b = (_a = step.dependencies) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : '');
|
|
69
|
+
onChange(__spreadArray(__spreadArray([], incidents, true), [newIncident], false));
|
|
70
|
+
setLocalForm(__assign(__assign({}, localForm), { steps: newSteps }));
|
|
71
|
+
});
|
|
71
72
|
};
|
|
72
73
|
var addRecursiveElementStep = function (idStep, step, idParent, steps, dependencyStore, idProjectDep) {
|
|
73
74
|
var _a, _b;
|
|
@@ -146,17 +146,7 @@ function AYFStepMapper(props) {
|
|
|
146
146
|
case AYFFormStepTypes.AYF_ICA_CITY:
|
|
147
147
|
return (_jsx(SmartSelectStep, __assign({}, props, { step: props.step, getOptions: getCiudadesOptions, getOptionSelected: function (option, value) {
|
|
148
148
|
return option === value;
|
|
149
|
-
}, getValueString: function (value) { return value; },
|
|
150
|
-
var _a;
|
|
151
|
-
var missingDeps = [];
|
|
152
|
-
for (var _i = 0, _b = (_a = step.dependencies) !== null && _a !== void 0 ? _a : []; _i < _b.length; _i++) {
|
|
153
|
-
var idDep = _b[_i];
|
|
154
|
-
if (depStore[idDep] === null) {
|
|
155
|
-
missingDeps.push(idDep);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return missingDeps;
|
|
159
|
-
}, icon: _jsx(LocationOnRoundedIcon, { fill: "#757575", style: {
|
|
149
|
+
}, getValueString: function (value) { return value; }, icon: _jsx(LocationOnRoundedIcon, { fill: "#757575", style: {
|
|
160
150
|
display: 'flex',
|
|
161
151
|
height: 23,
|
|
162
152
|
width: 23,
|
|
@@ -74,47 +74,17 @@ function EntityValuePicker(_a) {
|
|
|
74
74
|
var _b = useState(level === 0
|
|
75
75
|
? calcFillerSize(step, form.steps, getValues(), form.size)
|
|
76
76
|
: 0), fillerSize = _b[0], setFillerSize = _b[1];
|
|
77
|
-
useEffect(function () {
|
|
78
|
-
if (!others.originalValues[step.id] && others.defaultValue) {
|
|
79
|
-
others.setDependencyStore(function (deps) {
|
|
80
|
-
var _a;
|
|
81
|
-
return (__assign(__assign({}, deps), (_a = {}, _a[step.id] = others.defaultValue, _a)));
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}, []);
|
|
85
77
|
var getEntityValueOptions = function (_a, _step, dependencyStore, domain) {
|
|
86
78
|
var idOrganization = _a.idOrganization;
|
|
87
79
|
return __awaiter(_this, void 0, void 0, function () {
|
|
88
|
-
var
|
|
80
|
+
var urlPath, _i, _b, path, idEntityValue, currentValue, params, _c, _d, filter, currentValue, url, response;
|
|
89
81
|
var _e, _f, _g;
|
|
90
82
|
return __generator(this, function (_h) {
|
|
91
83
|
switch (_h.label) {
|
|
92
84
|
case 0:
|
|
93
|
-
params = new URLSearchParams({});
|
|
94
|
-
for (_i = 0, _b = step.filters; _i < _b.length; _i++) {
|
|
95
|
-
filter = _b[_i];
|
|
96
|
-
switch (filter.type) {
|
|
97
|
-
case EntityValueDataTypes.STEP:
|
|
98
|
-
currentValue = dependencyStore[filter.idStep];
|
|
99
|
-
if (currentValue) {
|
|
100
|
-
if (typeof currentValue === 'string')
|
|
101
|
-
params.set(filter.idProperty, currentValue);
|
|
102
|
-
else
|
|
103
|
-
params.set(filter.idProperty, (_e = currentValue._id) !== null && _e !== void 0 ? _e : currentValue.id);
|
|
104
|
-
}
|
|
105
|
-
else if (filter.required) {
|
|
106
|
-
return [2 /*return*/, null];
|
|
107
|
-
}
|
|
108
|
-
break;
|
|
109
|
-
case EntityValueDataTypes.VALUE:
|
|
110
|
-
default:
|
|
111
|
-
params.set(filter.idProperty, filter.value);
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
85
|
urlPath = '';
|
|
116
|
-
for (
|
|
117
|
-
path =
|
|
86
|
+
for (_i = 0, _b = step.path; _i < _b.length; _i++) {
|
|
87
|
+
path = _b[_i];
|
|
118
88
|
idEntityValue = 'null';
|
|
119
89
|
switch (path.type) {
|
|
120
90
|
case EntityValueDataTypes.STEP:
|
|
@@ -124,11 +94,11 @@ function EntityValuePicker(_a) {
|
|
|
124
94
|
if (typeof currentValue === 'string')
|
|
125
95
|
idEntityValue = currentValue;
|
|
126
96
|
else
|
|
127
|
-
idEntityValue = (
|
|
97
|
+
idEntityValue = (_e = currentValue._id) !== null && _e !== void 0 ? _e : currentValue.id;
|
|
128
98
|
break;
|
|
129
99
|
case EntityValueDataTypes.VALUE:
|
|
130
100
|
default:
|
|
131
|
-
idEntityValue = (
|
|
101
|
+
idEntityValue = (_f = path.idEntityValue) !== null && _f !== void 0 ? _f : 'null';
|
|
132
102
|
break;
|
|
133
103
|
}
|
|
134
104
|
urlPath +=
|
|
@@ -136,6 +106,28 @@ function EntityValuePicker(_a) {
|
|
|
136
106
|
path.idEntity +
|
|
137
107
|
(idEntityValue ? '/' + idEntityValue : '');
|
|
138
108
|
}
|
|
109
|
+
params = new URLSearchParams({});
|
|
110
|
+
for (_c = 0, _d = step.filters; _c < _d.length; _c++) {
|
|
111
|
+
filter = _d[_c];
|
|
112
|
+
switch (filter.type) {
|
|
113
|
+
case EntityValueDataTypes.STEP:
|
|
114
|
+
currentValue = dependencyStore[filter.idStep];
|
|
115
|
+
if (currentValue) {
|
|
116
|
+
if (typeof currentValue === 'string')
|
|
117
|
+
params.set(filter.idProperty, currentValue);
|
|
118
|
+
else
|
|
119
|
+
params.set(filter.idProperty, (_g = currentValue._id) !== null && _g !== void 0 ? _g : currentValue.id);
|
|
120
|
+
}
|
|
121
|
+
else if (filter.required) {
|
|
122
|
+
return [2 /*return*/, null];
|
|
123
|
+
}
|
|
124
|
+
break;
|
|
125
|
+
case EntityValueDataTypes.VALUE:
|
|
126
|
+
default:
|
|
127
|
+
params.set(filter.idProperty, filter.value);
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
139
131
|
url = "".concat(domain !== null && domain !== void 0 ? domain : idOrganization, "/entities/").concat(step.idEntity).concat(urlPath, "?").concat(params.toString());
|
|
140
132
|
return [4 /*yield*/, (domain
|
|
141
133
|
? widgetInstance.get(url)
|
|
@@ -195,12 +187,30 @@ function EntityValuePicker(_a) {
|
|
|
195
187
|
export default EntityValuePickerStep;
|
|
196
188
|
function EntityValuePickerStep(props) {
|
|
197
189
|
var _a, _b;
|
|
190
|
+
var step = props.step, dependencyStore = props.dependencyStore, defaultValue = props.defaultValue, originalValues = props.originalValues;
|
|
191
|
+
useEffect(function () {
|
|
192
|
+
/** Al modificar tambien modificar en SmartSelect */
|
|
193
|
+
if (!originalValues[step.id] && defaultValue) {
|
|
194
|
+
props.setDependencyStore(function (dependencies) {
|
|
195
|
+
var _a;
|
|
196
|
+
return (__assign(__assign({}, dependencies), (_a = {}, _a[step.id] = props.defaultValue, _a)));
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}, []);
|
|
198
200
|
return (_jsx(Controller, { name: props.step.id, control: props.control, defaultValue: (_b = (_a = props.originalValues[props.step.id]) !== null && _a !== void 0 ? _a : props.defaultValue) !== null && _b !== void 0 ? _b : null, rules: {
|
|
199
201
|
required: props.step.required
|
|
200
202
|
? 'Este campo es obligatorio'
|
|
201
203
|
: undefined,
|
|
202
204
|
}, shouldUnregister: true, render: function (_a) {
|
|
203
205
|
var _b = _a.field, ref = _b.ref, field = __rest(_b, ["ref"]);
|
|
204
|
-
return (_jsx(EntityValuePicker, __assign({}, props, field, { inputRef: ref
|
|
206
|
+
return (_jsx(EntityValuePicker, __assign({}, props, field, { inputRef: ref, onChange: function (value) {
|
|
207
|
+
if (dependencyStore[step.id] !== undefined) {
|
|
208
|
+
props.setDependencyStore(function (dependencies) {
|
|
209
|
+
var _a;
|
|
210
|
+
return (__assign(__assign({}, dependencies), (_a = {}, _a[step.id] = value !== null && value !== void 0 ? value : null, _a)));
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
field.onChange(value);
|
|
214
|
+
} })));
|
|
205
215
|
} }));
|
|
206
216
|
}
|
|
@@ -247,8 +247,22 @@ function calcRecursiveData(element, newSteps, deps, customSteps, originalValues)
|
|
|
247
247
|
break;
|
|
248
248
|
}
|
|
249
249
|
case StepTypes.ENTITYVALUEPICKER:
|
|
250
|
-
for (var _j = 0, _k = step.
|
|
251
|
-
var
|
|
250
|
+
for (var _j = 0, _k = step.path; _j < _k.length; _j++) {
|
|
251
|
+
var path = _k[_j];
|
|
252
|
+
switch (path.type) {
|
|
253
|
+
case EntityValueDataTypes.STEP:
|
|
254
|
+
var newId = element.ids[path.idStep];
|
|
255
|
+
if (newId) {
|
|
256
|
+
path.idStep = newId;
|
|
257
|
+
deps[newId] = calcStepDependencyValue(newSteps[newId], originalValues);
|
|
258
|
+
}
|
|
259
|
+
break;
|
|
260
|
+
default:
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
for (var _l = 0, _m = step.filters; _l < _m.length; _l++) {
|
|
265
|
+
var filter = _m[_l];
|
|
252
266
|
switch (filter.type) {
|
|
253
267
|
case EntityValueDataTypes.STEP:
|
|
254
268
|
var newId = element.ids[filter.idStep];
|
|
@@ -261,8 +275,8 @@ function calcRecursiveData(element, newSteps, deps, customSteps, originalValues)
|
|
|
261
275
|
break;
|
|
262
276
|
}
|
|
263
277
|
}
|
|
264
|
-
for (var
|
|
265
|
-
var idOption =
|
|
278
|
+
for (var _o = 0, _p = Object.keys((_a = step.options) !== null && _a !== void 0 ? _a : {}); _o < _p.length; _o++) {
|
|
279
|
+
var idOption = _p[_o];
|
|
266
280
|
var option = step.options[idOption];
|
|
267
281
|
if (option.type === EntityValueOptionTypes.NESTED) {
|
|
268
282
|
for (var i = 0; i < option.steps.length; i++) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { SmartSelectStepProps } from '../SmartSelectStep';
|
|
3
|
-
export declare function SmartSelect({ icon, step, form, value, onBlur, errors, setFocus, children, editable, onChange, inputRef, postview, formStyle, getOptions, widthStats, organization, calcDepError, valueOverwrite, getValueString, originalValues, changeListener, dependencyStore,
|
|
3
|
+
export declare function SmartSelect({ icon, step, form, value, onBlur, errors, setFocus, children, editable, onChange, inputRef, postview, formStyle, getOptions, widthStats, organization, calcDepError, valueOverwrite, getValueString, originalValues, changeListener, dependencyStore, getValueWarning, getOptionSelected, setDependencyStore, ...others }: SmartSelectStepProps & {
|
|
4
4
|
onChange: Function;
|
|
5
5
|
onBlur: (event: any) => void;
|
|
6
6
|
value: any;
|
package/dist/FormComponents/Step/SmartSelectStep/MaterialSmartSelectStep/MaterialSmartSelectStep.js
CHANGED
|
@@ -56,6 +56,15 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
56
56
|
}
|
|
57
57
|
return t;
|
|
58
58
|
};
|
|
59
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
60
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
61
|
+
if (ar || !(i in from)) {
|
|
62
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
63
|
+
ar[i] = from[i];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
67
|
+
};
|
|
59
68
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
60
69
|
import styles from './MaterialSmartSelectStep.module.css';
|
|
61
70
|
import { Controller } from 'react-hook-form';
|
|
@@ -66,34 +75,46 @@ import React from 'react';
|
|
|
66
75
|
export function SmartSelect(_a) {
|
|
67
76
|
var _this = this;
|
|
68
77
|
var _b, _c, _d, _e;
|
|
69
|
-
var icon = _a.icon, step = _a.step, form = _a.form, value = _a.value, onBlur = _a.onBlur, errors = _a.errors, setFocus = _a.setFocus, children = _a.children, editable = _a.editable, onChange = _a.onChange, inputRef = _a.inputRef, postview = _a.postview, formStyle = _a.formStyle, getOptions = _a.getOptions, widthStats = _a.widthStats, organization = _a.organization, calcDepError = _a.calcDepError, valueOverwrite = _a.valueOverwrite, getValueString = _a.getValueString, originalValues = _a.originalValues, changeListener = _a.changeListener, dependencyStore = _a.dependencyStore,
|
|
70
|
-
|
|
78
|
+
var icon = _a.icon, step = _a.step, form = _a.form, value = _a.value, onBlur = _a.onBlur, errors = _a.errors, setFocus = _a.setFocus, children = _a.children, editable = _a.editable, onChange = _a.onChange, inputRef = _a.inputRef, postview = _a.postview, formStyle = _a.formStyle, getOptions = _a.getOptions, widthStats = _a.widthStats, organization = _a.organization, calcDepError = _a.calcDepError, valueOverwrite = _a.valueOverwrite, getValueString = _a.getValueString, originalValues = _a.originalValues, changeListener = _a.changeListener, dependencyStore = _a.dependencyStore, getValueWarning = _a.getValueWarning, getOptionSelected = _a.getOptionSelected, setDependencyStore = _a.setDependencyStore, others = __rest(_a, ["icon", "step", "form", "value", "onBlur", "errors", "setFocus", "children", "editable", "onChange", "inputRef", "postview", "formStyle", "getOptions", "widthStats", "organization", "calcDepError", "valueOverwrite", "getValueString", "originalValues", "changeListener", "dependencyStore", "getValueWarning", "getOptionSelected", "setDependencyStore"]);
|
|
79
|
+
var _f = useState(true), first = _f[0], setFirst = _f[1];
|
|
80
|
+
var _g = useState(), options = _g[0], setOptions = _g[1];
|
|
81
|
+
var _h = useState(), error = _h[0], setError = _h[1];
|
|
82
|
+
var _j = useState(false), loading = _j[0], setLoading = _j[1];
|
|
83
|
+
var calcInvalidDeps = function () {
|
|
84
|
+
var calcDependencies = function (idStep, deps) {
|
|
85
|
+
if (deps === void 0) { deps = []; }
|
|
86
|
+
var step = form.steps[idStep];
|
|
87
|
+
if (step.dependencies) {
|
|
88
|
+
for (var _i = 0, _a = step.dependencies; _i < _a.length; _i++) {
|
|
89
|
+
var dep = _a[_i];
|
|
90
|
+
if (!deps.includes(dep)) {
|
|
91
|
+
deps.push.apply(deps, __spreadArray(__spreadArray([], calcDependencies(dep, deps), false), [dep], false));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return deps;
|
|
96
|
+
};
|
|
71
97
|
var missingDeps = [];
|
|
72
|
-
for (var _i = 0,
|
|
73
|
-
var idDep =
|
|
74
|
-
if (
|
|
98
|
+
for (var _i = 0, _a = calcDependencies(step.id); _i < _a.length; _i++) {
|
|
99
|
+
var idDep = _a[_i];
|
|
100
|
+
if (dependencyStore[idDep] === null) {
|
|
75
101
|
missingDeps.push(idDep);
|
|
76
102
|
}
|
|
77
103
|
}
|
|
78
104
|
return missingDeps;
|
|
79
|
-
}
|
|
80
|
-
var _g = useState(true), first = _g[0], setFirst = _g[1];
|
|
81
|
-
var _h = useState(), options = _h[0], setOptions = _h[1];
|
|
82
|
-
var _j = useState(), error = _j[0], setError = _j[1];
|
|
83
|
-
var _k = useState(false), loading = _k[0], setLoading = _k[1];
|
|
105
|
+
};
|
|
84
106
|
var calcOptions = function (currentValue, invalidDeps) { return __awaiter(_this, void 0, void 0, function () {
|
|
85
107
|
var resp, currentOption, invalids, error_1;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
switch (_b.label) {
|
|
108
|
+
return __generator(this, function (_a) {
|
|
109
|
+
switch (_a.label) {
|
|
89
110
|
case 0:
|
|
90
111
|
setOptions(undefined);
|
|
91
|
-
|
|
112
|
+
_a.label = 1;
|
|
92
113
|
case 1:
|
|
93
|
-
|
|
114
|
+
_a.trys.push([1, 3, , 4]);
|
|
94
115
|
return [4 /*yield*/, (getOptions === null || getOptions === void 0 ? void 0 : getOptions(organization, step, dependencyStore, others.domain))];
|
|
95
116
|
case 2:
|
|
96
|
-
resp =
|
|
117
|
+
resp = _a.sent();
|
|
97
118
|
if (resp !== null) {
|
|
98
119
|
if (invalidDeps !== undefined && currentValue) {
|
|
99
120
|
currentOption = resp.find(function (option) {
|
|
@@ -104,7 +125,7 @@ export function SmartSelect(_a) {
|
|
|
104
125
|
}
|
|
105
126
|
}
|
|
106
127
|
else {
|
|
107
|
-
invalids =
|
|
128
|
+
invalids = calcInvalidDeps();
|
|
108
129
|
if (invalids.length === 0) {
|
|
109
130
|
setError(undefined);
|
|
110
131
|
}
|
|
@@ -113,7 +134,7 @@ export function SmartSelect(_a) {
|
|
|
113
134
|
setOptions(resp);
|
|
114
135
|
return [3 /*break*/, 4];
|
|
115
136
|
case 3:
|
|
116
|
-
error_1 =
|
|
137
|
+
error_1 = _a.sent();
|
|
117
138
|
console.error(error_1);
|
|
118
139
|
setOptions(null);
|
|
119
140
|
return [3 /*break*/, 4];
|
|
@@ -127,7 +148,7 @@ export function SmartSelect(_a) {
|
|
|
127
148
|
if (!postview) {
|
|
128
149
|
if (first) {
|
|
129
150
|
setFirst(false);
|
|
130
|
-
var invalids = calcInvalidDeps(
|
|
151
|
+
var invalids = calcInvalidDeps().filter(function (idDep) { return originalValues[idDep]; });
|
|
131
152
|
setError(calcDepError === null || calcDepError === void 0 ? void 0 : calcDepError(invalids.map(function (idDep) { return form.steps[idDep]; })));
|
|
132
153
|
calcOptions(value, invalids);
|
|
133
154
|
}
|
|
@@ -161,7 +182,7 @@ export function SmartSelect(_a) {
|
|
|
161
182
|
var invalids;
|
|
162
183
|
return __generator(this, function (_a) {
|
|
163
184
|
if (step.dependencies) {
|
|
164
|
-
invalids = calcInvalidDeps(
|
|
185
|
+
invalids = calcInvalidDeps();
|
|
165
186
|
setError(calcDepError === null || calcDepError === void 0 ? void 0 : calcDepError(invalids
|
|
166
187
|
.map(function (idDep) { return form.steps[idDep]; })
|
|
167
188
|
.filter(function (idDep) { return idDep !== undefined; })));
|
|
@@ -201,10 +222,6 @@ export function SmartSelect(_a) {
|
|
|
201
222
|
setLoading(true);
|
|
202
223
|
}
|
|
203
224
|
}, disabled: options === null, loading: loading, options: options !== null && options !== void 0 ? options : undefined, inputRef: inputRef, cantEdit: !editable || postview, fullWidth: true, backgroundColor: (_d = formStyle.stepBackgroundColor) !== null && _d !== void 0 ? _d : 'white', label: step.label, required: step.required, height: '31px', changeListener: changeListener, searchable: step.searchable, icon: step.showIcon ? icon : undefined, helperTextColor: formStyle.descriptionTextColor, focusColor: formStyle.primaryColor, outlineColor: formStyle.outlineColor, errorColor: formStyle.errorColor, color: formStyle.textColor, containerMargin: "0px", handleUpdate: function (value) {
|
|
204
|
-
var _a;
|
|
205
|
-
if (dependencyStore[step.id] !== undefined) {
|
|
206
|
-
setDependencyStore(__assign(__assign({}, dependencyStore), (_a = {}, _a[step.id] = value !== null && value !== void 0 ? value : null, _a)));
|
|
207
|
-
}
|
|
208
225
|
valueOverwrite
|
|
209
226
|
? onChange(valueOverwrite(value))
|
|
210
227
|
: onChange(value);
|
|
@@ -221,22 +238,31 @@ export function SmartSelect(_a) {
|
|
|
221
238
|
}
|
|
222
239
|
function SmartSelectStep(props) {
|
|
223
240
|
var _a, _b;
|
|
241
|
+
var step = props.step, dependencyStore = props.dependencyStore, defaultValue = props.defaultValue, originalValues = props.originalValues;
|
|
224
242
|
useEffect(function () {
|
|
225
|
-
/** Al modificar tambien modificar en
|
|
226
|
-
if (!
|
|
227
|
-
props.setDependencyStore(function (
|
|
243
|
+
/** Al modificar tambien modificar en EntityValue */
|
|
244
|
+
if (!originalValues[step.id] && defaultValue) {
|
|
245
|
+
props.setDependencyStore(function (dependencies) {
|
|
228
246
|
var _a;
|
|
229
|
-
return (__assign(__assign({},
|
|
247
|
+
return (__assign(__assign({}, dependencies), (_a = {}, _a[step.id] = props.defaultValue, _a)));
|
|
230
248
|
});
|
|
231
249
|
}
|
|
232
250
|
}, []);
|
|
233
|
-
return (_jsx(Controller, { name:
|
|
234
|
-
required:
|
|
251
|
+
return (_jsx(Controller, { name: step.id, control: props.control, defaultValue: (_b = (_a = originalValues[step.id]) !== null && _a !== void 0 ? _a : defaultValue) !== null && _b !== void 0 ? _b : null, rules: {
|
|
252
|
+
required: step.required
|
|
235
253
|
? 'Este campo es obligatorio'
|
|
236
254
|
: undefined,
|
|
237
255
|
}, shouldUnregister: true, render: function (_a) {
|
|
238
256
|
var _b = _a.field, ref = _b.ref, field = __rest(_b, ["ref"]);
|
|
239
|
-
return (_jsx(SmartSelect, __assign({}, props, field, { inputRef: ref
|
|
257
|
+
return (_jsx(SmartSelect, __assign({}, props, field, { inputRef: ref, onChange: function (value) {
|
|
258
|
+
if (dependencyStore[step.id] !== undefined) {
|
|
259
|
+
props.setDependencyStore(function (dependencies) {
|
|
260
|
+
var _a;
|
|
261
|
+
return (__assign(__assign({}, dependencies), (_a = {}, _a[step.id] = value !== null && value !== void 0 ? value : null, _a)));
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
field.onChange(value);
|
|
265
|
+
} })));
|
|
240
266
|
} }));
|
|
241
267
|
}
|
|
242
268
|
export default SmartSelectStep;
|
|
@@ -18,8 +18,6 @@ export interface SmartSelectStepProps extends Omit<StepProps, 'step'> {
|
|
|
18
18
|
getValueWarning?: (value: any) => string | null;
|
|
19
19
|
/** Function that returns the error message based on the types of the missing Dependencies, undefined if no error msg */
|
|
20
20
|
calcDepError?: (types: FormStep[]) => string | undefined;
|
|
21
|
-
/** Function that returns the missing dependencies based on the current value */
|
|
22
|
-
calcInvalidDeps?: (step: GSmartSelect, dependencyStore: Record<string, any>) => string[];
|
|
23
21
|
/** children to render */
|
|
24
22
|
children?: React.ReactElement<any, string>;
|
|
25
23
|
/** Function that overwrites the value before setting it */
|
package/package.json
CHANGED