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 collection = params.get("target") || "";
|
||||
|
||||
// 🔁 CHANGE: fetch fields via server proxy (uses Directus token server-side)
|
||||
const metaRes = await fetch(
|
||||
`/api/directus/fields?collection=${encodeURIComponent(collection)}`,
|
||||
{ cache: "no-store" }
|
||||
);
|
||||
if (!metaRes.ok) throw new Error(`Fields ${metaRes.status}`);
|
||||
// Call our server proxy so it can use the server token
|
||||
const proxyUrl = `/api/directus/fields?collection=${encodeURIComponent(collection)}`;
|
||||
const metaRes = await fetch(proxyUrl, { cache: "no-store" });
|
||||
if (!metaRes.ok) throw new Error(`Proxy ${metaRes.status} fetching ${proxyUrl}`);
|
||||
|
||||
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>
|
||||
const parent = rows.find((r: any) => r?.field === group);
|
||||
const nestedChildren = parent?.meta?.options?.fields || [];
|
||||
let child =
|
||||
nestedChildren.find((f: any) => f?.field === field) ||
|
||||
// Flat fallback: "group.field"
|
||||
rows.find((r: any) => r?.field === `${group}.${field}`);
|
||||
|
||||
// Choices can live on child.options.choices or child.meta.options.choices
|
||||
|
|
@ -148,6 +146,8 @@ function useOptions(path: string) {
|
|||
setLoading(false);
|
||||
}
|
||||
return; // short-circuit
|
||||
}
|
||||
|
||||
} else {
|
||||
// unknown path → empty
|
||||
setOpts([]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue