feat: Add smart density defaults based on material type (#2)
Some checks failed
CI / style (push) Has been cancelled
CI / build-client (push) Has been cancelled
CI / build-amd64 (push) Has been cancelled
CI / build-tester (push) Has been cancelled
CI / test (cockroachdb) (push) Has been cancelled
CI / test (mariadb) (push) Has been cancelled
CI / test (postgres) (push) Has been cancelled
CI / test (sqlite) (push) Has been cancelled
CI / build-arm64 (push) Has been cancelled
CI / build-armv7 (push) Has been cancelled
CI / publish-images (push) Has been cancelled
CI / publish-release (push) Has been cancelled

Auto-fill density when entering material type in filament forms:
- Add materialDefaults.ts with standard densities for common materials
  (PLA, ABS, PETG, TPU, PC, etc.)
- Material field now uses AutoComplete with suggestions
- Density auto-fills on material select or blur (fuzzy matching)
- New filaments default to 1.75mm diameter and 1.24 g/cm³ (PLA)
- Applied to both full filament create page and quick create modal

Reduces tedious data entry for common materials while still allowing
custom values for specialty filaments.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-14 19:54:30 -06:00
parent 27d85eb479
commit 478806dcc8
4 changed files with 162 additions and 11 deletions

View File

@@ -1,11 +1,17 @@
import { useSelect } from "@refinedev/antd";
import { useInvalidate, useTranslate } from "@refinedev/core";
import { Button, ColorPicker, Divider, Form, Input, InputNumber, Modal, Select, message } from "antd";
import { AutoComplete, Button, ColorPicker, Divider, Form, Input, InputNumber, Modal, Select, message } from "antd";
import { PlusOutlined } from "@ant-design/icons";
import { useState } from "react";
import { useMemo, useState } from "react";
import { Color } from "antd/es/color-picker";
import { IFilament } from "../pages/filaments/model";
import { IVendor } from "../pages/vendors/model";
import {
DEFAULT_DENSITY,
DEFAULT_DIAMETER,
getDensityForMaterial,
KNOWN_MATERIALS,
} from "../utils/materialDefaults";
import { getAPIURL } from "../utils/url";
import { VendorCreateModal } from "./vendorCreateModal";
@@ -15,10 +21,6 @@ export interface FilamentCreateModalProps {
onClose: () => void;
}
// Default values for common filament properties
const DEFAULT_DIAMETER = 1.75;
const DEFAULT_DENSITY = 1.24; // PLA
/**
* Modal for quickly creating a filament inline without navigating away from the current page.
* Includes essential fields and the ability to create a vendor inline.
@@ -29,6 +31,23 @@ export function FilamentCreateModal(props: FilamentCreateModalProps) {
const invalidate = useInvalidate();
const [isSubmitting, setIsSubmitting] = useState(false);
const [isVendorModalOpen, setIsVendorModalOpen] = useState(false);
const [materialSearch, setMaterialSearch] = useState("");
// Material options for AutoComplete
const materialOptions = useMemo(() => {
const filtered = materialSearch
? KNOWN_MATERIALS.filter((m) => m.toLowerCase().includes(materialSearch.toLowerCase()))
: KNOWN_MATERIALS;
return filtered.map((material) => ({ value: material, label: material }));
}, [materialSearch]);
// Auto-fill density when material is selected or entered
const handleMaterialChange = (value: string) => {
const density = getDensityForMaterial(value);
if (density !== undefined) {
form.setFieldValue("density", density);
}
};
// Vendor select
const { selectProps: vendorSelectProps } = useSelect<IVendor>({
@@ -171,7 +190,14 @@ export function FilamentCreateModal(props: FilamentCreateModalProps) {
label={t("filament.fields.material")}
name="material"
>
<Input maxLength={64} placeholder="PLA, PETG, ABS, etc." />
<AutoComplete
options={materialOptions}
onSearch={setMaterialSearch}
onSelect={handleMaterialChange}
onBlur={(e) => handleMaterialChange((e.target as HTMLInputElement).value)}
placeholder={t("filament.form.material_placeholder")}
maxLength={64}
/>
</Form.Item>
<Form.Item