@arquimedes.co/eureka-forms 2.0.85 → 2.0.86
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.
|
@@ -66,7 +66,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
66
66
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
67
67
|
};
|
|
68
68
|
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
69
|
-
import React, { useContext } from 'react';
|
|
69
|
+
import React, { useContext, useMemo } from 'react';
|
|
70
70
|
import FormStepTypes, { ApiSelectorOptionTypes, ApiSelectorParamTypes, } from '../../../constants/FormStepTypes';
|
|
71
71
|
import StepComponent from '../../Step';
|
|
72
72
|
import SmartSelect from '../../SmartSelectStep/MaterialSmartSelectStep/MaterialSmartSelectStep';
|
|
@@ -78,6 +78,7 @@ import StepFillerContainer from '../../Utils/@StepFiller/StepFiller';
|
|
|
78
78
|
import { recursivelyCalcConditionSteps } from '../../StepHooks';
|
|
79
79
|
import { evaluateCondition } from '../../StepFunctions';
|
|
80
80
|
function ApiSelectorComponent(_a) {
|
|
81
|
+
var _this = this;
|
|
81
82
|
var step = _a.step, editable = _a.editable, others = __rest(_a, ["step", "editable"]);
|
|
82
83
|
var form = useContext(FormContext);
|
|
83
84
|
function calcOptionId(option) {
|
|
@@ -88,6 +89,67 @@ function ApiSelectorComponent(_a) {
|
|
|
88
89
|
var _a;
|
|
89
90
|
return (_a = option === null || option === void 0 ? void 0 : option[step.labelAttribute]) !== null && _a !== void 0 ? _a : '';
|
|
90
91
|
}
|
|
92
|
+
var getApiOptions = useMemo(function () {
|
|
93
|
+
return function (idOrganization, step, dependencyStore) { return __awaiter(_this, void 0, void 0, function () {
|
|
94
|
+
function calcOptionId(option) {
|
|
95
|
+
var _a;
|
|
96
|
+
return (_a = option === null || option === void 0 ? void 0 : option[step.idAttribute]) !== null && _a !== void 0 ? _a : '';
|
|
97
|
+
}
|
|
98
|
+
var params, _i, _a, filter, currentValue, filterStep, url, response;
|
|
99
|
+
var _b, _c;
|
|
100
|
+
return __generator(this, function (_d) {
|
|
101
|
+
switch (_d.label) {
|
|
102
|
+
case 0:
|
|
103
|
+
params = new URLSearchParams({});
|
|
104
|
+
for (_i = 0, _a = step.queryParams; _i < _a.length; _i++) {
|
|
105
|
+
filter = _a[_i];
|
|
106
|
+
switch (filter.type) {
|
|
107
|
+
case ApiSelectorParamTypes.STEP: {
|
|
108
|
+
currentValue = (_b = dependencyStore[filter.idStep]) === null || _b === void 0 ? void 0 : _b.value;
|
|
109
|
+
filterStep = form.steps[filter.idStep];
|
|
110
|
+
if (currentValue) {
|
|
111
|
+
if (filterStep.type ===
|
|
112
|
+
FormStepTypes.API_SELECTOR) {
|
|
113
|
+
params.set(filter.key, currentValue[step.idAttribute]);
|
|
114
|
+
}
|
|
115
|
+
else if (typeof currentValue === 'string')
|
|
116
|
+
params.set(filter.key, currentValue);
|
|
117
|
+
else
|
|
118
|
+
params.set(filter.key, (_c = currentValue.label) !== null && _c !== void 0 ? _c : currentValue.id);
|
|
119
|
+
}
|
|
120
|
+
else if (filter.required) {
|
|
121
|
+
return [2 /*return*/, null];
|
|
122
|
+
}
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
case ApiSelectorParamTypes.VALUE:
|
|
126
|
+
default:
|
|
127
|
+
params.set(filter.key, filter.value);
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
url = step.url.replace('capta.co', process.env.REACT_APP_DOMAIN);
|
|
132
|
+
if (idOrganization &&
|
|
133
|
+
url.includes(process.env.REACT_APP_DOMAIN))
|
|
134
|
+
params.set('idOrganization', idOrganization);
|
|
135
|
+
if (!step.url.includes('?'))
|
|
136
|
+
url += '?';
|
|
137
|
+
url += params.toString();
|
|
138
|
+
return [4 /*yield*/, (idOrganization
|
|
139
|
+
? widgetInstance.get(url)
|
|
140
|
+
: axiosInstance.get(url))];
|
|
141
|
+
case 1:
|
|
142
|
+
response = _d.sent();
|
|
143
|
+
return [2 /*return*/, response.data.filter(function (option) {
|
|
144
|
+
var _a;
|
|
145
|
+
return calcOptionId(option) &&
|
|
146
|
+
((_a = step.options[calcOptionId(option)]) === null || _a === void 0 ? void 0 : _a.type) !==
|
|
147
|
+
ApiSelectorOptionTypes.HIDE;
|
|
148
|
+
})];
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}); };
|
|
152
|
+
}, [form]);
|
|
91
153
|
return (_jsx(StepFillerContainer, __assign({ step: step }, { children: _jsx(SmartSelect, __assign({}, others, { editable: editable, step: step, icon: step.icon ? _jsx(InputIcon, { icon: step.icon }) : undefined, getOptions: getApiOptions, getOptionSelected: function (option, value) {
|
|
92
154
|
return calcOptionId(option) === calcOptionId(value);
|
|
93
155
|
}, calcDepError: function (steps) {
|
|
@@ -137,56 +199,3 @@ function ApiSelectorComponent(_a) {
|
|
|
137
199
|
} })) })));
|
|
138
200
|
}
|
|
139
201
|
export default ApiSelectorComponent;
|
|
140
|
-
var getApiOptions = function (idOrganization, step, dependencyStore) { return __awaiter(void 0, void 0, void 0, function () {
|
|
141
|
-
function calcOptionId(option) {
|
|
142
|
-
var _a;
|
|
143
|
-
return (_a = option === null || option === void 0 ? void 0 : option[step.idAttribute]) !== null && _a !== void 0 ? _a : '';
|
|
144
|
-
}
|
|
145
|
-
var params, _i, _a, filter, currentValue, url, response;
|
|
146
|
-
var _b, _c;
|
|
147
|
-
return __generator(this, function (_d) {
|
|
148
|
-
switch (_d.label) {
|
|
149
|
-
case 0:
|
|
150
|
-
params = new URLSearchParams({});
|
|
151
|
-
for (_i = 0, _a = step.queryParams; _i < _a.length; _i++) {
|
|
152
|
-
filter = _a[_i];
|
|
153
|
-
switch (filter.type) {
|
|
154
|
-
case ApiSelectorParamTypes.STEP: {
|
|
155
|
-
currentValue = (_b = dependencyStore[filter.idStep]) === null || _b === void 0 ? void 0 : _b.value;
|
|
156
|
-
if (currentValue) {
|
|
157
|
-
if (typeof currentValue === 'string')
|
|
158
|
-
params.set(filter.key, currentValue);
|
|
159
|
-
else
|
|
160
|
-
params.set(filter.key, (_c = currentValue.label) !== null && _c !== void 0 ? _c : currentValue.id);
|
|
161
|
-
}
|
|
162
|
-
else if (filter.required) {
|
|
163
|
-
return [2 /*return*/, null];
|
|
164
|
-
}
|
|
165
|
-
break;
|
|
166
|
-
}
|
|
167
|
-
case ApiSelectorParamTypes.VALUE:
|
|
168
|
-
default:
|
|
169
|
-
params.set(filter.key, filter.value);
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
url = step.url.replace('capta.co', process.env.REACT_APP_DOMAIN);
|
|
174
|
-
if (idOrganization && url.includes(process.env.REACT_APP_DOMAIN))
|
|
175
|
-
params.set('idOrganization', idOrganization);
|
|
176
|
-
if (!step.url.includes('?'))
|
|
177
|
-
url += '?';
|
|
178
|
-
url += params.toString();
|
|
179
|
-
return [4 /*yield*/, (idOrganization
|
|
180
|
-
? widgetInstance.get(url)
|
|
181
|
-
: axiosInstance.get(url))];
|
|
182
|
-
case 1:
|
|
183
|
-
response = _d.sent();
|
|
184
|
-
return [2 /*return*/, response.data.filter(function (option) {
|
|
185
|
-
var _a;
|
|
186
|
-
return calcOptionId(option) &&
|
|
187
|
-
((_a = step.options[calcOptionId(option)]) === null || _a === void 0 ? void 0 : _a.type) !==
|
|
188
|
-
ApiSelectorOptionTypes.HIDE;
|
|
189
|
-
})];
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
}); };
|