reformat
This commit is contained in:
@@ -50,7 +50,7 @@ export const SpoolCreate: React.FC<IResourceComponentsProps & CreateOrCloneProps
|
|||||||
label: label,
|
label: label,
|
||||||
value: item.id,
|
value: item.id,
|
||||||
weight: item.weight,
|
weight: item.weight,
|
||||||
spool_weight: item.spool_weight
|
spool_weight: item.spool_weight,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
filamentOptions?.sort((a, b) => a.label.localeCompare(b.label, undefined, { sensitivity: "base" }));
|
filamentOptions?.sort((a, b) => a.label.localeCompare(b.label, undefined, { sensitivity: "base" }));
|
||||||
@@ -58,8 +58,8 @@ export const SpoolCreate: React.FC<IResourceComponentsProps & CreateOrCloneProps
|
|||||||
const [weightToEnter, setWeightToEnter] = useState(1);
|
const [weightToEnter, setWeightToEnter] = useState(1);
|
||||||
const [usedWeight, setUsedWeight] = useState(0);
|
const [usedWeight, setUsedWeight] = useState(0);
|
||||||
|
|
||||||
const selectedFilamentID = Form.useWatch('filament_id', form);
|
const selectedFilamentID = Form.useWatch("filament_id", form);
|
||||||
const selectedFilament = filamentOptions?.find(obj => {
|
const selectedFilament = filamentOptions?.find((obj) => {
|
||||||
return obj.value === selectedFilamentID;
|
return obj.value === selectedFilamentID;
|
||||||
});
|
});
|
||||||
const filamentWeight = selectedFilament?.weight || 0;
|
const filamentWeight = selectedFilament?.weight || 0;
|
||||||
@@ -82,11 +82,10 @@ export const SpoolCreate: React.FC<IResourceComponentsProps & CreateOrCloneProps
|
|||||||
|
|
||||||
const weightChange = (weight: number) => {
|
const weightChange = (weight: number) => {
|
||||||
setUsedWeight(weight);
|
setUsedWeight(weight);
|
||||||
form.setFieldsValue(
|
form.setFieldsValue({
|
||||||
{
|
used_weight: weight,
|
||||||
used_weight: weight
|
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Create
|
<Create
|
||||||
@@ -144,14 +143,8 @@ export const SpoolCreate: React.FC<IResourceComponentsProps & CreateOrCloneProps
|
|||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
<Form.Item
|
<Form.Item hidden={true} name={["used_weight"]} initialValue={0}>
|
||||||
hidden={true}
|
<InputNumber value={usedWeight} />
|
||||||
name={["used_weight"]}
|
|
||||||
initialValue={0}
|
|
||||||
>
|
|
||||||
<InputNumber
|
|
||||||
value={usedWeight}
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
<Form.Item label={t("spool.fields.weight_to_use")} help={t("spool.fields_help.weight_to_use")}>
|
<Form.Item label={t("spool.fields.weight_to_use")} help={t("spool.fields_help.weight_to_use")}>
|
||||||
@@ -162,9 +155,23 @@ export const SpoolCreate: React.FC<IResourceComponentsProps & CreateOrCloneProps
|
|||||||
defaultValue={1}
|
defaultValue={1}
|
||||||
value={weightToEnter}
|
value={weightToEnter}
|
||||||
>
|
>
|
||||||
<Radio.Button value={1}>{t("spool.fields.used_weight")}</Radio.Button>
|
<Radio.Button
|
||||||
<Radio.Button value={2} disabled={!filamentWeight}>{t("spool.fields.remaining_weight")}</Radio.Button>
|
value={1}
|
||||||
<Radio.Button value={3} disabled={!(filamentWeight && spoolWeight)}>{t("spool.fields.measured_weight")}</Radio.Button>
|
>
|
||||||
|
{t("spool.fields.used_weight")}
|
||||||
|
</Radio.Button>
|
||||||
|
<Radio.Button
|
||||||
|
value={2}
|
||||||
|
disabled={!filamentWeight}
|
||||||
|
>
|
||||||
|
{t("spool.fields.remaining_weight")}
|
||||||
|
</Radio.Button>
|
||||||
|
<Radio.Button
|
||||||
|
value={3}
|
||||||
|
disabled={!(filamentWeight && spoolWeight)}
|
||||||
|
>
|
||||||
|
{t("spool.fields.measured_weight")}
|
||||||
|
</Radio.Button>
|
||||||
</Radio.Group>
|
</Radio.Group>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
@@ -219,7 +226,7 @@ export const SpoolCreate: React.FC<IResourceComponentsProps & CreateOrCloneProps
|
|||||||
formatter={numberFormatter}
|
formatter={numberFormatter}
|
||||||
parser={numberParser}
|
parser={numberParser}
|
||||||
disabled={weightToEnter != 3}
|
disabled={weightToEnter != 3}
|
||||||
value={(filamentWeight && spoolWeight) ? filamentWeight - usedWeight + spoolWeight : 0}
|
value={filamentWeight && spoolWeight ? filamentWeight - usedWeight + spoolWeight : 0}
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
weightChange(filamentWeight - ((value ?? 0) - spoolWeight));
|
weightChange(filamentWeight - ((value ?? 0) - spoolWeight));
|
||||||
}}
|
}}
|
||||||
|
|||||||
Reference in New Issue
Block a user