Skip to content

Commit 6cc2d91

Browse files
authored
Fix class id input to only allow integers (#125)
AC-353
1 parent 9a64f0a commit 6cc2d91

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

public/locales/en/messages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@
6464
"Choose the geographic layers used to generate the friction surface.": "Choose the geographic layers used to generate the friction surface.",
6565
"Choose the health facilities layer.": "Choose the health facilities layer.",
6666
"Class": "Class",
67+
"Class id": "Class id",
6768
"Class label": "Class label",
6869
"Class labels": "Class labels",
69-
"Class value": "Class value",
7070
"Close": "Close",
7171
"Computation failed. Check your input data.": "Computation failed. Check your input data.",
7272
"Configure your project": "Configure your project",

public/locales/fr/messages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@
6767
"Choose the geographic layers used to generate the friction surface.": "",
6868
"Choose the health facilities layer.": "",
6969
"Class": "",
70+
"Class id": "",
7071
"Class label": "",
7172
"Class labels": "",
72-
"Class value": "",
7373
"Close": "",
7474
"Computation failed. Check your input data.": "",
7575
"Configure your project": "",

src/features/dataset/ClassLabelsGrid.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,29 @@ const ClassLabelsGrid = ({ labels, editable, onChange }: Props) => {
8080
return cols;
8181
}, [labels, onChange, t, editable]);
8282

83-
const onAddItem = useCallback(() => {
84-
if (!classInputRef.current?.value || !editable) return;
83+
const onAddItem = () => {
84+
if (
85+
!classInputRef.current?.value ||
86+
!editable ||
87+
!classInputRef.current?.checkValidity()
88+
) {
89+
return;
90+
}
8591
onChange([[classInputRef.current.value, ""], ...labels]);
8692
classInputRef.current.value = "";
87-
}, [classInputRef, labels, onChange, editable]);
93+
};
8894

8995
return (
9096
<div>
9197
{editable && (
9298
<div className="mb-1 flex items-center gap-2">
9399
<Input
94100
ref={classInputRef}
95-
placeholder={t("Class value")}
101+
placeholder={t("Class id")}
102+
min={0}
103+
step={1}
104+
required
105+
pattern="\d*"
96106
type="number"
97107
/>
98108
<Button variant="secondary" onClick={onAddItem}>

0 commit comments

Comments
 (0)