From fff9049ff6181a333660956413ecd92270fb58a1 Mon Sep 17 00:00:00 2001 From: rizrmd Date: Wed, 12 Jun 2024 11:16:13 -0700 Subject: [PATCH] fix --- comps/custom/Breadcrumb.tsx | 127 ++--- comps/form/Form.tsx | 27 +- comps/form/field/Field.tsx | 44 +- comps/form/field/FieldInput.tsx | 87 +++- comps/form/field/table-edit/TableEdit.tsx | 164 ++++--- comps/form/field/type/TypeDropdown.tsx | 32 +- comps/form/field/type/TypeInput.tsx | 29 +- comps/form/field/type/TypeMoney.tsx | 9 +- comps/form/field/type/TypeRichText.tsx | 2 - comps/form/field/type/TypeUpload.tsx | 12 +- comps/form/gen/fields.ts | 126 +++-- comps/form/gen/gen-form.ts | 554 ++++++++++++---------- comps/form/gen/gen-label.ts | 25 +- comps/form/gen/gen-rel-many.ts | 30 +- comps/form/gen/gen-rel.ts | 29 +- comps/form/gen/gen-table-edit.ts | 101 ++-- comps/form/gen/get-value.ts | 50 +- comps/form/gen/on_load.ts | 26 +- comps/form/gen/on_load_rel.ts | 73 +-- comps/form/gen/set-value.ts | 16 +- comps/form/typings.ts | 9 +- comps/form/utils/init.tsx | 5 +- comps/form/utils/use-field.tsx | 1 + comps/list/TableList.tsx | 107 +++-- comps/md/MasterDetail.tsx | 16 +- comps/md/gen/gen-table-list.ts | 12 +- comps/md/gen/md-form.ts | 11 +- comps/md/gen/md-gen.ts | 1 - comps/md/gen/md-list.ts | 35 +- comps/md/gen/md-select.ts | 11 +- comps/md/gen/tbl-list/on_load.ts | 80 ++-- comps/md/parts/MDDetail.tsx | 7 +- comps/md/parts/MDHeader.tsx | 4 +- comps/md/parts/MDMaster.tsx | 14 +- comps/md/utils/editor-init.tsx | 4 +- comps/md/utils/md-bread.tsx | 43 -- comps/md/utils/typings.ts | 14 +- comps/ui/button.tsx | 13 +- comps/ui/typeahead-opt.tsx | 8 +- comps/ui/typeahead.tsx | 22 +- exports.tsx | 5 +- gen/gen_form/on_submit.ts | 1 + preset/login/Login.tsx | 10 +- preset/login/utils/generate.ts | 3 +- preset/login/utils/load.ts | 35 +- preset/login/utils/logout.ts | 4 +- preset/login/utils/user.ts | 13 - preset/menu/Layout.tsx | 16 +- utils/is-empty-string.ts | 6 + utils/soft-del-rel.ts | 18 + utils/soft-delete-filter.ts | 26 +- 51 files changed, 1174 insertions(+), 943 deletions(-) delete mode 100755 comps/md/utils/md-bread.tsx delete mode 100755 preset/login/utils/user.ts create mode 100755 utils/is-empty-string.ts create mode 100755 utils/soft-del-rel.ts diff --git a/comps/custom/Breadcrumb.tsx b/comps/custom/Breadcrumb.tsx index 7dd0b30..630d081 100755 --- a/comps/custom/Breadcrumb.tsx +++ b/comps/custom/Breadcrumb.tsx @@ -2,6 +2,7 @@ import { useLocal } from "@/utils/use-local"; import { FC, ReactNode, useEffect } from "react"; import { Skeleton } from "../ui/skeleton"; import get from "lodash.get"; +import { FieldLoading } from "../ui/field-loading"; export type BreadItem = { label: React.ReactNode; @@ -16,43 +17,7 @@ type BreadcrumbProps = { item?: PrasiItem; }; -export const Breadcrumb: FC = ({ - value, - className, - on_load, - item, -}) => { - const local = useLocal({ - list: [] as BreadItem[], - status: "init" as "init" | "loading" | "ready", - params: {}, - reload: () => { - if (typeof on_load === "function") { - local.status = "loading"; - on_load(local).then((res: any) => { - if (typeof res === "object") { - if (!Array.isArray(res)) { - local.list = get(res, "list") || []; - } else { - local.list = res; - } - } - local.status = "ready"; - local.render(); - }); - } - local.render(); - }, - }); - - useEffect(() => { - if (value) { - local.list = value; - local.status = "ready"; - } - local.reload(); - }, []); - +export const Breadcrumb: FC = ({ value, className }) => { return (
= ({ className )} > - {local.status !== "ready" ? ( - - ) : ( - <> - {local.list && - (local.list || []).map((item, index): ReactNode => { - const lastIndex = local.list.length - 1; + {(value || []).map((cur, index): ReactNode => { + const lastIndex = (value || []).length - 1; - return ( - <> - {index === lastIndex ? ( -

- {item?.label} -

- ) : ( -

{ - if (item.url) navigate(item.url || ""); - if (item.onClick) item.onClick(ev); - }} - > - {item?.label} -

- )} + return ( + <> + {index === lastIndex ? ( +

+ {cur?.label} +

+ ) : ( +

{ + if (isEditor) return; + if (cur.url) navigate(cur.url || ""); + if (cur.onClick) cur.onClick(ev); + }} + > + {cur?.label} +

+ )} - {index !== lastIndex && ( -
- - - -
- )} - - ); - })} - - )} + {index !== lastIndex && ( +
+ + + +
+ )} + + ); + })}
); }; diff --git a/comps/form/Form.tsx b/comps/form/Form.tsx index 8b87467..a1642b0 100755 --- a/comps/form/Form.tsx +++ b/comps/form/Form.tsx @@ -7,13 +7,14 @@ import { editorFormData } from "./utils/ed-data"; import { formInit } from "./utils/init"; import { formReload } from "./utils/reload"; import { getPathname } from "lib/utils/pathname"; +import { sofDeleteField } from "lib/utils/soft-del-rel"; const editorFormWidth = {} as Record; export { FMLocal } from "./typings"; export const Form: FC = (props) => { - const { PassProp, body } = props; + const { PassProp, body, feature, sfd_field } = props; const fm = useLocal({ data: editorFormData[props.item.id] ? editorFormData[props.item.id].data @@ -51,8 +52,30 @@ export const Form: FC = (props) => { ? editorFormWidth[props.item.id].f : "full", }, + soft_delete: { + field: null + } }); - + useEffect(() => { + // deteksi jika ada softdelete + if(Array.isArray(props.feature)){ + if(props.feature?.find((e) => e === "soft_delete")){ + const result = sofDeleteField(props.gen_table, sfd_field) + if (result instanceof Promise) { + result.then((e) => { + // simpan fields yang berisi name dan type fields soft delete + fm.soft_delete.field = e; + if(!isEditor){ + fm.render(); + } + }); + } + }else{ + fm.soft_delete.field = null; + } + } + + }, []) const ref = useRef({ el: null as null | HTMLFormElement, rob: new ResizeObserver(([e]) => { diff --git a/comps/form/field/Field.tsx b/comps/form/field/Field.tsx index 32b42f4..2b7b8e0 100755 --- a/comps/form/field/Field.tsx +++ b/comps/form/field/Field.tsx @@ -31,45 +31,7 @@ export const Field: FC = (arg) => { const errors = fm.error.get(name); const props = { ...arg.props }; delete props.className; - if (type === "-" || !type || sub_type === "-" || !sub_type) { - return ( - <> -
- ⚠️ Field {arg.label} is not ready -
-
- {arg.msg_error} -
-
- - ); - } - if ( - (type === "multi-option" && sub_type === "-") || - (type === "multi-option" && sub_type === "table-edit" && (!arg.gen_table || arg.gen_table === "")) - ) { - return ( - <> -
- ⚠️ Table Edit {arg.label} is not ready -
-
- {arg.msg_error} -
-
- - ); - } + return (