@luomus/laji-form 15.1.23 → 15.1.24

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.
@@ -89,7 +89,7 @@ let NamedPlaceChooserField = class NamedPlaceChooserField extends React.Componen
89
89
  };
90
90
  this.onPlaceDeleted = (place, success) => {
91
91
  this.apiClient.fetchRaw(`/named-places/${place.id}`, undefined, { method: "DELETE" }).then(response => {
92
- if (response.status === 204) {
92
+ if (response.status < 400) {
93
93
  // It takes a while for API to remove the place, so we remove it locally and then invalidate again after some time.
94
94
  this.removeIds[place.id] = true;
95
95
  this.apiClient.invalidateCachePath("/named-places");
@@ -27,6 +27,7 @@ const ReactContext_1 = require("../../ReactContext");
27
27
  const BaseComponent_1 = require("../BaseComponent");
28
28
  const Spinner = require("react-spinner");
29
29
  const MapArrayField_1 = require("./MapArrayField");
30
+ const memoize = require("memoizee");
30
31
  const SAVE = "SAVE", FETCH = "FETCH";
31
32
  /**
32
33
  * Compatible only with gathering field.
@@ -110,18 +111,17 @@ class PlaceSaverDialog extends React.Component {
110
111
  prepopulatedDocument: { gatherings: [gathering] }
111
112
  });
112
113
  };
113
- this.onOverwriteCurrent = () => {
114
- const { namedPlaceID } = this.props.gathering;
114
+ this.onOverwriteCurrentFor = memoize((namedPlaceID) => () => {
115
115
  const gathering = this.getGathering(); //eslint-disable-line no-unused-vars
116
116
  this.onSave(Object.assign(Object.assign({}, this.state.placeIdsToPlaces[namedPlaceID]), { name: this.state.value, prepopulatedDocument: { gatherings: [gathering] } }));
117
- };
118
- this.onOverwriteSelected = (place) => () => {
117
+ });
118
+ this.onOverwriteSelected = memoize((place) => () => {
119
119
  const gathering = this.getGathering(); //eslint-disable-line no-unused-vars
120
120
  this.onSave(Object.assign(Object.assign({}, place), { name: this.state.value, prepopulatedDocument: { gatherings: [gathering] } }));
121
- };
122
- this.onOverwriteExisting = () => {
123
- this.onOverwriteSelected(this.state.placeNamesToPlaces[this.state.value])();
124
- };
121
+ });
122
+ this.onOverwriteExistingFor = memoize((place) => () => {
123
+ this.onOverwriteSelected(place)();
124
+ });
125
125
  // Hack that fixed autofocus cursor position
126
126
  this.onFocus = (e) => {
127
127
  var val = e.target.value;
@@ -219,9 +219,9 @@ class PlaceSaverDialog extends React.Component {
219
219
  getButton(this.onSaveNew, `${translations.Save} ${translations.new}`) : null,
220
220
  " ",
221
221
  this.props.gathering.namedPlaceID ?
222
- getButton(this.onOverwriteCurrent, translations.SaveCurrentOverwrite) : null,
222
+ getButton(this.onOverwriteCurrentFor(this.props.gathering.namedPlaceID), translations.SaveCurrentOverwrite) : null,
223
223
  existingPlaces.length === 1 && !this.props.gathering.namedPlaceID ?
224
- getButton(this.onOverwriteExisting, translations.SaveExistingOverwrite) : null),
224
+ getButton(this.onOverwriteExistingFor(existingPlaces[0]), translations.SaveExistingOverwrite) : null),
225
225
  loading ? React.createElement("div", { className: "pull-right" },
226
226
  React.createElement(Spinner, null)) : null),
227
227
  !this.props.gathering.namedPlaceID && existingPlaces.length ?
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luomus/laji-form",
3
- "version": "15.1.23",
3
+ "version": "15.1.24",
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",