feat: Add quick wins batch (#42, #43, #25, #35, #20, #36, #39)
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
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
- #42: Allow spools heavier than theoretical max (remove weight clamps) - #43: Show filament custom fields on spool detail page - #25: Sort spools by custom fields and remaining weight - #35: Global search box for spool list - #20: Gallery view for spools (color grid with progress bars) - #36: Spool-level color override with ColorPicker - #39: Cost analytics endpoint, total spent & avg cost/kg stats - Fix: Filament select refresh after inline creation - Fix: Parse temperatures from filament comments Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { LeftOutlined, RightOutlined } from "@ant-design/icons";
|
||||
import { LeftOutlined, RightOutlined, ThunderboltOutlined } from "@ant-design/icons";
|
||||
import { Edit, useForm, useSelect } from "@refinedev/antd";
|
||||
import { HttpError, IResourceComponentsProps, useList, useTranslate } from "@refinedev/core";
|
||||
import { Alert, Button, ColorPicker, DatePicker, Form, Input, InputNumber, message, Radio, Select, Space, Typography } from "antd";
|
||||
@@ -14,6 +14,54 @@ import { getCurrencySymbol, useCurrency } from "../../utils/settings";
|
||||
import { IVendor } from "../vendors/model";
|
||||
import { IFilament, IFilamentParsedExtras } from "./model";
|
||||
|
||||
/**
|
||||
* Parse temperature ranges from a comment string.
|
||||
* Handles patterns like:
|
||||
* "extrude 190-230 / bed 50-70"
|
||||
* "nozzle: 200-220°C, bed: 60-70°C"
|
||||
* "hotend 200 bed 60"
|
||||
*/
|
||||
function parseTempsFromComment(comment: string): {
|
||||
extruderMin?: number;
|
||||
extruderMax?: number;
|
||||
bedMin?: number;
|
||||
bedMax?: number;
|
||||
} {
|
||||
const result: { extruderMin?: number; extruderMax?: number; bedMin?: number; bedMax?: number } = {};
|
||||
|
||||
// Patterns for extruder temperature
|
||||
const extruderPatterns = [
|
||||
/(?:extrud(?:e|er)|nozzle|hotend|print\s*temp)[:\s]*(\d{2,3})\s*[-–~to]+\s*(\d{2,3})/i,
|
||||
/(?:extrud(?:e|er)|nozzle|hotend|print\s*temp)[:\s]*(\d{2,3})\s*°?C?/i,
|
||||
];
|
||||
|
||||
// Patterns for bed temperature
|
||||
const bedPatterns = [
|
||||
/(?:bed|plate|build\s*plate)[:\s]*(\d{2,3})\s*[-–~to]+\s*(\d{2,3})/i,
|
||||
/(?:bed|plate|build\s*plate)[:\s]*(\d{2,3})\s*°?C?/i,
|
||||
];
|
||||
|
||||
for (const pattern of extruderPatterns) {
|
||||
const match = comment.match(pattern);
|
||||
if (match) {
|
||||
result.extruderMin = parseInt(match[1]);
|
||||
result.extruderMax = match[2] ? parseInt(match[2]) : parseInt(match[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (const pattern of bedPatterns) {
|
||||
const match = comment.match(pattern);
|
||||
if (match) {
|
||||
result.bedMin = parseInt(match[1]);
|
||||
result.bedMax = match[2] ? parseInt(match[2]) : parseInt(match[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
The API returns the extra fields as JSON values, but we need to parse them into their real types
|
||||
in order for Ant design's form to work properly. ParsedExtras does this for us.
|
||||
@@ -37,7 +85,7 @@ export const FilamentEdit: React.FC<IResourceComponentsProps> = () => {
|
||||
sorters: [{ field: "id", order: "asc" }],
|
||||
});
|
||||
|
||||
const { formProps, saveButtonProps, id } = useForm<IFilament, HttpError, IFilament, IFilament>({
|
||||
const { formProps, saveButtonProps, id, form } = useForm<IFilament, HttpError, IFilament, IFilament>({
|
||||
liveMode: "manual",
|
||||
onLiveEvent() {
|
||||
// Warn the user if the filament has been updated since the form was opened
|
||||
@@ -330,6 +378,29 @@ export const FilamentEdit: React.FC<IResourceComponentsProps> = () => {
|
||||
>
|
||||
<InputNumber addonAfter="g" precision={1} />
|
||||
</Form.Item>
|
||||
<div style={{ marginBottom: 16 }}>
|
||||
<Button
|
||||
size="small"
|
||||
icon={<ThunderboltOutlined />}
|
||||
onClick={() => {
|
||||
const comment = form.getFieldValue("comment") || "";
|
||||
const temps = parseTempsFromComment(comment);
|
||||
if (!temps.extruderMin && !temps.bedMin) {
|
||||
messageApi.warning(t("filament.form.no_temps_found"));
|
||||
return;
|
||||
}
|
||||
const fields: Record<string, number | undefined> = {};
|
||||
if (temps.extruderMin) fields.settings_extruder_temp_min = temps.extruderMin;
|
||||
if (temps.extruderMax) fields.settings_extruder_temp_max = temps.extruderMax;
|
||||
if (temps.bedMin) fields.settings_bed_temp_min = temps.bedMin;
|
||||
if (temps.bedMax) fields.settings_bed_temp_max = temps.bedMax;
|
||||
form.setFieldsValue(fields);
|
||||
messageApi.success(t("filament.form.temps_parsed"));
|
||||
}}
|
||||
>
|
||||
{t("filament.form.parse_temps")}
|
||||
</Button>
|
||||
</div>
|
||||
<Form.Item label={t("filament.fields.settings_extruder_temp")}>
|
||||
<Space.Compact>
|
||||
<Form.Item
|
||||
|
||||
Reference in New Issue
Block a user