From f418cb11d0ecb550d76446520987109907a23980 Mon Sep 17 00:00:00 2001 From: Rizky Date: Tue, 28 May 2024 13:07:53 +0000 Subject: [PATCH] fix lib --- comps/list/TableList.tsx | 2 - comps/md/gen/md-gen.ts | 29 +++--- comps/md/gen/md-list.ts | 168 +++++++++++++-------------------- comps/md/parts/MDMaster.tsx | 8 +- comps/md/utils/editor-init.tsx | 7 +- 5 files changed, 88 insertions(+), 126 deletions(-) diff --git a/comps/list/TableList.tsx b/comps/list/TableList.tsx index 98204ea..8dd8b0d 100755 --- a/comps/list/TableList.tsx +++ b/comps/list/TableList.tsx @@ -69,9 +69,7 @@ export const TableList: FC = ({ feature, filter_name, }) => { - console.log(`prasi_filter.${filter_name}`); const where = get(w, `prasi_filter.${filter_name}`); - console.log(w.prasi_filter); if (mode === "auto") { if (w.isMobile) { mode = "list"; diff --git a/comps/md/gen/md-gen.ts b/comps/md/gen/md-gen.ts index 4550cf7..b3097ea 100755 --- a/comps/md/gen/md-gen.ts +++ b/comps/md/gen/md-gen.ts @@ -13,27 +13,24 @@ export const generateMasterDetail: GenFn<{ item: PrasiItem, table: string, field const {item} = arg; // loading generate MD w.generating_prasi_md = { - master_detail: true, + master_detail: true, }; await generateList(arg, data); - // const result: any = {}; - // modify(result); + // const childs = item.edit.childs[0].edit.childs; - const childs = item.edit.childs[0].edit.childs; + // const master = childs.find( + // (e) => e.component?.id === "c68415ca-dac5-44fe-aeb6-936caf8cc491" + // ); - const master = childs.find( - (e) => e.component?.id === "c68415ca-dac5-44fe-aeb6-936caf8cc491" - ); + // if (master) { + // master.edit.setProp("on_init", { + // mode: "raw", + // value: `async (text: string) => { + // }`, + // }); - if (master) { - master.edit.setProp("on_init", { - mode: "raw", - value: `async (text: string) => { - }`, - }); - - await master.edit.commit(); - } + // await master.edit.commit(); + // } }; diff --git a/comps/md/gen/md-list.ts b/comps/md/gen/md-list.ts index 1f698b3..e9c0b01 100755 --- a/comps/md/gen/md-list.ts +++ b/comps/md/gen/md-list.ts @@ -5,114 +5,80 @@ export const generateList = async ( arg: { item: PrasiItem; table: string; fields: any }, data: any ) => { - console.log({ item: arg.item }); const item = arg.item; const tab_master = item.edit.childs[0].edit.childs.find( (e) => get(e, "component.id") === "c68415ca-dac5-44fe-aeb6-936caf8cc491" ); - const childs = get(tab_master, "edit.props.child.value") as PrasiItem; - console.log({ tab_master }); - const new_item = createItem({ - name: "halo item", - }); - console.log({ item }); - const md = createItem({ - component: { - id: "567d5362-2cc8-4ca5-a531-f771a5c866c2", - props: { - name: arg.table, - gen_table: arg.table, - generate: "y", - on_load: "", - row_click: "", - selected: "", - gen_fields: [JSON.stringify(arg.fields)], - child: { - childs: [], + tab_master?.edit.setChilds([ + { + type: "item", + name: "item", + component: { + id: "567d5362-2cc8-4ca5-a531-f771a5c866c2", + props: { + name: { + mode: "string", + value: arg.table, + }, + generate: { + mode: "string", + value: "y", + }, + on_load: { + mode: "string", + value: "", + }, + row_click: { + mode: "raw", + value: `\ +({ row, rows, idx, event }: OnRowClick) => { + md.selected = row; + md.internal.action_should_refresh = true; + md.params.apply(); + md.render(); +}; + +type OnRowClick = { + row: any; + rows: any[]; + idx: any; + event: React.MouseEvent; +} + `, + }, + selected: { + mode: "raw", + value: `\ +({ row, rows, idx }: SelectedRow) => { + try { + if (typeof md === "object") { + if (Array.isArray(md.selected)) { + if (md.selected.length) { + let select = md.selected.find((e) => e === row) + if(select) return true + } + } else { + if (md.selected === row) { + return true; + } + } + } + } catch (e) { + + } + return false; +}; + +type SelectedRow = { + row: any; + rows: any[]; + idx: any; +}`, + }, }, }, }, - }); - console.log({ md }); - console.log({ new_item }); - // tab_master?.edit.setProp("child", { - // type: "jsx", - // value: new_item - // }) - // console.log({new_item}) - - // childs.edit.childs.push(new_item); - console.log(`\ - [${JSON.stringify(arg.fields)}] - `) - childs.edit.setChilds([{ - type: "item", - name: "item", - component: { - id: "567d5362-2cc8-4ca5-a531-f771a5c866c2", - props: { - name: { - mode: "string", - value: arg.table - }, - generate:{ - mode: "string", - value: "y" - }, - on_load: { - mode: "string", - value: "" - }, - row_click: { - mode: "raw", - value:`\ - ({ row, rows, idx, event }: OnRowClick) => { - md.selected = row; - md.internal.action_should_refresh = true; - md.params.apply(); - md.render(); - }; - - type OnRowClick = { - row: any; - rows: any[]; - idx: any; - event: React.MouseEvent; - } - ` - }, - selected: { - mode: "raw", - value: `\ - ({ row, rows, idx }: SelectedRow) => { - try { - if (typeof md === "object") { - if (Array.isArray(md.selected)) { - if (md.selected.length) { - let select = md.selected.find((e) => e === row) - if(select) return true - } - } else { - if (md.selected === row) { - return true; - } - } - } - } catch (e) { - - } - return false; - }; - - type SelectedRow = { - row: any; - rows: any[]; - idx: any; - }` - }, - }, - } - }]); + ]); await item.edit.commit(); // childs.edit.childs[0].edit.setProp("selected", { // mode: "raw", diff --git a/comps/md/parts/MDMaster.tsx b/comps/md/parts/MDMaster.tsx index e62de1b..aea3195 100755 --- a/comps/md/parts/MDMaster.tsx +++ b/comps/md/parts/MDMaster.tsx @@ -24,10 +24,12 @@ export const MDRenderMaster: FC<{ size: width, min_size: min_width, }); - md.panel.min_size = min_width; - md.panel.size = width; + if (md.panel) { + md.panel.min_size = min_width; + md.panel.size = width; + } } - + return <>{child}; }; diff --git a/comps/md/utils/editor-init.tsx b/comps/md/utils/editor-init.tsx index fa85c68..7b08e1a 100755 --- a/comps/md/utils/editor-init.tsx +++ b/comps/md/utils/editor-init.tsx @@ -1,3 +1,4 @@ +import get from "lodash.get"; import { MDLocal, MDProps, MDRef } from "./typings"; export const editorMDInit = (md: MDLocal, mdr: MDRef, arg: MDProps) => { @@ -18,10 +19,8 @@ export const editorMDInit = (md: MDLocal, mdr: MDRef, arg: MDProps) => { md.props.gen_table = gen_table; md.props.on_init = on_init; - if ( - !mdr.master || - (mdr.master && mdr.master.edit.childs[0].childs.length === 0) - ) { + console.log(get(mdr, "master.edit.childs.0")); + if (!mdr.master || (mdr.master && !get(mdr, "master.edit.childs.0.childs.length"))) { md.breadcrumb = [ { label: (