diff --git a/comps/form/gen/fields.ts b/comps/form/gen/fields.ts index 3031058..4f537c4 100755 --- a/comps/form/gen/fields.ts +++ b/comps/form/gen/fields.ts @@ -110,6 +110,7 @@ export const newField = async ( table: arg.relation.to.table, select: res.select, pks: {}, + type: arg.type === "has-many" ? "typeahead" : "dropdown", }); if (["has-one"].includes(arg.type)) { const rel__gen_fields = JSON.stringify( @@ -171,7 +172,10 @@ export const newField = async ( result.on_load = `() => { return []; }`; } let child: any = { childs: [] }; - const relation = arg.relation?.fields.filter((e) => get(e, "name") !== opt.parent_table) || []; + const relation = + arg.relation?.fields.filter( + (e) => get(e, "name") !== opt.parent_table + ) || []; let rel__gen_fields: any = JSON.stringify( relation.map((e) => { const v = (e as any).value; diff --git a/comps/form/gen/gen-rel-many.ts b/comps/form/gen/gen-rel-many.ts index 79d3267..63437c3 100755 --- a/comps/form/gen/gen-rel-many.ts +++ b/comps/form/gen/gen-rel-many.ts @@ -17,11 +17,13 @@ export const genRelMany = (prop: { if (master) { const select = generateSelect(master.relation.fields); + console.log(master); result.on_load = on_load_rel({ pk: select.pk, table: master.name, select: select.select, pks: {}, + type: "typeahead", }); const pk_master = master.relation.fields.find((e: any) => get(e, "is_pk")); const get_value = `\ diff --git a/comps/form/gen/on_load_rel.ts b/comps/form/gen/on_load_rel.ts index 5f028d6..339f7ee 100755 --- a/comps/form/gen/on_load_rel.ts +++ b/comps/form/gen/on_load_rel.ts @@ -5,7 +5,7 @@ export const on_load_rel = ({ table, select, pks, - type + type, }: { pk: string; table: string; @@ -25,6 +25,11 @@ export const on_load_rel = ({ } } + const skip_select = + !isEmptyString(type) && + ["checkbox", "typeahead", "button"].includes(type as any); + + console.log(skip_select, type); return `\ async (arg: { reload: () => Promise; @@ -38,10 +43,13 @@ async (arg: { } return new Promise(async (done) => { - ${!isEmptyString(type) && ["checkbox", "typeahead", "button"].includes(type as any) ? `` : `const fields = parseGenField(rel__gen_fields); - const res = generateSelect(fields);`} - - + ${ + skip_select + ? `` + : ` + const fields = parseGenField(rel__gen_fields); + const res = generateSelect(fields); + const is_tree = typeof rel__feature !== "undefined" && Array.isArray(rel__feature) && @@ -49,21 +57,28 @@ async (arg: { if (is_tree && typeof rel__id_parent === "string" && rel__id_parent) { res.select[rel__id_parent] = true; + }` } - const items = await db.${table}.findMany({ - ${!isEmptyString(type) && ["checkbox", "typeahead", "button"].includes(type as any) ? `` : `select: { - ...${JSON.stringify(select)}, - ...(res?.select || {}) - },`} + + let items = await db.${table}.findMany({ + select: { + ...${JSON.stringify(select)} + ${skip_select ? `` : `,...(res?.select || {})`} + }, orderBy: arg.orderBy || { ${pk}: "desc" }, ...arg.paging, }); + ${ + skip_select + ? "" + : `\ if (is_tree && typeof rel__id_parent === "string" && rel__id_parent) { items = sortTree(items, rel__id_parent, "${pk}"); + }` } if(items.length){ @@ -79,9 +94,10 @@ async (arg: { } let blank: any = undefined; - if (ext__required !== "y") { + if ((ext__required as any) !== "y" && (sub_type as any) === 'dropdown') { blank = { value: undefined, label: "", data: {} }; } + done( [ blank, diff --git a/comps/list/TableList.css b/comps/list/TableList.css deleted file mode 100755 index 9e5d3ac..0000000 --- a/comps/list/TableList.css +++ /dev/null @@ -1,3 +0,0 @@ -.rdg-dark { - --rdg-color-scheme: light !important; -} \ No newline at end of file