From 248ceada52e68c87c1476ed839a9f41b9b88d907 Mon Sep 17 00:00:00 2001 From: rizky Date: Thu, 1 Aug 2024 04:04:44 -0700 Subject: [PATCH] fix --- comps/custom/Popover.tsx | 2 +- comps/form/field/table-edit/TableEdit.tsx | 272 +++++++++++++++++++++- comps/form/field/type/TypeUpload.tsx | 2 +- 3 files changed, 271 insertions(+), 5 deletions(-) diff --git a/comps/custom/Popover.tsx b/comps/custom/Popover.tsx index 6607642..357805a 100755 --- a/comps/custom/Popover.tsx +++ b/comps/custom/Popover.tsx @@ -9,7 +9,7 @@ import { offset, shift, useClick, - useDismiss, + useDismiss, useFloating, useId, useInteractions, diff --git a/comps/form/field/table-edit/TableEdit.tsx b/comps/form/field/table-edit/TableEdit.tsx index ec687ba..65af597 100755 --- a/comps/form/field/table-edit/TableEdit.tsx +++ b/comps/form/field/table-edit/TableEdit.tsx @@ -2,6 +2,7 @@ import { TableList } from "lib/comps/list/TableList"; import { useLocal } from "lib/utils/use-local"; import { FC, useEffect, useRef } from "react"; import { FMLocal } from "../../typings"; +import get from "lodash.get"; export const TableEdit: FC<{ on_init: () => FMLocal; @@ -30,11 +31,268 @@ export const TableEdit: FC<{ } } const value = fm.data[name]; - useEffect(() => { - local.tbl.render(); - }, [3000]); + local.tbl = { + data: value, + render: () => {}, + }; + local.render(); + }, []); + const raw_childs = get( + child, + "props.meta.item.component.props.child.content.childs" + ); + let columns: any[] = []; + let childs: any[] = []; + const mode_child = raw_childs.find((e: any) => + ["tbl-col", "table: columns"].includes(e.name) + ); + const tbl = item.edit.childs[0].edit.childs.find( + (e: any) => get(e, "id") === mode_child.id + ); + const meta = tbl; + if (meta && meta.childs) { + childs = meta.childs; + } + for (const child of childs) { + let key = getProp(child, "name", {}); + const label = getProp(child, "title", ""); + const type = getProp(child, "type", ""); + const width = parseInt(getProp(child, "width", {})); + if (type === "checkbox") { + const on_click = getProp(child, "opt__on_click", ""); + columns.push({ + key, + name, + width: 35, + minWidth: 45, + resizable: true, + sortable: true, + frozen: true, + renderCell(arg: any) { + // return <>; + const { props, tbl } = arg; + const fm_row = { ...fm, render: local.render }; + return ( + {}, + remove: () => { + const data = + tbl.data.filter((e: any) => e !== props.row) || []; + fm.data[name] = data; + fm.render(); + }, + add: (e: any) => { + tbl.data.push(e ? e : {}); + fm.render(); + }, + }} + > + {child} + + ); + }, + }); + } else { + columns.push({ + key, + label, + width: width > 0 ? width : undefined, + resizable: true, + sortable: true, + renderCell(arg: any) { + const { props, tbl } = arg; + const fm_row = { ...fm, render: local.render }; + fm_row.data = props.row; + local.tbl = tbl; + const key = props.column.key; + return ( + {}, + remove: () => { + const data = + tbl.data.filter((e: any) => e !== props.row) || []; + fm.data[name] = data; + fm.render(); + }, + add: (e: any) => { + tbl.data.push(e ? e : {}); + fm.render(); + }, + }} + > + {child} + + ); + }, + }); + } + } + return ( + <> + + + + ); return ( <>
@@ -201,3 +459,11 @@ export const TableEdit: FC<{ ); }; + +function getProp(child: any, name: string, defaultValue?: any) { + const fn = new Function( + `return ${get(child, `component.props.${name}.valueBuilt`) || `null`}` + ); + + return fn() || defaultValue; +} diff --git a/comps/form/field/type/TypeUpload.tsx b/comps/form/field/type/TypeUpload.tsx index 27e57ed..3fc71ff 100755 --- a/comps/form/field/type/TypeUpload.tsx +++ b/comps/form/field/type/TypeUpload.tsx @@ -157,7 +157,7 @@ export const FieldUpload: FC<{ input.ref.click(); } }} - className="c-items-center c-flex c-text-base c-px-5 c-outline-none c-rounded c-cursor-pointer " + className="c-items-center c-flex c-text-base c-px-3 c-outline-none c-rounded c-cursor-pointer " >