fix
This commit is contained in:
parent
3034a12ded
commit
032d9187ce
|
|
@ -109,6 +109,49 @@ export const newField = async (
|
||||||
} else if (["has-many", "has-one"].includes(field.type) && field.relation) {
|
} else if (["has-many", "has-one"].includes(field.type) && field.relation) {
|
||||||
const fields = parseGenField(opt.value);
|
const fields = parseGenField(opt.value);
|
||||||
const res = generateSelect(fields);
|
const res = generateSelect(fields);
|
||||||
|
let link_params = { where: "", create: "", update: "" };
|
||||||
|
let rel = field.relation;
|
||||||
|
let label = formatName(field.name);
|
||||||
|
|
||||||
|
if (field.relation) {
|
||||||
|
const rels = field.relation.fields.filter((e) => e.relation);
|
||||||
|
if (rels.length === 1) {
|
||||||
|
rel = rels[0].relation as any;
|
||||||
|
label = formatName(rel.to.table);
|
||||||
|
|
||||||
|
link_params = {
|
||||||
|
where: `{
|
||||||
|
"${rel.from.table}": {
|
||||||
|
some: {
|
||||||
|
"${field.relation.to.fields[0]}": fm.data["${field.relation.from.fields[0]}"],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} as Prisma.${rel.to.table}WhereInput`,
|
||||||
|
create: `{
|
||||||
|
"${rel.from.table}": {
|
||||||
|
create: {
|
||||||
|
"${field.relation.to.fields[0]}": fm.data["${field.relation.from.fields[0]}"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
} as Prisma.${rel.to.table}CreateInput`,
|
||||||
|
update: `{}`,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
link_params = {
|
||||||
|
where: `{
|
||||||
|
"${rel.to.fields[0]}": fm.data["${field.relation.from.fields[0]}"],
|
||||||
|
} as Prisma.${rel.to.table}WhereInput`,
|
||||||
|
create: `{
|
||||||
|
"${rel.from.table}": {
|
||||||
|
connect: {
|
||||||
|
"${rel.from.fields[0]}": fm.data["${field.relation.from.fields[0]}"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
} as Prisma.${rel.to.table}CreateInput`,
|
||||||
|
update: `{}`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (res && res.select && Object.keys(res.select).length === 1) {
|
if (res && res.select && Object.keys(res.select).length === 1) {
|
||||||
return createItem({
|
return createItem({
|
||||||
|
|
@ -118,22 +161,59 @@ export const newField = async (
|
||||||
name: field.name,
|
name: field.name,
|
||||||
label: formatName(field.name),
|
label: formatName(field.name),
|
||||||
type: "link",
|
type: "link",
|
||||||
link_opt: [
|
link__params: [
|
||||||
`({
|
`async (field: any) => {
|
||||||
url: () => {
|
return {
|
||||||
return "";
|
where: ${link_params.where},
|
||||||
},
|
create: ${link_params.create},
|
||||||
where: () => {
|
update: ${link_params.update}
|
||||||
return {} as ${
|
};
|
||||||
opt.parent_table
|
}`,
|
||||||
? `Prisma.${opt.parent_table}WhereInput`
|
],
|
||||||
: `Record<string, any>`
|
link__text: [
|
||||||
};
|
`
|
||||||
},
|
({ Link }) => {
|
||||||
breadcrumbs: (existing: any[]) => {
|
const rel = fm.data["${field.name}"];
|
||||||
return [...existing];
|
return (
|
||||||
},
|
<>
|
||||||
})`,
|
{Array.isArray(rel) && (
|
||||||
|
<div
|
||||||
|
className={cx(
|
||||||
|
"flex items-center border-r",
|
||||||
|
css\`padding:0px 10px 0px 5px;margin-right:10px;\`,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{rel.length === 0 ? "No" : rel.length}{" "}
|
||||||
|
{rel.length > 1 ? "items" : "item"}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<Link>
|
||||||
|
{({ icon }) => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div>Detail</div> {icon}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
</Link>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}`,
|
||||||
|
`({ Link }) => {
|
||||||
|
const rel = fm.data["${field.name}"];
|
||||||
|
return (React.createElement(React.Fragment, null,
|
||||||
|
Array.isArray(rel) && (React.createElement("div", { className: cx("flex items-center border-r", css\`padding:0px 10px 0px 5px;margin-right:10px;\`) },
|
||||||
|
rel.length === 0 ? "No" : rel.length,
|
||||||
|
" ",
|
||||||
|
rel.length > 1 ? "items" : "item")),
|
||||||
|
React.createElement(Link, null, ({ icon }) => {
|
||||||
|
return (React.createElement(React.Fragment, null,
|
||||||
|
React.createElement("div", null, "Detail"),
|
||||||
|
" ",
|
||||||
|
icon));
|
||||||
|
})));
|
||||||
|
};
|
||||||
|
`,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -147,6 +227,7 @@ export const newField = async (
|
||||||
pks: {},
|
pks: {},
|
||||||
type: field.type === "has-many" ? "typeahead" : "dropdown",
|
type: field.type === "has-many" ? "typeahead" : "dropdown",
|
||||||
});
|
});
|
||||||
|
|
||||||
if (["has-one"].includes(field.type)) {
|
if (["has-one"].includes(field.type)) {
|
||||||
const rel__gen_fields = JSON.stringify(
|
const rel__gen_fields = JSON.stringify(
|
||||||
field.relation?.fields.map((e) => {
|
field.relation?.fields.map((e) => {
|
||||||
|
|
@ -238,49 +319,6 @@ export const newField = async (
|
||||||
type = "link";
|
type = "link";
|
||||||
}
|
}
|
||||||
|
|
||||||
let label = formatName(field.name);
|
|
||||||
let link_params = { where: "", create: "", update: "" };
|
|
||||||
let rel = field.relation;
|
|
||||||
if (type === "link" && field.relation) {
|
|
||||||
const rels = field.relation.fields.filter((e) => e.relation);
|
|
||||||
if (rels.length === 1) {
|
|
||||||
rel = rels[0].relation as any;
|
|
||||||
label = formatName(rel.to.table);
|
|
||||||
|
|
||||||
link_params = {
|
|
||||||
where: `{
|
|
||||||
"${rel.from.table}": {
|
|
||||||
some: {
|
|
||||||
"${field.relation.to.fields[0]}": fm.data["${field.relation.from.fields[0]}"],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} as Prisma.${rel.to.table}WhereInput`,
|
|
||||||
create: `{
|
|
||||||
"${rel.from.table}": {
|
|
||||||
create: {
|
|
||||||
"${field.relation.to.fields[0]}": fm.data["${field.relation.from.fields[0]}"]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
} as Prisma.${rel.to.table}CreateInput`,
|
|
||||||
update: `{}`,
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
link_params = {
|
|
||||||
where: `{
|
|
||||||
"${rel.to.fields[0]}": fm.data["${field.relation.from.fields[0]}"],
|
|
||||||
} as Prisma.${rel.to.table}WhereInput`,
|
|
||||||
create: `{
|
|
||||||
"${rel.from.table}": {
|
|
||||||
connect: {
|
|
||||||
"${rel.from.fields[0]}": fm.data["${field.relation.from.fields[0]}"]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
} as Prisma.${rel.to.table}CreateInput`,
|
|
||||||
update: `{}`,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return createItem({
|
return createItem({
|
||||||
component: {
|
component: {
|
||||||
id: "32550d01-42a3-4b15-a04a-2c2d5c3c8e67",
|
id: "32550d01-42a3-4b15-a04a-2c2d5c3c8e67",
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,6 @@ export const generateTableList = async (
|
||||||
Object.keys(table_prop).map((e) => {
|
Object.keys(table_prop).map((e) => {
|
||||||
set(data, e, table_prop[e]);
|
set(data, e, table_prop[e]);
|
||||||
});
|
});
|
||||||
console.log(data, table_prop);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
import { useLocal } from "lib/utils/use-local";
|
||||||
|
import { FC } from "react";
|
||||||
|
|
||||||
|
export const Accordion: FC<{
|
||||||
|
on_load: () => Promise<any[]>;
|
||||||
|
PassProp: any;
|
||||||
|
child: any;
|
||||||
|
}> = ({ on_load, PassProp, child }) => {
|
||||||
|
const local = useLocal(
|
||||||
|
{ list: [] as any[], loading: true, active: 0 },
|
||||||
|
async () => {
|
||||||
|
local.list = await on_load();
|
||||||
|
local.loading = false;
|
||||||
|
local.render();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{local.loading ? (
|
||||||
|
<PassProp
|
||||||
|
loading={true}
|
||||||
|
item={{}}
|
||||||
|
activate={() => {}}
|
||||||
|
active={-1}
|
||||||
|
idx={-1}
|
||||||
|
>
|
||||||
|
{child}
|
||||||
|
</PassProp>
|
||||||
|
) : (
|
||||||
|
local.list.map((item, idx) => {
|
||||||
|
return (
|
||||||
|
<PassProp
|
||||||
|
loading={false}
|
||||||
|
item={item}
|
||||||
|
idx={idx}
|
||||||
|
key={idx}
|
||||||
|
active={local.active}
|
||||||
|
activate={() => {
|
||||||
|
local.active = idx;
|
||||||
|
local.render();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{child}
|
||||||
|
</PassProp>
|
||||||
|
);
|
||||||
|
})
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
@ -4,6 +4,10 @@ export { guessLabel } from "./utils/guess-label";
|
||||||
export { fetchLinkParams } from "./comps/form/field/type/TypeLink";
|
export { fetchLinkParams } from "./comps/form/field/type/TypeLink";
|
||||||
export { prasi_gen } from "./gen/prasi_gen";
|
export { prasi_gen } from "./gen/prasi_gen";
|
||||||
|
|
||||||
|
export const Accordion = lazify(
|
||||||
|
async () => (await import("@/comps/ui/accordion")).Accordion
|
||||||
|
);
|
||||||
|
|
||||||
export const Popover = lazify(
|
export const Popover = lazify(
|
||||||
async () => (await import("@/comps/custom/Popover")).Popover
|
async () => (await import("@/comps/custom/Popover")).Popover
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,6 @@ export const Layout: FC<LYTChild> = (props) => {
|
||||||
if (!w.user) {
|
if (!w.user) {
|
||||||
local.loading = true;
|
local.loading = true;
|
||||||
loadSession(props.login_url || "/auth/login");
|
loadSession(props.login_url || "/auth/login");
|
||||||
console.log(w.user);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue