submit 'type' fixes
This commit is contained in:
parent
e9ae08d725
commit
b7b3fb53f9
1 changed files with 8 additions and 5 deletions
|
|
@ -114,7 +114,7 @@ function useOptions(path: string) {
|
||||||
const field = params.get("field") || "";
|
const field = params.get("field") || "";
|
||||||
const collection = params.get("target") || "";
|
const collection = params.get("target") || "";
|
||||||
|
|
||||||
// Use server proxy so it can auth with server token
|
// Always go through our server proxy to read Directus field meta
|
||||||
const proxyUrl = `/api/directus/fields?collection=${encodeURIComponent(collection)}`;
|
const proxyUrl = `/api/directus/fields?collection=${encodeURIComponent(collection)}`;
|
||||||
const metaRes = await fetch(proxyUrl, { cache: "no-store" });
|
const metaRes = await fetch(proxyUrl, { cache: "no-store" });
|
||||||
if (!metaRes.ok) throw new Error(`Proxy ${metaRes.status} fetching ${proxyUrl}`);
|
if (!metaRes.ok) throw new Error(`Proxy ${metaRes.status} fetching ${proxyUrl}`);
|
||||||
|
|
@ -122,16 +122,18 @@ function useOptions(path: string) {
|
||||||
const metaJson = await metaRes.json().catch(() => ({}));
|
const metaJson = await metaRes.json().catch(() => ({}));
|
||||||
const rows: any[] = Array.isArray(metaJson?.data) ? metaJson.data : Array.isArray(metaJson) ? metaJson : [];
|
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>
|
// Nested repeater children live under parent.meta.options.fields
|
||||||
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) ||
|
||||||
rows.find((r: any) => r?.field === `${group}.${field}`);
|
rows.find((r: any) => r?.field === `${group}.${field}`); // flat fallback
|
||||||
|
|
||||||
// Choices can live on child.options.choices or child.meta.options.choices
|
// Choices may be on child.options.choices or child.meta.options.choices
|
||||||
const choices: any[] =
|
const choices: any[] =
|
||||||
(child?.options?.choices as any[]) ?? (child?.meta?.options?.choices as any[]) ?? [];
|
(child?.options?.choices as any[]) ??
|
||||||
|
(child?.meta?.options?.choices as any[]) ??
|
||||||
|
[];
|
||||||
|
|
||||||
const mapped: Opt[] = choices.map((c: any) => ({
|
const mapped: Opt[] = choices.map((c: any) => ({
|
||||||
id: String(c.value ?? c.key ?? c.id),
|
id: String(c.value ?? c.key ?? c.id),
|
||||||
|
|
@ -145,6 +147,7 @@ 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