@arquimedes.co/eureka-forms 1.9.93-test → 1.9.95-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.
@@ -1,4 +1,4 @@
1
- import Types, { ClassifierOptionTypes, OptionTypes, RatingTypes, MapperStyleTypes, EntityValueOptionTypes } from '../constants/FormStepTypes';
1
+ import Types, { ClassifierOptionTypes, OptionTypes, RatingTypes, MapperStyleTypes, EntityValueOptionTypes, EntityValueDataTypes } from '../constants/FormStepTypes';
2
2
  import * as GSteps from './GenericFormSteps';
3
3
  export type FormStep = Title | Rating | CheckBox | TextArea | TextInput | DatePicker | FileUpload | Separator | FormSelector | ClassifierSelector | Collapsible | EntityValuePicker | Mapper;
4
4
  export interface Title extends GSteps.GBaseStep {
@@ -98,17 +98,8 @@ export interface EntityValuePicker extends GSteps.GSmartSelect {
98
98
  type: Types.ENTITYVALUEPICKER;
99
99
  idEntity: string;
100
100
  icon: string | null;
101
- filters: {
102
- idProperty: string;
103
- idStep?: string;
104
- value?: string;
105
- required?: boolean;
106
- }[];
107
- path: {
108
- idEntity: string;
109
- idStep?: string;
110
- idEntityValue?: string;
111
- }[];
101
+ filters: EntityValuePickerFilter[];
102
+ path: EntityValuePickerPath[];
112
103
  options: Record<string, FormEntityValuePickerOption>;
113
104
  maxSize?: number;
114
105
  }
@@ -122,6 +113,31 @@ interface HideFormEntityValuePickerOption {
122
113
  type: EntityValueOptionTypes.HIDE;
123
114
  idEntityValue: String;
124
115
  }
116
+ export type EntityValuePickerPath = StepEntityValuePickerPath | ValueEntityValuePickerPath;
117
+ export interface StepEntityValuePickerPath {
118
+ idEntity: string;
119
+ type: EntityValueDataTypes.STEP;
120
+ idStep: string;
121
+ any: boolean;
122
+ }
123
+ export interface ValueEntityValuePickerPath {
124
+ idEntity: string;
125
+ type: EntityValueDataTypes.VALUE;
126
+ idEntityValue: string | null;
127
+ }
128
+ export type EntityValuePickerFilter = StepEntityValuePickerFilter | ValueEntityValuePickerFilter;
129
+ export interface StepEntityValuePickerFilter {
130
+ idProperty: string;
131
+ type: EntityValueDataTypes.STEP;
132
+ idStep: string;
133
+ any: boolean;
134
+ required: boolean;
135
+ }
136
+ export interface ValueEntityValuePickerFilter {
137
+ idProperty: string;
138
+ type: EntityValueDataTypes.VALUE;
139
+ value: any;
140
+ }
125
141
  export interface Mapper extends GSteps.GBaseStep {
126
142
  type: Types.MAPPER;
127
143
  style: {
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 = __assign({}, form.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
- var step = __assign({}, form.steps[idStep]);
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 getStaticWidth(step) {
364
- switch (step.size) {
365
- case SIZES.SMALL:
366
- return 1;
367
- case SIZES.MEDIUM:
368
- return 2;
369
- case SIZES.LARGE:
370
- default:
371
- return 4;
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 = {};
@@ -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: (values: Record<string, any>) => void;
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, calcInvalidDeps: calcInvalidDependencies, valueOverwrite: function (value) {
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' }), calcInvalidDeps: calcInvalidDependencies, getOptions: getElementOptions, calcDepError: calcDepError, getOptionSelected: function (option, value) {
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
- var deps = __assign({}, dependencyStore);
67
- 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 : '');
68
- onChange(__spreadArray(__spreadArray([], incidents, true), [newIncident], false));
69
- setLocalForm(__assign(__assign({}, localForm), { steps: newSteps }));
70
- setDependencyStore(deps);
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; }, calcInvalidDeps: function (step, depStore) {
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,
@@ -59,7 +59,7 @@ var __rest = (this && this.__rest) || function (s, e) {
59
59
  import { createElement as _createElement } from "react";
60
60
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
61
61
  import React, { useEffect, useState } from 'react';
62
- import FormStepTypes, { EntityValueOptionTypes, } from '../../../../constants/FormStepTypes';
62
+ import FormStepTypes, { EntityValueDataTypes, EntityValueOptionTypes, } from '../../../../constants/FormStepTypes';
63
63
  import styles from './MaterialEntityValuePickerStep.module.css';
64
64
  import StepComponent from '../../Step';
65
65
  import { Controller } from 'react-hook-form';
@@ -74,61 +74,66 @@ 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 params, _i, _b, filter, value_1, currentValue, url, response;
89
- var _c;
90
- return __generator(this, function (_d) {
91
- switch (_d.label) {
80
+ var params, _i, _b, filter, currentValue, urlPath, _c, _d, path, idEntityValue, currentValue, url, response;
81
+ var _e, _f, _g;
82
+ return __generator(this, function (_h) {
83
+ switch (_h.label) {
92
84
  case 0:
93
85
  params = new URLSearchParams({});
94
86
  for (_i = 0, _b = step.filters; _i < _b.length; _i++) {
95
87
  filter = _b[_i];
96
- value_1 = filter.value;
97
- if (filter.idStep) {
98
- currentValue = dependencyStore[filter.idStep];
99
- if (currentValue) {
100
- if (typeof currentValue === 'string')
101
- value_1 = currentValue;
102
- else
103
- value_1 = (_c = currentValue._id) !== null && _c !== void 0 ? _c : currentValue.id;
104
- //TODO: Manejo de multiple!
105
- }
106
- else if (filter.required) {
107
- return [2 /*return*/, null];
108
- }
88
+ switch (filter.type) {
89
+ case EntityValueDataTypes.STEP:
90
+ currentValue = dependencyStore[filter.idStep];
91
+ if (currentValue) {
92
+ if (typeof currentValue === 'string')
93
+ params.set(filter.idProperty, currentValue);
94
+ else
95
+ params.set(filter.idProperty, (_e = currentValue._id) !== null && _e !== void 0 ? _e : currentValue.id);
96
+ }
97
+ else if (filter.required) {
98
+ return [2 /*return*/, null];
99
+ }
100
+ break;
101
+ case EntityValueDataTypes.VALUE:
102
+ default:
103
+ params.set(filter.idProperty, filter.value);
104
+ break;
109
105
  }
110
- if (value_1)
111
- params.set(filter.idProperty, value_1);
112
106
  }
113
- url = "".concat(domain !== null && domain !== void 0 ? domain : idOrganization, "/entities/").concat(step.idEntity).concat(step.path.map(function (path) {
114
- var _a;
115
- var idEntityValue = path.idEntityValue;
116
- if (path.idStep) {
117
- var currentValue = dependencyStore[path.idStep];
118
- if (currentValue) {
107
+ urlPath = '';
108
+ for (_c = 0, _d = step.path; _c < _d.length; _c++) {
109
+ path = _d[_c];
110
+ idEntityValue = 'null';
111
+ switch (path.type) {
112
+ case EntityValueDataTypes.STEP:
113
+ currentValue = dependencyStore[path.idStep];
114
+ if (!currentValue)
115
+ return [2 /*return*/, null];
119
116
  if (typeof currentValue === 'string')
120
117
  idEntityValue = currentValue;
121
118
  else
122
- idEntityValue = (_a = currentValue._id) !== null && _a !== void 0 ? _a : currentValue.id;
123
- }
119
+ idEntityValue = (_f = currentValue._id) !== null && _f !== void 0 ? _f : currentValue.id;
120
+ break;
121
+ case EntityValueDataTypes.VALUE:
122
+ default:
123
+ idEntityValue = (_g = path.idEntityValue) !== null && _g !== void 0 ? _g : 'null';
124
+ break;
124
125
  }
125
- return ('/' + path.idEntity + (idEntityValue ? '/' + idEntityValue : ''));
126
- }), "?").concat(params.toString());
126
+ urlPath +=
127
+ '/' +
128
+ path.idEntity +
129
+ (idEntityValue ? '/' + idEntityValue : '');
130
+ }
131
+ url = "".concat(domain !== null && domain !== void 0 ? domain : idOrganization, "/entities/").concat(step.idEntity).concat(urlPath, "?").concat(params.toString());
127
132
  return [4 /*yield*/, (domain
128
133
  ? widgetInstance.get(url)
129
134
  : axiosInstance.get(url))];
130
135
  case 1:
131
- response = _d.sent();
136
+ response = _h.sent();
132
137
  return [2 /*return*/, response.data.filter(function (option) { var _a; return ((_a = step.options[option._id]) === null || _a === void 0 ? void 0 : _a.type) !== EntityValueOptionTypes.HIDE; })];
133
138
  }
134
139
  });
@@ -182,12 +187,30 @@ function EntityValuePicker(_a) {
182
187
  export default EntityValuePickerStep;
183
188
  function EntityValuePickerStep(props) {
184
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
+ }, []);
185
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: {
186
201
  required: props.step.required
187
202
  ? 'Este campo es obligatorio'
188
203
  : undefined,
189
204
  }, shouldUnregister: true, render: function (_a) {
190
205
  var _b = _a.field, ref = _b.ref, field = __rest(_b, ["ref"]);
191
- 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
+ } })));
192
215
  } }));
193
216
  }
@@ -33,7 +33,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
33
33
  import React, { useState, useEffect, cloneElement } from 'react';
34
34
  import styles from './MaterialMapperStep.module.css';
35
35
  import { Controller } from 'react-hook-form';
36
- import StepTypes, { ClassifierOptionTypes, EntityValueOptionTypes, MapperStyleTypes, OptionTypes, } from '../../../../constants/FormStepTypes';
36
+ import StepTypes, { ClassifierOptionTypes, EntityValueDataTypes, EntityValueOptionTypes, MapperStyleTypes, OptionTypes, } from '../../../../constants/FormStepTypes';
37
37
  import RoundedButton from '../../../../shared/RoundedButton/RoundedButton';
38
38
  import { nanoid } from 'nanoid';
39
39
  import { calcStepDependencyValue } from '../../../Form/ColumnForm/ColumnForm';
@@ -247,18 +247,36 @@ function calcRecursiveData(element, newSteps, deps, customSteps, originalValues)
247
247
  break;
248
248
  }
249
249
  case StepTypes.ENTITYVALUEPICKER:
250
- for (var _j = 0, _k = step.filters; _j < _k.length; _j++) {
251
- var filter = _k[_j];
252
- if (filter.idStep) {
253
- var newId = element.ids[filter.idStep];
254
- if (newId) {
255
- filter.idStep = newId;
256
- deps[newId] = calcStepDependencyValue(newSteps[newId], originalValues);
257
- }
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];
266
+ switch (filter.type) {
267
+ case EntityValueDataTypes.STEP:
268
+ var newId = element.ids[filter.idStep];
269
+ if (newId) {
270
+ filter.idStep = newId;
271
+ deps[newId] = calcStepDependencyValue(newSteps[newId], originalValues);
272
+ }
273
+ break;
274
+ default:
275
+ break;
258
276
  }
259
277
  }
260
- for (var _l = 0, _m = Object.keys((_a = step.options) !== null && _a !== void 0 ? _a : {}); _l < _m.length; _l++) {
261
- var idOption = _m[_l];
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];
262
280
  var option = step.options[idOption];
263
281
  if (option.type === EntityValueOptionTypes.NESTED) {
264
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, calcInvalidDeps, getValueWarning, getOptionSelected, setDependencyStore, ...others }: SmartSelectStepProps & {
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;
@@ -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, _f = _a.calcInvalidDeps, calcInvalidDeps = _f === void 0 ? function (step, depStore) {
70
- var _a;
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, _b = (_a = step.dependencies) !== null && _a !== void 0 ? _a : []; _i < _b.length; _i++) {
73
- var idDep = _b[_i];
74
- if (depStore[idDep] === null) {
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
- } : _f, 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", "calcInvalidDeps", "getValueWarning", "getOptionSelected", "setDependencyStore"]);
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
- var _a;
87
- return __generator(this, function (_b) {
88
- switch (_b.label) {
108
+ return __generator(this, function (_a) {
109
+ switch (_a.label) {
89
110
  case 0:
90
111
  setOptions(undefined);
91
- _b.label = 1;
112
+ _a.label = 1;
92
113
  case 1:
93
- _b.trys.push([1, 3, , 4]);
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 = _b.sent();
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 = (_a = calcInvalidDeps === null || calcInvalidDeps === void 0 ? void 0 : calcInvalidDeps(step, dependencyStore)) !== null && _a !== void 0 ? _a : [];
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 = _b.sent();
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(step, dependencyStore).filter(function (idDep) { return originalValues[idDep]; });
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(step, dependencyStore);
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 EntityValues */
226
- if (!props.originalValues[props.step.id] && props.defaultValue) {
227
- props.setDependencyStore(function (deps) {
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({}, deps), (_a = {}, _a[props.step.id] = props.defaultValue, _a)));
247
+ return (__assign(__assign({}, dependencies), (_a = {}, _a[step.id] = props.defaultValue, _a)));
230
248
  });
231
249
  }
232
250
  }, []);
233
- 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: {
234
- required: props.step.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 */
@@ -44,3 +44,7 @@ export declare enum MapperStyleTypes {
44
44
  LIST = "LIST",
45
45
  INLINE = "INLINE"
46
46
  }
47
+ export declare enum EntityValueDataTypes {
48
+ STEP = "STEP",
49
+ VALUE = "VALUE"
50
+ }
@@ -52,3 +52,8 @@ export var MapperStyleTypes;
52
52
  MapperStyleTypes["LIST"] = "LIST";
53
53
  MapperStyleTypes["INLINE"] = "INLINE";
54
54
  })(MapperStyleTypes || (MapperStyleTypes = {}));
55
+ export var EntityValueDataTypes;
56
+ (function (EntityValueDataTypes) {
57
+ EntityValueDataTypes["STEP"] = "STEP";
58
+ EntityValueDataTypes["VALUE"] = "VALUE";
59
+ })(EntityValueDataTypes || (EntityValueDataTypes = {}));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@arquimedes.co/eureka-forms",
3
3
  "repository": "git://github.com/Arquimede5/Eureka-Forms.git",
4
- "version":"1.9.93-test",
4
+ "version":"1.9.95-test",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
7
7
  "build": "react-scripts build",