fixing detail + field bug

This commit is contained in:
rizky 2024-08-14 02:34:24 -07:00
parent d611e4f4a4
commit 9261600dc0
6 changed files with 45 additions and 18 deletions

View File

@ -3,6 +3,7 @@ import { cx } from "class-variance-authority";
import { ArrowRight } from "lucide-react"; import { ArrowRight } from "lucide-react";
import { FC, useEffect } from "react"; import { FC, useEffect } from "react";
import { Skeleton } from "../ui/skeleton"; import { Skeleton } from "../ui/skeleton";
import { formatName } from "lib/gen/utils";
export const Detail: FC<{ export const Detail: FC<{
detail: ( detail: (
@ -15,7 +16,7 @@ export const Detail: FC<{
bind: (fn: (on_load: any) => void) => void; bind: (fn: (on_load: any) => void) => void;
}) => Promise<any>); }) => Promise<any>);
mode: "standard" | "compact" | "inline"; mode: "standard" | "compact" | "inline";
}> = ({ detail, mode, on_load }) => { }> = ({ detail: _detail, mode, on_load }) => {
const local = useLocal({ const local = useLocal({
status: "init" as "init" | "loading" | "ready", status: "init" as "init" | "loading" | "ready",
detail: null as any, detail: null as any,
@ -25,6 +26,20 @@ export const Detail: FC<{
bound: false, bound: false,
}); });
let detail: any = _detail;
if (typeof detail !== "function") {
detail = (load: any) => {
const result: any = {};
if (typeof load === "object" && !!load) {
for (const [k, v] of Object.entries(load)) {
if (k !== "id")
if (typeof v !== "object") result[k] = [formatName(k), v];
}
}
return result;
};
}
if (!isEditor) { if (!isEditor) {
if ( if (
location.pathname !== local.pathname || location.pathname !== local.pathname ||
@ -89,7 +104,11 @@ export const Detail: FC<{
if (!isEditor) { if (!isEditor) {
values = local.detail || {}; values = local.detail || {};
} else { } else {
values = detail(null); if (typeof on_load === "function") {
values = detail(on_load({} as any));
} else {
values = detail(on_load);
}
local.status = "ready"; local.status = "ready";
} }

View File

@ -13,16 +13,18 @@ const prepForSum = (obj: any): any => {
return obj.map((e) => prepForSum(e)); return obj.map((e) => prepForSum(e));
} }
const new_obj: any = {}; const new_obj: any = {};
for (const [k, v] of Object.entries(obj) as any) { if (obj) {
if (typeof v === "object" && v.id) { for (const [k, v] of Object.entries(obj) as any) {
new_obj[k] = v.id; if (typeof v === "object" && v.id) {
continue; new_obj[k] = v.id;
continue;
}
if (typeof v === "object" && v.connect.id) {
new_obj[k] = v.connect.id;
continue;
}
new_obj[k] = v;
} }
if (typeof v === "object" && v.connect.id) {
new_obj[k] = v.connect.id;
continue;
}
new_obj[k] = v;
} }
return new_obj; return new_obj;
}; };

View File

@ -1,4 +1,3 @@
import { update } from "autosize";
import { useLocal } from "lib/utils/use-local"; import { useLocal } from "lib/utils/use-local";
import { useEffect, useRef } from "react"; import { useEffect, useRef } from "react";

View File

@ -33,10 +33,10 @@ export const MDRenderMaster: FC<{
size: width, size: width,
min_size: min_width, min_size: min_width,
}); });
if (md.panel) { // if (md.panel) {
md.panel.min_size = min_width; // md.panel.min_size = min_width;
md.panel.size = width; // md.panel.size = width;
} // }
} }
}, Object.values(md.deps || {}) || []); }, Object.values(md.deps || {}) || []);

View File

@ -6,7 +6,7 @@ import { lazify, lazifyMany } from "@/utils/lazify";
import __get from "lodash.get"; import __get from "lodash.get";
import { sum } from "./utils/sum"; import { sum } from "./utils/sum";
export const _sum = sum; export const _sum = sum;
export const _get = __get; export const _get = __get;
export const Accordion = lazify( export const Accordion = lazify(
@ -19,9 +19,11 @@ export const Popover = lazify(
export const Progress = lazify( export const Progress = lazify(
async () => (await import("@/comps/ui/progress")).Progress async () => (await import("@/comps/ui/progress")).Progress
); );
export const Dialog = lazify( export const Dialog = lazify(
async () => (await import("@/comps/ui/dialog")).Dialog async () => (await import("@/comps/ui/dialog")).Dialog
); );
export const Typeahead = lazify( export const Typeahead = lazify(
async () => (await import("@/comps/ui/typeahead")).Typeahead async () => (await import("@/comps/ui/typeahead")).Typeahead
); );

View File

@ -171,9 +171,14 @@ export const FormatValue: FC<{
); );
} }
let _value = value;
if (typeof value === 'string' && value.startsWith('BigInt::')) {
_value = value.substring('BigInt::'.length)
}
return ( return (
<div className="c-flex c-space-x-2 c-items-center"> <div className="c-flex c-space-x-2 c-items-center">
<div>{value}</div> <div>{_value}</div>
</div> </div>
); );
}; };