Skip to content

Commit 6dab1f1

Browse files
authored
Merge pull request #1393 from WildMeOrg/1390_measurements_reset
1390 measurements reset
2 parents 1dece1d + 68409c0 commit 6dab1f1

File tree

8 files changed

+79
-50
lines changed

8 files changed

+79
-50
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React from "react";
2+
import { Form } from "react-bootstrap";
3+
4+
const NumberInput = ({
5+
value,
6+
onChange,
7+
placeholder = "input number",
8+
label,
9+
...props
10+
}) => {
11+
const handleChange = (e) => {
12+
const inputValue = e.target.value;
13+
14+
if (inputValue === "") {
15+
onChange("");
16+
return;
17+
}
18+
19+
if (/^-?\d*\.?\d*$/.test(inputValue)) {
20+
onChange(inputValue);
21+
}
22+
};
23+
24+
return (
25+
<Form.Group>
26+
{label && <Form.Label>{label}</Form.Label>}
27+
<Form.Control
28+
type="text"
29+
value={value}
30+
onChange={handleChange}
31+
placeholder={placeholder}
32+
{...props}
33+
/>
34+
</Form.Group>
35+
);
36+
};
37+
38+
export default NumberInput;

frontend/src/pages/Encounter/MeasurementsEdit.jsx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useContext } from "react";
22
import { observer } from "mobx-react-lite";
33
import SelectInput from "../../components/generalInputs/SelectInput";
4-
import TextInput from "../../components/generalInputs/TextInput";
4+
import NumberInput from "../../components/generalInputs/NumberInput";
55
import { Divider } from "../../components/Divider";
66
import LocaleContext from "../../IntlProvider";
77
import { useIntl } from "react-intl";
@@ -26,18 +26,11 @@ export const MeasurementsEdit = observer(({ store }) => {
2626
return (
2727
<div key={type}>
2828
<h6>{type}</h6>
29-
<TextInput
29+
<NumberInput
3030
label={unitLabel}
3131
value={cur.value ?? ""}
3232
onChange={(value) => {
3333
store.errors.setFieldError("measurement", type, null);
34-
if (value === "") {
35-
store.errors.setFieldError(
36-
"measurement",
37-
type,
38-
"Value cannot be empty",
39-
);
40-
}
4134
store.setMeasurementValue(type, value);
4235
}}
4336
/>
@@ -47,13 +40,6 @@ export const MeasurementsEdit = observer(({ store }) => {
4740
options={samplingProtocolOptions}
4841
onChange={(samplingProtocol) => {
4942
store.errors.setFieldError("measurement", type, null);
50-
if (!samplingProtocol || samplingProtocol === "") {
51-
store.errors.setFieldError(
52-
"measurement",
53-
type,
54-
"Value cannot be empty",
55-
);
56-
}
5743
store.setMeasurementSamplingProtocol(
5844
type,
5945
samplingProtocol,

frontend/src/pages/Encounter/stores/EncounterStore.js

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -954,25 +954,27 @@ class EncounterStore {
954954
async patchMeasurements() {
955955
const tasks = [];
956956
let hasErrors = false;
957+
957958
for (const m of this.measurementValues) {
958-
if (m.value == null || m.value === "") {
959-
this.errors.setFieldError(
960-
"measurement",
961-
m.type,
962-
"value cannot be empty",
963-
);
964-
continue;
965-
}
966-
const payload = {
967-
op: "replace",
968-
path: "measurements",
969-
value: {
970-
type: m.type,
971-
units: m.units,
972-
value: m.value,
973-
samplingProtocol: m.samplingProtocol,
974-
},
975-
};
959+
const isEmpty = m.value == null || m.value === "";
960+
961+
const payload = isEmpty
962+
? {
963+
op: "remove",
964+
path: "measurements",
965+
value: m.type,
966+
}
967+
: {
968+
op: "replace",
969+
path: "measurements",
970+
value: {
971+
type: m.type,
972+
units: m.units,
973+
value: m.value,
974+
samplingProtocol: m.samplingProtocol,
975+
},
976+
};
977+
976978
tasks.push(
977979
axios
978980
.patch(`/api/v3/encounters/${this.encounterData.id}`, [payload], {
@@ -983,12 +985,15 @@ class EncounterStore {
983985
this.errors.setFieldError(
984986
"measurement",
985987
m.type,
986-
"Failed to save measurement",
988+
isEmpty
989+
? "Failed to remove measurement"
990+
: "Failed to save measurement",
987991
);
988992
throw err;
989993
}),
990994
);
991995
}
996+
992997
if (tasks.length > 0) {
993998
await Promise.allSettled(tasks);
994999
}

src/main/resources/bundles/de/commonConfigurationLabels.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ meters.label=Meter
1515
ppm.label=ppm
1616
nounits=
1717

18-
samplingProtocol0.label=pers\u00F6nliche Vermutung
19-
samplingProtocol1.label=Sch\u00E4tzung des F\u00FChrers/Forschers
20-
samplingProtocol2.label=direkt gemessen
18+
samplingProtocol0.label=direkt gemessen
19+
samplingProtocol1.label=pers\u00F6nliche Vermutung
20+
samplingProtocol2.label=Sch\u00E4tzung des F\u00FChrers/Forschers
2121

2222
left.label=Links
2323
right.label=Rechts

src/main/resources/bundles/en/commonConfigurationLabels.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ meters.label=Meters
1515
ppm.label=ppm
1616
nounits=
1717

18-
samplingProtocol0.label=personal guess
19-
samplingProtocol1.label=guess of guide/researcher
20-
samplingProtocol2.label=directly measured
18+
samplingProtocol0.label=directly measured
19+
samplingProtocol1.label=personal guess
20+
samplingProtocol2.label=guess of guide/researcher
2121

2222
left.label=Left
2323
right.label=Right

src/main/resources/bundles/es/commonConfigurationLabels.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ meters.label=Metros
1515
ppm.label=ppm
1616
nounits =
1717

18-
samplingProtocol0.label=suposici\u00f3n personal
19-
samplingProtocol1.label=conjetura de gu\u00eda o investigador
20-
samplingProtocol2.label=medido directamente
18+
samplingProtocol0.label=medido directamente
19+
samplingProtocol1.label=suposici\u00f3n personal
20+
samplingProtocol2.label=conjetura de gu\u00eda o investigador
2121

2222
left.label = Izquierda
2323
right.label = Derecho

src/main/resources/bundles/fr/commonConfigurationLabels.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ meters.label=M\u00e8tres
1515
ppm.label=ppm
1616
nounits=
1717
18-
samplingProtocol0.label=estimation personnelle
19-
samplingProtocol1.label=estimation de guide/chercheur
20-
samplingProtocol2.label=directement mesur\u00e9
18+
samplingProtocol0.label=directement mesur\u00e9
19+
samplingProtocol1.label=estimation personnelle
20+
samplingProtocol2.label=estimation de guide/chercheur
2121
2222
left.label=Gauche
2323
right.label=Droite

src/main/resources/bundles/it/commonConfigurationLabels.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ meters.label=Metri
1515
ppm.label=ppm
1616
nounits=
1717

18-
samplingProtocol0.label = stima personale
19-
samplingProtocol1.label = stima della guida / del ricercatore
20-
samplingProtocol2.label = misurato direttamente
18+
samplingProtocol0.label = misurato direttamente
19+
samplingProtocol1.label = stima personale
20+
samplingProtocol2.label = stima della guida / del ricercatore
2121

2222
left.label = Sinistra
2323
right.label = Destra

0 commit comments

Comments
 (0)