@luomus/laji-form 15.1.112 → 15.1.113
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/lib/components/fields/MultiArrayField.d.ts +2 -3
- package/lib/components/fields/MultiArrayField.js +14 -19
- package/lib/components/fields/TaxonSetPopulatorField.d.ts +1 -0
- package/lib/components/fields/TaxonSetPopulatorField.js +26 -28
- package/lib/translations.json +5 -0
- package/lib/validation.js +3 -0
- package/package.json +2 -2
|
@@ -48,12 +48,11 @@ export default class MultiArrayField extends React.Component<any, any, any> {
|
|
|
48
48
|
};
|
|
49
49
|
constructor(props: any);
|
|
50
50
|
constructor(props: any, context: any);
|
|
51
|
-
|
|
52
|
-
render(): any;
|
|
51
|
+
render(): JSX.Element[];
|
|
53
52
|
cache: {}[] | undefined;
|
|
54
53
|
arrayKeyFunctions: any[] | undefined;
|
|
55
54
|
groupItemIds: {} | {}[] | undefined;
|
|
56
|
-
groupedItems:
|
|
55
|
+
groupedItems: never[][] | undefined;
|
|
57
56
|
onChange: ((idx: any) => (formData: any) => void) & memoize.Memoized<(idx: any) => (formData: any) => void>;
|
|
58
57
|
}
|
|
59
58
|
import * as React from "react";
|
|
@@ -47,7 +47,6 @@ const memoizee_1 = __importDefault(require("memoizee"));
|
|
|
47
47
|
class MultiArrayField extends React.Component {
|
|
48
48
|
constructor() {
|
|
49
49
|
super(...arguments);
|
|
50
|
-
this.itemIds = {};
|
|
51
50
|
this.onChange = (0, memoizee_1.default)((idx) => (formData) => {
|
|
52
51
|
let offset = 0;
|
|
53
52
|
for (let i = 0; i < idx; i++) {
|
|
@@ -114,27 +113,24 @@ class MultiArrayField extends React.Component {
|
|
|
114
113
|
this.groupItemIds = getGroupItemIds();
|
|
115
114
|
}
|
|
116
115
|
}
|
|
117
|
-
const
|
|
118
|
-
const addToGroup = (
|
|
116
|
+
const groupedItems = Array(groups.length + 1).fill(undefined).map(_ => []);
|
|
117
|
+
const addToGroup = (groupIdx, item) => {
|
|
119
118
|
const id = (0, utils_1.getUUID)(item);
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
this.itemIds[id] = true;
|
|
119
|
+
this.groupItemIds[groupIdx][id] = true;
|
|
120
|
+
groupedItems[groupIdx].push(item);
|
|
123
121
|
return true;
|
|
124
122
|
};
|
|
125
|
-
(props.formData || []).forEach(item => {
|
|
126
|
-
this.groupItemIds.forEach((_, groupIdx) => {
|
|
127
|
-
if (this.groupItemIds[groupIdx][(0, utils_1.getUUID)(item)]) {
|
|
128
|
-
addToGroup(groupIdx, item);
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
123
|
const nonGrouped = [];
|
|
133
|
-
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
124
|
+
(props.formData || []).forEach((item, idx) => {
|
|
125
|
+
const id = (0, utils_1.getUUID)(item);
|
|
126
|
+
// Restore persisted group
|
|
127
|
+
for (let g = 0; g < this.groupItemIds.length; g++) {
|
|
128
|
+
if (this.groupItemIds[g][id]) {
|
|
129
|
+
addToGroup(g, item);
|
|
130
|
+
return;
|
|
137
131
|
}
|
|
132
|
+
}
|
|
133
|
+
const addedToGroup = groups.some((group, groupIdx) => {
|
|
138
134
|
const { rules = [] } = group;
|
|
139
135
|
let passes;
|
|
140
136
|
if (cache) {
|
|
@@ -153,8 +149,7 @@ class MultiArrayField extends React.Component {
|
|
|
153
149
|
if (!addedToGroup) {
|
|
154
150
|
nonGrouped.push([item, idx]);
|
|
155
151
|
}
|
|
156
|
-
|
|
157
|
-
}, itemGroups);
|
|
152
|
+
});
|
|
158
153
|
nonGrouped.forEach(([item, idx]) => {
|
|
159
154
|
const context = (0, Context_1.default)(`${persistenceKey}_MULTI`);
|
|
160
155
|
const groupIdx = this.groupItemIds.length - 1;
|
|
@@ -54,6 +54,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
54
54
|
const React = __importStar(require("react"));
|
|
55
55
|
const PropTypes = __importStar(require("prop-types"));
|
|
56
56
|
const VirtualSchemaField_1 = __importDefault(require("../VirtualSchemaField"));
|
|
57
|
+
const utils_1 = require("../..//utils");
|
|
57
58
|
const propsPropType = PropTypes.shape({
|
|
58
59
|
from: PropTypes.string.isRequired,
|
|
59
60
|
fromArrayKey: PropTypes.string,
|
|
@@ -99,16 +100,7 @@ let TaxonSetPopulatorField = class TaxonSetPopulatorField extends React.Componen
|
|
|
99
100
|
return this.unitTaxonSets[unit.identifications[0].taxonID]
|
|
100
101
|
&& this.unitTaxonSets[unit.identifications[0].taxonID].includes(deletedTaxonSetId);
|
|
101
102
|
});
|
|
102
|
-
observationsExist = deletedTaxonSetUnits.some((unit) =>
|
|
103
|
-
var _a, _b, _c, _d;
|
|
104
|
-
return unit.maleIndividualCount ||
|
|
105
|
-
unit.femaleIndividualCount ||
|
|
106
|
-
unit.nestCount ||
|
|
107
|
-
((_a = unit.unitFact) === null || _a === void 0 ? void 0 : _a.destroyedNestCount) ||
|
|
108
|
-
((_b = unit.unitFact) === null || _b === void 0 ? void 0 : _b.broodCount) ||
|
|
109
|
-
((_c = unit.unitFact) === null || _c === void 0 ? void 0 : _c.femalesWithBroodsCount) ||
|
|
110
|
-
((_d = unit.unitFact) === null || _d === void 0 ? void 0 : _d.juvenileCount);
|
|
111
|
-
});
|
|
103
|
+
observationsExist = deletedTaxonSetUnits.some((unit) => unit.observationStatus !== "MY.observationStatusIgnored");
|
|
112
104
|
if (observationsExist) {
|
|
113
105
|
window.alert(translations === null || translations === void 0 ? void 0 : translations.TaxonSetDeletionFailed);
|
|
114
106
|
const restoredFormData = Object.assign(Object.assign({}, formData), { taxonCensus: [
|
|
@@ -126,7 +118,8 @@ let TaxonSetPopulatorField = class TaxonSetPopulatorField extends React.Componen
|
|
|
126
118
|
return !this.unitTaxonSets[unit.identifications[0].taxonID]
|
|
127
119
|
|| !this.unitTaxonSets[unit.identifications[0].taxonID].includes(deletedTaxonSetId);
|
|
128
120
|
});
|
|
129
|
-
const
|
|
121
|
+
const sortedUnits = this.sortByTaxonSet(updatedUnits, currentTaxonSets);
|
|
122
|
+
const updatedFormData = Object.assign(Object.assign({}, formData), { units: sortedUnits });
|
|
130
123
|
this.props.onChange(updatedFormData);
|
|
131
124
|
});
|
|
132
125
|
return;
|
|
@@ -142,32 +135,20 @@ let TaxonSetPopulatorField = class TaxonSetPopulatorField extends React.Componen
|
|
|
142
135
|
return;
|
|
143
136
|
}
|
|
144
137
|
const results = yield this.fetchTaxaFromSet(this.props, addedTaxonSets);
|
|
145
|
-
|
|
146
|
-
if (addedTaxonSets.length > 1) {
|
|
147
|
-
results.sort((a, b) => {
|
|
148
|
-
const aIndex = (a.taxonSets || []).reduce((min, taxonSet) => {
|
|
149
|
-
const idx = addedTaxonSets.indexOf(taxonSet);
|
|
150
|
-
return idx !== -1 && idx < min ? idx : min;
|
|
151
|
-
}, addedTaxonSets.length);
|
|
152
|
-
const bIndex = (b.taxonSets || []).reduce((min, taxonSet) => {
|
|
153
|
-
const idx = addedTaxonSets.indexOf(taxonSet);
|
|
154
|
-
return idx !== -1 && idx < min ? idx : min;
|
|
155
|
-
}, addedTaxonSets.length);
|
|
156
|
-
return aIndex - bIndex;
|
|
157
|
-
});
|
|
158
|
-
}
|
|
138
|
+
const tmpIdTree = this.props.formContext.services.ids.getRelativeTmpIdTree(this.props.idSchema.units.$id);
|
|
159
139
|
const newUnits = results.map((result) => {
|
|
160
140
|
this.unitTaxonSets[result.id] = result.taxonSets || [];
|
|
161
|
-
return {
|
|
141
|
+
return (0, utils_1.addLajiFormIds)({
|
|
162
142
|
identifications: [{
|
|
163
143
|
taxon: result.scientificName,
|
|
164
144
|
taxonID: result.id,
|
|
165
145
|
taxonVerbatim: result.vernacularName
|
|
166
146
|
}],
|
|
167
147
|
informalTaxonGroups: result.informalTaxonGroups || []
|
|
168
|
-
};
|
|
148
|
+
}, tmpIdTree, false)[0];
|
|
169
149
|
});
|
|
170
|
-
const
|
|
150
|
+
const sortedUnits = this.sortByTaxonSet([...currentUnits, ...newUnits], currentTaxonSets);
|
|
151
|
+
const updatedFormData = Object.assign(Object.assign({}, formData), { units: sortedUnits });
|
|
171
152
|
this.props.onChange(updatedFormData);
|
|
172
153
|
return;
|
|
173
154
|
}
|
|
@@ -204,6 +185,23 @@ let TaxonSetPopulatorField = class TaxonSetPopulatorField extends React.Componen
|
|
|
204
185
|
});
|
|
205
186
|
});
|
|
206
187
|
}
|
|
188
|
+
// sort unit by taxon set (lowest index of unit's taxon sets in currentTaxonSets)
|
|
189
|
+
sortByTaxonSet(units, taxonSets) {
|
|
190
|
+
return units.sort((a, b) => {
|
|
191
|
+
var _a, _b, _c, _d;
|
|
192
|
+
const aTaxonSets = this.unitTaxonSets[(_b = (_a = a.identifications) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.taxonID] || [];
|
|
193
|
+
const bTaxonSets = this.unitTaxonSets[(_d = (_c = b.identifications) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.taxonID] || [];
|
|
194
|
+
const aIndex = aTaxonSets.reduce((min, taxonSet) => {
|
|
195
|
+
const idx = taxonSets.indexOf(taxonSet);
|
|
196
|
+
return idx !== -1 && idx < min ? idx : min;
|
|
197
|
+
}, taxonSets.length);
|
|
198
|
+
const bIndex = bTaxonSets.reduce((min, taxonSet) => {
|
|
199
|
+
const idx = taxonSets.indexOf(taxonSet);
|
|
200
|
+
return idx !== -1 && idx < min ? idx : min;
|
|
201
|
+
}, taxonSets.length);
|
|
202
|
+
return aIndex - bIndex;
|
|
203
|
+
});
|
|
204
|
+
}
|
|
207
205
|
fetchTaxaFromSet(props, taxonSets) {
|
|
208
206
|
return __awaiter(this, void 0, void 0, function* () {
|
|
209
207
|
var _a;
|
package/lib/translations.json
CHANGED
|
@@ -894,6 +894,11 @@
|
|
|
894
894
|
"en": "The same value may not be used more than once",
|
|
895
895
|
"sv": "Samma värde får inte användas mer än en gång"
|
|
896
896
|
},
|
|
897
|
+
"valueMustBe": {
|
|
898
|
+
"fi": "Arvon on oltava",
|
|
899
|
+
"en": "Value must be",
|
|
900
|
+
"sv": "Värdet måste vara"
|
|
901
|
+
},
|
|
897
902
|
"taxonSetDeletionFailed": {
|
|
898
903
|
"fi": "Tätä lajiryhmää ei voi poistaa, koska siihen on kirjattu havaintoja.",
|
|
899
904
|
"en": "This taxon set cannot be removed because it contains observations.",
|
package/lib/validation.js
CHANGED
|
@@ -74,6 +74,9 @@ function transformErrors(translations, errors) {
|
|
|
74
74
|
else if (error.name === "uniqueItems") {
|
|
75
75
|
error.message = translations.UniqueItems + ".";
|
|
76
76
|
}
|
|
77
|
+
else if (error.name === "minimum") {
|
|
78
|
+
error.message = translations.ValueMustBe + " " + error.params.comparison + " " + error.params.limit + ".";
|
|
79
|
+
}
|
|
77
80
|
return error;
|
|
78
81
|
});
|
|
79
82
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luomus/laji-form",
|
|
3
|
-
"version": "15.1.
|
|
3
|
+
"version": "15.1.113",
|
|
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",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"license": "MIT",
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@luomus/laji-map": "^5.1.19",
|
|
44
|
-
"@luomus/laji-validate": "^0.0.
|
|
44
|
+
"@luomus/laji-validate": "^0.0.132",
|
|
45
45
|
"@rjsf/core": "~5.1.0",
|
|
46
46
|
"@rjsf/utils": "~5.1.0",
|
|
47
47
|
"@rjsf/validator-ajv6": "~5.1.0",
|