@luomus/laji-form 15.1.68 → 15.1.70
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/lib/ApiClient.js
CHANGED
|
@@ -164,9 +164,9 @@ class ApiClient {
|
|
|
164
164
|
delete _query.lang;
|
|
165
165
|
}
|
|
166
166
|
const pathSegments = splitAndResolvePath(path, params);
|
|
167
|
-
options = Object.assign(Object.assign({}, options), { headers: Object.assign(Object.assign({}, (options.
|
|
167
|
+
options = Object.assign(Object.assign({}, options), { headers: Object.assign(Object.assign({}, (options.headers || {})), { "API-Version": 1, "Accept-Language": this.lang }) });
|
|
168
168
|
if (body && !otherThanJSON(body)) {
|
|
169
|
-
options = Object.assign(Object.assign({}, options), { headers: Object.assign(Object.assign({}, (options.
|
|
169
|
+
options = Object.assign(Object.assign({}, options), { headers: Object.assign(Object.assign({}, (options.headers || {})), { "Content-Type": "application/json", "Accept": "application/json" }) });
|
|
170
170
|
body = JSON.stringify(body);
|
|
171
171
|
}
|
|
172
172
|
const response = yield this.apiClient.fetch(pathSegments.join(""), _query, Object.assign({ method, body }, options));
|
|
@@ -195,78 +195,73 @@ let GeocoderField = class GeocoderField extends React.Component {
|
|
|
195
195
|
responseField: "long_name"
|
|
196
196
|
}
|
|
197
197
|
};
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if (
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
return found[field] && found[field][typeIdx];
|
|
214
|
-
});
|
|
198
|
+
const found = {};
|
|
199
|
+
Object.keys(parsers).forEach(field => {
|
|
200
|
+
const parser = parsers[field];
|
|
201
|
+
parser.type.some((type, typeIdx) => {
|
|
202
|
+
response.results.forEach(result => result.address_components.forEach(addressComponent => {
|
|
203
|
+
if (addressComponent.types.includes(type)) {
|
|
204
|
+
if (!found[field])
|
|
205
|
+
found[field] = {};
|
|
206
|
+
if (!found[field][typeIdx])
|
|
207
|
+
found[field][typeIdx] = {};
|
|
208
|
+
const responseField = addressComponent[parser.responseField] ? parser.responseField : "short_name";
|
|
209
|
+
found[field][typeIdx][addressComponent[responseField]] = true;
|
|
210
|
+
}
|
|
211
|
+
}));
|
|
212
|
+
return found[field] && found[field][typeIdx];
|
|
215
213
|
});
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
else {
|
|
242
|
-
changes[field] = join(changes[field], value);
|
|
214
|
+
});
|
|
215
|
+
Object.keys(parsers).forEach(field => {
|
|
216
|
+
if (!fieldByKeys[field] || !this.props.schema.properties[field]) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
if (found[field]) {
|
|
220
|
+
const keys = Object.keys(found[field]);
|
|
221
|
+
const responseForField = found[field][keys[0]];
|
|
222
|
+
Object.keys(responseForField).forEach(value => {
|
|
223
|
+
// If target field is array.
|
|
224
|
+
if (this.props.schema.properties[field].type === "array") {
|
|
225
|
+
const temp = Array.from((this.props.formData || {})[field] || []);
|
|
226
|
+
// Find correct enum from fieldOptions.
|
|
227
|
+
const fieldOptions = this.props.uiSchema["ui:options"].fieldOptions;
|
|
228
|
+
const enumField = fieldOptions[fieldOptions.findIndex(element => {
|
|
229
|
+
return element.field === field;
|
|
230
|
+
})].enum;
|
|
231
|
+
// Find enum value from key (eg. municipalityName --> municipalityId).
|
|
232
|
+
const _enum = this.props.formContext.uiSchemaContext[enumField].oneOf;
|
|
233
|
+
const enumValue = _enum.find(item => item.title === value).const;
|
|
234
|
+
// Push enum value to changes.
|
|
235
|
+
if (enumValue !== undefined) {
|
|
236
|
+
!temp.includes(enumValue) && temp.push(enumValue);
|
|
237
|
+
changes[field] = temp;
|
|
243
238
|
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
changes
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
changes[field] = join(changes[field], value);
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
changes[field] = (0, utils_1.getDefaultFormState)(this.props.schema.properties[field]);
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
if (country && this.props.schema.properties.country && fieldByKeys.country)
|
|
250
|
+
changes.country = country;
|
|
251
|
+
success(() => {
|
|
252
|
+
if (timestamp !== this.promiseTimestamp)
|
|
253
|
+
return;
|
|
254
|
+
if (this.mounted) {
|
|
255
|
+
this.props.onChange(Object.assign(Object.assign({}, (this.props.formData || {})), changes));
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
const pointer = this.props.formContext.services.ids.getJSONPointerFromLajiFormIdAndFormDataAndIdSchemaId(this.props.idSchema.$id, (0, utils_1.getFieldUUID)(this.props));
|
|
259
|
+
const newFormData = Object.assign(Object.assign({}, (0, utils_1.parseJSONPointer)(lajiFormInstance.getFormData(), pointer)), changes);
|
|
260
|
+
lajiFormInstance.onChange((0, utils_1.updateSafelyWithJSONPointer)(lajiFormInstance.getFormData(), newFormData, pointer));
|
|
261
|
+
}
|
|
262
|
+
if (callback)
|
|
263
|
+
callback();
|
|
264
|
+
});
|
|
270
265
|
};
|
|
271
266
|
const fetchForeign = () => {
|
|
272
267
|
if (!props.formContext.googleApiKey)
|
|
@@ -584,9 +584,7 @@ class Autosuggest extends React.Component {
|
|
|
584
584
|
let timestamp = Date.now();
|
|
585
585
|
this.promiseTimestamp = timestamp;
|
|
586
586
|
try {
|
|
587
|
-
let suggestionsResponse = yield this.apiClient.get(this.props.basePath || "/autocomplete" + "/" + autosuggestField, { query: Object.assign({
|
|
588
|
-
// Hack for laji-form in Kotka, since it uses API that isn't laji-api and q was renamed to query in laji-api
|
|
589
|
-
q: value, query: value, matchType: "exact,partial", includeHidden: false }, query) }, this.props.cache);
|
|
587
|
+
let suggestionsResponse = yield this.apiClient.get(this.props.basePath || "/autocomplete" + "/" + autosuggestField, { query: Object.assign({ query: value, matchType: "exact,partial", includeHidden: false }, query) }, this.props.cache);
|
|
590
588
|
// Hack for laji-form in Kotka, since it uses API that isn't laji-api and might have different response signature.
|
|
591
589
|
let suggestions = Array.isArray(suggestionsResponse) ? suggestionsResponse : suggestionsResponse.results;
|
|
592
590
|
if (this.props.prepareSuggestion) {
|