@nivaro/react 0.2.51 → 0.2.52
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/full.css +1 -1
- package/dist/hooks/useSessionRecorder.js +1 -1
- package/dist/index.d.ts +204 -6
- package/dist/index.js +442 -439
- package/dist/layout-editor.d.ts +80 -0
- package/dist/layout-editor.js +11 -0
- package/dist/shared/components/ItemEditForm.js +4044 -3866
- package/dist/shared/components/RecordDrilldownSheet.js +114 -97
- package/dist/shared/components/RecordReadView.js +637 -570
- package/dist/shared/components/ai/ExplainButton.js +1 -1
- package/dist/shared/components/item-edit/GroupSection.js +489 -466
- package/dist/shared/components/item-edit/HeaderBand.js +47 -44
- package/dist/shared/components/item-edit/M2MStagingContext.js +3 -3
- package/dist/shared/components/item-edit/O2MStagingContext.js +1 -1
- package/dist/shared/components/item-edit/RecordGrantTools.js +206 -0
- package/dist/shared/components/item-edit/StepsBar.js +49 -43
- package/dist/shared/components/item-edit/SummaryPanel.js +1 -1
- package/dist/shared/components/item-edit/config-update.js +6 -0
- package/dist/shared/components/item-edit/layout-editing-quiet.js +25 -0
- package/dist/shared/components/layout-editor/AddPanel.js +301 -0
- package/dist/shared/components/layout-editor/DesignNode.js +173 -0
- package/dist/shared/components/layout-editor/EditorCanvas.js +52 -0
- package/dist/shared/components/layout-editor/EditorTopBar.js +241 -0
- package/dist/shared/components/layout-editor/HistoryPanel.js +179 -0
- package/dist/shared/components/layout-editor/LayoutEditor.js +393 -0
- package/dist/shared/components/layout-editor/LayoutsRail.js +89 -0
- package/dist/shared/components/layout-editor/add-target.js +103 -0
- package/dist/shared/components/layout-editor/bundle-to-active.js +86 -0
- package/dist/shared/components/layout-editor/canvases/PdfCanvas.js +90 -0
- package/dist/shared/components/layout-editor/canvases/TableColumnsCanvas.js +246 -0
- package/dist/shared/components/layout-editor/collection-meta.js +22 -0
- package/dist/shared/components/layout-editor/design-canvas.js +81 -0
- package/dist/shared/components/layout-editor/design-context.js +21 -0
- package/dist/shared/components/layout-editor/dnd/LayoutDndProvider.js +225 -0
- package/dist/shared/components/layout-editor/dnd/collision.js +107 -0
- package/dist/shared/components/layout-editor/dnd/node.js +164 -0
- package/dist/shared/components/layout-editor/dnd/order.js +122 -0
- package/dist/shared/components/layout-editor/editors/DefaultValuesEditor.js +223 -0
- package/dist/shared/components/layout-editor/editors/QuickPickerStepsEditor.js +129 -0
- package/dist/shared/components/layout-editor/editors/ReadPresentationEditor.js +134 -0
- package/dist/shared/components/layout-editor/editors/RecordConditionsEditor.js +249 -0
- package/dist/shared/components/layout-editor/editors/RolesPicker.js +77 -0
- package/dist/shared/components/layout-editor/editors/cascade-filters.js +556 -0
- package/dist/shared/components/layout-editor/editors/cascade-rule-row.js +150 -0
- package/dist/shared/components/layout-editor/editors/controls.js +73 -0
- package/dist/shared/components/layout-editor/editors/editor-api.js +21 -0
- package/dist/shared/components/layout-editor/editors/editor-queries.js +25 -0
- package/dist/shared/components/layout-editor/editors/field-default-value.js +131 -0
- package/dist/shared/components/layout-editor/editors/grid-presets.js +310 -0
- package/dist/shared/components/layout-editor/editors/inline-display.js +157 -0
- package/dist/shared/components/layout-editor/editors/layout-picker.js +80 -0
- package/dist/shared/components/layout-editor/editors/layout-rows.js +55 -0
- package/dist/shared/components/layout-editor/editors/lock-conditions.js +109 -0
- package/dist/shared/components/layout-editor/editors/o2m-agg-field.js +25 -0
- package/dist/shared/components/layout-editor/editors/pdf-field-config.js +107 -0
- package/dist/shared/components/layout-editor/editors/report-widget-config.js +94 -0
- package/dist/shared/components/layout-editor/editors/row-rule-check.js +225 -0
- package/dist/shared/components/layout-editor/editors/row-rule-row.js +1353 -0
- package/dist/shared/components/layout-editor/editors/swap-config.js +245 -0
- package/dist/shared/components/layout-editor/focus-buffer.js +32 -0
- package/dist/shared/components/layout-editor/host.js +15 -0
- package/dist/shared/components/layout-editor/inspector/AdvancedTab.js +296 -0
- package/dist/shared/components/layout-editor/inspector/GridTab.js +767 -0
- package/dist/shared/components/layout-editor/inspector/GroupInspector.js +456 -0
- package/dist/shared/components/layout-editor/inspector/HeaderItemInspector.js +268 -0
- package/dist/shared/components/layout-editor/inspector/Inspector.js +332 -0
- package/dist/shared/components/layout-editor/inspector/LookTab.js +310 -0
- package/dist/shared/components/layout-editor/inspector/PickerTab.js +333 -0
- package/dist/shared/components/layout-editor/inspector/RulesTab.js +323 -0
- package/dist/shared/components/layout-editor/inspector/SlotInspector.js +179 -0
- package/dist/shared/components/layout-editor/inspector/SubtitleInspector.js +154 -0
- package/dist/shared/components/layout-editor/inspector/WidgetInspector.js +262 -0
- package/dist/shared/components/layout-editor/inspector/applies.js +27 -0
- package/dist/shared/components/layout-editor/inspector/field-context.js +134 -0
- package/dist/shared/components/layout-editor/inspector/interfaces.js +126 -0
- package/dist/shared/components/layout-editor/inspector/kit.js +595 -0
- package/dist/shared/components/layout-editor/inspector/model.js +307 -0
- package/dist/shared/components/layout-editor/overview/OverviewActions.js +15 -0
- package/dist/shared/components/layout-editor/overview/describe-conditions.js +121 -0
- package/dist/shared/components/layout-editor/overview/overview-api.js +141 -0
- package/dist/shared/components/layout-editor/overview/purpose.js +62 -0
- package/dist/shared/components/layout-editor/overview/record-count.js +65 -0
- package/dist/shared/components/layout-editor/panel-frame.js +99 -0
- package/dist/shared/components/layout-editor/panel-style.js +19 -0
- package/dist/shared/components/layout-editor/pickers/field-picker.js +230 -0
- package/dist/shared/components/layout-editor/pickers/icon-picker.js +233 -0
- package/dist/shared/components/layout-editor/pickers/relation-label.js +34 -0
- package/dist/shared/components/layout-editor/pickers/relation-picker.js +136 -0
- package/dist/shared/components/layout-editor/record-queries.js +15 -0
- package/dist/shared/components/layout-editor/settings/AddendumSection.js +52 -0
- package/dist/shared/components/layout-editor/settings/ButtonsSection.js +45 -0
- package/dist/shared/components/layout-editor/settings/DefaultsSection.js +67 -0
- package/dist/shared/components/layout-editor/settings/FormSettings.js +146 -0
- package/dist/shared/components/layout-editor/settings/InheritanceSection.js +37 -0
- package/dist/shared/components/layout-editor/settings/LayoutSection.js +70 -0
- package/dist/shared/components/layout-editor/settings/PdfSection.js +176 -0
- package/dist/shared/components/layout-editor/settings/ReadSection.js +79 -0
- package/dist/shared/components/layout-editor/settings/TextSetting.js +55 -0
- package/dist/shared/components/layout-editor/settings/ToggleSetting.js +33 -0
- package/dist/shared/components/layout-editor/settings/ToolsSection.js +179 -0
- package/dist/shared/components/layout-editor/settings/WhoSection.js +213 -0
- package/dist/shared/components/layout-editor/settings/controls.js +214 -0
- package/dist/shared/components/layout-editor/settings/section-props.js +17 -0
- package/dist/shared/components/layout-editor/settings/settings-api.js +151 -0
- package/dist/shared/components/layout-editor/settings/settings-registry.js +445 -0
- package/dist/shared/components/layout-editor/slot-names.js +20 -0
- package/dist/shared/components/layout-editor/summary-pref.js +21 -0
- package/dist/shared/components/layout-editor/useLayoutDraft.js +474 -0
- package/dist/shared/components/pipeline/relations.js +28 -23
- package/dist/shared/components/ui/popover.js +17 -17
- package/dist/shared/components/ui/scroll-area.js +38 -0
- package/dist/shared/hooks/useRelationOptions.js +60 -0
- package/dist/shared/lib/layout-grants.js +9 -0
- package/dist/shared/lib/layout-ops.js +348 -0
- package/dist/shared/lib/layout-slots.js +11 -7
- package/dist/shared/lib/request-gate.js +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { jsxs as c, jsx as t } from "react/jsx-runtime";
|
|
2
|
+
import { useQuery as u } from "@tanstack/react-query";
|
|
3
|
+
import { cn as h } from "../../../lib/utils.js";
|
|
4
|
+
import { SimpleSelect as g } from "../../ui/SimpleSelect.js";
|
|
5
|
+
import { tintCard as x, inputBase as N } from "../panel-style.js";
|
|
6
|
+
import { useEditorApi as f } from "./editor-api.js";
|
|
7
|
+
function S({
|
|
8
|
+
roleIds: i,
|
|
9
|
+
onRoleIdsChange: a
|
|
10
|
+
}) {
|
|
11
|
+
const l = f(), { data: r } = u({
|
|
12
|
+
queryKey: ["roles-list-for-lock"],
|
|
13
|
+
queryFn: () => l.get("/roles").then((s) => s.data.data),
|
|
14
|
+
staleTime: 6e4
|
|
15
|
+
}), n = r ?? [];
|
|
16
|
+
return /* @__PURE__ */ c("div", { className: h(x, "space-y-1 px-2.5 py-2"), children: [
|
|
17
|
+
n.length === 0 && /* @__PURE__ */ t("p", { className: "text-[12px] text-slate-500", children: "No roles found." }),
|
|
18
|
+
n.map((s) => /* @__PURE__ */ c(
|
|
19
|
+
"label",
|
|
20
|
+
{
|
|
21
|
+
className: "flex items-center gap-1.5 text-[12px] cursor-pointer select-none",
|
|
22
|
+
children: [
|
|
23
|
+
/* @__PURE__ */ t(
|
|
24
|
+
"input",
|
|
25
|
+
{
|
|
26
|
+
type: "checkbox",
|
|
27
|
+
checked: i.includes(s.id),
|
|
28
|
+
onChange: (d) => {
|
|
29
|
+
d.target.checked ? a([...i, s.id]) : a(i.filter((o) => o !== s.id));
|
|
30
|
+
},
|
|
31
|
+
className: "rounded"
|
|
32
|
+
}
|
|
33
|
+
),
|
|
34
|
+
/* @__PURE__ */ t("span", { className: "text-slate-700 dark:text-foreground", children: s.name })
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
s.id
|
|
38
|
+
))
|
|
39
|
+
] });
|
|
40
|
+
}
|
|
41
|
+
function T({
|
|
42
|
+
collection: i,
|
|
43
|
+
pipelineId: a,
|
|
44
|
+
stateKeys: l,
|
|
45
|
+
onPipelineChange: r,
|
|
46
|
+
onStateKeysChange: n
|
|
47
|
+
}) {
|
|
48
|
+
const s = f(), { data: d } = u({
|
|
49
|
+
queryKey: ["pipelines-list-for-lock"],
|
|
50
|
+
queryFn: () => s.get("/pipelines").then((e) => e.data.data),
|
|
51
|
+
staleTime: 6e4
|
|
52
|
+
}), o = (d ?? []).filter(
|
|
53
|
+
(e) => !i || e.collections.includes(i)
|
|
54
|
+
), { data: p } = u({
|
|
55
|
+
queryKey: ["pipeline-detail-lock", a],
|
|
56
|
+
queryFn: () => s.get(`/pipelines/${a}`).then((e) => e.data.data),
|
|
57
|
+
staleTime: 6e4,
|
|
58
|
+
enabled: !!a
|
|
59
|
+
}), m = (p == null ? void 0 : p.states) ?? [];
|
|
60
|
+
return /* @__PURE__ */ c("div", { className: "space-y-1.5", children: [
|
|
61
|
+
/* @__PURE__ */ t("div", { "data-setting": "field.lock_conditions.pipeline_id", children: /* @__PURE__ */ t(
|
|
62
|
+
g,
|
|
63
|
+
{
|
|
64
|
+
value: a ?? "",
|
|
65
|
+
onChange: (e) => r(e || void 0),
|
|
66
|
+
className: h(N, "focus:ring-0 focus:ring-offset-0"),
|
|
67
|
+
options: [
|
|
68
|
+
{ value: "", label: "— Select pipeline —" },
|
|
69
|
+
...o.map((e) => ({ value: e.id, label: e.name }))
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
) }),
|
|
73
|
+
o.length === 0 && /* @__PURE__ */ t("p", { className: "text-[12px] text-slate-500", children: "No pipelines bound to this collection." }),
|
|
74
|
+
!a && /* @__PURE__ */ t("p", { className: "text-[12px] text-slate-500", children: "Pick a pipeline to choose its states." }),
|
|
75
|
+
a && m.length > 0 && /* @__PURE__ */ t(
|
|
76
|
+
"div",
|
|
77
|
+
{
|
|
78
|
+
className: h(x, "space-y-1 px-2.5 py-2"),
|
|
79
|
+
"data-setting": "field.lock_conditions.state_keys",
|
|
80
|
+
children: m.map((e) => /* @__PURE__ */ c(
|
|
81
|
+
"label",
|
|
82
|
+
{
|
|
83
|
+
className: "flex items-center gap-1.5 text-[12px] cursor-pointer select-none",
|
|
84
|
+
children: [
|
|
85
|
+
/* @__PURE__ */ t(
|
|
86
|
+
"input",
|
|
87
|
+
{
|
|
88
|
+
type: "checkbox",
|
|
89
|
+
checked: l.includes(e.key),
|
|
90
|
+
onChange: (k) => {
|
|
91
|
+
k.target.checked ? n([...l, e.key]) : n(l.filter((y) => y !== e.key));
|
|
92
|
+
},
|
|
93
|
+
className: "rounded"
|
|
94
|
+
}
|
|
95
|
+
),
|
|
96
|
+
/* @__PURE__ */ t("span", { className: "text-slate-700 dark:text-foreground", children: e.label })
|
|
97
|
+
]
|
|
98
|
+
},
|
|
99
|
+
e.key
|
|
100
|
+
))
|
|
101
|
+
}
|
|
102
|
+
),
|
|
103
|
+
a && m.length === 0 && /* @__PURE__ */ t("p", { className: "text-[12px] text-slate-500", children: "No states defined for this pipeline." })
|
|
104
|
+
] });
|
|
105
|
+
}
|
|
106
|
+
export {
|
|
107
|
+
T as PipelineStateConditionRow,
|
|
108
|
+
S as RoleConditionRow
|
|
109
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx as d } from "react/jsx-runtime";
|
|
2
|
+
import { Combobox as m } from "./controls.js";
|
|
3
|
+
import { useEditorFieldList as c } from "./editor-queries.js";
|
|
4
|
+
function g({
|
|
5
|
+
relatedCollection: n,
|
|
6
|
+
value: s,
|
|
7
|
+
onChange: e
|
|
8
|
+
}) {
|
|
9
|
+
const { data: l = [] } = c(n), i = l.filter((o) => !o.field.startsWith("_")), r = i.map((o) => ({ value: o.field, label: o.field }));
|
|
10
|
+
return /* @__PURE__ */ d(
|
|
11
|
+
m,
|
|
12
|
+
{
|
|
13
|
+
value: s,
|
|
14
|
+
onChange: (o) => {
|
|
15
|
+
const t = i.find((f) => f.field === o), p = t != null && t.options ? typeof t.options == "string" ? t.options : JSON.stringify(t.options) : null;
|
|
16
|
+
e(o, p);
|
|
17
|
+
},
|
|
18
|
+
options: r,
|
|
19
|
+
placeholder: "Select column…"
|
|
20
|
+
}
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
g as O2MAggFieldCombobox
|
|
25
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { jsxs as n, jsx as l } from "react/jsx-runtime";
|
|
2
|
+
import { useQuery as N } from "@tanstack/react-query";
|
|
3
|
+
import { ChevronDown as k } from "lucide-react";
|
|
4
|
+
import { useMemo as C, useState as j } from "react";
|
|
5
|
+
import { Command as w, CommandInput as F, CommandList as S, CommandEmpty as P, CommandItem as u } from "../../ui/command.js";
|
|
6
|
+
import { Popover as $, PopoverTrigger as D, PopoverContent as E } from "../../ui/popover.js";
|
|
7
|
+
import { useEditorApi as L } from "./editor-api.js";
|
|
8
|
+
import { editorQueryKeys as M } from "./editor-queries.js";
|
|
9
|
+
function z({
|
|
10
|
+
tableName: o,
|
|
11
|
+
value: s,
|
|
12
|
+
filenameTemplate: x,
|
|
13
|
+
onChange: c,
|
|
14
|
+
onFilenameChange: h
|
|
15
|
+
}) {
|
|
16
|
+
const _ = L(), { data: a } = N({
|
|
17
|
+
queryKey: M.relationsFor(o),
|
|
18
|
+
queryFn: () => _.get(`/data-model/relations/for/${o}`).then((t) => t.data.data ?? []),
|
|
19
|
+
enabled: !!o,
|
|
20
|
+
staleTime: 3e4
|
|
21
|
+
}), i = C(() => {
|
|
22
|
+
if (!a) return [];
|
|
23
|
+
const t = a.filter(
|
|
24
|
+
(e) => e.one_collection === o && e.junction_field != null
|
|
25
|
+
), m = [], p = /* @__PURE__ */ new Set();
|
|
26
|
+
for (const e of t) {
|
|
27
|
+
if (p.has(e.many_collection)) continue;
|
|
28
|
+
const g = a.find(
|
|
29
|
+
(f) => f.many_collection === e.many_collection && f.one_collection === "nivaro_files"
|
|
30
|
+
), b = e.junction_field ?? "";
|
|
31
|
+
if (!(!!g || /file/i.test(b) || /file/i.test(e.many_collection))) continue;
|
|
32
|
+
p.add(e.many_collection);
|
|
33
|
+
const v = e.one_field && e.one_field !== "id" ? e.one_field : e.many_collection.replace(new RegExp(`^${o}_?|_?${o}$`, "i"), "").replace(/^_|_$/g, "") || e.many_collection;
|
|
34
|
+
m.push({ field: v, junction: e.many_collection });
|
|
35
|
+
}
|
|
36
|
+
return m;
|
|
37
|
+
}, [a, o]), [y, r] = j(!1), d = i.find((t) => t.field === s) ?? null;
|
|
38
|
+
return /* @__PURE__ */ n("div", { className: "mt-1.5 space-y-1", children: [
|
|
39
|
+
/* @__PURE__ */ l("p", { className: "text-[11px] font-medium text-slate-400", children: "Attach PDF to field" }),
|
|
40
|
+
/* @__PURE__ */ l("div", { "data-setting": "pdf_button.attach_to_field", children: /* @__PURE__ */ n($, { open: y, onOpenChange: r, children: [
|
|
41
|
+
/* @__PURE__ */ l(D, { asChild: !0, children: /* @__PURE__ */ n(
|
|
42
|
+
"button",
|
|
43
|
+
{
|
|
44
|
+
type: "button",
|
|
45
|
+
className: "flex w-full items-center justify-between rounded border border-slate-200 bg-white px-2 py-1 text-[11px] text-slate-700 hover:border-nvr-cyan/50 dark:border-border dark:bg-card dark:text-slate-200",
|
|
46
|
+
children: [
|
|
47
|
+
/* @__PURE__ */ l("span", { children: d ? d.field : /* @__PURE__ */ l("span", { className: "text-slate-400", children: "Select file field…" }) }),
|
|
48
|
+
/* @__PURE__ */ l(k, { className: "h-3 w-3 text-slate-400" })
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
) }),
|
|
52
|
+
/* @__PURE__ */ l(E, { className: "w-56 p-0", align: "start", children: /* @__PURE__ */ n(w, { children: [
|
|
53
|
+
/* @__PURE__ */ l(F, { placeholder: "Search fields…", className: "text-[12px]" }),
|
|
54
|
+
/* @__PURE__ */ n(S, { children: [
|
|
55
|
+
/* @__PURE__ */ l(P, { className: "py-2 text-center text-[11px] text-slate-400", children: i.length === 0 ? "No file M2M fields found" : "No match" }),
|
|
56
|
+
s && /* @__PURE__ */ l(
|
|
57
|
+
u,
|
|
58
|
+
{
|
|
59
|
+
value: "__clear__",
|
|
60
|
+
onSelect: () => {
|
|
61
|
+
c(null), r(!1);
|
|
62
|
+
},
|
|
63
|
+
className: "text-[11px] text-slate-400",
|
|
64
|
+
children: "Clear"
|
|
65
|
+
}
|
|
66
|
+
),
|
|
67
|
+
i.map((t) => /* @__PURE__ */ n(
|
|
68
|
+
u,
|
|
69
|
+
{
|
|
70
|
+
value: t.field,
|
|
71
|
+
onSelect: () => {
|
|
72
|
+
c(t.field), r(!1);
|
|
73
|
+
},
|
|
74
|
+
className: "text-[11px]",
|
|
75
|
+
children: [
|
|
76
|
+
t.field,
|
|
77
|
+
/* @__PURE__ */ l("span", { className: "ml-auto text-[11px] text-slate-400 truncate", children: t.junction })
|
|
78
|
+
]
|
|
79
|
+
},
|
|
80
|
+
t.field
|
|
81
|
+
))
|
|
82
|
+
] })
|
|
83
|
+
] }) })
|
|
84
|
+
] }) }),
|
|
85
|
+
/* @__PURE__ */ n("div", { className: "mt-2 space-y-1", "data-setting": "pdf_button.filename_template", children: [
|
|
86
|
+
/* @__PURE__ */ l("p", { className: "text-[11px] font-medium text-slate-400", children: "Filename template" }),
|
|
87
|
+
/* @__PURE__ */ l(
|
|
88
|
+
"input",
|
|
89
|
+
{
|
|
90
|
+
type: "text",
|
|
91
|
+
value: x ?? "",
|
|
92
|
+
onChange: (t) => h(t.target.value || null),
|
|
93
|
+
placeholder: "e.g. {{title}}-report",
|
|
94
|
+
className: "w-full rounded border border-slate-200 bg-white px-2 py-1 text-[11px] text-slate-700 placeholder:text-slate-300 focus:border-nvr-cyan/50 focus:outline-none dark:border-border dark:bg-card dark:text-slate-200"
|
|
95
|
+
}
|
|
96
|
+
),
|
|
97
|
+
/* @__PURE__ */ n("p", { className: "text-[11px] text-slate-400", children: [
|
|
98
|
+
"Use ",
|
|
99
|
+
"{{field}}",
|
|
100
|
+
" tokens. Defaults to template name."
|
|
101
|
+
] })
|
|
102
|
+
] })
|
|
103
|
+
] });
|
|
104
|
+
}
|
|
105
|
+
export {
|
|
106
|
+
z as PdfFieldConfig
|
|
107
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { jsxs as h, jsx as d } from "react/jsx-runtime";
|
|
2
|
+
import { useQueryClient as w, useMutation as q, useQuery as g } from "@tanstack/react-query";
|
|
3
|
+
import { useState as c } from "react";
|
|
4
|
+
import { Combobox as f } from "./controls.js";
|
|
5
|
+
import { useEditorApi as v } from "./editor-api.js";
|
|
6
|
+
function N(i) {
|
|
7
|
+
const t = v(), { data: o = [] } = g({
|
|
8
|
+
queryKey: ["report-studio-list"],
|
|
9
|
+
queryFn: () => t.get("/report-studio").then((r) => r.data.data ?? []),
|
|
10
|
+
staleTime: 6e4
|
|
11
|
+
}), { data: a } = g({
|
|
12
|
+
queryKey: ["report-studio-detail", i],
|
|
13
|
+
queryFn: () => t.get(`/report-studio/${i}`).then((r) => r.data.data),
|
|
14
|
+
enabled: !!i,
|
|
15
|
+
staleTime: 6e4
|
|
16
|
+
}), n = ((a == null ? void 0 : a.widgets) ?? []).filter((r) => r.type !== "divider");
|
|
17
|
+
return { reports: o, widgets: n };
|
|
18
|
+
}
|
|
19
|
+
function j({
|
|
20
|
+
widgetId: i,
|
|
21
|
+
config: t,
|
|
22
|
+
onSave: o
|
|
23
|
+
}) {
|
|
24
|
+
const a = v(), n = w(), [r, _] = c(
|
|
25
|
+
typeof (t == null ? void 0 : t.report_id) == "string" ? t.report_id : ""
|
|
26
|
+
), [p, y] = c(
|
|
27
|
+
typeof (t == null ? void 0 : t.widget_id) == "string" ? t.widget_id : ""
|
|
28
|
+
), [u, C] = c(
|
|
29
|
+
typeof (t == null ? void 0 : t.entity_filter_field) == "string" ? t.entity_filter_field : ""
|
|
30
|
+
), { reports: F, widgets: k } = N(r), b = (e, s, l) => ({
|
|
31
|
+
...t ?? {},
|
|
32
|
+
report_id: e,
|
|
33
|
+
widget_id: s,
|
|
34
|
+
entity_filter_field: l.trim() || null
|
|
35
|
+
}), m = q({
|
|
36
|
+
mutationFn: (e) => a.patch(`/widgets-internal/${i}`, { config: e }),
|
|
37
|
+
onSuccess: () => n.invalidateQueries({ queryKey: ["widgets-internal"] })
|
|
38
|
+
}), x = (e, s, l) => {
|
|
39
|
+
!e || !s || (o ? o(b(e, s, l)) : m.mutate(b(e, s, l)));
|
|
40
|
+
};
|
|
41
|
+
return /* @__PURE__ */ h("div", { className: "space-y-1.5 border-t border-slate-100 pt-1.5 dark:border-border", children: [
|
|
42
|
+
/* @__PURE__ */ d("p", { className: "text-[11px] font-medium text-slate-400", children: "Report widget" }),
|
|
43
|
+
/* @__PURE__ */ d(
|
|
44
|
+
f,
|
|
45
|
+
{
|
|
46
|
+
value: r,
|
|
47
|
+
onChange: (e) => {
|
|
48
|
+
_(e), y("");
|
|
49
|
+
},
|
|
50
|
+
options: F.map((e) => ({ value: e.id, label: e.name })),
|
|
51
|
+
placeholder: "Report…"
|
|
52
|
+
}
|
|
53
|
+
),
|
|
54
|
+
/* @__PURE__ */ d(
|
|
55
|
+
f,
|
|
56
|
+
{
|
|
57
|
+
value: p,
|
|
58
|
+
onChange: (e) => {
|
|
59
|
+
y(e), x(r, e, u);
|
|
60
|
+
},
|
|
61
|
+
options: k.map((e) => ({ value: e.id, label: e.title || e.type })),
|
|
62
|
+
placeholder: "Widget…",
|
|
63
|
+
disabled: !r
|
|
64
|
+
}
|
|
65
|
+
),
|
|
66
|
+
/* @__PURE__ */ h("div", { className: "flex items-center gap-1", children: [
|
|
67
|
+
/* @__PURE__ */ d(
|
|
68
|
+
"input",
|
|
69
|
+
{
|
|
70
|
+
type: "text",
|
|
71
|
+
placeholder: "Entity filter field",
|
|
72
|
+
value: u,
|
|
73
|
+
onChange: (e) => C(e.target.value),
|
|
74
|
+
className: "min-w-0 flex-1 rounded border border-slate-200 bg-slate-50 px-1.5 py-1 text-[11px] focus:outline-none focus:ring-1 focus:ring-nvr-cyan placeholder:text-slate-300 dark:bg-muted dark:border-border"
|
|
75
|
+
}
|
|
76
|
+
),
|
|
77
|
+
/* @__PURE__ */ d(
|
|
78
|
+
"button",
|
|
79
|
+
{
|
|
80
|
+
type: "button",
|
|
81
|
+
disabled: !r || !p || m.isPending,
|
|
82
|
+
onClick: () => x(r, p, u),
|
|
83
|
+
className: "shrink-0 rounded border border-slate-200 px-1.5 py-1 text-[11px] text-slate-500 hover:bg-muted disabled:opacity-40 dark:border-border",
|
|
84
|
+
children: m.isPending ? "…" : "Apply"
|
|
85
|
+
}
|
|
86
|
+
)
|
|
87
|
+
] }),
|
|
88
|
+
/* @__PURE__ */ d("p", { className: "text-[11px] leading-snug text-slate-400", children: "Filter field scopes the report data by a record value (bind “Filter value” below, or name a field the record already carries)." })
|
|
89
|
+
] });
|
|
90
|
+
}
|
|
91
|
+
export {
|
|
92
|
+
j as ReportWidgetConfigSection,
|
|
93
|
+
N as useReportPickers
|
|
94
|
+
};
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { jsx as r, jsxs as o } from "react/jsx-runtime";
|
|
2
|
+
import { useQuery as O } from "@tanstack/react-query";
|
|
3
|
+
import { useMemo as q, useState as _ } from "react";
|
|
4
|
+
import { cn as N } from "../../../lib/utils.js";
|
|
5
|
+
import { Button as S } from "../../ui/button.js";
|
|
6
|
+
import { Input as j } from "../../ui/input.js";
|
|
7
|
+
import { Label as E } from "../../ui/label.js";
|
|
8
|
+
import { tintCard as z } from "../panel-style.js";
|
|
9
|
+
import { useEditorApi as C } from "./editor-api.js";
|
|
10
|
+
import { editorQueryKeys as F } from "./editor-queries.js";
|
|
11
|
+
function I(p, h) {
|
|
12
|
+
const d = [], g = p.map((t, s) => ({ r: t, idx: s, sort: t.sort ?? s })).sort((t, s) => t.sort - s.sort), a = (t) => `rule ${t + 1}`, m = (t) => !t || t.startsWith("$parent.") || h.size === 0 || h.has(t);
|
|
13
|
+
for (const { r: t, idx: s } of g) {
|
|
14
|
+
t.target_field ? m(t.target_field) || d.push({
|
|
15
|
+
tone: "error",
|
|
16
|
+
text: `${a(s)} targets "${t.target_field}", which is not a field on this collection.`
|
|
17
|
+
}) : d.push({ tone: "error", text: `${a(s)} has no target field.` }), !t.trigger_field && !(t.trigger_fields ?? []).length && d.push({ tone: "warn", text: `${a(s)} has no trigger — it fires on every pass.` });
|
|
18
|
+
for (const n of [t.trigger_field, ...t.trigger_fields ?? []])
|
|
19
|
+
n && !m(n) && d.push({
|
|
20
|
+
tone: "error",
|
|
21
|
+
text: `${a(s)} is triggered by "${n}", which is not a field on this collection.`
|
|
22
|
+
});
|
|
23
|
+
t.target_type === "precedence" && !(t.sources ?? []).length && d.push({
|
|
24
|
+
tone: "warn",
|
|
25
|
+
text: `${a(s)} is a precedence rule with no sources — it always writes empty.`
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
const f = /* @__PURE__ */ new Map();
|
|
29
|
+
for (const t of g) {
|
|
30
|
+
if (!t.r.target_field) continue;
|
|
31
|
+
const s = f.get(t.r.target_field) ?? [];
|
|
32
|
+
s.push(t), f.set(t.r.target_field, s);
|
|
33
|
+
}
|
|
34
|
+
for (const [t, s] of f) {
|
|
35
|
+
const n = s.filter((c) => c.r.target_type !== "lock"), u = s.filter((c) => c.r.target_type === "lock");
|
|
36
|
+
if (n.length > 1) {
|
|
37
|
+
new Set(
|
|
38
|
+
n.map(
|
|
39
|
+
(l) => `${l.r.trigger_field ?? ""}|${l.r.trigger_op ?? ""}|${l.r.trigger_value ?? ""}|${l.r.trigger_related_field ?? ""}`
|
|
40
|
+
)
|
|
41
|
+
).size < n.length ? d.push({
|
|
42
|
+
tone: "warn",
|
|
43
|
+
text: `"${t}" is written by ${n.map((l) => a(l.idx)).join(" and ")} on the SAME trigger — the later one wins every time; the earlier is dead.`
|
|
44
|
+
}) : d.push({
|
|
45
|
+
tone: "info",
|
|
46
|
+
text: `"${t}" is written by ${n.map((l) => a(l.idx)).join(", ")}; on one pass the later rule wins when both fire.`
|
|
47
|
+
});
|
|
48
|
+
for (let l = 0; l < n.length; l++) {
|
|
49
|
+
const i = n[l];
|
|
50
|
+
if (!i.r.only_if_empty) continue;
|
|
51
|
+
const y = n.slice(l + 1).filter((b) => !b.r.only_if_empty);
|
|
52
|
+
y.length && d.push({
|
|
53
|
+
tone: "warn",
|
|
54
|
+
text: `${a(i.idx)} only fills "${t}" when empty, but ${y.map((b) => a(b.idx)).join(", ")} overwrite${y.length === 1 ? "s" : ""} it later in the same pass — the only-if-empty guard has no effect.`
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
u.length && n.length && d.push({
|
|
59
|
+
tone: "info",
|
|
60
|
+
text: `"${t}" is locked by ${u.map((c) => a(c.idx)).join(", ")} and set by ${n.map((c) => a(c.idx)).join(", ")} — rules still write it; the lock only refuses the user's edits.`
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return d;
|
|
64
|
+
}
|
|
65
|
+
function G({
|
|
66
|
+
rules: p,
|
|
67
|
+
childFieldNames: h
|
|
68
|
+
}) {
|
|
69
|
+
const d = q(() => I(p, h), [p, h]);
|
|
70
|
+
if (d.length === 0)
|
|
71
|
+
return /* @__PURE__ */ r("p", { className: "text-[11px] text-emerald-700 dark:text-emerald-300", children: "No conflicts between these rules." });
|
|
72
|
+
const g = (a) => a === "error" ? "text-red-700 bg-red-50 dark:bg-red-400/10 dark:text-red-300" : a === "warn" ? "text-amber-700 bg-amber-50 dark:bg-amber-400/10 dark:text-amber-300" : "text-slate-600 bg-slate-100 dark:bg-white/5 dark:text-slate-300";
|
|
73
|
+
return /* @__PURE__ */ r("ul", { className: "space-y-1", "aria-label": "Rule conflicts", children: d.map((a, m) => /* @__PURE__ */ r("li", { className: N("rounded px-2 py-1 text-[11px] leading-snug", g(a.tone)), children: a.text }, m)) });
|
|
74
|
+
}
|
|
75
|
+
function H({
|
|
76
|
+
childCollection: p,
|
|
77
|
+
parentCollection: h,
|
|
78
|
+
rowRules: d,
|
|
79
|
+
parentContextFields: g
|
|
80
|
+
}) {
|
|
81
|
+
var v;
|
|
82
|
+
const a = C(), [m, f] = _(""), [t, s] = _(""), [n, u] = _(!1), [c, l] = _(null), [i, y] = _(null), { data: b = [] } = O({
|
|
83
|
+
queryKey: F.relationsFor(p),
|
|
84
|
+
queryFn: () => a.get(`/data-model/relations/for/${p}`).then((e) => e.data.data ?? e.data)
|
|
85
|
+
}), R = ((v = b.find((e) => e.many_collection === p && e.one_collection === h)) == null ? void 0 : v.many_field) ?? null, $ = async () => {
|
|
86
|
+
var e, x;
|
|
87
|
+
if (m.trim()) {
|
|
88
|
+
u(!0), l(null);
|
|
89
|
+
try {
|
|
90
|
+
const w = await a.post("/field-rules/explain", {
|
|
91
|
+
collection: p,
|
|
92
|
+
record_id: m.trim(),
|
|
93
|
+
parent_collection: h,
|
|
94
|
+
fk_field: R,
|
|
95
|
+
parent_context_fields: g,
|
|
96
|
+
row_rules: d,
|
|
97
|
+
...t ? { changed_field: t } : {}
|
|
98
|
+
});
|
|
99
|
+
y(w.data.data);
|
|
100
|
+
} catch (w) {
|
|
101
|
+
l(
|
|
102
|
+
((x = (e = w == null ? void 0 : w.response) == null ? void 0 : e.data) == null ? void 0 : x.error) ?? "Dry run failed"
|
|
103
|
+
);
|
|
104
|
+
} finally {
|
|
105
|
+
u(!1);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}, k = (e) => e == null ? "—" : typeof e == "object" ? JSON.stringify(e) : String(e), T = (e) => e === "wrote" ? "text-emerald-700 bg-emerald-50 dark:bg-emerald-400/10 dark:text-emerald-300" : e === "lock" ? "text-violet-700 bg-violet-50 dark:bg-violet-400/10 dark:text-violet-300" : e === "not-triggered" ? "text-slate-600 bg-slate-100 dark:bg-white/5 dark:text-slate-400" : "text-amber-700 bg-amber-50 dark:bg-amber-400/10 dark:text-amber-300";
|
|
109
|
+
return /* @__PURE__ */ o("div", { className: N(z, "mt-2 space-y-2 p-3"), children: [
|
|
110
|
+
/* @__PURE__ */ o("div", { className: "space-y-0.5", children: [
|
|
111
|
+
/* @__PURE__ */ r(E, { className: "text-[12px] font-medium text-slate-800 dark:text-foreground", children: "Test rules against a record" }),
|
|
112
|
+
/* @__PURE__ */ r("p", { className: "text-[12px] leading-snug text-slate-500 dark:text-muted-foreground", children: "Uses the rules as edited above. Nothing is saved." })
|
|
113
|
+
] }),
|
|
114
|
+
/* @__PURE__ */ o("div", { className: "flex flex-wrap items-center gap-1.5", children: [
|
|
115
|
+
/* @__PURE__ */ r(
|
|
116
|
+
j,
|
|
117
|
+
{
|
|
118
|
+
value: m,
|
|
119
|
+
onChange: (e) => f(e.target.value),
|
|
120
|
+
placeholder: "Row id",
|
|
121
|
+
"aria-label": "Row id",
|
|
122
|
+
className: "h-7 min-w-0 flex-1 basis-28 text-[12px]",
|
|
123
|
+
onKeyDown: (e) => {
|
|
124
|
+
e.key === "Enter" && $();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
),
|
|
128
|
+
/* @__PURE__ */ r(
|
|
129
|
+
j,
|
|
130
|
+
{
|
|
131
|
+
value: t,
|
|
132
|
+
onChange: (e) => s(e.target.value),
|
|
133
|
+
placeholder: "Changed field",
|
|
134
|
+
"aria-label": "Changed field (optional)",
|
|
135
|
+
className: "h-7 min-w-0 flex-1 basis-36 text-[12px]",
|
|
136
|
+
"data-tip": "Optional. Simulates a live edit of this field; blank = the create-time pass where every rule gets its chance"
|
|
137
|
+
}
|
|
138
|
+
),
|
|
139
|
+
/* @__PURE__ */ r(
|
|
140
|
+
S,
|
|
141
|
+
{
|
|
142
|
+
size: "sm",
|
|
143
|
+
variant: "outline",
|
|
144
|
+
className: "h-7 text-[12px]",
|
|
145
|
+
onClick: () => void $(),
|
|
146
|
+
disabled: n || !m.trim(),
|
|
147
|
+
children: n ? "Running…" : "Run"
|
|
148
|
+
}
|
|
149
|
+
)
|
|
150
|
+
] }),
|
|
151
|
+
c && /* @__PURE__ */ r("p", { className: "mt-1.5 text-[11px] text-red-600 dark:text-red-400", children: c }),
|
|
152
|
+
i && /* @__PURE__ */ o("div", { className: "mt-2 space-y-2", children: [
|
|
153
|
+
/* @__PURE__ */ o("div", { className: "flex flex-wrap gap-x-4 gap-y-1 text-[11px] text-slate-500", children: [
|
|
154
|
+
/* @__PURE__ */ o("span", { children: [
|
|
155
|
+
"record",
|
|
156
|
+
" ",
|
|
157
|
+
/* @__PURE__ */ r("span", { className: "font-mono text-slate-700 dark:text-slate-300", children: i.record_id })
|
|
158
|
+
] }),
|
|
159
|
+
/* @__PURE__ */ o("span", { children: [
|
|
160
|
+
"parent",
|
|
161
|
+
" ",
|
|
162
|
+
/* @__PURE__ */ r("span", { className: "font-mono text-slate-700 dark:text-slate-300", children: i.parent_id ?? "—" })
|
|
163
|
+
] }),
|
|
164
|
+
/* @__PURE__ */ o("span", { children: [
|
|
165
|
+
i.queries,
|
|
166
|
+
" ",
|
|
167
|
+
i.queries === 1 ? "query" : "queries",
|
|
168
|
+
" · ",
|
|
169
|
+
i.ms,
|
|
170
|
+
" ms"
|
|
171
|
+
] }),
|
|
172
|
+
i.locks.length > 0 && /* @__PURE__ */ o("span", { children: [
|
|
173
|
+
"locked: ",
|
|
174
|
+
i.locks.join(", ")
|
|
175
|
+
] }),
|
|
176
|
+
Object.keys(i.parent_context).length > 0 && /* @__PURE__ */ o("span", { children: [
|
|
177
|
+
"parent context:",
|
|
178
|
+
" ",
|
|
179
|
+
Object.entries(i.parent_context).map(([e, x]) => `${e}=${k(x)}`).join(", ")
|
|
180
|
+
] })
|
|
181
|
+
] }),
|
|
182
|
+
/* @__PURE__ */ r("div", { className: "overflow-x-auto rounded border border-slate-200 bg-white dark:border-border dark:bg-card", children: /* @__PURE__ */ o("table", { className: "w-full text-[12px]", children: [
|
|
183
|
+
/* @__PURE__ */ r("thead", { children: /* @__PURE__ */ o("tr", { className: "text-left text-[12px] text-slate-500 dark:text-slate-400", children: [
|
|
184
|
+
/* @__PURE__ */ r("th", { className: "px-2 py-1", children: "#" }),
|
|
185
|
+
/* @__PURE__ */ r("th", { className: "px-2 py-1", children: "Target" }),
|
|
186
|
+
/* @__PURE__ */ r("th", { className: "px-2 py-1", children: "Trigger → value" }),
|
|
187
|
+
/* @__PURE__ */ r("th", { className: "px-2 py-1", children: "Outcome" }),
|
|
188
|
+
/* @__PURE__ */ r("th", { className: "px-2 py-1", children: "Wrote" }),
|
|
189
|
+
/* @__PURE__ */ r("th", { className: "px-2 py-1 text-right", children: "ms" })
|
|
190
|
+
] }) }),
|
|
191
|
+
/* @__PURE__ */ r("tbody", { children: i.trace.map((e) => /* @__PURE__ */ o("tr", { className: "border-t border-slate-100 dark:border-border", children: [
|
|
192
|
+
/* @__PURE__ */ r("td", { className: "px-2 py-1 text-slate-500 dark:text-slate-400", children: e.index + 1 }),
|
|
193
|
+
/* @__PURE__ */ o("td", { className: "px-2 py-1 font-mono", children: [
|
|
194
|
+
e.target_field,
|
|
195
|
+
/* @__PURE__ */ r("span", { className: "ml-1 text-slate-500 dark:text-slate-400", children: e.target_type })
|
|
196
|
+
] }),
|
|
197
|
+
/* @__PURE__ */ o("td", { className: "px-2 py-1 font-mono text-slate-600 dark:text-slate-300", children: [
|
|
198
|
+
e.trigger_field ?? "—",
|
|
199
|
+
" → ",
|
|
200
|
+
k(e.trigger_value)
|
|
201
|
+
] }),
|
|
202
|
+
/* @__PURE__ */ r("td", { className: "px-2 py-1", children: /* @__PURE__ */ r(
|
|
203
|
+
"span",
|
|
204
|
+
{
|
|
205
|
+
className: N("rounded px-1 py-px font-medium", T(e.outcome)),
|
|
206
|
+
children: e.outcome
|
|
207
|
+
}
|
|
208
|
+
) }),
|
|
209
|
+
/* @__PURE__ */ r("td", { className: "px-2 py-1 font-mono", children: e.outcome === "wrote" ? k(e.value) : "" }),
|
|
210
|
+
/* @__PURE__ */ r("td", { className: "px-2 py-1 text-right tabular-nums text-slate-500", children: e.ms })
|
|
211
|
+
] }, e.index)) })
|
|
212
|
+
] }) }),
|
|
213
|
+
Object.keys(i.changes).length > 0 ? /* @__PURE__ */ o("div", { className: "text-[11px] text-slate-600 dark:text-slate-300", children: [
|
|
214
|
+
"Would change:",
|
|
215
|
+
" ",
|
|
216
|
+
Object.entries(i.changes).map(([e, x]) => `${e}: ${k(x.before)} → ${k(x.after)}`).join(" · ")
|
|
217
|
+
] }) : /* @__PURE__ */ r("div", { className: "text-[11px] text-slate-500", children: "No field would change on this record." })
|
|
218
|
+
] })
|
|
219
|
+
] });
|
|
220
|
+
}
|
|
221
|
+
export {
|
|
222
|
+
G as RowRuleLint,
|
|
223
|
+
H as RowRuleTester,
|
|
224
|
+
I as lintRowRules
|
|
225
|
+
};
|