submission form cleanup
This commit is contained in:
parent
d44d8448e7
commit
1156984fa6
3 changed files with 112 additions and 49 deletions
|
|
@ -92,9 +92,13 @@ export default function CO2GalvoDetail({ id, editable }: { id: string | number;
|
|||
const j = t ? JSON.parse(t) : null;
|
||||
const idVal = j?.data?.id ?? j?.id ?? null;
|
||||
if (alive) setMeId(idVal ? String(idVal) : null);
|
||||
} catch { /* ignore */ }
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
})();
|
||||
return () => { alive = false; };
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
|
|
@ -170,7 +174,9 @@ export default function CO2GalvoDetail({ id, editable }: { id: string | number;
|
|||
if (!dead) setLoading(false);
|
||||
}
|
||||
})();
|
||||
return () => { dead = true; };
|
||||
return () => {
|
||||
dead = true;
|
||||
};
|
||||
}, [id]);
|
||||
|
||||
if (loading) return <p className="p-6">Loading setting…</p>;
|
||||
|
|
@ -197,9 +203,16 @@ export default function CO2GalvoDetail({ id, editable }: { id: string | number;
|
|||
const isMine = meId && ownerId ? meId === ownerId : false;
|
||||
|
||||
// Small field renderer (label on top, value below)
|
||||
const Field = ({ label, value, suffix }: { label: string; value: React.ReactNode | string | number | null | undefined; suffix?: string }) => {
|
||||
const primitive =
|
||||
typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
||||
const Field = ({
|
||||
label,
|
||||
value,
|
||||
suffix,
|
||||
}: {
|
||||
label: string;
|
||||
value: React.ReactNode | string | number | null | undefined;
|
||||
suffix?: string;
|
||||
}) => {
|
||||
const primitive = typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
||||
const isEmpty = value == null || value === "" || (typeof value === "number" && isNaN(value as number));
|
||||
|
||||
return (
|
||||
|
|
@ -240,10 +253,19 @@ export default function CO2GalvoDetail({ id, editable }: { id: string | number;
|
|||
};
|
||||
const DITHER_LABEL = (v: string | undefined) => (v ? v.charAt(0).toUpperCase() + v.slice(1) : "—");
|
||||
|
||||
const asNumOrNull = (v: any): number | null => {
|
||||
if (typeof v === "number") return Number.isFinite(v) ? v : null;
|
||||
if (typeof v === "string" && v.trim() !== "") {
|
||||
const n = Number(v);
|
||||
return Number.isFinite(n) ? n : null;
|
||||
}
|
||||
// treat booleans/objects as null for numeric-only display
|
||||
return null;
|
||||
};
|
||||
|
||||
// ----- EDIT MODE -----
|
||||
if (editMode && rec) {
|
||||
const toId = (v: any) =>
|
||||
v == null ? "" : typeof v === "object" ? (v.id ?? v.submission_id ?? "") : String(v);
|
||||
const toId = (v: any) => (v == null ? "" : typeof v === "object" ? (v.id ?? v.submission_id ?? "") : String(v));
|
||||
|
||||
const initialValues = {
|
||||
submission_id: rec.submission_id,
|
||||
|
|
@ -307,9 +329,7 @@ export default function CO2GalvoDetail({ id, editable }: { id: string | number;
|
|||
<div className="grid gap-3">
|
||||
<Field label="Owner" value={ownerLabel(rec.owner)} />
|
||||
<Field label="Uploader" value={rec.uploader || "—"} />
|
||||
{rec.setting_notes ? (
|
||||
<Field label="Notes" value={<p className="whitespace-pre-wrap">{rec.setting_notes}</p>} />
|
||||
) : null}
|
||||
{rec.setting_notes ? <Field label="Notes" value={<p className="whitespace-pre-wrap">{rec.setting_notes}</p>} /> : null}
|
||||
</div>
|
||||
|
||||
{/* Images (side-by-side thumbnails) */}
|
||||
|
|
@ -356,11 +376,7 @@ export default function CO2GalvoDetail({ id, editable }: { id: string | number;
|
|||
<Field label="Beam Expander" value={optLabel(rec.lens_exp)} suffix="x" />
|
||||
<Field
|
||||
label="Scan Lens"
|
||||
value={
|
||||
rec.lens
|
||||
? `${rec.lens.field_size ?? "—"}${rec.lens.focal_length ? ` / ${rec.lens.focal_length}` : ""}`
|
||||
: "—"
|
||||
}
|
||||
value={rec.lens ? `${rec.lens.field_size ?? "—"}${rec.lens.focal_length ? ` / ${rec.lens.focal_length}` : ""}` : "—"}
|
||||
/>
|
||||
<Field label="Focus" value={rec.focus ?? "—"} suffix="mm" />
|
||||
<Field label="Repeat All" value={rec.repeat_all ?? "—"} />
|
||||
|
|
@ -396,9 +412,9 @@ export default function CO2GalvoDetail({ id, editable }: { id: string | number;
|
|||
<Field label="Speed" value={r.speed ?? "—"} suffix="mm/s" />
|
||||
<Field label="Interval" value={r.interval ?? "—"} suffix="mm" />
|
||||
<Field label="Angle" value={r.angle ?? "—"} suffix="°" />
|
||||
<Field label="Pass" value={r.pass ?? "—"} />
|
||||
<Field label="Passes" value={r.pass ?? "—"} />
|
||||
<Field label="Frequency" value={r.frequency ?? "—"} suffix="kHz" />
|
||||
<Field label="Pulse" value={r.pulse ?? "—"} suffix="ns" />
|
||||
{/* Pulse removed for CO2 */}
|
||||
</div>
|
||||
|
||||
<div className="grid sm:grid-cols-2 gap-2 items-center">
|
||||
|
|
@ -425,31 +441,35 @@ export default function CO2GalvoDetail({ id, editable }: { id: string | number;
|
|||
{rec.line_settings!.map((r: any, i: number) => {
|
||||
const perfEnabled = !!r.perf;
|
||||
const wobbleEnabled = !!r.wobble;
|
||||
const cutVal = asNumOrNull(r.cut);
|
||||
const skipVal = asNumOrNull(r.skip);
|
||||
const stepVal = asNumOrNull(r.step);
|
||||
const sizeVal = asNumOrNull(r.size);
|
||||
|
||||
return (
|
||||
<div key={i} className="border rounded p-3 space-y-2">
|
||||
<div className="font-medium">{r.name || `Line ${i + 1}`}</div>
|
||||
|
||||
{/* Base fields – match form order */}
|
||||
{/* Base fields – match form order (Pulse removed) */}
|
||||
<div className="grid sm:grid-cols-2 gap-2">
|
||||
<Field label="Frequency" value={r.frequency ?? "—"} suffix="kHz" />
|
||||
<Field label="Pulse" value={r.pulse ?? "—"} suffix="ns" />
|
||||
<Field label="Power" value={r.power ?? "—"} suffix="%" />
|
||||
<Field label="Speed" value={r.speed ?? "—"} suffix="mm/s" />
|
||||
<Field label="Pass" value={r.pass ?? "—"} />
|
||||
<Field label="Passes" value={r.pass ?? "—"} />
|
||||
</div>
|
||||
|
||||
{/* Perforation row */}
|
||||
<div className="grid sm:grid-cols-3 gap-2 items-center">
|
||||
<Field label="Perforation Mode" value={yesNo(perfEnabled)} />
|
||||
{perfEnabled && <Field label="Cut" value={r.cut ?? "—"} suffix="mm" />}
|
||||
{perfEnabled && <Field label="Skip" value={r.skip ?? "—"} suffix="mm" />}
|
||||
{perfEnabled && <Field label="Cut" value={cutVal ?? "—"} suffix="mm" />}
|
||||
{perfEnabled && <Field label="Skip" value={skipVal ?? "—"} suffix="mm" />}
|
||||
</div>
|
||||
|
||||
{/* Wobble row */}
|
||||
<div className="grid sm:grid-cols-3 gap-2 items-center">
|
||||
<Field label="Wobble" value={yesNo(wobbleEnabled)} />
|
||||
{wobbleEnabled && <Field label="Step" value={r.step ?? "—"} suffix="mm" />}
|
||||
{wobbleEnabled && <Field label="Size" value={r.size ?? "—"} suffix="mm" />}
|
||||
{wobbleEnabled && <Field label="Step" value={stepVal ?? "—"} suffix="mm" />}
|
||||
{wobbleEnabled && <Field label="Size" value={sizeVal ?? "—"} suffix="mm" />}
|
||||
</div>
|
||||
|
||||
{/* Simple toggle */}
|
||||
|
|
@ -478,9 +498,9 @@ export default function CO2GalvoDetail({ id, editable }: { id: string | number;
|
|||
<Field label="Power" value={r.power ?? "—"} suffix="%" />
|
||||
<Field label="Speed" value={r.speed ?? "—"} suffix="mm/s" />
|
||||
<Field label="Interval" value={r.interval ?? "—"} suffix="mm" />
|
||||
<Field label="Pass" value={r.pass ?? "—"} />
|
||||
<Field label="Passes" value={r.pass ?? "—"} />
|
||||
<Field label="Frequency" value={r.frequency ?? "—"} suffix="kHz" />
|
||||
<Field label="Pulse" value={r.pulse ?? "—"} suffix="ns" />
|
||||
{/* Pulse removed for CO2 */}
|
||||
{isHalftone && <Field label="Halftone Cell" value={r.halftone_cell ?? "—"} />}
|
||||
{isHalftone && <Field label="Halftone Angle" value={r.halftone_angle ?? "—"} />}
|
||||
<Field label="Dot Width Adjustment" value={r.dot ?? "—"} suffix="mm" />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue