co2 galvo owner test

This commit is contained in:
makearmy 2025-10-01 20:39:16 -04:00
parent a38aa4c2f9
commit f61029a8ca

View file

@ -34,8 +34,10 @@ export default function CO2GalvoSettingsPage() {
"submission_id", "submission_id",
"setting_title", "setting_title",
"uploader", "uploader",
// ensure relation expands
"owner.id", "owner.id",
"owner.username", "owner.username",
// assets / denorms
"photo.id", "photo.id",
"photo.title", "photo.title",
"mat.name", "mat.name",
@ -44,6 +46,7 @@ export default function CO2GalvoSettingsPage() {
"lens.field_size", "lens.field_size",
].join(","); ].join(",");
// IMPORTANT: go through our proxy so the user's ma_at cookie is used
const url = `/api/dx/items/settings_co2gal?fields=${encodeURIComponent(fields)}&limit=-1`; const url = `/api/dx/items/settings_co2gal?fields=${encodeURIComponent(fields)}&limit=-1`;
fetch(url, { cache: "no-store", credentials: "include" }) fetch(url, { cache: "no-store", credentials: "include" })
@ -89,9 +92,7 @@ export default function CO2GalvoSettingsPage() {
}, [settings, debouncedQuery]); }, [settings, debouncedQuery]);
const total = settings.length; const total = settings.length;
const uniqueMaterials = new Set( const uniqueMaterials = new Set(settings.map((s) => s.mat?.name).filter(Boolean)).size;
settings.map((s) => s.mat?.name).filter(Boolean)
).size;
const lensCounts = settings.reduce((acc: Record<string, number>, cur) => { const lensCounts = settings.reduce((acc: Record<string, number>, cur) => {
const v = cur.lens?.field_size; const v = cur.lens?.field_size;
@ -100,9 +101,7 @@ export default function CO2GalvoSettingsPage() {
return acc; return acc;
}, {}); }, {});
const mostCommonLens = const mostCommonLens =
Object.entries(lensCounts).sort( Object.entries(lensCounts).sort((a, b) => (Number(b[1]) || 0) - (Number(a[1]) || 0))[0]?.[0] || "—";
(a, b) => (Number(b[1]) || 0) - (Number(a[1]) || 0)
)[0]?.[0] || "—";
const srcCounts = settings.reduce((acc: Record<string, number>, cur) => { const srcCounts = settings.reduce((acc: Record<string, number>, cur) => {
const v = cur.source?.model; const v = cur.source?.model;
@ -111,13 +110,9 @@ export default function CO2GalvoSettingsPage() {
return acc; return acc;
}, {}); }, {});
const mostCommonSource = const mostCommonSource =
Object.entries(srcCounts).sort( Object.entries(srcCounts).sort((a, b) => (Number(b[1]) || 0) - (Number(a[1]) || 0))[0]?.[0] || "—";
(a, b) => (Number(b[1]) || 0) - (Number(a[1]) || 0)
)[0]?.[0] || "—";
const recent = [...settings] const recent = [...settings].sort((a, b) => Number(b.submission_id) - Number(a.submission_id)).slice(0, 5);
.sort((a, b) => Number(b.submission_id) - Number(a.submission_id))
.slice(0, 5);
return ( return (
<div className="p-6 max-w-7xl mx-auto"> <div className="p-6 max-w-7xl mx-auto">
@ -172,10 +167,7 @@ export default function CO2GalvoSettingsPage() {
<ul className="text-sm space-y-1"> <ul className="text-sm space-y-1">
{recent.map((s) => ( {recent.map((s) => (
<li key={s.submission_id}> <li key={s.submission_id}>
<Link <Link href={detailHref(s.submission_id)} className="underline text-accent">
href={detailHref(s.submission_id)}
className="underline text-accent"
>
{s.setting_title || "Untitled"} {s.setting_title || "Untitled"}
</Link>{" "} </Link>{" "}
<span className="text-muted-foreground"> <span className="text-muted-foreground">
@ -228,46 +220,32 @@ export default function CO2GalvoSettingsPage() {
<Link <Link
href={detailHref(s.submission_id)} href={detailHref(s.submission_id)}
className="text-accent underline" className="text-accent underline"
dangerouslySetInnerHTML={{ dangerouslySetInnerHTML={{ __html: highlight(s.setting_title || "—") }}
__html: highlight(s.setting_title || "—"),
}}
/> />
</td> </td>
<td <td
className="px-2 py-2 whitespace-nowrap" className="px-2 py-2 whitespace-nowrap"
dangerouslySetInnerHTML={{ dangerouslySetInnerHTML={{ __html: highlight(ownerLabel(s.owner)) }}
__html: highlight(ownerLabel(s.owner)),
}}
/> />
<td <td
className="px-2 py-2 whitespace-nowrap" className="px-2 py-2 whitespace-nowrap"
dangerouslySetInnerHTML={{ dangerouslySetInnerHTML={{ __html: highlight(s.uploader || "—") }}
__html: highlight(s.uploader || "—"),
}}
/> />
<td <td
className="px-2 py-2 whitespace-nowrap" className="px-2 py-2 whitespace-nowrap"
dangerouslySetInnerHTML={{ dangerouslySetInnerHTML={{ __html: highlight(s.mat?.name || "—") }}
__html: highlight(s.mat?.name || "—"),
}}
/> />
<td <td
className="px-2 py-2 whitespace-nowrap" className="px-2 py-2 whitespace-nowrap"
dangerouslySetInnerHTML={{ dangerouslySetInnerHTML={{ __html: highlight(s.mat_coat?.name || "—") }}
__html: highlight(s.mat_coat?.name || "—"),
}}
/> />
<td <td
className="px-2 py-2 whitespace-nowrap" className="px-2 py-2 whitespace-nowrap"
dangerouslySetInnerHTML={{ dangerouslySetInnerHTML={{ __html: highlight(s.source?.model || "—") }}
__html: highlight(s.source?.model || "—"),
}}
/> />
<td <td
className="px-2 py-2 whitespace-nowrap" className="px-2 py-2 whitespace-nowrap"
dangerouslySetInnerHTML={{ dangerouslySetInnerHTML={{ __html: highlight(s.lens?.field_size || "—") }}
__html: highlight(s.lens?.field_size || "—"),
}}
/> />
</tr> </tr>
))} ))}