cut,skip fix plus owner fix for view page
This commit is contained in:
parent
1156984fa6
commit
12dd2c6c06
2 changed files with 21 additions and 19 deletions
|
|
@ -1,7 +1,7 @@
|
|||
// components/details/CO2GalvoDetail.tsx
|
||||
"use client";
|
||||
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import SettingsSubmit from "@/components/forms/SettingsSubmit";
|
||||
|
||||
|
|
@ -82,6 +82,16 @@ export default function CO2GalvoDetail({ id, editable }: { id: string | number;
|
|||
return "—";
|
||||
};
|
||||
|
||||
// numeric helper (treat booleans/objects as null)
|
||||
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;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
// fetch me id
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
|
|
@ -253,16 +263,6 @@ 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));
|
||||
|
|
@ -281,7 +281,8 @@ export default function CO2GalvoDetail({ id, editable }: { id: string | number;
|
|||
mat_thickness: rec.mat_thickness ?? null,
|
||||
// Rig & Optics
|
||||
laser_soft: typeof rec.laser_soft === "object" ? String(rec.laser_soft?.id ?? "") : String(rec.laser_soft ?? "") || "",
|
||||
source: rec.source && typeof rec.source === "object" ? String(rec.source.submission_id ?? "") : String(rec.source ?? "") || "",
|
||||
source:
|
||||
rec.source && typeof rec.source === "object" ? String(rec.source.submission_id ?? "") : String(rec.source ?? "") || "",
|
||||
lens: toId(rec.lens) || "",
|
||||
focus: rec.focus ?? null,
|
||||
// CO2 triplet
|
||||
|
|
@ -441,8 +442,8 @@ 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 cutVal = asNumOrNull(r.cut ?? r.perf_cut ?? r.cut_length);
|
||||
const skipVal = asNumOrNull(r.skip ?? r.perf_skip ?? r.skip_length);
|
||||
const stepVal = asNumOrNull(r.step);
|
||||
const sizeVal = asNumOrNull(r.size);
|
||||
|
||||
|
|
@ -450,7 +451,7 @@ export default function CO2GalvoDetail({ id, editable }: { id: string | number;
|
|||
<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 (Pulse removed) */}
|
||||
{/* Base fields – Pulse removed for CO2 */}
|
||||
<div className="grid sm:grid-cols-2 gap-2">
|
||||
<Field label="Frequency" value={r.frequency ?? "—"} suffix="kHz" />
|
||||
<Field label="Power" value={r.power ?? "—"} suffix="%" />
|
||||
|
|
|
|||
|
|
@ -28,8 +28,6 @@ type Row = {
|
|||
lens?: { field_size?: string | number | null } | null;
|
||||
};
|
||||
|
||||
const API = (process.env.NEXT_PUBLIC_API_BASE_URL || "").replace(/\/$/, "");
|
||||
|
||||
async function readJson(r: Response) {
|
||||
const t = await r.text();
|
||||
try {
|
||||
|
|
@ -82,16 +80,19 @@ export default function CO2GalvoList({
|
|||
const fields = [
|
||||
"submission_id",
|
||||
"setting_title",
|
||||
// IMPORTANT: request the expanded relation only (do NOT include bare 'owner' id)
|
||||
"owner.id",
|
||||
"owner.username",
|
||||
"owner.first_name",
|
||||
"owner.last_name",
|
||||
"owner.email",
|
||||
"uploader",
|
||||
"mat.name",
|
||||
"mat_coat.name",
|
||||
"source.model",
|
||||
"lens.field_size",
|
||||
].join(",");
|
||||
const url = `${API}/items/settings_co2gal?fields=${encodeURIComponent(fields)}&limit=-1`;
|
||||
// Use the same proxy as Details so relation expansion & auth match
|
||||
const url = `/api/dx/items/settings_co2gal?fields=${encodeURIComponent(fields)}&limit=-1`;
|
||||
const r = await fetch(url, { credentials: "include", cache: "no-store" });
|
||||
if (!r.ok) {
|
||||
const j = await readJson(r);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue