This commit is contained in:
rizrmd 2024-06-14 08:54:56 -07:00
parent 0fe4955ecb
commit b9f9c07e01
35 changed files with 776 additions and 367 deletions

View File

@ -28,7 +28,37 @@ export const FilterContent: FC<{
&.filter-inline { &.filter-inline {
display: flex; display: flex;
align-items: center; align-items: center;
/* Styles specific to topbar */
.field {
padding-top: 0px;
align-items: center;
}
.field > .label {
display: none;
}
.field-inner {
min-height: 25px;
}
.form-inner {
align-items: center;
}
.field-input {
margin-top: 0 !important;
}
.field-outer {
margin-top: 3px;
margin-bottom: 3px;
}
.search-all {
input {
width: 150px;
}
}
.search-focus {
width: 250px !important;
}
} }
&.filter-popup { &.filter-popup {
@ -39,6 +69,10 @@ export const FilterContent: FC<{
z-index: 1000; z-index: 1000;
/* Styles specific to popup */ /* Styles specific to popup */
} }
.form-inner {
position: relative;
}
` `
)} )}
> >
@ -60,8 +94,7 @@ export const FilterContent: FC<{
); );
}} }}
</BaseForm> </BaseForm>
</div> </div>
); );
}; };

View File

@ -30,23 +30,27 @@ export const FilterField: FC<{
}, 500); }, 500);
}, [filter.form?.data[name]]); }, [filter.form?.data[name]]);
let show_modifier = filter.mode !== "inline";
return ( return (
<BaseField <BaseField
{...filter.form.fieldProps({ {...filter.form.fieldProps({
name: name || "", name: name || "",
label: label || name || "", label: label || name || "",
render: internal.render, render: internal.render,
prefix: () => ( prefix: show_modifier
<FieldModifier ? () => (
onChange={(modifier) => { <FieldModifier
filter.modifiers[name] = modifier; onChange={(modifier) => {
filter.render(); filter.modifiers[name] = modifier;
filter_window.prasiContext.render(); filter.render();
}} filter_window.prasiContext.render();
modifier={filter.modifiers[name]} }}
type={type} modifier={filter.modifiers[name]}
/> type={type}
), />
)
: undefined,
onLoad() { onLoad() {
return [{ label: "halo", value: "asda" }]; return [{ label: "halo", value: "asda" }];
}, },
@ -55,98 +59,132 @@ export const FilterField: FC<{
: "typeahead", : "typeahead",
})} })}
> >
{(field) => ( {(field) => {
<> if (type === "search-all") {
{type === "text" && ( return (
<FieldTypeInput <div className={cx("search-all c-flex items-center")}>
{...field} <div className="c-pl-2">
prop={{ <svg
type: "input", xmlns="http://www.w3.org/2000/svg"
sub_type: "text", width="14"
prefix: "", height="14"
suffix: "", viewBox="0 0 24 24"
}} fill="none"
/> stroke="currentColor"
)} strokeWidth="2"
{type === "number" && ( strokeLinecap="round"
<> strokeLinejoin="round"
>
<circle cx="11" cy="11" r="8" />
<path d="m21 21-4.3-4.3" />
</svg>
</div>
<FieldTypeInput <FieldTypeInput
{...field} {...field}
field={{
...field.field,
name:
filter.modifiers[name] === "between"
? name
: `${name}_from`,
}}
prop={{ prop={{
type: "input", type: "input",
sub_type: "number", sub_type: "search",
prefix: "", placeholder: "Search...",
suffix: "", onFocus(e) {
e.currentTarget.classList.add("search-focus");
},
onBlur(e) {
e.currentTarget.classList.remove("search-focus");
},
}} }}
/> />
{filter.modifiers[name] === "between" && ( </div>
);
}
return (
<>
{type === "text" && (
<FieldTypeInput
{...field}
prop={{
type: "input",
sub_type: "text",
}}
/>
)}
{type === "number" && (
<>
<FieldTypeInput <FieldTypeInput
{...field} {...field}
field={{ ...field.field, name: `${name}_to` }} field={{
...field.field,
name:
filter.modifiers[name] === "between"
? name
: `${name}_from`,
}}
prop={{ prop={{
type: "input", type: "input",
sub_type: "number", sub_type: "number",
prefix: "",
suffix: "",
}} }}
/> />
)} {filter.modifiers[name] === "between" && (
</> <FieldTypeInput
)} {...field}
{type === "date" && ( field={{ ...field.field, name: `${name}_to` }}
<> prop={{
<FieldTypeInput type: "input",
{...field} sub_type: "number",
field={{ }}
...field.field, />
name: )}
filter.modifiers[name] === "between" </>
? name )}
: `${name}_from`, {type === "date" && (
}} <>
prop={{
type: "input",
sub_type: "date",
prefix: "",
suffix: "",
}}
/>
{filter.modifiers[name] === "between" && (
<FieldTypeInput <FieldTypeInput
{...field} {...field}
field={{ ...field.field, name: `${name}_to` }} field={{
...field.field,
name:
filter.modifiers[name] === "between"
? name
: `${name}_from`,
}}
prop={{ prop={{
type: "input", type: "input",
sub_type: "date", sub_type: "date",
prefix: "",
suffix: "",
}} }}
/> />
)} {filter.modifiers[name] === "between" && (
</> <FieldTypeInput
)} {...field}
{type === "boolean" && ( field={{ ...field.field, name: `${name}_to` }}
<FieldCheckbox arg={field.arg} field={field.field} fm={field.fm} /> prop={{
)} type: "input",
{type === "options" && ( sub_type: "date",
<> }}
{singleOptions.includes(filter.modifiers[name]) && ( />
<SingleOption {...field} /> )}
)} </>
{multiOptions.includes(filter.modifiers[name]) && ( )}
<MultiOption {...field} /> {type === "boolean" && (
)} <FieldCheckbox
</> arg={field.arg}
)} field={field.field}
</> fm={field.fm}
)} />
)}
{type === "options" && (
<>
{singleOptions.includes(filter.modifiers[name]) && (
<SingleOption {...field} />
)}
{multiOptions.includes(filter.modifiers[name]) && (
<MultiOption {...field} />
)}
</>
)}
</>
);
}}
</BaseField> </BaseField>
); );
}; };

View File

@ -5,6 +5,7 @@ import { GenField } from "../form/typings";
import { default_filter_local, filter_window } from "./utils/types"; import { default_filter_local, filter_window } from "./utils/types";
import { FilterContent } from "./FilterContent"; import { FilterContent } from "./FilterContent";
import { getPathname } from "lib/utils/pathname"; import { getPathname } from "lib/utils/pathname";
import { getFilter } from "./utils/get-filter";
type FilterMode = "regular" | "inline" | "popup"; type FilterMode = "regular" | "inline" | "popup";
@ -34,18 +35,25 @@ export const MasterFilter: FC<FilterProps> = ({
}): ReactNode => { }): ReactNode => {
const filter = useLocal({ ...default_filter_local }); const filter = useLocal({ ...default_filter_local });
filter.name = name; filter.name = name;
filter.mode = mode;
if (!isEditor) { if (!isEditor) {
if (!filter_window.prasi_filter) { const wf = getFilter(name);
filter_window.prasi_filter = {}; if (wf) {
} wf.filter.ref[_item.id] = filter;
const pf = filter_window.prasi_filter; wf.list.render();
if (pf) {
const pathname = getPathname();
if (!pf[pathname]) pf[pathname] = {};
if (!pf[pathname][name]) pf[pathname][name] = {};
pf[pathname][name][_item.id] = filter;
} }
// if (!filter_window.prasi_filter) {
// filter_window.prasi_filter = {};
// }
// const pf = filter_window.prasi_filter;
// if (pf) {
// const pathname = getPathname();
// if (!pf[pathname]) pf[pathname] = {};
// if (!pf[pathname][name]) pf[pathname][name] = {};
// pf[pathname][name][_item.id] = filter;
// }
} }
if (mode === "popup") { if (mode === "popup") {
@ -92,12 +100,15 @@ export const MasterFilter: FC<FilterProps> = ({
} }
return ( return (
<FilterContent <>
PassProp={PassProp} <FilterContent
_item={_item} PassProp={PassProp}
child={child} _item={_item}
mode={mode} child={child}
filter={filter} mode={mode}
/> filter={filter}
/>
</>
); );
}; };

View File

View File

@ -5,7 +5,6 @@ export const filterModifier = (type: keyof typeof modifiers) => {
return { return {
label: v, label: v,
value: k, value: k,
checked: true,
}; };
}); });
}; };

View File

@ -0,0 +1,31 @@
import { getPathname } from "../../../..";
import { filter_window } from "./types";
export const getFilter = (name: string) => {
if (!filter_window.prasi_filter) {
filter_window.prasi_filter = {};
}
const pf = filter_window.prasi_filter;
if (pf) {
const pathname = getPathname();
if (!pf[pathname]) pf[pathname] = {};
if (!pf[pathname][name])
pf[pathname][name] = {
filter: {
ref: {},
render: () => {},
},
list: {
ref: {},
render: () => {},
reload() {
for (const [k, v] of Object.entries(this.ref)) {
v.reload();
}
},
},
};
return pf[pathname][name];
}
};

View File

@ -2,6 +2,7 @@ import { BaseFormLocal } from "../../form/base/types";
import { GenField } from "../../form/typings"; import { GenField } from "../../form/typings";
export type FilterFieldType = export type FilterFieldType =
| "search-all"
| "text" | "text"
| "number" | "number"
| "boolean" | "boolean"
@ -17,9 +18,17 @@ export const default_filter_local = {
modifiers: {} as Record<string, string>, modifiers: {} as Record<string, string>,
types: {} as Record<string, FilterFieldType>, types: {} as Record<string, FilterFieldType>,
name: "", name: "",
mode: "",
}; };
export const modifiers = { export const modifiers = {
"search-all": {
contains: "Contains",
starts_with: "Starts With",
ends_with: "Ends With",
equal: "Equal",
not_equal: "Not Equal",
},
text: { text: {
contains: "Contains", contains: "Contains",
starts_with: "Starts With", starts_with: "Starts With",
@ -55,8 +64,22 @@ export type FilterModifier = typeof modifiers;
export type FilterLocal = typeof default_filter_local & { render: () => void }; export type FilterLocal = typeof default_filter_local & { render: () => void };
export const filter_window = window as unknown as { export const filter_window = window as unknown as {
prasi_filter: Record<string, Record<string, Record<string, FilterLocal>>>; prasi_filter: Record<
string,
Record<
string,
{
filter: {ref: Record<string, FilterLocal>, render: () => void;};
list: {
ref: Record<string, { reload: () => void }>;
reload: () => void;
render: () => void;
};
}
>
>;
prasiContext: { prasiContext: {
render: () => void; render: () => void;
}; };
}; };

View File

@ -7,7 +7,7 @@ import { editorFormData } from "./utils/ed-data";
import { formInit } from "./utils/init"; import { formInit } from "./utils/init";
import { formReload } from "./utils/reload"; import { formReload } from "./utils/reload";
import { getPathname } from "lib/utils/pathname"; import { getPathname } from "lib/utils/pathname";
import { sofDeleteField } from "lib/utils/soft-del-rel"; import { sofDeleteField as softDeleteField } from "lib/utils/soft-del-rel";
const editorFormWidth = {} as Record<string, { w: number; f: any }>; const editorFormWidth = {} as Record<string, { w: number; f: any }>;
@ -60,7 +60,7 @@ export const Form: FC<FMProps> = (props) => {
// deteksi jika ada softdelete // deteksi jika ada softdelete
if(Array.isArray(props.feature)){ if(Array.isArray(props.feature)){
if(props.feature?.find((e) => e === "soft_delete")){ if(props.feature?.find((e) => e === "soft_delete")){
const result = sofDeleteField(props.gen_table, sfd_field) const result = softDeleteField(props.gen_table, sfd_field)
if (result instanceof Promise) { if (result instanceof Promise) {
result.then((e) => { result.then((e) => {
// simpan fields yang berisi name dan type fields soft delete // simpan fields yang berisi name dan type fields soft delete

View File

@ -52,11 +52,11 @@ export const BaseField = (prop: {
)} )}
> >
{mode !== "hidden" && <Label field={field} fm={fm} />} {mode !== "hidden" && <Label field={field} fm={fm} />}
<div className="field-inner c-flex c-flex-1 c-flex-col"> <div className="field-input c-flex c-flex-1 c-flex-col">
<div <div
className={cx( className={cx(
!["toogle", "button", "radio", "checkbox"].includes(arg.sub_type) !["toogle", "button", "radio", "checkbox"].includes(arg.sub_type)
? "field-outer c-flex c-flex-1 c-flex-row c-rounded c-border c-text-sm" ? "field-outer c-overflow-hidden c-flex c-flex-1 c-flex-row c-rounded c-border c-text-sm"
: "", : "",
fm.status === "loading" fm.status === "loading"
? css` ? css`

View File

@ -97,6 +97,12 @@ export const BaseForm = <T extends Record<string, any>>(
useEffect(() => { useEffect(() => {
form.data = data; form.data = data;
form.render(); form.render();
if (form.internal.width === 0) {
setTimeout(() => {
form.render();
}, 1000);
}
}, [data]); }, [data]);
if (form.status === "init") { if (form.status === "init") {
@ -125,6 +131,7 @@ export const BaseForm = <T extends Record<string, any>>(
); );
} }
} }
return ( return (
<form <form
onSubmit={(e) => { onSubmit={(e) => {
@ -151,10 +158,11 @@ export const BaseForm = <T extends Record<string, any>>(
} }
}} }}
> >
{form.internal.width && ( {form.internal.width > 0 && (
<>{typeof children === "function" ? children(form) : children}</> <>{typeof children === "function" ? children(form) : children}</>
)} )}
</div> </div>
</form> </form>
); );
}; };

View File

@ -52,6 +52,7 @@ export const Field: FC<FieldProp> = (arg) => {
mode === "vertical" && "c-flex-col c-space-y-1" mode === "vertical" && "c-flex-col c-space-y-1"
)} )}
{...props} {...props}
ref={typeof arg.field_ref === 'function' ? arg.field_ref : undefined}
> >
{mode !== "hidden" && showlabel === "y" && ( {mode !== "hidden" && showlabel === "y" && (
<Label field={field} fm={fm} /> <Label field={field} fm={fm} />

View File

@ -104,7 +104,7 @@ export const FieldInput: FC<{
<div <div
className={cx( className={cx(
!["toogle", "button", "radio", "checkbox"].includes(arg.sub_type) !["toogle", "button", "radio", "checkbox"].includes(arg.sub_type)
? "field-outer c-flex c-flex-1 c-flex-row c-rounded c-border c-text-sm c-bg-white" ? "field-outer c-overflow-hidden c-flex c-flex-1 c-flex-row c-rounded c-border c-text-sm c-bg-white"
: "", : "",
fm.status === "loading" fm.status === "loading"
? css` ? css`
@ -160,8 +160,6 @@ export const FieldInput: FC<{
{ {
type: type_field as any, type: type_field as any,
sub_type: arg.sub_type, sub_type: arg.sub_type,
prefix,
suffix,
} as PropTypeInput } as PropTypeInput
} }
/> />
@ -195,3 +193,4 @@ export const FieldInput: FC<{
</div> </div>
); );
}; };

View File

@ -1,7 +1,6 @@
import { TableList } from "lib/comps/list/TableList"; import { TableList } from "lib/comps/list/TableList";
import { useLocal } from "lib/utils/use-local"; import { useLocal } from "lib/utils/use-local";
import { FC, ReactElement, useEffect, useRef } from "react"; import { FC, useRef } from "react";
import { BaseForm } from "../../base/BaseForm";
import { FMLocal } from "../../typings"; import { FMLocal } from "../../typings";
export const TableEdit: FC<{ export const TableEdit: FC<{
@ -18,6 +17,7 @@ export const TableEdit: FC<{
const local = useLocal( const local = useLocal(
{ {
tbl: null as any, tbl: null as any,
rowHeight: new WeakMap<any, Record<string, HTMLDivElement>>(),
}, },
() => {} () => {}
); );
@ -41,6 +41,7 @@ export const TableEdit: FC<{
css` css`
.rdg { .rdg {
overflow-y: hidden !important; overflow-y: hidden !important;
height: var(--rdg-scroll-height) !important;
} }
.rdg-cell > div { .rdg-cell > div {
flex-direction: row; flex-direction: row;
@ -54,13 +55,13 @@ export const TableEdit: FC<{
.field-error { .field-error {
display: none; display: none;
} }
.rdg-cell {
min-height: 50px !important;
}
.rdg-header-row { .rdg-header-row {
border-top-right-radius: 5px; border-top-right-radius: 5px;
border-top-left-radius: 5px; border-top-left-radius: 5px;
} }
.table-list-inner {
position: relative !important;
}
`, `,
value.length === 0 && value.length === 0 &&
(show_header === "n" (show_header === "n"
@ -68,13 +69,8 @@ export const TableEdit: FC<{
display: none; display: none;
` `
: css` : css`
height: 50px; min-height: 35px;
`), `),
value.length > 0 &&
css`
height: ${50 *
(show_header === "n" ? value.length : value.length + 1)}px;
`,
show_header === "n" && show_header === "n" &&
css` css`
.rdg-header-row { .rdg-header-row {
@ -85,7 +81,16 @@ export const TableEdit: FC<{
ref={ref} ref={ref}
> >
<TableList <TableList
row_height={50} row_height={(row) => {
const rh = local.rowHeight.get(row);
console.log(rh);
if (rh) {
for (const div of Object.values(rh)) {
if (div.offsetHeight > 50) return div.offsetHeight + 6;
}
}
return 50;
}}
feature={[]} feature={[]}
child={child} child={child}
PassProp={PassProp} PassProp={PassProp}
@ -125,6 +130,17 @@ export const TableEdit: FC<{
}} }}
rows={tbl.data} rows={tbl.data}
fm={fm_row} 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;
}
}
}}
ext_fm={{ ext_fm={{
change: () => {}, change: () => {},
remove: () => { remove: () => {

View File

@ -8,6 +8,7 @@ export const FieldCheckbox: FC<{
fm: FMLocal; fm: FMLocal;
arg: FieldProp; arg: FieldProp;
}> = ({ field, fm, arg }) => { }> = ({ field, fm, arg }) => {
// console.log({field, fm, arg})
const local = useLocal({ const local = useLocal({
list: [] as any[], list: [] as any[],
}); });

View File

@ -1,7 +1,6 @@
import { useLocal } from "@/utils/use-local";
import { FC, isValidElement } from "react"; import { FC, isValidElement } from "react";
import { FMLocal, FieldLocal } from "../../typings"; import { FMLocal, FieldLocal } from "../../typings";
import { useLocal } from "@/utils/use-local";
import { FieldTypeInput } from "./TypeInput";
export const TypeCustom: FC<{ field: FieldLocal; fm: FMLocal }> = ({ export const TypeCustom: FC<{ field: FieldLocal; fm: FMLocal }> = ({
field, field,

View File

@ -117,7 +117,7 @@ export const TypeDropdown: FC<{
selected: values, selected: values,
}); });
}} }}
allowNew={false} allowNew={true}
autoPopupWidth={true} autoPopupWidth={true}
focusOpen={true} focusOpen={true}
mode={"multi"} mode={"multi"}

View File

@ -1,14 +1,13 @@
import { AutoHeightTextarea } from "@/comps/custom/AutoHeightTextarea"; import { AutoHeightTextarea } from "@/comps/custom/AutoHeightTextarea";
import { useLocal } from "@/utils/use-local"; import { useLocal } from "@/utils/use-local";
import parser from "any-date-parser"; import parser from "any-date-parser";
import { FC } from "react"; import Datepicker from "lib/comps/custom/Datepicker";
import { EyeIcon, EyeOff } from "lucide-react";
import { FC, FocusEvent, MouseEvent } from "react";
import { FMLocal, FieldLocal, FieldProp } from "../../typings"; import { FMLocal, FieldLocal, FieldProp } from "../../typings";
import { FieldMoney } from "./TypeMoney"; import { FieldMoney } from "./TypeMoney";
import { FieldRichText } from "./TypeRichText"; import { FieldRichText } from "./TypeRichText";
import { FieldUpload } from "./TypeUpload"; import { FieldUpload } from "./TypeUpload";
import day from "dayjs";
import { EyeIcon, EyeOff } from "lucide-react";
import Datepicker from "lib/comps/custom/Datepicker";
export type PropTypeInput = { export type PropTypeInput = {
type: "input"; type: "input";
@ -25,9 +24,11 @@ export type PropTypeInput = {
| "rich-text" | "rich-text"
| "upload" | "upload"
| "file" | "file"
| "search"
| "password"; | "password";
suffix: string; placeholder?: string;
prefix: string; onFocus?: (e: FocusEvent<HTMLDivElement>) => void;
onBlur?: (e: FocusEvent<HTMLDivElement>) => void;
}; };
const parse = parser.exportAsFunctionAny("en-US"); const parse = parser.exportAsFunctionAny("en-US");
@ -91,9 +92,9 @@ export const FieldTypeInput: FC<{
input.change_timeout = setTimeout(fm.render, 300); input.change_timeout = setTimeout(fm.render, 300);
}; };
return ( switch (type_field) {
<> case "textarea":
{type_field === "textarea" ? ( return (
<AutoHeightTextarea <AutoHeightTextarea
onChange={(ev) => { onChange={(ev) => {
fm.data[field.name] = ev.currentTarget.value; fm.data[field.name] = ev.currentTarget.value;
@ -113,128 +114,84 @@ export const FieldTypeInput: FC<{
field.render(); field.render();
}} }}
/> />
) : type_field === "upload" ? ( );
<> case "upload":
<FieldUpload field={field} fm={fm} prop={prop} /> return <FieldUpload field={field} fm={fm} prop={prop} />;
{/* <input case "money":
type="file" return <FieldMoney field={field} fm={fm} prop={prop} arg={arg} />;
id="avatar" case "rich-text":
name="avatar" return <FieldRichText field={field} fm={fm} prop={prop} />;
accept="image/png, image/jpeg" case "date":
onChange={async (event: any) => { return (
let file = null; <Datepicker
try { value={{ startDate: value, endDate: value }}
file = event.target.files[0]; displayFormat="DD MMM YYYY"
} catch (ex) {} asSingle={true}
const formData = new FormData(); useRange={false}
formData.append("file", file); onChange={(value) => {
const response = await fetch( fm.data[field.name] = value?.startDate
"https://prasi.avolut.com/_proxy/https%3A%2F%2Feam.avolut.com%2F_upload", ? new Date(value?.startDate)
{ : null;
method: "POST", renderOnChange();
body: formData, }}
} />
); );
}
if (response.ok) { return (
const contentType: any = response.headers.get("content-type"); <div className="c-flex c-relative c-flex-1">
let result; <input
if (contentType.includes("application/json")) { type={type_field}
result = await response.json(); tabIndex={0}
} else if (contentType.includes("text/plain")) { onChange={(ev) => {
result = await response.text(); if (["date", "datetime", "datetime-local"].includes(type_field)) {
} else { let result = null;
result = await response.blob(); try {
} result = new Date(ev.currentTarget.value);
if (Array.isArray(result)) { } catch (ex) {}
fm.data[field.name] = get(result, "[0]"); fm.data[field.name] = result;
fm.render(); } else {
} else { fm.data[field.name] = ev.currentTarget.value;
alert("Error upload"); }
} renderOnChange();
} else { }}
} placeholder={prop.placeholder || arg.placeholder || ""}
}} value={value}
/> */} disabled={field.disabled}
</> className="c-flex-1 c-transition-all c-bg-transparent c-outline-none c-px-2 c-text-sm c-w-full"
) : type_field === "money" ? ( spellCheck={false}
<> onFocus={(e) => {
<FieldMoney field={field} fm={fm} prop={prop} arg={arg} /> field.focused = true;
</> display = "";
) : type_field === "rich-text" ? ( field.render();
<> prop.onFocus?.(e);
<FieldRichText field={field} fm={fm} prop={prop} /> }}
</> onKeyDown={(e) => {
) : type_field === "date" ? ( if (e.key === "Enter" && fm.status === "ready") fm.submit();
<> }}
<Datepicker onBlur={(e) => {
value={{ startDate: value, endDate: value }} field.focused = false;
displayFormat="DD MMM YYYY" field.render();
asSingle={true} prop.onBlur?.(e);
useRange={false} }}
onChange={(value) => { />
fm.data[field.name] = value?.startDate {arg.sub_type === "password" && (
? new Date(value?.startDate) <div
: null; className="c-absolute c-right-0 c-h-full c-flex c-items-center c-cursor-pointer"
renderOnChange(); onClick={() => {
}} input.show_pass = !input.show_pass;
/> input.render();
</> }}
) : ( >
<div className="c-flex c-relative c-flex-1"> <div className="">
<input {input.show_pass ? (
type={type_field} <EyeIcon className="c-h-4" />
tabIndex={0} ) : (
onChange={(ev) => { <EyeOff className="c-h-4" />
if (["date", "datetime", "datetime-local"].includes(type_field)) { )}
let result = null; </div>
try {
result = new Date(ev.currentTarget.value);
} catch (ex) {}
fm.data[field.name] = result;
} else {
fm.data[field.name] = ev.currentTarget.value;
}
renderOnChange();
}}
placeholder={arg.placeholder || ""}
value={value}
disabled={field.disabled}
className="c-flex-1 c-bg-transparent c-outline-none c-px-2 c-text-sm c-w-full"
spellCheck={false}
onFocus={() => {
field.focused = true;
display = "";
field.render();
}}
onKeyDown={(e) => {
if (e.key === "Enter" && fm.status === "ready") fm.submit();
}}
onBlur={() => {
field.focused = false;
field.render();
}}
/>
{arg.sub_type === "password" && (
<div
className="c-absolute c-right-0 c-h-full c-flex c-items-center c-cursor-pointer"
onClick={() => {
input.show_pass = !input.show_pass;
input.render();
}}
>
<div className="">
{input.show_pass ? (
<EyeIcon className="c-h-4" />
) : (
<EyeOff className="c-h-4" />
)}
</div>
</div>
)}
</div> </div>
)} )}
</> </div>
); );
}; };
const isTimeString = (time: any) => { const isTimeString = (time: any) => {
@ -242,3 +199,4 @@ const isTimeString = (time: any) => {
const timePattern = /^([01]\d|2[0-3]):([0-5]\d)(:[0-5]\d)?$/; const timePattern = /^([01]\d|2[0-3]):([0-5]\d)(:[0-5]\d)?$/;
return timePattern.test(time); return timePattern.test(time);
}; };

View File

@ -8,6 +8,7 @@ import { get_value } from "./get-value";
import { on_load_rel } from "./on_load_rel"; import { on_load_rel } from "./on_load_rel";
import { set_value } from "./set-value"; import { set_value } from "./set-value";
import { createId } from "@paralleldrive/cuid2"; import { createId } from "@paralleldrive/cuid2";
import get from "lodash.get";
export type GFCol = { export type GFCol = {
name: string; name: string;
type: string; type: string;
@ -166,17 +167,21 @@ export const newField = async (
rel: fields, rel: fields,
}); });
if (!result.on_load) {
result.on_load = `() => { return []; }`;
}
let child: any = { childs: [] }; let child: any = { childs: [] };
let rel__gen_fields: any = undefined; const relation = arg.relation?.fields.filter((e) => get(e, "name") !== opt.parent_table) || [];
let sub_type = "checkbox"; let rel__gen_fields: any = JSON.stringify(
if (arg.relation?.fields?.length > 1) { relation.map((e) => {
const v = (e as any).value;
return v;
})
);
let sub_type = "typeahead";
if (arg.relation?.fields?.length > 2) {
sub_type = "table-edit"; sub_type = "table-edit";
rel__gen_fields = JSON.stringify(
arg.relation?.fields.map((e) => {
const v = (e as any).value;
return v;
})
);
child = createItem({ child = createItem({
childs: await generateRelation( childs: await generateRelation(
{ {

256
comps/form/gen/gen-field.ts Executable file
View File

@ -0,0 +1,256 @@
import { generateSelect } from "lib/comps/md/gen/md-select";
import { parseGenField } from "lib/gen/utils";
import { on_load_rel } from "./on_load_rel";
import { gen_rel_many, getColumn } from "./gen-rel-many";
import get from "lodash.get";
export const generateField = async (
data: any,
item: PrasiItem,
commit: boolean
) => {
let fieldType = getString(data.sub_type.value) as string;
let table = getString(data.rel__gen_table.value) as string;
const raw_fields = JSON.parse(data.rel__gen_fields.value) as (
| string
| { value: string; checked: string[] }
)[];
if (["checkbox", "button"].includes(fieldType)) {
const fields = parseGenField(raw_fields);
const res = generateSelect(fields);
const master = fields.find(
(e: any) => e.type === "has-one" && e.name !== table
) as any;
const pk = fields.find((e: any) => get(e, "is_pk")) as any;
const pk_master = master.relation.fields.find((e: any) => get(e, "is_pk"));
console.log(getColumn(res));
const load = on_load_rel({
pk: generateSelect(parseGenField(master.value.checked)).pk,
table: master?.name,
select: generateSelect(parseGenField(master.value.checked)).select,
pks: {},
type: fieldType,
} as any);
const result = {
opt__on_load: load,
opt__get_value: `\
(arg: {
options: { label: string; value: string; item?: string }[];
fm: FMLocal;
name: string;
type: string;
}) => {
const { options, fm, name, type } = arg;
if (isEditor) {
return fm.data[name];
}
let result = null;
result = fm.data[name];
switch (type) {
case "single-option":
try {
const data = fm.data[name];
if (typeof data === "object") {
if (typeof data?.connect?.id === "string") {
result = data.connect.id;
}else if (typeof data?.id === "string") {
result = data.id;
}
}
} catch (ex) { }
break;
case "multi-option":
const selected = [];
const data = fm.data[name];
if (Array.isArray(data) && data.length) {
data.map((e) => {
try {
if (typeof e === "object") {
if (typeof e["${master.name}"].connect?.${pk_master.name} === "string") {
selected.push(e["${master.name}"].connect.${pk_master.name});
} else if (typeof e["${master.name}"]?.${pk_master.name} === "string") {
selected.push(e["${master.name}"].${pk_master.name});
}
}
} catch (ex) { }
})
}
return selected;
break;
}
return result;
}
`,
opt__set_value: `\
(arg: {
selected: any[];
options: { label: string; value: string; item?: string }[];
fm: FMLocal;
name: string;
type: string;
}) => {
const { selected, options, fm, name, type } = arg;
switch (type) {
case "single-option":
fm.data[name] = {
connect: {
id: selected[0],
},
};
break;
case "multi-option":
let parent = {} as any;
const fields = parseGenField(fm.props.gen_fields);
const res = generateSelect(fields);
try {
parent = {
[fm.props.gen_table]: {
connect: {
[res.pk]: fm.data.id || null,
},
},
};
} catch (e) {}
fm.data[name] = selected.map((e) => {
return {
${master.name}: {
connect: {
id: e,
},
},
...parent,
};
});
break;
default:
fm.data[name] = selected.map((e) => e);
}
fm.render();
}
`,
opt__label: `\
(row: { value: string; label: string; data?: any }) => {
const cols = ${JSON.stringify(
getColumn(generateSelect(parseGenField(master.value.checked)))
)};
if (isEditor) {
return row.label;
}
const result = [];
if (!!row.data && !row.label && !Array.isArray(row.data)) {
if(cols.length > 0){
cols.map((e) => {
if (row.data[e]) {
result.push(row.data[e]);
}
});
return result.join(" - ");
} else {
const fields = parseGenField(rel__gen_fields);
return fields
.filter((e) => !e.is_pk)
.map((e) => row.data[e.name])
.filter((e) => e)
.join(" - ");
}
}
return row.label;
}
`,
} as any;
Object.keys(result).map((e) => {
item.edit.setProp(e, {
mode: "raw",
value: result[e],
});
});
await item.edit.commit();
// console.log("halo", {fieldType, table, fields, res, load});
// console.log({
// table_parent: table,
// arg: fields.find(
// (e: any) => e.type === "has-one" && e.name !== table
// ),
// rel: fields.filter(
// (e: any) => e.type !== "has-many"
// ),
// })
// const result = gen_rel_many({
// table_parent: table,
// arg: fields.find(
// (e: any) => e.type === "has-one" && e.name !== table
// ),
// rel: fields.filter(
// (e: any) => e.type !== "has-many"
// ),
// });
} else if (["table-edit"].includes(fieldType)) {
const result = {
opt__on_load: "() => { return []; }",
opt__get_value: `\
(arg: {
options: { label: string; value: string; item?: string }[];
fm: FMLocal;
name: string;
type: string;
}) => {
const { options, fm, name, type } = arg;
if (isEditor) {
return fm.data[name];
}
let result = null;
result = fm.data[name];
switch (type) {
case "single-option":
try {
const data = fm.data[name];
if (typeof data === "object") {
if (typeof data?.connect?.id === "string") {
result = data.connect.id;
}else if (typeof data?.id === "string") {
result = data.id;
}
}
} catch (ex) { }
break;
}
return result;
}
`,
opt__set_value: `\
(arg: {
selected: any[];
options: { label: string; value: string; item?: string }[];
fm: FMLocal;
name: string;
type: string;
}) => {
fm.render();
}
`,
opt__label: `\
(row: { value: string; label: string; item?: any }) => {
return row.label;
}
`,
} as any;
Object.keys(result).map((e) => {
item.edit.setProp(e, {
mode: "raw",
value: result[e],
});
});
await item.edit.commit();
}
};
export const getString = (data: string) => {
let result = null;
try {
result = eval(data);
} catch (e) {
result = data;
}
return result;
};

View File

@ -116,12 +116,7 @@ export const gen_rel_many = (prop: {
fm.render(); fm.render();
} }
`; `;
const cols = []; const cols = getColumn(select) || [];
for (const [k, v] of Object.entries(select.select) as any) {
if (k !== select.pk && typeof v !== "object") {
cols.push(k);
}
}
const get_label = `\ const get_label = `\
(row: { value: string; label: string; data?: any }) => { (row: { value: string; label: string; data?: any }) => {
const cols = ${JSON.stringify(cols)}; const cols = ${JSON.stringify(cols)};
@ -161,7 +156,6 @@ export const gen_rel_many = (prop: {
} }
`; `;
result.get_value = `\ result.get_value = `\
(arg: { (arg: {
options: { label: string; value: string; item?: string }[]; options: { label: string; value: string; item?: string }[];
@ -207,3 +201,13 @@ export const gen_rel_many = (prop: {
} }
return result; return result;
}; };
export const getColumn = (data: any) => {
const cols = [];
for (const [k, v] of Object.entries(data.select) as any) {
if (k !== data.pk && typeof v !== "object") {
cols.push(k);
}
}
return cols;
};

View File

@ -38,7 +38,6 @@ export const generateRelation = async (
return result; return result;
} }
} else { } else {
console.log(item.edit.props);
} }
}; };

View File

@ -1,13 +1,17 @@
import { isEmptyString } from "lib/utils/is-empty-string";
export const on_load_rel = ({ export const on_load_rel = ({
pk, pk,
table, table,
select, select,
pks, pks,
type
}: { }: {
pk: string; pk: string;
table: string; table: string;
select: any; select: any;
pks: Record<string, string>; pks: Record<string, string>;
type?: string;
}) => { }) => {
const sample = { const sample = {
label: "sample", label: "sample",
@ -34,15 +38,15 @@ export const on_load_rel = ({
if (arg.mode === 'count') { if (arg.mode === 'count') {
return await db.${table}.count(); return await db.${table}.count();
} }
${!isEmptyString(type) && ["checkbox", "typeahead", "button"].includes(type as any) ? `` : `const fields = parseGenField(rel__gen_fields);
const fields = parseGenField(rel__gen_fields); const res = generateSelect(fields);`}
const res = generateSelect(fields);
const items = await db.${table}.findMany({ const items = await db.${table}.findMany({
select: { ${!isEmptyString(type) && ["checkbox", "typeahead", "button"].includes(type as any) ? `` : `select: {
...${JSON.stringify(select)}, ...${JSON.stringify(select)},
...(res?.select || {}) ...(res?.select || {})
}, },`}
orderBy: arg.orderBy || { orderBy: arg.orderBy || {
${pk}: "desc" ${pk}: "desc"
}, },

View File

@ -1,5 +1,5 @@
import { GFCol } from "@/gen/utils"; import { GFCol } from "@/gen/utils";
import { ReactNode } from "react"; import { MutableRefObject, ReactNode } from "react";
import { editorFormData } from "./utils/ed-data"; import { editorFormData } from "./utils/ed-data";
export type FMProps = { export type FMProps = {
@ -49,6 +49,7 @@ export type FieldProp = {
fm: FMLocal; fm: FMLocal;
type: FieldType | (() => FieldType); type: FieldType | (() => FieldType);
required: ("y" | "n") | (() => "y" | "n"); required: ("y" | "n") | (() => "y" | "n");
field_ref?: (ref: any) => void;
required_msg: (name: string) => string; required_msg: (name: string) => string;
on_change: (arg: { value: any }) => void | Promise<void>; on_change: (arg: { value: any }) => void | Promise<void>;
PassProp: any; PassProp: any;
@ -72,7 +73,7 @@ export type FieldProp = {
name: string; name: string;
type: string; type: string;
}) => any; }) => any;
tbl_show_header?: "y" | "n" tbl_show_header?: "y" | "n";
opt_set_value: (arg: { opt_set_value: (arg: {
selected: string[]; selected: string[];
options: { label: string; value: string; item?: string }[]; options: { label: string; value: string; item?: string }[];
@ -157,7 +158,11 @@ export type FieldInternal<T extends FieldProp["type"]> = {
options: { options: {
on_load?: () => Promise<{ value: string; label: string }[]>; on_load?: () => Promise<{ value: string; label: string }[]>;
}; };
on_change?: (arg: { value: any, name: string, fm: FMLocal }) => void | Promise<void>; on_change?: (arg: {
value: any;
name: string;
fm: FMLocal;
}) => void | Promise<void>;
prop?: any; prop?: any;
}; };
export type FieldLocal = FieldInternal<any> & { export type FieldLocal = FieldInternal<any> & {
@ -249,3 +254,4 @@ export const FieldTypeCustom = `type CustomField =
{ field: "text", type: "text" | "password" | "number" | "date" | "datetime" } { field: "text", type: "text" | "password" | "number" | "date" | "datetime" }
| { field: "relation", type: "has-many" | "has-one" } | { field: "relation", type: "has-many" | "has-one" }
`; `;

View File

@ -1,5 +1,5 @@
import { useLocal } from "@/utils/use-local"; import { useLocal } from "@/utils/use-local";
import { useEffect } from "react"; import { useEffect, useRef } from "react";
import { FieldInternal, FieldProp } from "../typings"; import { FieldInternal, FieldProp } from "../typings";
export const useField = ( export const useField = (
@ -14,8 +14,11 @@ export const useField = (
return <arg.PassProp>{arg.child}</arg.PassProp>; return <arg.PassProp>{arg.child}</arg.PassProp>;
}, },
input: {}, input: {},
ref: null as any,
} as any); } as any);
const ref = useRef(null as any)
field.ref = ref;
const name = typeof arg.name === "string" ? arg.name : arg.name(); const name = typeof arg.name === "string" ? arg.name : arg.name();
const label = typeof arg.label === "string" ? arg.label : arg.label(); const label = typeof arg.label === "string" ? arg.label : arg.label();
const required = const required =

View File

@ -10,6 +10,7 @@ import {
MouseEvent, MouseEvent,
ReactElement, ReactElement,
ReactNode, ReactNode,
useCallback,
useEffect, useEffect,
} from "react"; } from "react";
import DataGrid, { import DataGrid, {
@ -25,6 +26,8 @@ import { filterWhere } from "../filter/utils/filter-where";
import { Skeleton } from "../ui/skeleton"; import { Skeleton } from "../ui/skeleton";
import "./TableList.css"; import "./TableList.css";
import { sortTree } from "./utils/sort-tree"; import { sortTree } from "./utils/sort-tree";
import { getFilter } from "../filter/utils/get-filter";
import { callback } from "chart.js/dist/helpers/helpers.core";
type OnRowClick = (arg: { type OnRowClick = (arg: {
row: any; row: any;
@ -55,7 +58,7 @@ type TableListProp = {
feature?: Array<any>; feature?: Array<any>;
filter_name: string; filter_name: string;
render_row?: (child: any, data: any) => ReactNode; render_row?: (child: any, data: any) => ReactNode;
row_height?: number; row_height?: number | ((row: any) => number);
render_col?: (arg: { render_col?: (arg: {
props: RenderCellProps<any, unknown>; props: RenderCellProps<any, unknown>;
tbl: any; tbl: any;
@ -76,6 +79,7 @@ const selectCellClassname = css`
margin: 0; margin: 0;
} }
`; `;
export const TableList: FC<TableListProp> = ({ export const TableList: FC<TableListProp> = ({
name, name,
on_load, on_load,
@ -90,7 +94,6 @@ export const TableList: FC<TableListProp> = ({
id_parent, id_parent,
feature, feature,
filter_name, filter_name,
render_row,
row_height: rowHeight, row_height: rowHeight,
render_col, render_col,
show_header, show_header,
@ -200,6 +203,52 @@ export const TableList: FC<TableListProp> = ({
}, },
}); });
const reload = useCallback(() => {
if (typeof on_load === "function") {
local.status = "loading";
local.render();
const orderBy = local.sort.orderBy || undefined;
const load_args: any = {
async reload() {},
where,
orderBy,
paging: {
take: local.paging.take > 0 ? local.paging.take : undefined,
skip: local.paging.skip,
},
};
if (id_parent) {
load_args.paging = {};
}
const result = on_load({ ...load_args, mode: "query" });
const callback = (data: any[]) => {
if (local.paging.skip === 0) {
local.data = data;
} else {
local.data = [...local.data, ...data];
}
local.status = "ready";
local.render();
};
if (result instanceof Promise) result.then(callback);
else callback(result);
}
}, [
on_load,
local.sort.orderBy,
where,
local.paging.take,
local.paging.skip,
]);
if (filter_name) {
const f = getFilter(filter_name);
if (f) {
f.list.ref[_item.id] = { reload };
}
}
// code ini digunakan untuk mengambil nama dari pk yang akan digunakan sebagai key untuk id // code ini digunakan untuk mengambil nama dari pk yang akan digunakan sebagai key untuk id
const pk = local.pk?.name || "id"; const pk = local.pk?.name || "id";
useEffect(() => { useEffect(() => {
@ -210,34 +259,7 @@ export const TableList: FC<TableListProp> = ({
(async () => { (async () => {
on_init(local); on_init(local);
if (local.status === "reload" && typeof on_load === "function") { if (local.status === "reload" && typeof on_load === "function") {
local.status = "loading"; reload();
local.render();
const orderBy = local.sort.orderBy || undefined;
const load_args: any = {
async reload() {},
where,
orderBy,
paging: {
take: local.paging.take > 0 ? local.paging.take : undefined,
skip: local.paging.skip,
},
};
if (id_parent) {
load_args.paging = {};
}
const result = on_load({ ...load_args, mode: "query" });
const callback = (data: any[]) => {
if (local.paging.skip === 0) {
local.data = data;
} else {
local.data = [...local.data, ...data];
}
local.status = "ready";
local.render();
};
if (result instanceof Promise) result.then(callback);
else callback(result);
} }
})(); })();
}, [local.status, on_load, local.sort.orderBy]); }, [local.status, on_load, local.sort.orderBy]);
@ -258,7 +280,7 @@ export const TableList: FC<TableListProp> = ({
sub_name = "tbl-col"; sub_name = "tbl-col";
break; break;
case "list": case "list":
sub_name = "md-list"; sub_name = "list-row";
break; break;
} }
@ -646,7 +668,7 @@ export const TableList: FC<TableListProp> = ({
{data.map((e, idx) => { {data.map((e, idx) => {
return ( return (
<div <div
className="flex-grow hover:c-bg-[#e2f1ff]" className="flex-grow"
onClick={(ev) => { onClick={(ev) => {
if (!isEditor && typeof row_click === "function") { if (!isEditor && typeof row_click === "function") {
row_click({ row_click({

View File

@ -12,6 +12,12 @@ import {
import { MDLocalInternal, MDProps } from "./utils/typings"; import { MDLocalInternal, MDProps } from "./utils/typings";
import { mdRenderLoop } from "./utils/md-render-loop"; import { mdRenderLoop } from "./utils/md-render-loop";
import { parseGenField } from "lib/gen/utils"; import { parseGenField } from "lib/gen/utils";
import { toast } from "sonner";
import { Loader2 } from "lucide-react";
import get from "lodash.get";
const w = window as unknown as {
generating_prasi_md: Record<string, true>;
};
export const MasterDetail: FC<MDProps> = (arg) => { export const MasterDetail: FC<MDProps> = (arg) => {
const { const {
@ -95,6 +101,14 @@ export const MasterDetail: FC<MDProps> = (arg) => {
} }
} }
} }
if (get(w, "generating_prasi_md.master_detail"))
return (
<div className="c-relative c-p-4 c-w-full c-bg-white c-rounded-lg c-overflow-hidden c-h-full c-shadow c-flex c-justify-center c-items-center">
<Loader2 className="c-h-4 c-w-4 c-animate-spin" />
Loading Master Detail...
</div>
);
return ( return (
<div <div
className={cx( className={cx(

View File

@ -7,33 +7,20 @@ const w = window as unknown as {
generating_prasi_md: Record<string, true>; generating_prasi_md: Record<string, true>;
}; };
export const generateMasterDetail: GenFn<{ item: PrasiItem, table: string, fields: any }> = async ( export const generateMasterDetail: GenFn<{
modify, item: PrasiItem;
data, table: string;
arg fields: any;
) => { }> = async (modify, data, arg) => {
const {item} = arg; const { item } = arg;
// loading generate MD // w.generating_prasi_md = {
w.generating_prasi_md = { // master_detail: true,
master_detail: true, // };
}; // const result: any = {};
// modify(result);
await generateList(arg, data, false); await generateList(arg, data, false);
await generateMDForm(arg, data, false) await generateMDForm(arg, data, false);
// const childs = item.edit.childs[0].edit.childs;
// const master = childs.find(
// (e) => e.component?.id === "c68415ca-dac5-44fe-aeb6-936caf8cc491"
// );
// if (master) {
// master.edit.setProp("on_init", {
// mode: "raw",
// value: `async (text: string) => {
// }`,
// });
//
// }
await item.edit.commit(); await item.edit.commit();
// delete w.generating_prasi_md["master_detail"];
// modify({});
}; };

View File

@ -5,7 +5,7 @@ export const modeTableList = (mode: string) => {
sub_name = "tbl-col"; sub_name = "tbl-col";
break; break;
case "list": case "list":
sub_name = "md-list"; sub_name = "list-row";
break; break;
} }
return sub_name; return sub_name;

View File

@ -23,8 +23,8 @@ export const on_load = ({
}); });
const field = fields.find((e) => e.name === k); const field = fields.find((e) => e.name === k);
sample[k] = val; sample[k] = val;
if(field){ if (field) {
if(field.type === "has-many"){ if (field.type === "has-many") {
sample[k] = [val]; sample[k] = [val];
} }
} }
@ -74,7 +74,7 @@ export const on_load = ({
orderBy?: Record<string, "asc" | "desc">; orderBy?: Record<string, "asc" | "desc">;
paging: { take: number; skip: number }; paging: { take: number; skip: number };
mode: 'count' | 'query'; mode: 'count' | 'query';
where?: any where?: Record<string, any>;
} }
`; `;
}; };

View File

@ -16,7 +16,6 @@ export const MDRenderMaster: FC<{
let md = on_init(); let md = on_init();
md.header.breadcrumb = breadcrumb(); md.header.breadcrumb = breadcrumb();
md.header.render(); md.header.render();
if (md) { if (md) {
let width = 0; let width = 0;
let min_width = 0; let min_width = 0;

View File

@ -75,7 +75,7 @@ export { password } from "@/utils/password";
export { generateTableList } from "@/comps/md/gen/gen-table-list"; export { generateTableList } from "@/comps/md/gen/gen-table-list";
export { generateForm } from "@/comps/form/gen/gen-form"; export { generateForm } from "@/comps/form/gen/gen-form";
export { generateSelect } from "@/comps/md/gen/md-select"; export { generateSelect } from "@/comps/md/gen/md-select";
export {generateField} from "@/comps/form/gen/gen-field";
/** Session */ /** Session */
export { export {
registerSession, registerSession,

View File

@ -59,7 +59,7 @@ export const gen_table_list = async (
sub_name = "tbl-col"; sub_name = "tbl-col";
break; break;
case "list": case "list":
sub_name = "md-list"; sub_name = "list-row";
break; break;
} }

View File

@ -51,7 +51,7 @@ type TableOnLoad = {
orderBy?: Record<string, "asc" | "desc">; orderBy?: Record<string, "asc" | "desc">;
paging: { take: number; skip: number }; paging: { take: number; skip: number };
mode: 'count' | 'query'; mode: 'count' | 'query';
where?: any where?: Record<string, any>;
} }
`; `;
}; };

View File

@ -75,7 +75,7 @@ export const Layout: FC<LYTChild> = (props) => {
} }
} }
if (!w.user) return props.blank_layout; if (!w.user && !isEditor) return props.blank_layout;
return <>{props.default_layout}</>; return <>{props.default_layout}</>;
}; };

View File

@ -16,12 +16,11 @@ export const Menu: FC<MenuProp> = (props) => {
cache: false, cache: false,
active: null as any, active: null as any,
mode: "full" as "full" | "mini", mode: "full" as "full" | "mini",
}); });
useEffect(( )=>{ useEffect(() => {
local.mode = props.mode; local.mode = props.mode;
local.render(); local.render();
}, [props.mode]) }, [props.mode]);
if (!local.open.length && !local.cache) { if (!local.open.length && !local.cache) {
const result = findChildMenu(menu, (e: any) => e[2] === pathname); const result = findChildMenu(menu, (e: any) => e[2] === pathname);
if (Array.isArray(result)) { if (Array.isArray(result)) {
@ -31,9 +30,6 @@ export const Menu: FC<MenuProp> = (props) => {
local.render(); local.render();
} }
} }
const styles = props.style;
const PassProp = props.PassProp;
return ( return (
<div <div
className={cx( className={cx(
@ -41,16 +37,13 @@ export const Menu: FC<MenuProp> = (props) => {
"c-h-full c-w-full c-flex c-flex-col c-flex-grow c-px-3 c-py-4 c-overflow-y-auto c-rounded " "c-h-full c-w-full c-flex c-flex-col c-flex-grow c-px-3 c-py-4 c-overflow-y-auto c-rounded "
)} )}
> >
<div className="c-px-2 c-py-2" onClick={async () => { <SideBar
const item = props.item; data={menu}
// item.edit.setProp("mode", props.mode === "mini" ? "full": "mini"); local={local}
// await item.edit.commit(); pm={props}
local.mode = local.mode === "mini" ? "full": "mini"; depth={0}
local.render(); mode={local.mode}
}}> />
{/* {icon.hamburger} */}
</div>
<SideBar data={menu} local={local} pm={props} depth={0} mode={local.mode}/>
</div> </div>
); );
}; };