fixing lib

This commit is contained in:
rizky 2024-08-13 15:44:07 -07:00
parent d14e07a1fc
commit d733a1c52b
4 changed files with 84 additions and 37 deletions

View File

@ -14,6 +14,7 @@ export const filterWhere = (filter_name: string, p: any) => {
if (pf.mode === "raw") { if (pf.mode === "raw") {
const data = pf.data?._where ? pf.data?._where : pf.data; const data = pf.data?._where ? pf.data?._where : pf.data;
for (const [k, v] of Object.entries(data)) { for (const [k, v] of Object.entries(data)) {
if (k.startsWith("_")) continue;
where[k] = v; where[k] = v;
} }
} else { } else {

View File

@ -1,12 +1,31 @@
import { useLocal } from "@/utils/use-local"; import { useLocal } from "@/utils/use-local";
import { call_prasi_events } from "lib/exports"; import { call_prasi_events } from "lib/exports";
import { hashSum } from "lib/utils/hash-sum";
import { FC, useEffect } from "react"; import { FC, useEffect } from "react";
import { FieldProp } from "../typings"; import { FieldProp } from "../typings";
import { useField } from "../utils/use-field"; import { useField } from "../utils/use-field";
import { validate } from "../utils/validate"; import { validate } from "../utils/validate";
import { FieldInput } from "./FieldInput"; import { FieldInput } from "./FieldInput";
import { Label } from "./Label"; import { Label } from "./Label";
import { hashSum } from "lib/utils/hash-sum";
const prepForSum = (obj: any): any => {
if (Array.isArray(obj)) {
return obj.map((e) => prepForSum(e));
}
const new_obj: any = {};
for (const [k, v] of Object.entries(obj) as any) {
if (typeof v === "object" && v.id) {
new_obj[k] = v.id;
continue;
}
if (typeof v === "object" && v.connect.id) {
new_obj[k] = v.connect.id;
continue;
}
new_obj[k] = v;
}
return new_obj;
};
export const Field: FC<FieldProp> = (arg) => { export const Field: FC<FieldProp> = (arg) => {
const showlabel = arg.show_label || "y"; const showlabel = arg.show_label || "y";
@ -22,8 +41,9 @@ export const Field: FC<FieldProp> = (arg) => {
useEffect(() => { useEffect(() => {
if (fm.save_status === "init" || fm.status !== "ready") return; if (fm.save_status === "init" || fm.status !== "ready") return;
if (local.prev_val === undefined) { if (local.prev_val === undefined) {
if (typeof fm.data[name] === "object") { if (typeof fm.data[name] === "object" && fm.deps.md) {
const sfied = hashSum(fm.data[name]); const sfied = hashSum(prepForSum(fm.data[name]));
if (sfied !== local.prev_val) { if (sfied !== local.prev_val) {
local.prev_val = sfied; local.prev_val = sfied;
} else { } else {
@ -36,8 +56,9 @@ export const Field: FC<FieldProp> = (arg) => {
} }
if (local.prev_val !== fm.data[name]) { if (local.prev_val !== fm.data[name]) {
if (typeof fm.data[name] === "object") { if (typeof fm.data[name] === "object" && fm.deps.md) {
const sfied = hashSum(fm.data[name]); const sfied = hashSum(prepForSum(fm.data[name]));
if (sfied !== local.prev_val) { if (sfied !== local.prev_val) {
local.prev_val = sfied; local.prev_val = sfied;
} else { } else {
@ -58,7 +79,9 @@ export const Field: FC<FieldProp> = (arg) => {
arg.on_change({ value: fm.data[name], name, fm }); arg.on_change({ value: fm.data[name], name, fm });
} }
if (fm.deps.md) {
fm.save_status = "unsaved"; fm.save_status = "unsaved";
}
if (!fm.events) { if (!fm.events) {
fm.events = { fm.events = {

View File

@ -190,6 +190,7 @@ export const TableEdit: FC<{
` `
)} )}
> >
{show_header !== "n" && (
<thead> <thead>
<tr className=" "> <tr className=" ">
{columns.map((header) => { {columns.map((header) => {
@ -225,7 +226,17 @@ export const TableEdit: FC<{
})} })}
</tr> </tr>
</thead> </thead>
<tbody className="c-pb-2"> )}
<tbody
className={cx(
"c-pb-2",
css`
label {
width: 100%;
}
`
)}
>
{Array.isArray(value) && value.length ? ( {Array.isArray(value) && value.length ? (
<> <>
{value.map((row: any, idx: number) => { {value.map((row: any, idx: number) => {
@ -233,8 +244,21 @@ export const TableEdit: FC<{
<tr> <tr>
{columns.map((header) => { {columns.map((header) => {
return ( return (
<td> <td
<div className="c-flex c-flex-row c-py-2 c-w-full c-h-full"> className={cx(
header.width > 0
? css`
width: ${header.width}px;
`
: ""
)}
>
<div
className={cx(
"c-flex c-flex-row c-pb-1 c-w-full c-h-full",
idx === 0 && "c-pt-1"
)}
>
{header.renderCell({ {header.renderCell({
props: { props: {
row: row, row: row,

View File

@ -22,7 +22,6 @@ export const FieldMoney: FC<{
const disabled = const disabled =
typeof field.disabled === "function" ? field.disabled() : field.disabled; typeof field.disabled === "function" ? field.disabled() : field.disabled;
const money = formatMoney(Number(value) || 0);
return ( return (
<div className="c-flex-grow c-flex-row c-flex c-w-full c-h-full"> <div className="c-flex-grow c-flex-row c-flex c-w-full c-h-full">
<input <input