@arquimedes.co/eureka-forms 1.4.7-test → 1.4.8-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.
@@ -257,12 +257,13 @@ function stringToDraft(text) {
257
257
  return draftStructure;
258
258
  }
259
259
  function calcDependencies(steps, originalValues) {
260
+ var _a;
260
261
  var dependencies = {};
261
- for (var _i = 0, _a = Object.values(steps); _i < _a.length; _i++) {
262
- var step = _a[_i];
262
+ for (var _i = 0, _b = Object.values(steps); _i < _b.length; _i++) {
263
+ var step = _b[_i];
263
264
  if (step.dependencies) {
264
- for (var _b = 0, _c = step.dependencies; _b < _c.length; _b++) {
265
- var idDep = _c[_b];
265
+ for (var _c = 0, _d = step.dependencies; _c < _d.length; _c++) {
266
+ var idDep = _d[_c];
266
267
  var depStep = steps[idDep];
267
268
  if (depStep && dependencies[idDep] === undefined) {
268
269
  switch (depStep === null || depStep === void 0 ? void 0 : depStep.type) {
@@ -277,7 +278,7 @@ function calcDependencies(steps, originalValues) {
277
278
  break;
278
279
  }
279
280
  default:
280
- dependencies[idDep] = originalValues[idDep];
281
+ dependencies[idDep] = (_a = originalValues[idDep]) !== null && _a !== void 0 ? _a : null;
281
282
  break;
282
283
  }
283
284
  }
@@ -58,7 +58,12 @@ function CBRLocativasStep(props) {
58
58
  } }, void 0), getOptions: getLocativasOptions, getOptionSelected: function (option, value) {
59
59
  return option.id === value.id;
60
60
  }, calcDepError: calcDepError, calcInvalidDeps: calcInvaidDependencies, valueOverwrite: function (value) {
61
- return __assign(__assign({}, value), { subStep: props.step.subStep });
61
+ if (value) {
62
+ return __assign(__assign({}, value), { subStep: props.step.subStep });
63
+ }
64
+ else {
65
+ return null;
66
+ }
62
67
  }, iconComponent: LeakIconComponent }, { children: _jsx(LocativasSubStepRenderer, {}, void 0) }), void 0));
63
68
  }
64
69
  export default CBRLocativasStep;
@@ -91,18 +96,22 @@ function LeakIconComponent(props) {
91
96
  }
