Client: Better locale comma support
This commit is contained in:
@@ -4,6 +4,7 @@ import { Create, useForm, useSelect } from "@refinedev/antd";
|
||||
import { Form, Input, Select, InputNumber, ColorPicker } from "antd";
|
||||
import TextArea from "antd/es/input/TextArea";
|
||||
import { IVendor } from "../vendors/model";
|
||||
import { numberFormatter, numberParser } from "../../utils/parsing";
|
||||
|
||||
interface CreateOrCloneProps {
|
||||
mode: "create" | "clone";
|
||||
@@ -90,7 +91,12 @@ export const FilamentCreate: React.FC<
|
||||
},
|
||||
]}
|
||||
>
|
||||
<InputNumber min={0} />
|
||||
<InputNumber
|
||||
min={0}
|
||||
precision={2}
|
||||
formatter={numberFormatter}
|
||||
parser={numberParser}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="Density"
|
||||
@@ -101,7 +107,13 @@ export const FilamentCreate: React.FC<
|
||||
},
|
||||
]}
|
||||
>
|
||||
<InputNumber min={0} addonAfter="g/cm³" />
|
||||
<InputNumber
|
||||
min={0}
|
||||
addonAfter="g/cm³"
|
||||
precision={3}
|
||||
formatter={numberFormatter}
|
||||
parser={numberParser}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="Diameter"
|
||||
@@ -112,7 +124,13 @@ export const FilamentCreate: React.FC<
|
||||
},
|
||||
]}
|
||||
>
|
||||
<InputNumber min={0} addonAfter="mm" />
|
||||
<InputNumber
|
||||
min={0}
|
||||
addonAfter="mm"
|
||||
precision={2}
|
||||
formatter={numberFormatter}
|
||||
parser={numberParser}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="Weight"
|
||||
@@ -124,7 +142,7 @@ export const FilamentCreate: React.FC<
|
||||
},
|
||||
]}
|
||||
>
|
||||
<InputNumber min={0} addonAfter="g" />
|
||||
<InputNumber min={0} addonAfter="g" precision={0} />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="Spool Weight"
|
||||
@@ -136,7 +154,7 @@ export const FilamentCreate: React.FC<
|
||||
},
|
||||
]}
|
||||
>
|
||||
<InputNumber min={0} addonAfter="g" />
|
||||
<InputNumber min={0} addonAfter="g" precision={0} />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="Override Extruder Temperature"
|
||||
@@ -148,7 +166,7 @@ export const FilamentCreate: React.FC<
|
||||
},
|
||||
]}
|
||||
>
|
||||
<InputNumber min={0} addonAfter="°C" />
|
||||
<InputNumber min={0} addonAfter="°C" precision={0} />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="Override Bed Temperature"
|
||||
@@ -160,7 +178,7 @@ export const FilamentCreate: React.FC<
|
||||
},
|
||||
]}
|
||||
>
|
||||
<InputNumber min={0} addonAfter="°C" />
|
||||
<InputNumber min={0} addonAfter="°C" precision={0} />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="Article Number"
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
import dayjs from "dayjs";
|
||||
import TextArea from "antd/es/input/TextArea";
|
||||
import { IVendor } from "../vendors/model";
|
||||
import { numberFormatter, numberParser } from "../../utils/parsing";
|
||||
|
||||
export const FilamentEdit: React.FC<IResourceComponentsProps> = () => {
|
||||
const { formProps, saveButtonProps } = useForm();
|
||||
@@ -120,7 +121,12 @@ export const FilamentEdit: React.FC<IResourceComponentsProps> = () => {
|
||||
},
|
||||
]}
|
||||
>
|
||||
<InputNumber min={0} />
|
||||
<InputNumber
|
||||
min={0}
|
||||
precision={2}
|
||||
formatter={numberFormatter}
|
||||
parser={numberParser}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="Density"
|
||||
@@ -131,7 +137,13 @@ export const FilamentEdit: React.FC<IResourceComponentsProps> = () => {
|
||||
},
|
||||
]}
|
||||
>
|
||||
<InputNumber min={0} addonAfter="g/cm³" />
|
||||
<InputNumber
|
||||
min={0}
|
||||
addonAfter="g/cm³"
|
||||
precision={3}
|
||||
formatter={numberFormatter}
|
||||
parser={numberParser}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="Diameter"
|
||||
@@ -142,7 +154,13 @@ export const FilamentEdit: React.FC<IResourceComponentsProps> = () => {
|
||||
},
|
||||
]}
|
||||
>
|
||||
<InputNumber min={0} addonAfter="mm" />
|
||||
<InputNumber
|
||||
min={0}
|
||||
addonAfter="mm"
|
||||
precision={2}
|
||||
formatter={numberFormatter}
|
||||
parser={numberParser}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="Weight"
|
||||
@@ -154,7 +172,7 @@ export const FilamentEdit: React.FC<IResourceComponentsProps> = () => {
|
||||
},
|
||||
]}
|
||||
>
|
||||
<InputNumber min={0} addonAfter="g" />
|
||||
<InputNumber min={0} addonAfter="g" precision={0} />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="Spool Weight"
|
||||
@@ -166,7 +184,7 @@ export const FilamentEdit: React.FC<IResourceComponentsProps> = () => {
|
||||
},
|
||||
]}
|
||||
>
|
||||
<InputNumber min={0} addonAfter="g" />
|
||||
<InputNumber min={0} addonAfter="g" precision={0} />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="Override Extruder Temperature"
|
||||
@@ -178,7 +196,7 @@ export const FilamentEdit: React.FC<IResourceComponentsProps> = () => {
|
||||
},
|
||||
]}
|
||||
>
|
||||
<InputNumber min={0} addonAfter="°C" />
|
||||
<InputNumber min={0} addonAfter="°C" precision={0} />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="Override Bed Temperature"
|
||||
@@ -190,7 +208,7 @@ export const FilamentEdit: React.FC<IResourceComponentsProps> = () => {
|
||||
},
|
||||
]}
|
||||
>
|
||||
<InputNumber min={0} addonAfter="°C" />
|
||||
<InputNumber min={0} addonAfter="°C" precision={0} />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="Article Number"
|
||||
|
||||
@@ -98,7 +98,7 @@ export const SpoolCreate: React.FC<
|
||||
},
|
||||
]}
|
||||
>
|
||||
<InputNumber min={0} addonAfter="g" />
|
||||
<InputNumber min={0} addonAfter="g" precision={0} />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="Location"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React from "react";
|
||||
import { IResourceComponentsProps } from "@refinedev/core";
|
||||
import { Edit, useForm, useSelect } from "@refinedev/antd";
|
||||
import { Form, Input, DatePicker, Select } from "antd";
|
||||
import { Form, Input, DatePicker, Select, InputNumber } from "antd";
|
||||
import dayjs from "dayjs";
|
||||
import TextArea from "antd/es/input/TextArea";
|
||||
import { IFilament } from "../filaments/model";
|
||||
@@ -108,7 +108,10 @@ export const SpoolEdit: React.FC<IResourceComponentsProps> = () => {
|
||||
},
|
||||
]}
|
||||
>
|
||||
<Input min={0} addonAfter="g" />
|
||||
<InputNumber min={0} addonAfter="g" precision={0} />
|
||||
{/* TODO: Allow higher precision here.
|
||||
However, that requires that we can handle the , -> . replacement in the number parser
|
||||
more elegantly for locales which use , as a thousands separator. */}
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="Location"
|
||||
|
||||
10
client/src/utils/parsing.ts
Normal file
10
client/src/utils/parsing.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
// Number formatter that nicely formats numbers with correct decimal separator
|
||||
export function numberFormatter(value: number | undefined) {
|
||||
return value ? Number(value).toLocaleString() : "";
|
||||
}
|
||||
|
||||
// Number parser that supports both comma and dot as decimal separator
|
||||
export function numberParser(value: string | undefined) {
|
||||
return Number(value?.replace(",", ".") ?? 0);
|
||||
}
|
||||
Reference in New Issue
Block a user