This commit is contained in:
rizky 2024-04-14 00:32:00 -07:00
parent fc8d54816a
commit dff267ebdd
5 changed files with 37 additions and 3 deletions

View File

@ -5,6 +5,7 @@ import { FormHook } from "../form-old/utils/utils";
import { editorFormData } from "./utils/ed-data";
import { PropTypeText } from "./field/type/TypeText";
import { PropTypeRelation } from "./field/type/TypeRelation";
import { getProp } from "../../..";
export type FMProps = {
on_init: (arg: { fm: FMLocal; submit: any; reload: any }) => any;
@ -164,3 +165,34 @@ export const formType = (active: { item_id: string }, meta: any) => {
};
}`;
};
export const fieldType = (item: any, meta: any, fm: FMLocal) => {
const m = meta[item.id];
if (m) {
const name = getProp(m.item, "name");
const field = fm.fields[name];
const def = fm.field_def[name];
return `
const field = null as unknown as {
status: "init" | "loading" | "ready";
name: "${name}";
type: "${field.type}";
label: any;
desc: any;
prefix: any;
suffix: any;
width: any;
required: boolean;
focused: boolean;
disabled: boolean;
required_msg: any;
col?: GFCol;
Child: () => ReactNode;
input: Record<string, any> & {
render: () => void;
};
prop?: any;
}
`;
}
};

View File

@ -1,6 +1,6 @@
import { useLocal } from "@/utils/use-local";
import { FMLocal, FieldInternal, FieldProp } from "../typings";
import { useEffect } from "react";
import { FieldInternal, FieldProp } from "../typings";
export const useField = (arg: FieldProp) => {
const field = useLocal<FieldInternal<typeof arg.type>>({
@ -32,7 +32,7 @@ export const useField = (arg: FieldProp) => {
const fm = arg.fm;
useEffect(() => {
if (field.status === "init") {
if (field.status === "init" || !fm.fields[arg.name]) {
field.status = "ready";
fm.fields[arg.name] = field;
field.render();

View File

@ -50,7 +50,7 @@ export type MDLocalInternal = {
export type MDRef = { PassProp: any; child: any };
export type MDLocal = MDLocalInternal & { render: (force?: boolean) => void };
export const MasterDetailType = `{
export const MasterDetailType = `const md = {
name: string;
breadcrumb: {
label: React.ReactNode;

View File

@ -3,6 +3,7 @@ export { FieldTypeRelation } from "./comps/form/field/type/TypeRelation";
export { Form } from "@/comps/form/Form";
export { Field } from "@/comps/form/field/Field";
export { formType } from "@/comps/form/typings";
export { fieldType } from "@/comps/form/typings";
export { TableList } from "@/comps/list/TableList";
export { TableListType } from "@/comps/list/typings";
export { MasterDetail } from "@/comps/md/MasterDetail";

View File

@ -35,6 +35,7 @@ export const gen_relation = async (modify: (data: any) => void, data: any) => {
alert("Failed to generate! Primary Key not found. ");
return;
}
if (pk) {
const code = {} as any;
if (data["on_load"]) {