@luomus/laji-form 15.1.94 → 15.1.95
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.
|
@@ -41,7 +41,8 @@ export default class TaxonSetPopulatorField extends React.Component<FieldProps>
|
|
|
41
41
|
formData: PropTypes.Validator<object>;
|
|
42
42
|
};
|
|
43
43
|
static getName(): string;
|
|
44
|
-
|
|
44
|
+
selectedTaxonSets: string[];
|
|
45
|
+
unitTaxonSets: Record<string, string[]>;
|
|
45
46
|
getStateFromProps(): {
|
|
46
47
|
onChange: (formData: any) => Promise<void>;
|
|
47
48
|
};
|
|
@@ -80,21 +80,23 @@ const propsPropType = PropTypes.shape({
|
|
|
80
80
|
let TaxonSetPopulatorField = class TaxonSetPopulatorField extends React.Component {
|
|
81
81
|
constructor() {
|
|
82
82
|
super(...arguments);
|
|
83
|
-
this.
|
|
83
|
+
this.selectedTaxonSets = [];
|
|
84
|
+
this.unitTaxonSets = {};
|
|
84
85
|
this.onChange = (formData) => __awaiter(this, void 0, void 0, function* () {
|
|
85
86
|
var _a, _b, _c;
|
|
86
|
-
const previousTaxonSets = this.
|
|
87
|
+
const previousTaxonSets = this.selectedTaxonSets;
|
|
87
88
|
const currentTaxonSets = ((_a = formData === null || formData === void 0 ? void 0 : formData.taxonCensus) === null || _a === void 0 ? void 0 : _a.map((item) => item.censusTaxonSetID)) || [];
|
|
88
89
|
const deletedTaxonSets = previousTaxonSets.filter((item) => !currentTaxonSets.includes(item));
|
|
89
90
|
const addedTaxonSets = currentTaxonSets.filter((item) => !previousTaxonSets.includes(item));
|
|
90
|
-
this.
|
|
91
|
+
this.selectedTaxonSets = ((_b = formData === null || formData === void 0 ? void 0 : formData.taxonCensus) === null || _b === void 0 ? void 0 : _b.map((item) => item.censusTaxonSetID)) || [];
|
|
91
92
|
if (deletedTaxonSets.length > 0) {
|
|
92
93
|
deletedTaxonSets.map((deletedTaxonSetId) => {
|
|
93
94
|
var _a;
|
|
94
95
|
const currentUnits = Array.isArray((_a = this.props.formData) === null || _a === void 0 ? void 0 : _a.units) ? this.props.formData.units : [];
|
|
95
96
|
let observationsExist = false;
|
|
96
97
|
const deletedTaxonSetUnits = currentUnits.filter((unit) => {
|
|
97
|
-
return
|
|
98
|
+
return this.unitTaxonSets[unit.identifications[0].taxonID]
|
|
99
|
+
&& this.unitTaxonSets[unit.identifications[0].taxonID].includes(deletedTaxonSetId);
|
|
98
100
|
});
|
|
99
101
|
deletedTaxonSetUnits.map((unit) => {
|
|
100
102
|
var _a, _b, _c, _d;
|
|
@@ -116,7 +118,7 @@ let TaxonSetPopulatorField = class TaxonSetPopulatorField extends React.Componen
|
|
|
116
118
|
taxonCensusType: "MY.taxonCensusTypeCounted"
|
|
117
119
|
}
|
|
118
120
|
] });
|
|
119
|
-
this.
|
|
121
|
+
this.selectedTaxonSets = [...this.selectedTaxonSets, deletedTaxonSetId];
|
|
120
122
|
this.props.onChange(updatedFormData);
|
|
121
123
|
return;
|
|
122
124
|
}
|
|
@@ -125,7 +127,8 @@ let TaxonSetPopulatorField = class TaxonSetPopulatorField extends React.Componen
|
|
|
125
127
|
return;
|
|
126
128
|
}
|
|
127
129
|
const updatedUnits = currentUnits.filter((unit) => {
|
|
128
|
-
return !
|
|
130
|
+
return !this.unitTaxonSets[unit.identifications[0].taxonID]
|
|
131
|
+
|| !this.unitTaxonSets[unit.identifications[0].taxonID].includes(deletedTaxonSetId);
|
|
129
132
|
});
|
|
130
133
|
const updatedFormData = Object.assign(Object.assign({}, formData), { units: updatedUnits });
|
|
131
134
|
this.props.onChange(updatedFormData);
|
|
@@ -135,21 +138,22 @@ let TaxonSetPopulatorField = class TaxonSetPopulatorField extends React.Componen
|
|
|
135
138
|
const currentUnits = Array.isArray((_c = this.props.formData) === null || _c === void 0 ? void 0 : _c.units) ? this.props.formData.units : [];
|
|
136
139
|
// if current units include any units with taxon sets that are being added, return to avoid duplicates
|
|
137
140
|
const duplicateUnits = currentUnits.filter((unit) => {
|
|
138
|
-
return
|
|
141
|
+
return this.unitTaxonSets[unit.identifications[0].taxonID]
|
|
142
|
+
&& this.unitTaxonSets[unit.identifications[0].taxonID].some((taxonSetId) => addedTaxonSets.includes(taxonSetId));
|
|
139
143
|
});
|
|
140
144
|
if (duplicateUnits.length > 0) {
|
|
141
145
|
return;
|
|
142
146
|
}
|
|
143
147
|
const results = yield this.fetchTaxaFromSet(this.props, addedTaxonSets);
|
|
144
148
|
const newUnits = results.map((result) => {
|
|
149
|
+
this.unitTaxonSets[result.id] = result.taxonSets || [];
|
|
145
150
|
return {
|
|
146
151
|
identifications: [{
|
|
147
152
|
taxon: result.scientificName,
|
|
148
153
|
taxonID: result.id,
|
|
149
154
|
taxonVerbatim: result.vernacularName
|
|
150
155
|
}],
|
|
151
|
-
informalTaxonGroups: result.informalTaxonGroups || []
|
|
152
|
-
taxonSets: result.taxonSets || []
|
|
156
|
+
informalTaxonGroups: result.informalTaxonGroups || []
|
|
153
157
|
};
|
|
154
158
|
});
|
|
155
159
|
const updatedFormData = Object.assign(Object.assign({}, formData), { units: [...currentUnits, ...newUnits] });
|