@oondemand/oon-core-front 0.3.43 → 0.3.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +25 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2478,6 +2478,18 @@ function CoreRowAction({ action, row, parent, onOpenDetail, onRefresh, onUpdate
|
|
|
2478
2478
|
|
|
2479
2479
|
// src/components/internal/CoreRelatedGrid.tsx
|
|
2480
2480
|
import { Fragment as Fragment2, jsx as jsx14, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
2481
|
+
function parentValueAt(parent, path) {
|
|
2482
|
+
return path.split(".").reduce((current, part) => {
|
|
2483
|
+
if (!current || typeof current !== "object") return void 0;
|
|
2484
|
+
return current[part];
|
|
2485
|
+
}, parent);
|
|
2486
|
+
}
|
|
2487
|
+
function mergeCreateFields(schemaFields, overrides, foreignKey) {
|
|
2488
|
+
const base = schemaFields.filter((field) => ![foreignKey, "_id", "createdAt", "updatedAt"].includes(field.field));
|
|
2489
|
+
if (!overrides?.length) return base;
|
|
2490
|
+
const byName = new Map(base.map((field) => [field.field, field]));
|
|
2491
|
+
return overrides.map((override) => ({ ...byName.get(override.field) ?? {}, ...override }));
|
|
2492
|
+
}
|
|
2481
2493
|
function CoreRelatedGrid({
|
|
2482
2494
|
tab: rawTab,
|
|
2483
2495
|
parent,
|
|
@@ -2502,6 +2514,17 @@ function CoreRelatedGrid({
|
|
|
2502
2514
|
() => (tab.columns?.length ? tab.columns : schema?.fields.slice(0, 8).map((field) => field.name) ?? []).map((column) => normalizeColumn(column, schema)).filter((column) => !column.hidden),
|
|
2503
2515
|
[tab.columns, schema]
|
|
2504
2516
|
);
|
|
2517
|
+
const schemaFormFields = useMemo5(() => formFieldsFromMeta(schema?.fields ?? []), [schema?.fields]);
|
|
2518
|
+
const createFields = useMemo5(
|
|
2519
|
+
() => mergeCreateFields(schemaFormFields, tab.create?.fields, relation?.foreignKey),
|
|
2520
|
+
[schemaFormFields, tab.create?.fields, relation?.foreignKey]
|
|
2521
|
+
);
|
|
2522
|
+
const createInitialValues = useMemo5(() => {
|
|
2523
|
+
const inherited = Object.fromEntries(
|
|
2524
|
+
Object.entries(tab.create?.initialValuesFromParent ?? {}).map(([field, path]) => [field, parentValueAt(parent, path)])
|
|
2525
|
+
);
|
|
2526
|
+
return { ...tab.create?.initialValues ?? {}, ...inherited };
|
|
2527
|
+
}, [tab.create?.initialValues, tab.create?.initialValuesFromParent, parent]);
|
|
2505
2528
|
const [drafts, setDrafts] = useState7({});
|
|
2506
2529
|
const [errors, setErrors] = useState7({});
|
|
2507
2530
|
const [creating, setCreating] = useState7(false);
|
|
@@ -2520,7 +2543,7 @@ function CoreRelatedGrid({
|
|
|
2520
2543
|
});
|
|
2521
2544
|
const createMutation = useMutation({
|
|
2522
2545
|
mutationFn: (values) => resource.create({
|
|
2523
|
-
...
|
|
2546
|
+
...createInitialValues,
|
|
2524
2547
|
...values,
|
|
2525
2548
|
...relation && parentValue != null ? { [relation.foreignKey]: parentValue } : {}
|
|
2526
2549
|
}),
|
|
@@ -2542,7 +2565,6 @@ function CoreRelatedGrid({
|
|
|
2542
2565
|
...current,
|
|
2543
2566
|
[id]: { ...current[id] ?? {}, [field]: value }
|
|
2544
2567
|
}));
|
|
2545
|
-
const createFields = tab.create?.fields?.length ? tab.create.fields : formFieldsFromMeta(schema?.fields ?? []).filter((field) => ![relation.foreignKey, "_id", "createdAt", "updatedAt"].includes(field.field));
|
|
2546
2568
|
return /* @__PURE__ */ jsxs9(Box7, { children: [
|
|
2547
2569
|
canCreate ? /* @__PURE__ */ jsx14(Flex5, { justify: "flex-end", mb: "10px", children: /* @__PURE__ */ jsx14(Button6, { size: "sm", colorPalette: "brand", onClick: () => {
|
|
2548
2570
|
setCreateError(null);
|
|
@@ -2619,7 +2641,7 @@ function CoreRelatedGrid({
|
|
|
2619
2641
|
title: tab.create?.label ?? `Novo ${schema?.singular ?? relation.model}`,
|
|
2620
2642
|
eyebrow: "Registro relacionado",
|
|
2621
2643
|
fields: createFields,
|
|
2622
|
-
initialValues:
|
|
2644
|
+
initialValues: createInitialValues,
|
|
2623
2645
|
submitting: createMutation.isPending,
|
|
2624
2646
|
error: createError,
|
|
2625
2647
|
onSubmit: (values) => createMutation.mutate(values),
|