From 5d0056e394d3f11381e333d212fd87d5479c7dc7 Mon Sep 17 00:00:00 2001 From: rizky Date: Fri, 2 Aug 2024 02:14:31 -0700 Subject: [PATCH] fix --- comps/form/gen/gen-form.ts | 106 ++++++++++++++++++------------------- comps/md/gen/md-gen.ts | 11 ++++ 2 files changed, 64 insertions(+), 53 deletions(-) diff --git a/comps/form/gen/gen-form.ts b/comps/form/gen/gen-form.ts index 1d7d93c..047b548 100755 --- a/comps/form/gen/gen-form.ts +++ b/comps/form/gen/gen-form.ts @@ -147,67 +147,67 @@ export const generateForm = async ( walkGenForm(new_body, existing_childs as any); } - const prop_item = propFromItem(item); - const current_body = prop_item?.body?.value as IItem; + // const prop_item = propFromItem(item); + // const current_body = prop_item?.body?.value as IItem; - if (current_body) { - const mapping = mapCompItemTree(new_body, { - shouldAdd({ item }) { - if (item.component?.props?.sub_type?.value === "table-edit") - return "add-skip-children"; + // if (current_body) { + // const mapping = mapCompItemTree(new_body, { + // shouldAdd({ item }) { + // if (item.component?.props?.sub_type?.value === "table-edit") + // return "add-skip-children"; - return "add"; - }, - }); + // return "add"; + // }, + // }); - reduceItemMapping(current_body, mapping, (old_item, new_item) => { - const pold = propFromItem(old_item); - const pnew = propFromItem(new_item); + // reduceItemMapping(current_body, mapping, (old_item, new_item) => { + // const pold = propFromItem(old_item); + // const pnew = propFromItem(new_item); - let result = old_item; - if ( - result.component && - result.component?.id === "32550d01-42a3-4b15-a04a-2c2d5c3c8e67" - ) { - if (pold.type.value !== pnew.type.value) { - result = new_item; - } else if (pold.sub_type.value !== pnew.sub_type.value) { - result = new_item; - } + // let result = old_item; + // if ( + // result.component && + // result.component?.id === "32550d01-42a3-4b15-a04a-2c2d5c3c8e67" + // ) { + // if (pold.type.value !== pnew.type.value) { + // result = new_item; + // } else if (pold.sub_type.value !== pnew.sub_type.value) { + // result = new_item; + // } - copyProps(old_item, new_item, [ - "placeholder", - "label", - "link__url", - "ext__width", - "opt__load_trigger", - "ext__on_change", - "ext__description", - "ext__show_label", - "ext__disabled", - "ext__prefix", - "ext__suffix", - ]); - } + // copyProps(old_item, new_item, [ + // "placeholder", + // "label", + // "link__url", + // "ext__width", + // "opt__load_trigger", + // "ext__on_change", + // "ext__description", + // "ext__show_label", + // "ext__disabled", + // "ext__prefix", + // "ext__suffix", + // ]); + // } - return result; - }); + // return result; + // }); - if ( - mapping["32550d01-42a3-4b15-a04a-2c2d5c3c8e67"] && - Object.keys(mapping["32550d01-42a3-4b15-a04a-2c2d5c3c8e67"]).length > 0 - ) { - for (const val of Object.values( - mapping["32550d01-42a3-4b15-a04a-2c2d5c3c8e67"] - )) { - current_body.childs?.[0]?.childs.push(val); - } - } + // if ( + // mapping["32550d01-42a3-4b15-a04a-2c2d5c3c8e67"] && + // Object.keys(mapping["32550d01-42a3-4b15-a04a-2c2d5c3c8e67"]).length > 0 + // ) { + // for (const val of Object.values( + // mapping["32550d01-42a3-4b15-a04a-2c2d5c3c8e67"] + // )) { + // current_body.childs?.[0]?.childs.push(val); + // } + // } - if (current_body?.childs?.length > 0) { - new_body = current_body; - } - } + // if (current_body?.childs?.length > 0) { + // new_body = current_body; + // } + // } if (commit) { Object.keys(result).map((e) => { diff --git a/comps/md/gen/md-gen.ts b/comps/md/gen/md-gen.ts index 6446bc3..5e92e81 100755 --- a/comps/md/gen/md-gen.ts +++ b/comps/md/gen/md-gen.ts @@ -1,6 +1,9 @@ import { formatName, GenFn } from "lib/gen/utils"; import { generateMDForm } from "./md-form"; import { generateMDList } from "./md-list"; +import { getValueProp } from "lib/comps/form/gen/gen-rel"; +import { getProp } from "lib/utils/get-prop"; +import { propFromItem } from "lib/utils/diff-gen"; const w = window as any; export const generateMasterDetail: GenFn<{ item: PrasiItem; @@ -21,6 +24,14 @@ export const generateMasterDetail: GenFn<{ } } catch (e) {} + if (!arg.fields && data?.gen_fields?.valueBuilt) { + eval(`arg.fields = ${data.gen_fields.valueBuilt}`); + } + + if (!arg.table && data?.gen_table?.valueBuilt) { + eval(`arg.table = ${data.gen_table.valueBuilt}`); + } + await generateMDList(arg, data, false); await generateMDForm(arg, data, false); await item.edit.commit();