fix table edit

This commit is contained in:
rizky 2024-07-25 05:09:41 -07:00
parent c9e591fac3
commit 3cbe406f67
8 changed files with 43 additions and 26 deletions

View File

@ -62,6 +62,9 @@ export const TableEdit: FC<{
.table-list-inner {
position: relative !important;
}
.typeahead-arrow {
margin-right: 10px;
}
`,
value.length === 0 &&
(show_header === "n"
@ -83,12 +86,16 @@ export const TableEdit: FC<{
<TableList
row_height={(row) => {
const rh = local.rowHeight.get(row);
let h = 50;
if (rh) {
for (const div of Object.values(rh)) {
if (div.offsetHeight > 50) return div.offsetHeight + 6;
if (div) {
if (div.offsetHeight > 50) h = div.offsetHeight + 6;
}
}
}
return 50;
return h;
}}
feature={[]}
child={child}
@ -118,6 +125,14 @@ export const TableEdit: FC<{
local.tbl = tbl;
const key = props.column.key;
if (!local.rowHeight.has(props.row)) {
local.rowHeight.set(props.row, {});
}
const rh = local.rowHeight.get(props.row);
if (rh && tbl.el) {
rh[props.column.key] = tbl.el.querySelector(".field");
}
return (
<PassProp
idx={props.rowIdx}
@ -129,17 +144,6 @@ export const TableEdit: FC<{
}}
rows={tbl.data}
fm={fm_row}
field_ref={(ref: any) => {
if (ref) {
if (!local.rowHeight.has(props.row)) {
local.rowHeight.set(props.row, {});
}
const rh = local.rowHeight.get(props.row);
if (rh) {
rh[props.column.key] = ref;
}
}
}}
fm_parent={parent}
ext_fm={{
idx: props.rowIdx,

View File

@ -308,7 +308,7 @@ return (React.createElement(React.Fragment, null,
let sub_type = "typeahead";
if (field.relation?.fields.filter((e) => !e.is_pk)?.length >= 2) {
sub_type = "table-edit";
sub_type = "table-edit";
child = createItem({
childs: await generateRelation(
{
@ -320,7 +320,7 @@ return (React.createElement(React.Fragment, null,
false
),
});
} else {
} else if (!opt.is_from_table_edit) {
type = "link";
}

View File

@ -58,11 +58,11 @@ export const genRelMany = (prop: {
data.map((e) => {
try {
if (typeof e === "object") {
if (typeof e["${master.name}"].connect?.${pk_master.name} === "string") {
if (typeof e["${master.name}"]?.connect?.${pk_master.name} !== "undefined") {
selected.push(e["${master.name}"].connect.${pk_master.name});
} else if (typeof e["${master.name}"]?.${pk_master.name} === "string") {
} else if (typeof e["${master.name}"]?.${pk_master.name}!== "undefined") {
selected.push(e["${master.name}"].${pk_master.name});
}
}
}
} catch (ex) { }
})
@ -92,15 +92,18 @@ export const genRelMany = (prop: {
break;
case "multi-option":
let parent = {} as any;
try {
call_prasi_events("form", "relation_before_save", ["${arg.relation.to.table}", parent]);
if (fm.data.id){
parent = {
...parent,
${arg.relation.from.table}: {
connect: {
${arg.relation.from.fields[0]}: fm.data.id || null,
},
},
};
} catch (e) {}
}
fm.data[name] = selected.map((e) => {
return {
${master.name}: {

View File

@ -46,7 +46,7 @@ export const genTableEdit = async (
parent_table: table,
value,
on_change: `() => { ext_fm.change(); }`,
is_from_table_edit: true
is_from_table_edit: true,
},
false
);
@ -78,6 +78,7 @@ export const genTableEdit = async (
props: {
name: "option",
title: "",
width: "`75`",
child: {
id: createId(),
name: "option",
@ -88,6 +89,7 @@ export const genTableEdit = async (
adv: { css: "" },
dim: { h: "fit", w: "fit" },
name: "info",
hidden: "all",
type: "item",
childs: [
{

View File

@ -73,7 +73,7 @@ async (arg: {
items = sortTree(items, rel__id_parent, "${pk}");
}
if(items.length){
if(Array.isArray(items) && items.length){
const cols = ${JSON.stringify(cols)};
const getLabel = (data: any) => {
const result = [];

View File

@ -15,6 +15,14 @@ export const generateSelect = (data: Array<any>) => {
}
} else {
select[f.name].select[r.name] = true;
if (r.relation) {
if (r.relation?.fields) {
select[f.name].select[r.name] = {
select: generateSelect(r.relation?.fields).select,
};
}
}
}
}
}

View File

@ -316,7 +316,7 @@ export const Typeahead: FC<{
return item;
}
const item = local.options.find((item) => item.value === value);
const item = local.options.find((e) => e.value === value);
return item;
});
@ -378,7 +378,6 @@ export const Typeahead: FC<{
) : (
<></>
)}
<TypeaheadOptions
popup={true}
onOpenChange={(open) => {
@ -534,11 +533,10 @@ export const Typeahead: FC<{
onKeyDown={keydown}
/>
</TypeaheadOptions>
{local.mode === "single" && (
<div
className={cx(
"c-absolute c-pointer-events-none c-z-10 c-inset-0 c-left-auto c-flex c-items-center ",
"typeahead-arrow c-absolute c-pointer-events-none c-z-10 c-inset-0 c-left-auto c-flex c-items-center ",
" c-justify-center c-w-6 c-mr-1 c-my-2 c-bg-white",
disabled && "c-hidden"
)}

View File

@ -78,6 +78,7 @@ type SimplifiedItem = {
dim?: any;
layout?: any;
border?: any;
hidden?: string;
};
export const createItem = (arg: SimplifiedItem): any => {
@ -145,6 +146,7 @@ export const createItem = (arg: SimplifiedItem): any => {
type: "item",
component,
adv: arg.adv,
hidden: arg.hidden,
childs: arg.childs?.map(createItem) || [],
};
};