From 96a07a79cb13e3ec9d5b15bba8c7962466861d0c Mon Sep 17 00:00:00 2001 From: rizky Date: Sat, 20 Jul 2024 22:44:07 -0700 Subject: [PATCH] fix --- comps/filter/FilterContent.tsx | 3 +-- comps/form/Form.tsx | 12 +++++---- comps/form/field/type/TypeLink.tsx | 39 +++++++++++++++++++++++++++--- comps/form/gen/gen-form.ts | 23 +++++++++++------- comps/form/gen/on_load.ts | 15 ++++++++---- comps/form/utils/init.tsx | 9 +++---- comps/md/MasterDetail.tsx | 31 ++++++++++++++++++------ utils/prasi-events.ts | 7 ++++++ 8 files changed, 101 insertions(+), 38 deletions(-) diff --git a/comps/filter/FilterContent.tsx b/comps/filter/FilterContent.tsx index 4ec2a77..aaaeede 100755 --- a/comps/filter/FilterContent.tsx +++ b/comps/filter/FilterContent.tsx @@ -48,8 +48,7 @@ export const FilterContent: FC<{ margin-top: 0 !important; } .field-outer { - margin-top: 3px; - margin-bottom: 3px; + margin: 3px; } .search-all { diff --git a/comps/form/Form.tsx b/comps/form/Form.tsx index b75d8ff..0cdeff5 100755 --- a/comps/form/Form.tsx +++ b/comps/form/Form.tsx @@ -223,11 +223,13 @@ export const Form: FC = (props) => { ` )} > - {fm.status !== "init" && fm.size.width > 0 && ( - - {body} - - )} + <> + {fm.status !== "init" && fm.size.width > 0 && ( + + {!fm.data ? <>NO DATA : body} + + )} + diff --git a/comps/form/field/type/TypeLink.tsx b/comps/form/field/type/TypeLink.tsx index 1c59258..8904473 100755 --- a/comps/form/field/type/TypeLink.tsx +++ b/comps/form/field/type/TypeLink.tsx @@ -4,7 +4,7 @@ import { FieldLoading, Spinner } from "lib/comps/ui/field-loading"; import { hashSum } from "lib/utils/hash-sum"; import { getPathname } from "lib/utils/pathname"; import { useLocal } from "lib/utils/use-local"; -import { ArrowUpRight } from "lucide-react"; +import { ArrowUpRight, Construction, Cuboid, Loader } from "lucide-react"; import { FC, ReactNode, useEffect } from "react"; import { FMLocal, FieldLocal, FieldProp } from "../../typings"; @@ -30,14 +30,47 @@ export const FieldLink: FC<{ const link_local = useLocal({ navigating: false, }); + + const pk = Object.values(fm.field_def).find((e) => e.is_pk); + if (!pk) { + return <>No Primary Key; + } + + if (!fm.data[pk.name]) { + return ( +
+
+
Unsaved
+
+
No Item
+
+ ); + } + return (
{ call_prasi_events("form", "after_load", [opt?.fm]); diff --git a/comps/form/utils/init.tsx b/comps/form/utils/init.tsx index af6469e..69f5a49 100755 --- a/comps/form/utils/init.tsx +++ b/comps/form/utils/init.tsx @@ -64,13 +64,10 @@ export const formInit = (fm: FMLocal, props: FMProps) => { } else { result = on_load_result; } - if (!!result) { - fm.data = result; - } - if (!fm.data) { - fm.data = {}; - } + fm.data = result; + + if (result === undefined) fm.data = {}; if (isEditor) { const item_id = props.item.id; diff --git a/comps/md/MasterDetail.tsx b/comps/md/MasterDetail.tsx index dccc863..fd41fe8 100755 --- a/comps/md/MasterDetail.tsx +++ b/comps/md/MasterDetail.tsx @@ -92,16 +92,31 @@ export const MasterDetail: FC = (arg) => { md.params.parse(); if (pk) { const value = md.params.hash[md.name]; + if (!value && md.selected && Object.keys(md.selected).length === 0) { + md.params.hash[md.name] = "+"; + md.params.apply(); + } + if (value) { - if (md.selected && md.selected[pk.name] === value) { - } else { - md.selected = { [pk.name]: value }; - } - const tab = md.params.tabs[md.name]; - if (tab && md.tab.list.includes(tab)) { - md.tab.active = tab; - } else { + if (value === "+") { md.tab.active = "detail"; + if (!md.selected) { + md.selected = {}; + } else if (md.selected && md.selected[pk.name]) { + md.params.hash[md.name] = md.selected[pk.name]; + md.params.apply(); + } + } else { + if (md.selected && md.selected[pk.name] === value) { + } else { + md.selected = { [pk.name]: value }; + } + const tab = md.params.tabs[md.name]; + if (tab && md.tab.list.includes(tab)) { + md.tab.active = tab; + } else { + md.tab.active = "detail"; + } } } } diff --git a/utils/prasi-events.ts b/utils/prasi-events.ts index ba12304..bb9def9 100755 --- a/utils/prasi-events.ts +++ b/utils/prasi-events.ts @@ -2,6 +2,7 @@ import { FieldLocal } from "lib/comps/form/typings"; import { FMLocal } from "../.."; import { Prisma } from "../../typings/prisma"; import { set } from "./set"; +import { MDLocal } from "lib/comps/md/utils/typings"; const events = { form: { @@ -10,6 +11,12 @@ const events = { after_save: async (fm: FMLocal, record: any) => {}, before_load: async (fm: FMLocal) => {}, after_load: async (fm: FMLocal) => {}, + before_delete: async (md: MDLocal, fm: FMLocal) => { + return { + preventDelete: false as boolean, + navigateBack: true as boolean, + }; + }, }, field: { relation_load: async (fm: FMLocal, field: FieldLocal) => {