submit 'type' fixes
This commit is contained in:
parent
132c3b10d2
commit
aa8436da93
1 changed files with 8 additions and 8 deletions
|
|
@ -113,21 +113,19 @@ function useOptions(path: string) {
|
||||||
const field = params.get("field") || "";
|
const field = params.get("field") || "";
|
||||||
const collection = params.get("target") || "";
|
const collection = params.get("target") || "";
|
||||||
|
|
||||||
// 🔁 CHANGE: fetch fields via server proxy (uses Directus token server-side)
|
// Call our server proxy so it can use the server token
|
||||||
const metaRes = await fetch(
|
const proxyUrl = `/api/directus/fields?collection=${encodeURIComponent(collection)}`;
|
||||||
`/api/directus/fields?collection=${encodeURIComponent(collection)}`,
|
const metaRes = await fetch(proxyUrl, { cache: "no-store" });
|
||||||
{ cache: "no-store" }
|
if (!metaRes.ok) throw new Error(`Proxy ${metaRes.status} fetching ${proxyUrl}`);
|
||||||
);
|
|
||||||
if (!metaRes.ok) throw new Error(`Fields ${metaRes.status}`);
|
|
||||||
const metaJson = await metaRes.json().catch(() => ({}));
|
const metaJson = await metaRes.json().catch(() => ({}));
|
||||||
const rows: any[] = Array.isArray(metaJson?.data) ? metaJson.data : [];
|
const rows: any[] = Array.isArray(metaJson?.data) ? metaJson.data : Array.isArray(metaJson) ? metaJson : [];
|
||||||
|
|
||||||
// Try nested child first: parent.meta.options.fields -> child where field === <field>
|
// Try nested child first: parent.meta.options.fields -> child where field === <field>
|
||||||
const parent = rows.find((r: any) => r?.field === group);
|
const parent = rows.find((r: any) => r?.field === group);
|
||||||
const nestedChildren = parent?.meta?.options?.fields || [];
|
const nestedChildren = parent?.meta?.options?.fields || [];
|
||||||
let child =
|
let child =
|
||||||
nestedChildren.find((f: any) => f?.field === field) ||
|
nestedChildren.find((f: any) => f?.field === field) ||
|
||||||
// Flat fallback: "group.field"
|
|
||||||
rows.find((r: any) => r?.field === `${group}.${field}`);
|
rows.find((r: any) => r?.field === `${group}.${field}`);
|
||||||
|
|
||||||
// Choices can live on child.options.choices or child.meta.options.choices
|
// Choices can live on child.options.choices or child.meta.options.choices
|
||||||
|
|
@ -148,6 +146,8 @@ function useOptions(path: string) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
return; // short-circuit
|
return; // short-circuit
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// unknown path → empty
|
// unknown path → empty
|
||||||
setOpts([]);
|
setOpts([]);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue