@luomus/laji-form 15.1.69 → 15.1.71
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/dist/laji-form.js +1 -1
- package/dist/styles.css +2 -2
- package/lib/ApiClient.d.ts +66 -21
- package/lib/ApiClient.js +174 -68
- package/lib/components/LajiForm.d.ts +10 -2
- package/lib/components/LajiForm.js +1 -1
- package/lib/components/fields/AnnotationField.js +26 -22
- package/lib/components/fields/AudioArrayField.js +18 -5
- package/lib/components/fields/AutosuggestField.d.ts +2 -2
- package/lib/components/fields/AutosuggestField.js +4 -4
- package/lib/components/fields/CondensedObjectField.js +3 -5
- package/lib/components/fields/EnumRangeArrayField.js +1 -1
- package/lib/components/fields/GeocoderField.js +67 -79
- package/lib/components/fields/ImageArrayField.d.ts +9 -5
- package/lib/components/fields/ImageArrayField.js +103 -122
- package/lib/components/fields/MapArrayField.js +13 -5
- package/lib/components/fields/MapField.d.ts +1 -1
- package/lib/components/fields/MapField.js +13 -5
- package/lib/components/fields/NamedPlaceChooserField/NamedPlaceChooser.d.ts +2 -1
- package/lib/components/fields/NamedPlaceChooserField/NamedPlaceChooserField.d.ts +9 -4
- package/lib/components/fields/NamedPlaceChooserField/NamedPlaceChooserField.js +51 -51
- package/lib/components/fields/NamedPlaceChooserField/Popup.d.ts +2 -1
- package/lib/components/fields/NamedPlaceSaverField.js +22 -18
- package/lib/components/fields/PrefixArrayField.js +3 -3
- package/lib/components/fields/ScopeField.js +1 -1
- package/lib/components/fields/SectionArrayField.js +1 -1
- package/lib/components/fields/SingleActiveArrayField.js +7 -7
- package/lib/components/fields/SortArrayField.js +1 -1
- package/lib/components/fields/TableField.js +2 -2
- package/lib/components/fields/UnitCountShorthandField.js +1 -1
- package/lib/components/fields/UnitListShorthandArrayField.js +2 -2
- package/lib/components/fields/UnitShorthandField.js +14 -18
- package/lib/components/templates/ArrayFieldTemplate.js +2 -2
- package/lib/components/widgets/AutosuggestWidget.js +77 -66
- package/lib/components/widgets/InformalTaxonGroupChooserWidget.js +1 -1
- package/lib/components/widgets/InputWithDefaultValueButtonWidget.js +1 -2
- package/lib/themes/bs5.js +10 -2
- package/lib/validation.js +1 -1
- package/package.json +5 -3
|
@@ -36,7 +36,7 @@ export default class MapField extends React.Component<any, any, any> {
|
|
|
36
36
|
componentDidUpdate(prevProps: any): void;
|
|
37
37
|
_lastFormData: any;
|
|
38
38
|
_zoomToDataOnNextTick: boolean | undefined;
|
|
39
|
-
geocode: (prevProps: any) => void
|
|
39
|
+
geocode: (prevProps: any) => Promise<void>;
|
|
40
40
|
zoomIfExternalEdit: (props: any) => void;
|
|
41
41
|
setMapRef: (mapComponent: any) => void;
|
|
42
42
|
map: any;
|
|
@@ -32,6 +32,15 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
35
44
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
36
45
|
var t = {};
|
|
37
46
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -107,7 +116,7 @@ class MapField extends React.Component {
|
|
|
107
116
|
this.setState({ locateOn: true });
|
|
108
117
|
}
|
|
109
118
|
};
|
|
110
|
-
this.geocode = (prevProps) => {
|
|
119
|
+
this.geocode = (prevProps) => __awaiter(this, void 0, void 0, function* () {
|
|
111
120
|
let { area } = (0, utils_1.getUiOptions)(this.props.uiSchema);
|
|
112
121
|
if (area instanceof Array) {
|
|
113
122
|
area = area[0];
|
|
@@ -120,11 +129,10 @@ class MapField extends React.Component {
|
|
|
120
129
|
|| (geoData.type === "FeatureCollection" && geoData.features.length === 0);
|
|
121
130
|
});
|
|
122
131
|
if (isEmptyAndWasEmpty && area && area.length > 0) {
|
|
123
|
-
this.props.formContext.apiClient.
|
|
124
|
-
|
|
125
|
-
});
|
|
132
|
+
const { name } = yield this.props.formContext.apiClient.get(`/areas/${area}`);
|
|
133
|
+
this.map.geocode(name, undefined, 8);
|
|
126
134
|
}
|
|
127
|
-
};
|
|
135
|
+
});
|
|
128
136
|
this.zoomIfExternalEdit = (props) => {
|
|
129
137
|
if (!equals(this._lastFormData, props.formData)) {
|
|
130
138
|
this.map.zoomToData();
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { ByLang, FormContext } from "../../LajiForm";
|
|
3
|
-
import { NamedPlace } from "@luomus/laji-schema";
|
|
4
3
|
import memoize from "memoizee";
|
|
4
|
+
import type { components } from "generated/api.d";
|
|
5
|
+
type NamedPlace = components["schemas"]["namedPlace"];
|
|
5
6
|
type Props = {
|
|
6
7
|
places: NamedPlace[];
|
|
7
8
|
failed?: boolean;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { FieldProps, JSONSchemaArray, JSONSchemaObject } from "../../../types";
|
|
3
|
-
import {
|
|
3
|
+
import type { components } from "generated/api.d";
|
|
4
|
+
type NamedPlace = components["schemas"]["namedPlace"];
|
|
4
5
|
type Props = FieldProps<NamedPlace, JSONSchemaObject | JSONSchemaArray<JSONSchemaObject>>;
|
|
5
6
|
type State = {
|
|
6
7
|
show?: boolean;
|
|
@@ -11,7 +12,6 @@ type State = {
|
|
|
11
12
|
/** Compatible only with gatherings array and gathering object */
|
|
12
13
|
export default class NamedPlaceChooserField extends React.Component<Props, State> {
|
|
13
14
|
static contextType: React.Context<import("../../../ReactContext").ContextProps>;
|
|
14
|
-
removeIds: Record<string, boolean>;
|
|
15
15
|
mounted: boolean;
|
|
16
16
|
state: State;
|
|
17
17
|
getUiSchema: (props: Props, buttonDefinition: any) => import("../../../types").UiSchema<any> | {
|
|
@@ -60,9 +60,14 @@ export default class NamedPlaceChooserField extends React.Component<Props, State
|
|
|
60
60
|
};
|
|
61
61
|
isGatheringsArray: (schema: JSONSchemaObject | JSONSchemaArray<JSONSchemaObject>) => schema is JSONSchemaArray<JSONSchemaObject>;
|
|
62
62
|
onPlaceSelected: (place: NamedPlace) => void;
|
|
63
|
-
onPlaceDeleted: (place: NamedPlace
|
|
63
|
+
onPlaceDeleted: (place: NamedPlace & {
|
|
64
|
+
id: string;
|
|
65
|
+
}, end: () => void) => Promise<void>;
|
|
64
66
|
onButtonClick: () => () => void;
|
|
65
|
-
updatePlaces: (
|
|
67
|
+
updatePlaces: (response: {
|
|
68
|
+
results: NamedPlace[];
|
|
69
|
+
}) => void;
|
|
70
|
+
getNamedPlacesUnsubscribe: () => void;
|
|
66
71
|
componentDidMount(): void;
|
|
67
72
|
componentWillUnmount(): void;
|
|
68
73
|
onHide: () => void;
|
|
@@ -32,6 +32,15 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
35
44
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
45
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
46
|
};
|
|
@@ -59,7 +68,6 @@ const PLACE_DELETE_FAIL = "PLACE_DELETE_FAIL";
|
|
|
59
68
|
class NamedPlaceChooserField extends React.Component {
|
|
60
69
|
constructor() {
|
|
61
70
|
super(...arguments);
|
|
62
|
-
this.removeIds = {};
|
|
63
71
|
this.mounted = false;
|
|
64
72
|
this.state = {};
|
|
65
73
|
this.getUiSchema = (props, buttonDefinition) => {
|
|
@@ -122,69 +130,61 @@ class NamedPlaceChooserField extends React.Component {
|
|
|
122
130
|
this.setState({ failed: PLACE_USE_FAIL });
|
|
123
131
|
}
|
|
124
132
|
};
|
|
125
|
-
this.onPlaceDeleted = (place,
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
setTimeout(() => this.props.formContext.apiClient.invalidateCachePath("/named-places"), 2000);
|
|
132
|
-
success();
|
|
133
|
-
}
|
|
134
|
-
}).catch(() => {
|
|
133
|
+
this.onPlaceDeleted = (place, end) => __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
try {
|
|
135
|
+
yield this.props.formContext.apiClient.delete("/named-places/{id}", { path: { id: place.id } });
|
|
136
|
+
end();
|
|
137
|
+
}
|
|
138
|
+
catch (e) {
|
|
135
139
|
this.setState({ failed: PLACE_DELETE_FAIL });
|
|
136
140
|
this.props.formContext.notifier.error(this.props.formContext.translations.PlaceRemovalFailed);
|
|
137
|
-
|
|
138
|
-
|
|
141
|
+
end();
|
|
142
|
+
}
|
|
143
|
+
});
|
|
139
144
|
this.onButtonClick = () => () => {
|
|
140
145
|
this.setState({ show: true });
|
|
141
146
|
};
|
|
142
|
-
this.updatePlaces = () => {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
this.setState(state);
|
|
174
|
-
}).catch(() => {
|
|
175
|
-
this.setState({ failed: PLACES_FETCH_FAIL });
|
|
176
|
-
});
|
|
147
|
+
this.updatePlaces = (response) => {
|
|
148
|
+
var _a;
|
|
149
|
+
if (!this.mounted)
|
|
150
|
+
return;
|
|
151
|
+
const state = { places: response.results.sort((a, b) => {
|
|
152
|
+
if (a.name < b.name)
|
|
153
|
+
return -1;
|
|
154
|
+
if (a.name > b.name)
|
|
155
|
+
return 1;
|
|
156
|
+
return 0;
|
|
157
|
+
}) };
|
|
158
|
+
if (!((_a = response.results) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const buttonDefinition = {
|
|
162
|
+
fn: this.onButtonClick,
|
|
163
|
+
fnName: "addNamedPlace",
|
|
164
|
+
glyph: "map-marker",
|
|
165
|
+
label: this.props.formContext.translations.ChooseFromNamedPlace,
|
|
166
|
+
id: this.props.idSchema.$id,
|
|
167
|
+
changesFormData: true,
|
|
168
|
+
variant: "primary"
|
|
169
|
+
};
|
|
170
|
+
if (this.isGatheringsArray(this.props.schema)) {
|
|
171
|
+
buttonDefinition.rules = { canAdd: true };
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
buttonDefinition.position = "top";
|
|
175
|
+
}
|
|
176
|
+
state.buttonDefinition = buttonDefinition;
|
|
177
|
+
this.setState(state);
|
|
177
178
|
};
|
|
178
179
|
this.onHide = () => this.setState({ show: false });
|
|
179
180
|
}
|
|
180
181
|
componentDidMount() {
|
|
181
182
|
this.mounted = true;
|
|
182
|
-
this.updatePlaces();
|
|
183
|
-
this.props.formContext.apiClient.onCachePathInvalidation("/named-places", this.updatePlaces);
|
|
183
|
+
this.getNamedPlacesUnsubscribe = this.props.formContext.apiClient.subscribe("/named-places", { query: { includePublic: false, pageSize: 100000 } }, this.updatePlaces, () => this.setState({ failed: PLACES_FETCH_FAIL }), 1000);
|
|
184
184
|
}
|
|
185
185
|
componentWillUnmount() {
|
|
186
186
|
this.mounted = false;
|
|
187
|
-
this.
|
|
187
|
+
this.getNamedPlacesUnsubscribe();
|
|
188
188
|
}
|
|
189
189
|
render() {
|
|
190
190
|
const { registry: { fields: { SchemaField } }, formContext } = this.props;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { NamedPlace } from "@luomus/laji-schema";
|
|
3
2
|
import { FormContext } from "src/components/LajiForm";
|
|
3
|
+
import type { components } from "generated/api.d";
|
|
4
|
+
type NamedPlace = components["schemas"]["namedPlace"];
|
|
4
5
|
type Props = {
|
|
5
6
|
onPlaceSelected: (place: NamedPlace) => void;
|
|
6
7
|
onPlaceDeleted: (place: NamedPlace) => void;
|
|
@@ -38,6 +38,15 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
38
38
|
return result;
|
|
39
39
|
};
|
|
40
40
|
})();
|
|
41
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
42
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
43
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
44
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
45
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
46
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
47
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
48
|
+
});
|
|
49
|
+
};
|
|
41
50
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
42
51
|
var t = {};
|
|
43
52
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -182,7 +191,7 @@ class PlaceSaverDialog extends React.Component {
|
|
|
182
191
|
}
|
|
183
192
|
componentDidMount() {
|
|
184
193
|
this.mounted = true;
|
|
185
|
-
this.apiClient.
|
|
194
|
+
this.apiClient.get("/named-places", { query: { includePublic: false, pageSize: 100000 } }).then(response => {
|
|
186
195
|
if (!this.mounted)
|
|
187
196
|
return;
|
|
188
197
|
const state = {
|
|
@@ -213,23 +222,18 @@ class PlaceSaverDialog extends React.Component {
|
|
|
213
222
|
});
|
|
214
223
|
}
|
|
215
224
|
onSave(place) {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
return response.json();
|
|
229
|
-
}).then(this.props.onSave)
|
|
230
|
-
.catch(() => {
|
|
231
|
-
this.props.formContext.services.blocker.pop();
|
|
232
|
-
this.setState({ failed: SAVE });
|
|
225
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
226
|
+
place = Object.assign(Object.assign({}, place), { geometry: place.prepopulatedDocument.gatherings[0].geometry });
|
|
227
|
+
this.props.formContext.services.blocker.push();
|
|
228
|
+
try {
|
|
229
|
+
const savedPlace = yield this.apiClient[place.id ? "put" : "post"](`/named-places${place.id ? "/{id}" : ""}`, place.id ? { path: { id: place.id } } : undefined, place);
|
|
230
|
+
this.props.formContext.services.blocker.pop();
|
|
231
|
+
yield this.props.onSave(savedPlace);
|
|
232
|
+
}
|
|
233
|
+
catch (e) {
|
|
234
|
+
this.props.formContext.services.blocker.pop();
|
|
235
|
+
this.setState({ failed: SAVE });
|
|
236
|
+
}
|
|
233
237
|
});
|
|
234
238
|
}
|
|
235
239
|
render() {
|
|
@@ -89,8 +89,8 @@ let PrefixArrayField = class PrefixArrayField extends React.Component {
|
|
|
89
89
|
}
|
|
90
90
|
render() {
|
|
91
91
|
const SchemaField = this.props.registry.fields.SchemaField;
|
|
92
|
-
const { schema, uiSchema, idSchema, errorSchema, required, formContext: { Label, translations } } = this.props;
|
|
93
|
-
const { prefixValues = [], addFieldPlaceholder } = (0, utils_1.getUiOptions)(uiSchema);
|
|
92
|
+
const { schema, uiSchema, idSchema, errorSchema, required, disabled, readonly, formContext: { Label, translations, uiSchemaContext } } = this.props;
|
|
93
|
+
const { prefixValues = [], addFieldPlaceholder, confirmDelete = uiSchemaContext.confirmDelete } = (0, utils_1.getUiOptions)(uiSchema);
|
|
94
94
|
const childProps = this.state.fieldValues.map((value, idx) => {
|
|
95
95
|
return {
|
|
96
96
|
schema: schema.items,
|
|
@@ -114,7 +114,7 @@ let PrefixArrayField = class PrefixArrayField extends React.Component {
|
|
|
114
114
|
React.createElement("div", { className: "laji-form-field-template-schema" },
|
|
115
115
|
React.createElement(SchemaField, Object.assign({}, this.props, props, { key: idx, onChange: this.onFieldChange(idx) }))),
|
|
116
116
|
React.createElement("div", { className: "laji-form-field-template-buttons" },
|
|
117
|
-
React.createElement(components_1.DeleteButton, { id: props.idSchema.$id, onClick: this.onFieldDelete(idx), translations: translations })))),
|
|
117
|
+
React.createElement(components_1.DeleteButton, { id: props.idSchema.$id, onClick: this.onFieldDelete(idx), translations: translations, confirm: confirmDelete, disabled: disabled || readonly })))),
|
|
118
118
|
React.createElement(SelectWidget_1.default, { key: childProps.length, options: { enumOptions: selectableFieldEnums, placeholder: addFieldPlaceholder !== null && addFieldPlaceholder !== void 0 ? addFieldPlaceholder : `${translations.AddField}` }, onChange: this.onSelectFieldChange, includeEmpty: true, schema: {}, id: `${idSchema.$id}_field_select`, formContext: this.props.formContext, disabled: this.props.disabled, readonly: this.props.readonly })));
|
|
119
119
|
}
|
|
120
120
|
};
|
|
@@ -50,7 +50,7 @@ const utils_2 = require("@rjsf/utils");
|
|
|
50
50
|
const scopeFieldSettings = {
|
|
51
51
|
taxonGroups: {
|
|
52
52
|
translate: (props, taxonGroup) => {
|
|
53
|
-
return props.formContext.apiClient.
|
|
53
|
+
return props.formContext.apiClient.get("/informal-taxon-groups/" + taxonGroup).then((response) => {
|
|
54
54
|
return response.name;
|
|
55
55
|
}).catch(() => {
|
|
56
56
|
return "";
|
|
@@ -357,7 +357,7 @@ let SectionArrayFieldTemplate = class SectionArrayFieldTemplate extends React.Co
|
|
|
357
357
|
return null;
|
|
358
358
|
}
|
|
359
359
|
const { children, hasRemove, index, disabled, readonly, onDropIndexClick } = this.props.items[idx];
|
|
360
|
-
const del = hasRemove && (React.createElement(components_1.DeleteButton, { id: `${this.props.idSchema.$id}_${index}`, disabled: disabled || readonly, translations: this.props.formContext.translations, onClick: onDropIndexClick(index), className: "horizontally-centered" }));
|
|
360
|
+
const del = hasRemove && (React.createElement(components_1.DeleteButton, { id: `${this.props.idSchema.$id}_${index}`, disabled: disabled || readonly, translations: this.props.formContext.translations, confirm: this.props.formContext.uiSchemaContext.confirmDelete, onClick: onDropIndexClick(index), className: "horizontally-centered" }));
|
|
361
361
|
const sectionLabel = (React.createElement(components_1.Affix, { className: index % 2 ? "background" : " darker", containerRef: this.containerRef, topOffset: this.props.formContext.topOffset, bottomOffset: this.props.formContext.bottomOffset },
|
|
362
362
|
React.createElement("legend", { className: "horizontally-centered" }, (0, utils_1.parseJSONPointer)(this.props.formData[index], sectionField))));
|
|
363
363
|
const [arr, field] = rowValueField.split("/%{row}");
|
|
@@ -471,8 +471,8 @@ let AccordionArrayFieldTemplate = class AccordionArrayFieldTemplate extends Reac
|
|
|
471
471
|
const that = this.props.formContext.this;
|
|
472
472
|
const arrayFieldTemplateProps = this.props;
|
|
473
473
|
const activeIdx = that.state.activeIdx;
|
|
474
|
-
const {
|
|
475
|
-
const {
|
|
474
|
+
const { translations, uiSchemaContext } = this.props.formContext;
|
|
475
|
+
const { confirmDelete = uiSchemaContext.confirmDelete, closeButton, affixed } = (0, utils_1.getUiOptions)(arrayFieldTemplateProps.uiSchema);
|
|
476
476
|
const { disabled, readonly } = arrayFieldTemplateProps;
|
|
477
477
|
const containerRefs = {};
|
|
478
478
|
(0, utils_1.asArray)(activeIdx).forEach(idx => {
|
|
@@ -526,8 +526,8 @@ let PagerArrayFieldTemplate = class PagerArrayFieldTemplate extends React.Compon
|
|
|
526
526
|
render() {
|
|
527
527
|
const that = this.props.formContext.this;
|
|
528
528
|
const arrayTemplateFieldProps = this.props;
|
|
529
|
-
const { translations } = that.props.formContext;
|
|
530
|
-
const { buttons, affixed, headerClassName, confirmDelete } = (0, utils_1.getUiOptions)(arrayTemplateFieldProps.uiSchema);
|
|
529
|
+
const { translations, uiSchemaContext } = that.props.formContext;
|
|
530
|
+
const { buttons, affixed, headerClassName, confirmDelete = uiSchemaContext.confirmDelete } = (0, utils_1.getUiOptions)(arrayTemplateFieldProps.uiSchema);
|
|
531
531
|
const activeIdx = that.state.activeIdx;
|
|
532
532
|
const { Pager } = this.context.theme;
|
|
533
533
|
let header = (React.createElement("div", { className: `laji-form-panel-header laji-form-accordion-header${headerClassName ? ` ${headerClassName}` : ""}`, ref: this.setHeaderRef },
|
|
@@ -800,7 +800,7 @@ let TableArrayFieldTemplate = class TableArrayFieldTemplate extends React.Compon
|
|
|
800
800
|
const that = this.props.formContext.this;
|
|
801
801
|
const { errorSchema } = that.props;
|
|
802
802
|
const activeIdx = that.state.activeIdx;
|
|
803
|
-
const { confirmDelete } = (0, utils_1.getUiOptions)(uiSchema);
|
|
803
|
+
const { confirmDelete = this.props.formContext.uiSchemaContext.confirmDelete } = (0, utils_1.getUiOptions)(uiSchema);
|
|
804
804
|
const getDeleteButtonFor = (idx, item) => {
|
|
805
805
|
return removable && React.createElement(components_1.DeleteButton, { id: `${that.props.idSchema.$id}_${idx}`, disabled: disabled || readonly, ref: this.getDeleteButtonRef(idx), key: (0, utils_1.getUUID)(this.props.formData[item.index]) || item.key, confirm: confirmDelete, translations: this.props.formContext.translations, onClick: that.onDelete(item) });
|
|
806
806
|
};
|
|
@@ -911,13 +911,13 @@ const headerFormatters = {
|
|
|
911
911
|
this.fetch = (props) => {
|
|
912
912
|
const { namedPlaceID } = (props.that.props.formData || {})[props.idx] || {};
|
|
913
913
|
if (namedPlaceID)
|
|
914
|
-
props.that.props.formContext.apiClient.
|
|
914
|
+
props.that.props.formContext.apiClient.get("/named-places/{id}", { path: { id: namedPlaceID } }).then(response => {
|
|
915
915
|
if (this.mounted && response.name !== this.state.name)
|
|
916
916
|
this.setState({
|
|
917
917
|
namedPlaceID,
|
|
918
918
|
name: response.name
|
|
919
919
|
});
|
|
920
|
-
});
|
|
920
|
+
}).catch(() => { });
|
|
921
921
|
};
|
|
922
922
|
this.state = {};
|
|
923
923
|
}
|
|
@@ -69,7 +69,7 @@ class TaxonomicComparer extends Comparer {
|
|
|
69
69
|
}
|
|
70
70
|
initialize() {
|
|
71
71
|
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
-
this.idToIdx = (yield this.formContext.apiClient.
|
|
72
|
+
this.idToIdx = (yield this.formContext.apiClient.get("/taxa", { query: Object.assign(Object.assign({}, this.options.query), { pageSize: 10000, selectedFields: "id" }) }))
|
|
73
73
|
.results.reduce((idToIdx, { id }, idx) => {
|
|
74
74
|
idToIdx[id] = idx;
|
|
75
75
|
return idToIdx;
|
|
@@ -135,7 +135,7 @@ exports.default = TableField;
|
|
|
135
135
|
let TableArrayFieldTemplate = class TableArrayFieldTemplate extends React.Component {
|
|
136
136
|
render() {
|
|
137
137
|
const { props } = this;
|
|
138
|
-
const { schema, uiSchema, formContext: { cols, wrapperCols, schemaPropsArray }, idSchema, readonly, disabled } = props;
|
|
138
|
+
const { schema, uiSchema, formContext: { cols, wrapperCols, schemaPropsArray, uiSchemaContext }, idSchema, readonly, disabled } = props;
|
|
139
139
|
const schemaProps = schema.additionalItems ? schema.additionalItems.properties : schema.items.properties;
|
|
140
140
|
const { Label } = this.props.formContext;
|
|
141
141
|
const { Row, Col } = this.context.theme;
|
|
@@ -146,7 +146,7 @@ let TableArrayFieldTemplate = class TableArrayFieldTemplate extends React.Compon
|
|
|
146
146
|
|| propUiSchema["ui:required"], uiSchema: propUiSchema })));
|
|
147
147
|
});
|
|
148
148
|
const options = (0, utils_1.getUiOptions)(props.uiSchema);
|
|
149
|
-
const { confirmDelete, deleteCorner, removable = true, nonRemovables = [], buttons, "ui:deleteHelp": deleteHelp } = options;
|
|
149
|
+
const { confirmDelete = uiSchemaContext.confirmDelete, deleteCorner, removable = true, nonRemovables = [], buttons, "ui:deleteHelp": deleteHelp } = options;
|
|
150
150
|
if (!this.deleteButtonRefs)
|
|
151
151
|
this.deleteButtonRefs = [];
|
|
152
152
|
const getRefFor = i => elem => { this.deleteButtonRefs[i] = elem; };
|
|
@@ -82,7 +82,7 @@ let UnitCountShorthandField = class UnitCountShorthandField extends React.Compon
|
|
|
82
82
|
resolve({ success: undefined });
|
|
83
83
|
return;
|
|
84
84
|
}
|
|
85
|
-
apiClient.
|
|
85
|
+
apiClient.get("/shorthand/unit/water-bird-pair-count", { query: { query: value, taxonID: taxonId } }).then(suggestion => {
|
|
86
86
|
if (timestamp !== this.promiseTimestamp) {
|
|
87
87
|
reject();
|
|
88
88
|
return;
|
|
@@ -69,8 +69,8 @@ let UnitListShorthandArrayField = class UnitListShorthandArrayField extends Reac
|
|
|
69
69
|
this.onHide();
|
|
70
70
|
const { translations, notifier, apiClient } = this.props.formContext;
|
|
71
71
|
this.props.formContext.services.blocker.push();
|
|
72
|
-
apiClient.
|
|
73
|
-
units =
|
|
72
|
+
apiClient.get("/shorthand/unit/list", { query: { query: value } }).then(({ results, nonMatchingCount }) => {
|
|
73
|
+
const units = results.map(unit => {
|
|
74
74
|
unit = (0, utils_1.getDefaultFormState)(this.props.schema.items, unit);
|
|
75
75
|
unit = (0, utils_1.bringRemoteFormData)(unit, this.props.formContext);
|
|
76
76
|
unit = (0, utils_1.assignUUID)(unit);
|
|
@@ -51,7 +51,6 @@ const ReactContext_1 = __importDefault(require("../../ReactContext"));
|
|
|
51
51
|
const components_1 = require("../components");
|
|
52
52
|
const AutosuggestWidget_1 = require("../widgets/AutosuggestWidget");
|
|
53
53
|
const ArrayFieldTemplate_1 = require("../templates/ArrayFieldTemplate");
|
|
54
|
-
const LINE_TRANSECT_IDS = ["MHL.1162", "MHL.27", "MHL.28"];
|
|
55
54
|
let UnitShorthandField = class UnitShorthandField extends React.Component {
|
|
56
55
|
constructor(props) {
|
|
57
56
|
super(props);
|
|
@@ -125,13 +124,13 @@ let UnitShorthandField = class UnitShorthandField extends React.Component {
|
|
|
125
124
|
render() {
|
|
126
125
|
const { uiSchema, formContext, disabled, readonly } = this.props;
|
|
127
126
|
const { SchemaField } = this.props.registry.fields;
|
|
128
|
-
const
|
|
127
|
+
const { shorthandField, lineTransect } = (0, utils_1.getUiOptions)(this.props.uiSchema);
|
|
129
128
|
const toggleButton = this.getToggleButton();
|
|
130
129
|
const tailUiSchema = (0, utils_1.getNestedTailUiSchema)(uiSchema);
|
|
131
|
-
let help = tailUiSchema && tailUiSchema[
|
|
132
|
-
const uiSchemaWithoutHelp = (0, utils_1.isEmptyString)(help) ? uiSchema : (0, utils_1.updateTailUiSchema)(uiSchema, { [
|
|
133
|
-
const id = (
|
|
134
|
-
this.props.idSchema[
|
|
130
|
+
let help = tailUiSchema && tailUiSchema[shorthandField] && tailUiSchema[shorthandField]["ui:belowHelp"];
|
|
131
|
+
const uiSchemaWithoutHelp = (0, utils_1.isEmptyString)(help) ? uiSchema : (0, utils_1.updateTailUiSchema)(uiSchema, { [shorthandField]: { "ui:belowHelp": { $set: undefined } } });
|
|
132
|
+
const id = (shorthandField && this.props.idSchema[shorthandField]) ?
|
|
133
|
+
this.props.idSchema[shorthandField].$id :
|
|
135
134
|
`${this.props.idSchema.$id}_shortHandField`;
|
|
136
135
|
let innerUiSchema = undefined;
|
|
137
136
|
if (this.state.showSchema) {
|
|
@@ -140,7 +139,7 @@ let UnitShorthandField = class UnitShorthandField extends React.Component {
|
|
|
140
139
|
innerUiSchema = Object.assign(Object.assign({}, innerUiSchema), { "ui:options": Object.assign(Object.assign({}, innerOptions), { buttons: [...(innerOptions.buttons || []), toggleButton] }) });
|
|
141
140
|
}
|
|
142
141
|
return !this.state.showSchema ? (React.createElement("div", { className: "laji-form-field-template-item", id: `_laji-form_${id}` },
|
|
143
|
-
React.createElement(CodeReader, { translations: this.props.formContext.translations, onChange: this.onCodeChange, value: this.props.formData[
|
|
142
|
+
React.createElement(CodeReader, { translations: this.props.formContext.translations, onChange: this.onCodeChange, value: this.props.formData[shorthandField], formID: (0, utils_1.getUiOptions)(this.props.uiSchema).formID || formContext.formID || formContext.uiSchemaContext.formID, help: help, id: id, formContext: formContext, disabled: disabled, readonly: readonly, lineTransect: lineTransect, className: "laji-form-field-template-schema" }),
|
|
144
143
|
React.createElement("div", { className: "laji-form-field-template-buttons" }, (0, ArrayFieldTemplate_1.getButton)(toggleButton)))) : (React.createElement(SchemaField, Object.assign({}, this.props, { uiSchema: innerUiSchema })));
|
|
145
144
|
}
|
|
146
145
|
};
|
|
@@ -185,14 +184,14 @@ let CodeReader = class CodeReader extends React.Component {
|
|
|
185
184
|
this.onAutosuggestChange = (formData) => {
|
|
186
185
|
this.props.onChange(formData);
|
|
187
186
|
};
|
|
188
|
-
this.onSuggestionSelected = ({
|
|
187
|
+
this.onSuggestionSelected = ({ unit }) => {
|
|
189
188
|
const { formContext } = this.props;
|
|
190
189
|
unit = (0, utils_1.bringRemoteFormData)(unit, formContext);
|
|
191
190
|
this.props.onChange(unit);
|
|
192
191
|
};
|
|
193
192
|
this.renderSuggestion = (suggestion) => {
|
|
194
193
|
const { translations } = this.props;
|
|
195
|
-
return suggestion.
|
|
194
|
+
return suggestion.isNonMatching
|
|
196
195
|
? React.createElement("span", { className: "text-muted" },
|
|
197
196
|
suggestion.value,
|
|
198
197
|
" ",
|
|
@@ -212,8 +211,8 @@ let CodeReader = class CodeReader extends React.Component {
|
|
|
212
211
|
}
|
|
213
212
|
else if (value.length >= 3) {
|
|
214
213
|
this.mounted && this.setState({ loading: true });
|
|
215
|
-
this.apiClient.
|
|
216
|
-
this.props.onChange(response.
|
|
214
|
+
this.apiClient.get("/shorthand/unit/line-transect", { query: { query: value } }).then(response => {
|
|
215
|
+
this.props.onChange(response.unit);
|
|
217
216
|
}).catch(() => {
|
|
218
217
|
this.mounted && this.setState({ failed: true, loading: false });
|
|
219
218
|
});
|
|
@@ -230,18 +229,15 @@ let CodeReader = class CodeReader extends React.Component {
|
|
|
230
229
|
this.mounted = false;
|
|
231
230
|
}
|
|
232
231
|
render() {
|
|
233
|
-
const { translations, readonly, disabled } = this.props;
|
|
232
|
+
const { translations, readonly, disabled, lineTransect } = this.props;
|
|
234
233
|
let validationState = null;
|
|
235
234
|
if (this.state.failed === true)
|
|
236
235
|
validationState = "warning";
|
|
237
236
|
else if (!(0, utils_1.isEmptyString)(this.props.value) && this.props.value === this.state.value)
|
|
238
237
|
validationState = "success";
|
|
239
|
-
const {
|
|
240
|
-
const inputElem =
|
|
241
|
-
React.createElement(AutosuggestWidget_1.Autosuggest, { autosuggestField: "unit",
|
|
242
|
-
formID,
|
|
243
|
-
includeNonMatching: true
|
|
244
|
-
}, onSuggestionSelected: this.onSuggestionSelected, renderSuggestion: this.renderSuggestion, onChange: this.onAutosuggestChange, formContext: formContext, allowNonsuggestedValue: false })));
|
|
238
|
+
const { formContext } = this.props;
|
|
239
|
+
const inputElem = lineTransect ? (React.createElement(components_1.FetcherInput, { id: this.props.id, loading: this.state.loading, value: this.state.value, validationState: validationState, onChange: this.onFetcherInputChange, onBlur: this.getCode, onKeyDown: this.onKeyDown, readonly: readonly, disabled: disabled })) : (React.createElement("div", { className: "unit-shorthand" },
|
|
240
|
+
React.createElement(AutosuggestWidget_1.Autosuggest, { autosuggestField: "unit", onSuggestionSelected: this.onSuggestionSelected, renderSuggestion: this.renderSuggestion, onChange: this.onAutosuggestChange, formContext: formContext, allowNonsuggestedValue: false })));
|
|
245
241
|
const { FormGroup, HelpBlock } = this.context.theme;
|
|
246
242
|
return (React.createElement(FormGroup, { validationState: this.state.failed ? "error" : undefined },
|
|
247
243
|
inputElem,
|
|
@@ -301,9 +301,9 @@ class ArrayFieldTemplateWithoutKeyHandling extends React.Component {
|
|
|
301
301
|
}
|
|
302
302
|
render() {
|
|
303
303
|
const { props } = this;
|
|
304
|
-
const { confirmDelete, renderTitleAsLabel, deleteCorner, removable = true, orderable, nonRemovables = [], nonOrderables = [], "ui:deleteHelp": deleteHelp, buttons = [] } = (0, utils_1.getUiOptions)(props.uiSchema);
|
|
305
304
|
const { readonly, disabled } = this.props;
|
|
306
|
-
const { Label } = this.props.formContext;
|
|
305
|
+
const { Label, uiSchemaContext } = this.props.formContext;
|
|
306
|
+
const { confirmDelete = uiSchemaContext.confirmDelete, renderTitleAsLabel, deleteCorner, removable = true, orderable, nonRemovables = [], nonOrderables = [], "ui:deleteHelp": deleteHelp, buttons = [] } = (0, utils_1.getUiOptions)(props.uiSchema);
|
|
307
307
|
const Title = renderTitleAsLabel ? Label : (0, utils_2.getTemplate)("TitleFieldTemplate", props.registry, (0, utils_1.getUiOptions)(props.uiSchema));
|
|
308
308
|
const Description = (0, utils_2.getTemplate)("DescriptionFieldTemplate", this.props.registry, (0, utils_1.getUiOptions)(props.uiSchema));
|
|
309
309
|
if (!this.deleteButtonRefs)
|