92
97
  var getLocativasOptions = function (step, dependencyStore) { return __awaiter(void 0, void 0, void 0, function () {
93
98
  var idProyecto, response, father_1, locativasList;
94
- var _a, _b;
95
- return __generator(this, function (_c) {
99
+ var _a;
100
+ return __generator(this, function (_b) {
96
101
  if (step.dependencies) {
97
102
  idProyecto = (_a = dependencyStore[step.dependencies[0]]) === null || _a === void 0 ? void 0 : _a.id;
98
103
  if (!idProyecto) {
99
104
  return [2 /*return*/, null]; //null para indicar que falta la depedency
100
105
  }
101
106
  response = LocativasData;
102
- father_1 = (_b = dependencyStore[step.dependencies[1]]) === null || _b === void 0 ? void 0 : _b.id;
107
+ father_1 = dependencyStore[step.dependencies[1]];
108
+ if (father_1 !== undefined && father_1.id === undefined) {
109
+ return [2 /*return*/, null];
110
+ }
103
111
  locativasList = response.lstLocativas.TipoLocativas.filter(function (locativa) {
104
- if (father_1) {
105
- return (locativa.Id.startsWith(father_1) && locativa.Id !== father_1);
112
+ if (father_1 === null || father_1 === void 0 ? void 0 : father_1.id) {
113
+ return (locativa.Id.startsWith(father_1.id) &&
114
+ locativa.Id !== father_1.id);
106
115
  }
107
116
  else {
108
117
  return locativa.Id.length === 2;
@@ -66,12 +66,22 @@ import React from 'react';
66
66
  function SmartSelect(_a) {
67
67
  var _this = this;
68
68
  var _b, _c, _d;
69
- var icon = _a.icon, step = _a.step, form = _a.form, value = _a.value, onBlur = _a.onBlur, errors = _a.errors, trigger = _a.trigger, children = _a.children, onChange = _a.onChange, inputRef = _a.inputRef, postview = _a.postview, formStyle = _a.formStyle, getOptions = _a.getOptions, widthStats = _a.widthStats, calcDepError = _a.calcDepError, iconComponent = _a.iconComponent, valueOverwrite = _a.valueOverwrite, dependencyStore = _a.dependencyStore, calcInvalidDeps = _a.calcInvalidDeps, getOptionSelected = _a.getOptionSelected, setDependencyStore = _a.setDependencyStore, others = __rest(_a, ["icon", "step", "form", "value", "onBlur", "errors", "trigger", "children", "onChange", "inputRef", "postview", "formStyle", "getOptions", "widthStats", "calcDepError", "iconComponent", "valueOverwrite", "dependencyStore", "calcInvalidDeps", "getOptionSelected", "setDependencyStore"]);
70
- var _e = useState(true), first = _e[0], setFirst = _e[1];
71
- var _f = useState(), options = _f[0], setOptions = _f[1];
72
- var _g = useState(), depError = _g[0], setDepError = _g[1];
73
- var calcOptions = function () { return __awaiter(_this, void 0, void 0, function () {
74
- var resp, invalidDeps;
69
+ var icon = _a.icon, step = _a.step, form = _a.form, value = _a.value, onBlur = _a.onBlur, errors = _a.errors, trigger = _a.trigger, children = _a.children, onChange = _a.onChange, inputRef = _a.inputRef, postview = _a.postview, formStyle = _a.formStyle, getOptions = _a.getOptions, widthStats = _a.widthStats, calcDepError = _a.calcDepError, iconComponent = _a.iconComponent, valueOverwrite = _a.valueOverwrite, dependencyStore = _a.dependencyStore, _e = _a.calcInvalidDeps, calcInvalidDeps = _e === void 0 ? function (step, depStore) {
70
+ var _a;
71
+ 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) {
75
+ missingDeps.push(idDep);
76
+ }
77
+ }
78
+ return missingDeps;
79
+ } : _e, getOptionSelected = _a.getOptionSelected, setDependencyStore = _a.setDependencyStore, others = __rest(_a, ["icon", "step", "form", "value", "onBlur", "errors", "trigger", "children", "onChange", "inputRef", "postview", "formStyle", "getOptions", "widthStats", "calcDepError", "iconComponent", "valueOverwrite", "dependencyStore", "calcInvalidDeps", "getOptionSelected", "setDependencyStore"]);
80
+ var _f = useState(true), first = _f[0], setFirst = _f[1];
81
+ var _g = useState(), options = _g[0], setOptions = _g[1];
82
+ var _h = useState(), error = _h[0], setError = _h[1];
83
+ var calcOptions = function (currentValue, invalidDeps) { return __awaiter(_this, void 0, void 0, function () {
84
+ var resp, currentOption, invalids;
75
85
  var _a;
76
86
  return __generator(this, function (_b) {
77
87
  switch (_b.label) {
@@ -79,9 +89,19 @@ function SmartSelect(_a) {
79
89
  case 1:
80
90
  resp = _b.sent();
81
91
  if (resp !== null) {
82
- invalidDeps = (_a = calcInvalidDeps === null || calcInvalidDeps === void 0 ? void 0 : calcInvalidDeps(step, dependencyStore)) !== null && _a !== void 0 ? _a : [];
83
- if (invalidDeps.length === 0) {
84
- setDepError(undefined);
92
+ if (invalidDeps !== undefined && currentValue) {
93
+ currentOption = resp.find(function (option) {
94
+ return getOptionSelected(option, currentValue);
95
+ });
96
+ if (!currentOption) {
97
+ setError('Este campo es obligatorio');
98
+ }
99
+ }
100
+ else {
101
+ invalids = (_a = calcInvalidDeps === null || calcInvalidDeps === void 0 ? void 0 : calcInvalidDeps(step, dependencyStore)) !== null && _a !== void 0 ? _a : [];
102
+ if (invalids.length === 0) {
103
+ setError(undefined);
104
+ }
85
105
  }
86
106
  }
87
107
  setOptions(resp);
@@ -90,34 +110,29 @@ function SmartSelect(_a) {
90
110
  });
91
111
  }); };
92
112
  useEffect(function () {
93
- var _a;
94
113
  if (first) {
95
114
  setFirst(false);
96
- var invalidDeps = (_a = calcInvalidDeps === null || calcInvalidDeps === void 0 ? void 0 : calcInvalidDeps(step, dependencyStore)) !== null && _a !== void 0 ? _a : [];
97
- if (invalidDeps.length > 0) {
98
- setDepError(calcDepError === null || calcDepError === void 0 ? void 0 : calcDepError(invalidDeps.map(function (idDep) { var _a; return (_a = form.steps[idDep]) === null || _a === void 0 ? void 0 : _a.type; })));
99
- }
115
+ var invalids = calcInvalidDeps(step, dependencyStore);
116
+ setError(calcDepError === null || calcDepError === void 0 ? void 0 : calcDepError(invalids.map(function (idDep) { var _a; return (_a = form.steps[idDep]) === null || _a === void 0 ? void 0 : _a.type; })));
117
+ calcOptions(value, invalids);
100
118
  }
101
- else if (value) {
102
- onChange(null);
119
+ else {
120
+ if (value)
121
+ onChange(null);
122
+ calcOptions(null);
103
123
  }
104
- calcOptions();
105
124
  }, (_c = (_b = step.dependencies) === null || _b === void 0 ? void 0 : _b.map(function (dep) { return dependencyStore[dep]; })) !== null && _c !== void 0 ? _c : []);
106
125
  var handleMissingDep = function () { return __awaiter(_this, void 0, void 0, function () {
107
- var missingDeps, _i, _a, idDep;
108
- return __generator(this, function (_b) {
126
+ var invalids;
127
+ return __generator(this, function (_a) {
109
128
  if (step.dependencies) {
110
- missingDeps = [];
111
- for (_i = 0, _a = step.dependencies; _i < _a.length; _i++) {
112
- idDep = _a[_i];
113
- if (dependencyStore[idDep] === null) {
114
- missingDeps.push(idDep);
129
+ invalids = calcInvalidDeps(step, dependencyStore);
130
+ setError(calcDepError === null || calcDepError === void 0 ? void 0 : calcDepError(invalids.map(function (idDep) { var _a; return (_a = form.steps[idDep]) === null || _a === void 0 ? void 0 : _a.type; })));
131
+ if (!value) {
132
+ if (invalids.length > 0) {
133
+ trigger(invalids, { shouldFocus: true });
115
134
  }
116
135
  }
117
- setDepError(calcDepError === null || calcDepError === void 0 ? void 0 : calcDepError(missingDeps.map(function (idDep) { var _a; return (_a = form.steps[idDep]) === null || _a === void 0 ? void 0 : _a.type; })));
118
- if (missingDeps.length > 0) {
119
- trigger(missingDeps, { shouldFocus: true });
120
- }
121
136
  }
122
137
  return [2 /*return*/];
123
138
  });
@@ -139,9 +154,10 @@ function SmartSelect(_a) {
139
154
  valueOverwrite
140
155
  ? onChange(valueOverwrite(value))
141
156
  : onChange(value);
142
- }, getOptionSelected: getOptionSelected, helperText: depError !== null && depError !== void 0 ? depError : (errors[step.id]
157
+ setError(undefined);
158
+ }, getOptionSelected: getOptionSelected, helperText: error !== null && error !== void 0 ? error : (errors[step.id]
143
159
  ? errors[step.id].message
144
- : step.description), error: depError !== undefined || !!errors[step.id] }, void 0) }), void 0), children &&
160
+ : step.description), error: error !== undefined || !!errors[step.id] }, void 0) }), void 0), children &&
145
161
  cloneElement(children, {
146
162
  value: value,
147
163
  stepProps: __assign({ step: step, form: form, errors: errors, trigger: trigger, postview: postview, formStyle: formStyle, widthStats: widthStats, dependencyStore: dependencyStore, setDependencyStore: setDependencyStore }, others),
@@ -10,9 +10,9 @@ export interface SmartSelectStepProps extends Omit<StepProps, 'step'> {
10
10
  /** The iconComponent to display in the selector */
11
11
  iconComponent?: any;
12
12
  /** Function to call to get the options of the selector, return null if dependency is not met */
13
- getOptions?: (step: GSmartSelect, dependencyStore: Record<string, any>) => Promise<any[] | null>;
13
+ getOptions: (step: GSmartSelect, dependencyStore: Record<string, any>) => Promise<any[] | null>;
14
14
  /** Function to determine the currently selected option */
15
- getOptionSelected?: (option: any, value: any) => boolean;
15
+ getOptionSelected: (option: any, value: any) => boolean;
16
16
  /** Function that returns the error message based on the types of the missing Dependencies, undefined if no error msg */
17
17
  calcDepError?: (types: Types[]) => string | undefined;
18
18
  /** Function that returns the missing dependencies based on the current value */
@@ -20,7 +20,7 @@ export interface SmartSelectStepProps extends Omit<StepProps, 'step'> {
20
20
  /** children to render */
21
21
  children?: React.ReactElement<any, string>;
22
22
  /** Function that overwrites the value before setting it */
23
- valueOverwrite?: (value: any) => any;
23
+ valueOverwrite?: (value: any | null) => any;
24
24
  }
25
25
  declare function SmartSelectStep(props: SmartSelectStepProps): JSX.Element;
26
26
  export default SmartSelectStep;
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.4.7-test",
4
+ "version":"1.4.8-test",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
7
7
  "build": "react-scripts build",