From b1f410758dac5b8789a2d476e4d0137eb94cd5a7 Mon Sep 17 00:00:00 2001 From: Rizky Date: Mon, 8 Jul 2024 02:29:40 -0700 Subject: [PATCH] fix --- comps/form/field/FieldInput.tsx | 3 +- comps/form/field/type/TypeInput.tsx | 6 ++ comps/form/gen/gen-form.ts | 4 - comps/md/gen/md-form.ts | 1 + comps/ui/typeahead.tsx | 7 +- gen/gen_form/gen_form.ts | 132 +++++++++++++++------------- 6 files changed, 84 insertions(+), 69 deletions(-) diff --git a/comps/form/field/FieldInput.tsx b/comps/form/field/FieldInput.tsx index ac98b50..4ba6777 100755 --- a/comps/form/field/FieldInput.tsx +++ b/comps/form/field/FieldInput.tsx @@ -36,7 +36,8 @@ export const FieldInput: FC<{ const errors = fm.error.get(name); let type_field: any = typeof arg.type === "function" ? arg.type() : arg.type; // tipe field - const disabled = typeof field.disabled === "function" ? field.disabled() : field.disabled; + const disabled = + typeof field.disabled === "function" ? field.disabled() : field.disabled; let custom = <>; if (field.type === "custom") { let res = arg.custom?.() || <>; diff --git a/comps/form/field/type/TypeInput.tsx b/comps/form/field/type/TypeInput.tsx index 553ece5..b55e8df 100755 --- a/comps/form/field/type/TypeInput.tsx +++ b/comps/form/field/type/TypeInput.tsx @@ -74,6 +74,11 @@ export const FieldTypeInput: FC<{ } else { value = null; } + + if (type_field === "datetime-local" && date instanceof Date) { + date.setMinutes(date.getMinutes() - date.getTimezoneOffset()); + value = date.toISOString().slice(0, 16); + } } else { try { let date = parse(value); @@ -98,6 +103,7 @@ export const FieldTypeInput: FC<{ const disabled = typeof field.disabled === "function" ? field.disabled() : field.disabled; + switch (type_field) { case "toggle": return ( diff --git a/comps/form/gen/gen-form.ts b/comps/form/gen/gen-form.ts index d0653df..76658be 100755 --- a/comps/form/gen/gen-form.ts +++ b/comps/form/gen/gen-form.ts @@ -37,10 +37,6 @@ export const generateForm = async ( return; } if (pk) { - let is_md: boolean | string = - item.edit?.parent?.item?.component?.id === - "cb52075a-14ab-455a-9847-6f1d929a2a73"; - if (!is_md) is_md = ""; if (data["on_load"]) { result.on_load = { diff --git a/comps/md/gen/md-form.ts b/comps/md/gen/md-form.ts index e764fdb..9ed49f8 100755 --- a/comps/md/gen/md-form.ts +++ b/comps/md/gen/md-form.ts @@ -50,6 +50,7 @@ export const generateMDForm = async ( }, }; generateForm(async (props: any) => {}, props, tablelist, false, true); + tab_detail?.edit.setProp("breadcrumb", { mode: "raw", value: `\ diff --git a/comps/ui/typeahead.tsx b/comps/ui/typeahead.tsx index 6171ea8..69324a0 100755 --- a/comps/ui/typeahead.tsx +++ b/comps/ui/typeahead.tsx @@ -320,7 +320,12 @@ export const Typeahead: FC<{ let inputval = local.search.input; if (!local.open && local.mode === "single" && local.value?.length > 0) { - inputval = local.value[0]; + const found = options.find((e) => e.value === local.value[0]); + if (found) { + inputval = found.label; + } else { + inputval = local.value[0]; + } } return ( diff --git a/gen/gen_form/gen_form.ts b/gen/gen_form/gen_form.ts index 030fb4a..899070f 100755 --- a/gen/gen_form/gen_form.ts +++ b/gen/gen_form/gen_form.ts @@ -4,73 +4,79 @@ import { GFCol, parseGenField } from "../utils"; import { newField } from "./new_field"; import { on_submit } from "./on_submit"; -export const gen_form = async (modify: (data: any) => void, data: any, is_md?: boolean) => { - const table = JSON.parse(data.gen_table.value); - const raw_fields = JSON.parse(data.gen_fields.value) as ( - | string - | { value: string; checked: string[] } - )[]; - const select = {} as any; - let pk: null | GFCol = null; - let pks: Record = {}; +export const gen_form = async ( + modify: (data: any) => void, + data: any, + is_md?: boolean +) => { + console.error("FAILED TO GENERATE: OBSOLETE FUNCTION"); + // const table = JSON.parse(data.gen_table.value); + // const raw_fields = JSON.parse(data.gen_fields.value) as ( + // | string + // | { value: string; checked: string[] } + // )[]; + // const select = {} as any; + // let pk: null | GFCol = null; + // let pks: Record = {}; - const fields = parseGenField(raw_fields); - const result = {} as any; - for (const f of fields) { - select[f.name] = true; - if (f.relation) { - select[f.name] = { - select: {}, - }; - for (const r of f.relation.fields) { - select[f.name].select[r.name] = true; - if (r.is_pk) { - pks[f.name] = r.name; - } - } - } + // const fields = parseGenField(raw_fields); + // const result = {} as any; + // for (const f of fields) { + // select[f.name] = true; + // if (f.relation) { + // select[f.name] = { + // select: {}, + // }; + // for (const r of f.relation.fields) { + // select[f.name].select[r.name] = true; + // if (r.is_pk) { + // pks[f.name] = r.name; + // } + // } + // } - if (f.is_pk) { - pk = f; - } - } + // if (f.is_pk) { + // pk = f; + // } + // } - if (!pk) { - alert("Failed to generate! Primary Key not found. "); - return; - } - if (pk) { - const code = {} as any; - if (data["on_load"]) { - result["on_load"] = data["on_load"]; - result["on_load"].value = on_load({ - pk: pk.name, - pks, - select, - table, - opt: is_md ? { is_md: true } : undefined, - }); - code.on_load = result["on_load"].value; - } + // if (!pk) { + // alert("Failed to generate! Primary Key not found. "); + // return; + // } - if (data["on_submit"]) { - result["on_submit"] = data["on_submit"]; - result["on_submit"].value = on_submit({ pk, table, select, pks }); - code.on_submit = result["on_submit"].value; - } + // if (pk) { + // const code = {} as any; + // if (data["on_load"]) { + // result["on_load"] = data["on_load"]; + // result["on_load"].value = on_load({ + // pk: pk.name, + // pks, + // select, + // table, + // opt: is_md ? { is_md: true } : undefined, + // }); + // code.on_load = result["on_load"].value; + // } - const res = await codeBuild(code); - for (const [k, v] of Object.entries(res)) { - result[k].valueBuilt = v[1]; - } + // if (data["on_submit"]) { + // result["on_submit"] = data["on_submit"]; + // result["on_submit"].value = on_submit({ pk, table, select, pks }); + // code.on_submit = result["on_submit"].value; + // } - result["body"] = data["body"]; - result.body.content.childs = []; - for (const item of fields.filter((e) => !e.is_pk)) { - result.body.content.childs.push( - await newField(item, { parent_table: table }) - ); - } - } - modify(result); + // const res = await codeBuild(code); + // for (const [k, v] of Object.entries(res)) { + // result[k].valueBuilt = v[1]; + // } + + // result["body"] = data["body"]; + // result.body.content.childs = []; + // for (const item of fields.filter((e) => !e.is_pk)) { + // result.body.content.childs.push( + // await newField(item, { parent_table: table }) + // ); + // } + // } + // modify(result); };