diff --git a/comps/md/MasterDetail.tsx b/comps/md/MasterDetail.tsx index d63f2f9..ef8858f 100755 --- a/comps/md/MasterDetail.tsx +++ b/comps/md/MasterDetail.tsx @@ -25,15 +25,18 @@ export const MasterDetail: FC = (arg) => { gen_table, on_init, _item, + title, } = arg; const _ref = useRef({ PassProp, item: _item, childs: {} }); const mdr = _ref.current; const md = useLocal({ name, + title, status: isEditor ? "init" : "ready", actions: [], header: { breadcrumb: [], + internalRender() {}, render: () => {}, }, selected: null, @@ -98,8 +101,18 @@ export const MasterDetail: FC = (arg) => { } } + if (isEditor) { + useEffect(() => { + md.title = title; + md.header.render(); + }, [title]); + } return ( -
+
{md.props.show_head === "always" && } {md.status === "ready" && ( <> diff --git a/comps/md/gen/md-form.ts b/comps/md/gen/md-form.ts index 4779e5f..79e21f8 100755 --- a/comps/md/gen/md-form.ts +++ b/comps/md/gen/md-form.ts @@ -57,7 +57,7 @@ export const generateMDForm = async ( () => { const breads: BreadItem[] = [ { - label: "List ${formatName(arg.table)}", + label: md.title || "List ${formatName(arg.table)}", onClick: () => { md.selected = null; md.tab.active = "master"; diff --git a/comps/md/gen/md-gen.ts b/comps/md/gen/md-gen.ts index 214f5d8..c9f09ce 100755 --- a/comps/md/gen/md-gen.ts +++ b/comps/md/gen/md-gen.ts @@ -10,6 +10,16 @@ export const generateMasterDetail: GenFn<{ }> = async (modify, data, arg) => { const { item } = arg; + try { + const fn_title = new Function( + `return ${item.edit.props?.title?.value || "''"}` + ); + const title = fn_title(); + if (!title && item.edit.props?.gen_table) { + item.edit.setProp('title', item.edit.props?.gen_table) + } + } catch (e) {} + await generateList(arg, data, false); await generateMDForm(arg, data, false); await item.edit.commit(); diff --git a/comps/md/gen/md-list.ts b/comps/md/gen/md-list.ts index 65eb0fd..bea739a 100755 --- a/comps/md/gen/md-list.ts +++ b/comps/md/gen/md-list.ts @@ -113,7 +113,7 @@ idx: any; value: `\ () => { return [ - { label: "List ${formatName(arg.table)}" }, + { label: md.title || "List ${formatName(arg.table)}" }, ] as BreadItem[]; }; type BreadItem = { diff --git a/comps/md/utils/typings.ts b/comps/md/utils/typings.ts index a191b4c..08c00dc 100755 --- a/comps/md/utils/typings.ts +++ b/comps/md/utils/typings.ts @@ -24,6 +24,7 @@ export type MDProps = { on_init: (md: MDLocal) => void; _item: PrasiItem; deps?: any[]; + title: string; }; export type MDActions = { @@ -34,6 +35,7 @@ export type MDActions = { export type MDLocalInternal = { name: string; + title: string; status: "init" | "unready" | "ready"; header: { breadcrumb: BreadItem[]; @@ -94,6 +96,7 @@ export type MDLocal = MDLocalInternal & { render: (force?: boolean) => void }; export const MasterDetailType = `const md = { name: string; + title: string; status: string; header: { render: () => void;