@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.header || {})), { "API-Version": 1, "Accept-Language": this.lang }) });
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.header || {})), { "Content-Type": "application/json", "Accept": "application/json" }) });
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
- if (response.status === "OK") {
199
- const found = {};
200
- Object.keys(parsers).forEach(field => {
201
- const parser = parsers[field];
202
- parser.type.some((type, typeIdx) => {
203
- response.results.forEach(result => result.address_components.forEach(addressComponent => {
204
- if (addressComponent.types.includes(type)) {
205
- if (!found[field])
206
- found[field] = {};
207
- if (!found[field][typeIdx])
208
- found[field][typeIdx] = {};
209
- const responseField = addressComponent[parser.responseField] ? parser.responseField : "short_name";
210
- found[field][typeIdx][addressComponent[responseField]] = true;
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
- Object.keys(parsers).forEach(field => {
217
- if (!fieldByKeys[field] || !this.props.schema.properties[field]) {
218
- return;
219
- }
220
- if (found[field]) {
221
- const keys = Object.keys(found[field]);
222
- const responseForField = found[field][keys[0]];
223
- Object.keys(responseForField).forEach(value => {
224
- // If target field is array.
225
- if (this.props.schema.properties[field].type === "array") {
226
- const temp = Array.from((this.props.formData || {})[field] || []);
227
- // Find correct enum from fieldOptions.
228
- const fieldOptions = this.props.uiSchema["ui:options"].fieldOptions;
229
- const enumField = fieldOptions[fieldOptions.findIndex(element => {
230
- return element.field === field;
231
- })].enum;
232
- // Find enum value from key (eg. municipalityName --> municipalityId).
233
- const _enum = this.props.formContext.uiSchemaContext[enumField].oneOf;
234
- const enumValue = _enum.find(item => item.title === value).const;
235
- // Push enum value to changes.
236
- if (enumValue !== undefined) {
237
- !temp.includes(enumValue) && temp.push(enumValue);
238
- changes[field] = temp;
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
- else {
247
- changes[field] = (0, utils_1.getDefaultFormState)(this.props.schema.properties[field]);
248
- }
249
- });
250
- if (country && this.props.schema.properties.country && fieldByKeys.country)
251
- changes.country = country;
252
- success(() => {
253
- if (timestamp !== this.promiseTimestamp)
254
- return;
255
- if (this.mounted) {
256
- this.props.onChange(Object.assign(Object.assign({}, (this.props.formData || {})), changes));
257
- }
258
- else {
259
- const pointer = this.props.formContext.services.ids.getJSONPointerFromLajiFormIdAndFormDataAndIdSchemaId(this.props.idSchema.$id, (0, utils_1.getFieldUUID)(this.props));
260
- const newFormData = Object.assign(Object.assign({}, (0, utils_1.parseJSONPointer)(lajiFormInstance.getFormData(), pointer)), changes);
261
- lajiFormInstance.onChange((0, utils_1.updateSafelyWithJSONPointer)(lajiFormInstance.getFormData(), newFormData, pointer));
262
- }
263
- if (callback)
264
- callback();
265
- });
266
- }
267
- else if (country) {
268
- fetchForeign();
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luomus/laji-form",
3
- "version": "15.1.68",
3
+ "version": "15.1.70",
4
4
  "description": "React module capable of building dynamic forms from Laji form json schemas",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",