co2 galvo owner test

This commit is contained in:
makearmy 2025-10-01 20:00:26 -04:00
parent 715be11ff9
commit a38aa4c2f9
5 changed files with 254 additions and 236 deletions

View file

@ -20,7 +20,6 @@ export default function CO2GalvoSettingDetailPage() {
"submission_id",
"setting_title",
"uploader",
// make sure owner expands
"owner.id",
"owner.username",
"setting_notes",
@ -41,7 +40,6 @@ export default function CO2GalvoSettingDetailPage() {
"lens_apt.name",
"lens_exp.name",
"focus",
// string-or-relation
"laser_soft",
"laser_soft.name",
"repeat_all",
@ -50,7 +48,8 @@ export default function CO2GalvoSettingDetailPage() {
"raster_settings",
].join(",");
const url = `/api/dx/items/settings_co2gal/${encodeURIComponent(String(id))}` +
const url =
`/api/dx/items/settings_co2gal/${encodeURIComponent(String(id))}` +
`?fields=${encodeURIComponent(fields)}`;
setLoading(true);
@ -73,7 +72,6 @@ export default function CO2GalvoSettingDetailPage() {
if (loading) return <p className="p-6">Loading setting...</p>;
if (!setting) return <p className="p-6">Setting not found.</p>;
// ---- display helpers ----
const ownerDisplay: string =
typeof setting?.owner === "object"
? (setting.owner?.username ?? setting.owner?.id ?? "—")

View file

@ -8,7 +8,6 @@ import Image from "next/image";
type Owner = {
id?: string | number;
username?: string | null;
// keep extras harmlessly if API returns them
first_name?: string | null;
last_name?: string | null;
email?: string | null;
@ -31,32 +30,31 @@ export default function CO2GalvoSettingsPage() {
}, [query]);
useEffect(() => {
const url =
`${process.env.NEXT_PUBLIC_API_BASE_URL}/items/settings_co2gal` +
`?fields=` +
[
const fields = [
"submission_id",
"setting_title",
"uploader",
// owner (M2O) ensure username is requested
"owner.id",
"owner.username",
// assets / denorms
"photo.id",
"photo.title",
"mat.name",
"mat_coat.name",
"source.model",
"lens.field_size",
].join(",") +
`&limit=-1`;
].join(",");
fetch(url, { cache: "no-store" })
.then((res) => {
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const url = `/api/dx/items/settings_co2gal?fields=${encodeURIComponent(fields)}&limit=-1`;
fetch(url, { cache: "no-store", credentials: "include" })
.then(async (res) => {
if (!res.ok) {
const j = await res.json().catch(() => ({}));
throw new Error(j?.errors?.[0]?.message || `HTTP ${res.status}`);
}
return res.json();
})
.then((data) => setSettings(data?.data || []))
.then((json) => setSettings(json?.data || []))
.catch((e) => {
console.error("CO2 Galvo settings fetch failed:", e);
setSettings([]);