fixing lib
This commit is contained in:
parent
d14e07a1fc
commit
d733a1c52b
|
|
@ -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 {
|
||||||
|
|
|
||||||
|
|
@ -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 });
|
||||||
}
|
}
|
||||||
|
|
||||||
fm.save_status = "unsaved";
|
if (fm.deps.md) {
|
||||||
|
fm.save_status = "unsaved";
|
||||||
|
}
|
||||||
|
|
||||||
if (!fm.events) {
|
if (!fm.events) {
|
||||||
fm.events = {
|
fm.events = {
|
||||||
|
|
|
||||||
|
|
@ -190,27 +190,17 @@ export const TableEdit: FC<{
|
||||||
`
|
`
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<thead>
|
{show_header !== "n" && (
|
||||||
<tr className=" ">
|
<thead>
|
||||||
{columns.map((header) => {
|
<tr className=" ">
|
||||||
return (
|
{columns.map((header) => {
|
||||||
<th
|
return (
|
||||||
key={header.key}
|
<th
|
||||||
className={cx(
|
key={header.key}
|
||||||
css`
|
|
||||||
background-color: #f9f9f9;
|
|
||||||
`,
|
|
||||||
header.width > 0
|
|
||||||
? css`
|
|
||||||
width: ${header.width}px;
|
|
||||||
`
|
|
||||||
: ""
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
className={cx(
|
className={cx(
|
||||||
"rdg-cell c-py-2 c-px-4 c-flex c-flex-row c-items-center c-h-full",
|
css`
|
||||||
|
background-color: #f9f9f9;
|
||||||
|
`,
|
||||||
header.width > 0
|
header.width > 0
|
||||||
? css`
|
? css`
|
||||||
width: ${header.width}px;
|
width: ${header.width}px;
|
||||||
|
|
@ -218,14 +208,35 @@ export const TableEdit: FC<{
|
||||||
: ""
|
: ""
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{header.label}
|
<div
|
||||||
</div>
|
className={cx(
|
||||||
</th>
|
"rdg-cell c-py-2 c-px-4 c-flex c-flex-row c-items-center c-h-full",
|
||||||
);
|
|
||||||
})}
|
header.width > 0
|
||||||
</tr>
|
? css`
|
||||||
</thead>
|
width: ${header.width}px;
|
||||||
<tbody className="c-pb-2">
|
`
|
||||||
|
: ""
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{header.label}
|
||||||
|
</div>
|
||||||
|
</th>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
)}
|
||||||
|
<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,
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue