@nivaro/react 0.3.20 → 0.3.21
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 +2 -0
- package/dist/shared/components/CollectionBrowserView.js +2668 -2613
- package/dist/shared/components/ItemEditForm.js +1501 -1480
- package/dist/shared/components/QueryTable.js +268 -239
- package/dist/shared/components/bulk/PushBulkButtons.js +17 -17
- package/dist/shared/components/bulk/RowPushActions.js +45 -35
- package/dist/shared/components/item-edit/RecordHeaderActions.js +140 -0
- package/dist/shared/components/queue/QueueWorklist.js +1026 -1006
- package/package.json +1 -1
|
@@ -10,14 +10,14 @@ import { cn as G } from "../../lib/utils.js";
|
|
|
10
10
|
import { Popover as be, PopoverTrigger as ke, PopoverContent as xe } from "../ui/popover.js";
|
|
11
11
|
import { useAvailableBulkActions as ge, bulkActionEnabled as ye } from "./BulkActionButtons.js";
|
|
12
12
|
function H(i, r, t, d) {
|
|
13
|
-
return ((i == null ? void 0 : i[t]) ?? []).some((
|
|
13
|
+
return ((i == null ? void 0 : i[t]) ?? []).some((m) => m.source === "builtin" && m.key === d) && ye(r, t, d);
|
|
14
14
|
}
|
|
15
15
|
function ve(i) {
|
|
16
16
|
const r = { succeeded: 0, failed: 0, skipped: 0, errors: [], outcomes: [] };
|
|
17
17
|
for (const { collection: t, data: d } of i) {
|
|
18
18
|
r.succeeded += d.succeeded ?? 0, r.failed += d.failed ?? 0, r.skipped += d.skipped ?? 0, r.errors.push(...d.errors ?? []);
|
|
19
|
-
for (const
|
|
20
|
-
r.outcomes.push({ ...
|
|
19
|
+
for (const m of d.outcomes ?? [])
|
|
20
|
+
r.outcomes.push({ ...m, item: `${t}:${m.item}` });
|
|
21
21
|
}
|
|
22
22
|
return r;
|
|
23
23
|
}
|
|
@@ -30,7 +30,7 @@ function Qe({
|
|
|
30
30
|
enabledKeys: r,
|
|
31
31
|
tone: t = "light",
|
|
32
32
|
disabled: d,
|
|
33
|
-
onDone:
|
|
33
|
+
onDone: m
|
|
34
34
|
}) {
|
|
35
35
|
const v = pe(), J = oe(), w = K(() => [...new Set(i.map((e) => e.collection))], [i]), { data: j } = ge(w), N = w.filter((e) => H(j, r, e, "push")), O = w.filter(
|
|
36
36
|
(e) => H(j, r, e, "retry-push")
|
|
@@ -44,29 +44,29 @@ function Qe({
|
|
|
44
44
|
const e = /* @__PURE__ */ new Map();
|
|
45
45
|
return N.forEach((s, a) => {
|
|
46
46
|
var o;
|
|
47
|
-
for (const n of ((o = P[a]) == null ? void 0 : o.data) ?? []) {
|
|
48
|
-
const
|
|
49
|
-
|
|
47
|
+
for (const n of (((o = P[a]) == null ? void 0 : o.data) ?? []).filter((u) => u.bulk !== !1)) {
|
|
48
|
+
const u = e.get(n.id);
|
|
49
|
+
u ? u.collections.push(s) : e.set(n.id, { ...n, collections: [s] });
|
|
50
50
|
}
|
|
51
51
|
}), [...e.values()];
|
|
52
52
|
}, [V, N.join(",")]), [X, S] = x(null), [g, A] = x(""), [M, _] = x(null), [Y, $] = x({}), [Z, E] = x({}), D = (e) => {
|
|
53
|
-
const [s, ...a] = e.split(":"), o = a.join(":"), n = i.find((
|
|
53
|
+
const [s, ...a] = e.split(":"), o = a.join(":"), n = i.find((u) => u.collection === s && String(u.id) === o);
|
|
54
54
|
return n != null && n.label ? String(n.label) : `#${o}`;
|
|
55
55
|
}, Q = async (e, s) => {
|
|
56
56
|
const a = e.kind === "push" ? e.action.collections : e.collections, o = [];
|
|
57
57
|
for (const n of a) {
|
|
58
|
-
const
|
|
59
|
-
if (
|
|
58
|
+
const u = i.filter((p) => p.collection === n).map((p) => p.id);
|
|
59
|
+
if (u.length === 0) continue;
|
|
60
60
|
const k = e.kind === "push" ? await v.request(
|
|
61
61
|
U("/bulk-actions/push", {
|
|
62
62
|
collection: n,
|
|
63
63
|
action_id: e.action.id,
|
|
64
|
-
ids:
|
|
64
|
+
ids: u,
|
|
65
65
|
dry_run: s,
|
|
66
66
|
...g.trim() ? { payload: { message: g.trim() } } : {}
|
|
67
67
|
})
|
|
68
68
|
) : await v.request(
|
|
69
|
-
U("/bulk-actions/retry-push", { collection: n, ids:
|
|
69
|
+
U("/bulk-actions/retry-push", { collection: n, ids: u, dry_run: s })
|
|
70
70
|
);
|
|
71
71
|
o.push({ collection: n, data: k.data });
|
|
72
72
|
}
|
|
@@ -117,13 +117,13 @@ function Qe({
|
|
|
117
117
|
);
|
|
118
118
|
return /* @__PURE__ */ l(ie, { children: B.map((e) => {
|
|
119
119
|
var F, L, z, T;
|
|
120
|
-
const s = C(e), a = R(e), o = e.kind === "push" ? e.action.collections : e.collections, n = i.filter((b) => o.includes(b.collection)).length,
|
|
120
|
+
const s = C(e), a = R(e), o = e.kind === "push" ? e.action.collections : e.collections, n = i.filter((b) => o.includes(b.collection)).length, u = X === s, k = M === s, p = e.kind === "push" ? (F = e.action.confirm) == null ? void 0 : F.input : void 0, h = Y[s], f = Z[s] ?? null, y = h && h !== "loading" ? h.succeeded : null, ne = n > 0 && !k && y !== 0 && (!(p != null && p.required) || g.trim().length > 0), re = e.kind === "push" ? ((L = e.action.confirm) == null ? void 0 : L.body) ?? `Runs "${e.action.label}" on each selected record, one at a time. Every record is a real request to the partner.` : "Re-sends the latest failed push of each selected record, partner by partner — the same stored request the record’s own Retry button sends.";
|
|
121
121
|
return /* @__PURE__ */ c(
|
|
122
122
|
be,
|
|
123
123
|
{
|
|
124
|
-
open:
|
|
124
|
+
open: u,
|
|
125
125
|
onOpenChange: (b) => {
|
|
126
|
-
S(b ? s : null), b ? (A(""), E((ae) => ({ ...ae, [s]: null })), ee(e)) : f && (
|
|
126
|
+
S(b ? s : null), b ? (A(""), E((ae) => ({ ...ae, [s]: null })), ee(e)) : f && (m == null || m(f));
|
|
127
127
|
},
|
|
128
128
|
children: [
|
|
129
129
|
/* @__PURE__ */ l(ke, { asChild: !0, children: /* @__PURE__ */ c(
|
|
@@ -134,7 +134,7 @@ function Qe({
|
|
|
134
134
|
"data-bulk-push-action": e.kind === "push" ? e.action.id : void 0,
|
|
135
135
|
"data-bulk-retry-push": e.kind === "retry" ? "" : void 0,
|
|
136
136
|
title: e.kind === "push" ? `Run ${e.action.label} on the selected records` : "Re-send each selected record’s latest failed push",
|
|
137
|
-
className: se(
|
|
137
|
+
className: se(u),
|
|
138
138
|
children: [
|
|
139
139
|
k ? /* @__PURE__ */ l(I, { className: "h-3.5 w-3.5 animate-spin" }) : /* @__PURE__ */ l(ce, { className: "h-3.5 w-3.5" }),
|
|
140
140
|
a
|
|
@@ -201,7 +201,7 @@ function Qe({
|
|
|
201
201
|
{
|
|
202
202
|
type: "button",
|
|
203
203
|
onClick: () => {
|
|
204
|
-
S(null), f && (
|
|
204
|
+
S(null), f && (m == null || m(f));
|
|
205
205
|
},
|
|
206
206
|
className: "h-8 rounded-md px-2.5 text-[12.5px] font-medium text-slate-600 hover:bg-muted dark:text-slate-300",
|
|
207
207
|
children: f ? "Done" : "Close"
|
|
@@ -1,53 +1,63 @@
|
|
|
1
|
-
import { useQuery as
|
|
2
|
-
import { useNivaroClient as
|
|
3
|
-
import { get as
|
|
1
|
+
import { useQuery as h } from "@tanstack/react-query";
|
|
2
|
+
import { useNivaroClient as g } from "../../context.js";
|
|
3
|
+
import { get as m, post as y } from "../../lib/commands.js";
|
|
4
4
|
import { builtinListed as p } from "./PushBulkButtons.js";
|
|
5
|
-
function
|
|
6
|
-
const
|
|
7
|
-
for (const
|
|
8
|
-
const r = String(
|
|
9
|
-
|
|
5
|
+
function w(s) {
|
|
6
|
+
const a = /* @__PURE__ */ new Set(), n = [];
|
|
7
|
+
for (const e of s) {
|
|
8
|
+
const r = String(e.external_api ?? "");
|
|
9
|
+
a.has(r) || (a.add(r), (e.status === "failed" || e.status === "rejected") && n.push(e.external_api_name ?? `API ${e.external_api ?? "?"}`));
|
|
10
10
|
}
|
|
11
11
|
return n;
|
|
12
12
|
}
|
|
13
13
|
function S({
|
|
14
|
-
collection:
|
|
15
|
-
id:
|
|
14
|
+
collection: s,
|
|
15
|
+
id: a,
|
|
16
16
|
open: n,
|
|
17
|
-
bulkData:
|
|
17
|
+
bulkData: e,
|
|
18
18
|
bulkEnabledKeys: r
|
|
19
19
|
}) {
|
|
20
|
-
const
|
|
21
|
-
queryKey: ["
|
|
22
|
-
queryFn: () =>
|
|
23
|
-
|
|
24
|
-
).then((h) => h.data ?? []).catch(() => []),
|
|
25
|
-
enabled: n && a,
|
|
20
|
+
const u = g(), i = p(e, r, s, "push"), c = p(e, r, s, "retry-push"), { data: o = [] } = h({
|
|
21
|
+
queryKey: ["bulk-push-actions", s],
|
|
22
|
+
queryFn: () => u.request(m("/item-actions/registered", { collection: s })).then((t) => t.data ?? []).catch(() => []),
|
|
23
|
+
enabled: n && i,
|
|
26
24
|
staleTime: 5 * 6e4
|
|
27
|
-
}), { data:
|
|
28
|
-
queryKey: ["
|
|
29
|
-
queryFn: () =>
|
|
25
|
+
}), { data: d = [] } = h({
|
|
26
|
+
queryKey: ["item-actions", s, String(a)],
|
|
27
|
+
queryFn: () => u.request(
|
|
28
|
+
m("/item-actions/registered", { collection: s, item: String(a) })
|
|
29
|
+
).then((t) => t.data ?? []).catch(() => []),
|
|
30
|
+
enabled: n && i,
|
|
31
|
+
staleTime: 5 * 6e4
|
|
32
|
+
}), { data: f = [] } = h({
|
|
33
|
+
queryKey: ["row-push-state", s, String(a)],
|
|
34
|
+
queryFn: () => u.request(m(`/erp-submissions/${s}/${a}`)).then((t) => w(t.data ?? [])).catch(() => []),
|
|
30
35
|
enabled: n && c,
|
|
31
36
|
staleTime: 15e3
|
|
32
|
-
})
|
|
33
|
-
|
|
37
|
+
}), q = new Set(d.map((t) => t.id)), l = [
|
|
38
|
+
...d.map((t) => ({ ...t, ready: !0 })),
|
|
39
|
+
// Not ready here: listed, disabled — unless it is withheld from this person
|
|
40
|
+
// (an addendum they could not create), which stays hidden.
|
|
41
|
+
...o.filter((t) => !q.has(t.id) && !t.requires_addendum_create).map((t) => ({ ...t, ready: !1 }))
|
|
42
|
+
];
|
|
43
|
+
return { pushActions: i ? l : [], failedPartners: c ? f : [] };
|
|
34
44
|
}
|
|
35
|
-
async function
|
|
36
|
-
var
|
|
37
|
-
const
|
|
38
|
-
return r != null && r.trim() && (
|
|
39
|
-
|
|
40
|
-
collection:
|
|
41
|
-
action_id:
|
|
45
|
+
async function k(s, a, n, e, r, u) {
|
|
46
|
+
var o, d;
|
|
47
|
+
const i = {};
|
|
48
|
+
return r != null && r.trim() && (i.message = r.trim()), e.kind === "push" && e.action.choose && u != null && (i[e.action.choose.key] = u), ((d = (o = (e.kind === "push" ? await s.request(
|
|
49
|
+
y("/bulk-actions/push", {
|
|
50
|
+
collection: a,
|
|
51
|
+
action_id: e.action.id,
|
|
42
52
|
ids: [n],
|
|
43
|
-
...Object.keys(
|
|
53
|
+
...Object.keys(i).length > 0 ? { payload: i } : {}
|
|
44
54
|
})
|
|
45
|
-
) : await
|
|
46
|
-
|
|
47
|
-
)).data) == null ? void 0 :
|
|
55
|
+
) : await s.request(
|
|
56
|
+
y("/bulk-actions/retry-push", { collection: a, ids: [n] })
|
|
57
|
+
)).data) == null ? void 0 : o.outcomes) == null ? void 0 : d[0]) ?? null;
|
|
48
58
|
}
|
|
49
59
|
export {
|
|
50
|
-
|
|
51
|
-
|
|
60
|
+
w as latestFailedPartners,
|
|
61
|
+
k as runRowPush,
|
|
52
62
|
S as useRowPushActions
|
|
53
63
|
};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { jsx as i, Fragment as w, jsxs as f } from "react/jsx-runtime";
|
|
2
|
+
import { useQuery as v, useQueryClient as q, useMutation as R } from "@tanstack/react-query";
|
|
3
|
+
import { Play as C, Pause as N, Zap as $ } from "lucide-react";
|
|
4
|
+
import { useMemo as b, useState as F } from "react";
|
|
5
|
+
import { toast as p } from "sonner";
|
|
6
|
+
import { useNivaroClient as x } from "../../context.js";
|
|
7
|
+
import { get as j, post as y } from "../../lib/commands.js";
|
|
8
|
+
import { userErrorMessage as A } from "../../lib/safe-error.js";
|
|
9
|
+
import { cn as S } from "../../lib/utils.js";
|
|
10
|
+
import { useAvailableBulkActions as B, guardMatches as P } from "../bulk/BulkActionButtons.js";
|
|
11
|
+
import { Button as k } from "../ui/button.js";
|
|
12
|
+
import { Dialog as T, DialogContent as D, DialogHeader as H, DialogTitle as M, DialogDescription as Q, DialogBody as _, DialogFooter as E } from "../ui/dialog.js";
|
|
13
|
+
import { Textarea as J } from "../ui/textarea.js";
|
|
14
|
+
import { invalidateRecordQueries as K } from "./RecordLiveSync.js";
|
|
15
|
+
function ie(e, n, t) {
|
|
16
|
+
const h = x(), m = !!n && n !== "new", { data: u } = B(m ? [e] : []), d = b(
|
|
17
|
+
() => ((u == null ? void 0 : u[e]) ?? []).filter(
|
|
18
|
+
(o) => o.header === !0 && (o.kind === "update_fields" || o.kind === "transition")
|
|
19
|
+
),
|
|
20
|
+
[u, e]
|
|
21
|
+
), s = b(() => {
|
|
22
|
+
const o = /* @__PURE__ */ new Set();
|
|
23
|
+
for (const a of d)
|
|
24
|
+
for (const r of a.guard ?? [])
|
|
25
|
+
r && typeof r.field == "string" && !(t && r.field in t) && o.add(r.field);
|
|
26
|
+
return [...o].sort();
|
|
27
|
+
}, [d, t]), { data: l } = v({
|
|
28
|
+
queryKey: ["record-header-action-guard", e, String(n), s.join(",")],
|
|
29
|
+
queryFn: () => h.request(
|
|
30
|
+
j(`/items/${encodeURIComponent(e)}/${encodeURIComponent(String(n))}`, {
|
|
31
|
+
fields: s.join(",")
|
|
32
|
+
})
|
|
33
|
+
).then((o) => o.data ?? {}).catch(() => ({})),
|
|
34
|
+
enabled: m && s.length > 0,
|
|
35
|
+
staleTime: 0
|
|
36
|
+
});
|
|
37
|
+
return b(() => {
|
|
38
|
+
if (s.length > 0 && !l) return d.filter((a) => {
|
|
39
|
+
var r;
|
|
40
|
+
return !((r = a.guard) != null && r.length);
|
|
41
|
+
});
|
|
42
|
+
const o = { ...l ?? {}, ...t ?? {} };
|
|
43
|
+
return d.filter((a) => P(a.guard, o) !== !1);
|
|
44
|
+
}, [d, s, l, t]);
|
|
45
|
+
}
|
|
46
|
+
function U(e) {
|
|
47
|
+
return /remove-hold|unhold/i.test(e.key) ? /* @__PURE__ */ i(C, { className: "h-3.5 w-3.5" }) : /hold/i.test(e.key) ? /* @__PURE__ */ i(N, { className: "h-3.5 w-3.5" }) : /* @__PURE__ */ i($, { className: "h-3.5 w-3.5" });
|
|
48
|
+
}
|
|
49
|
+
function W(e) {
|
|
50
|
+
const n = e.summary && e.summary !== "Built-in" ? e.summary : e.label;
|
|
51
|
+
return e.require_reason ? `${n}. You’ll be asked for a justification, saved as a note on the record.` : `${n}.`;
|
|
52
|
+
}
|
|
53
|
+
function ae({
|
|
54
|
+
actions: e,
|
|
55
|
+
onPick: n
|
|
56
|
+
}) {
|
|
57
|
+
return e.length === 0 ? null : /* @__PURE__ */ i(w, { children: e.map((t) => /* @__PURE__ */ f(
|
|
58
|
+
"button",
|
|
59
|
+
{
|
|
60
|
+
type: "button",
|
|
61
|
+
"data-record-header-action": t.key,
|
|
62
|
+
"data-tip": W(t),
|
|
63
|
+
onClick: () => n(t),
|
|
64
|
+
className: S(
|
|
65
|
+
"inline-flex h-9 shrink-0 items-center gap-1.5 whitespace-nowrap rounded-md border px-3 text-[13px] font-medium shadow-sm transition-colors",
|
|
66
|
+
t.variant === "danger" ? "border-red-300 text-red-600 hover:bg-red-50 dark:border-red-500/40 dark:text-red-400 dark:hover:bg-red-500/10" : "border-slate-300 bg-background text-slate-700 hover:bg-accent dark:border-border dark:text-slate-200"
|
|
67
|
+
),
|
|
68
|
+
children: [
|
|
69
|
+
U(t),
|
|
70
|
+
t.label
|
|
71
|
+
]
|
|
72
|
+
},
|
|
73
|
+
`${t.source}:${t.key}`
|
|
74
|
+
)) });
|
|
75
|
+
}
|
|
76
|
+
function se({
|
|
77
|
+
action: e,
|
|
78
|
+
collection: n,
|
|
79
|
+
itemId: t,
|
|
80
|
+
onClose: h,
|
|
81
|
+
onDone: m
|
|
82
|
+
}) {
|
|
83
|
+
const u = x(), d = q(), [s, l] = F(""), o = !!(e != null && e.require_reason), a = R({
|
|
84
|
+
mutationFn: async (r) => {
|
|
85
|
+
const c = { collection: n, ids: [t], reason: s.trim() || null }, g = r.source === "db" ? await u.request(y("/bulk-actions/run", { ...c, key: r.key })) : await u.request(y(`/bulk-actions/${r.key}/execute`, c));
|
|
86
|
+
return { a: r, result: g.data ?? {} };
|
|
87
|
+
},
|
|
88
|
+
onSuccess: ({ a: r, result: c }) => {
|
|
89
|
+
var g;
|
|
90
|
+
(g = c.errors) != null && g.length ? p.error(c.errors[0].error) : !c.succeeded && c.skipped ? p.info(`${r.label}: nothing to change on this record`) : p.success(`${r.label} — done`), K(d, n, [t]), d.invalidateQueries({ queryKey: ["record-header-action-guard", n] }), l(""), m == null || m(), h();
|
|
91
|
+
},
|
|
92
|
+
onError: (r) => p.error(A(r, "The action did not run"))
|
|
93
|
+
});
|
|
94
|
+
return /* @__PURE__ */ i(
|
|
95
|
+
T,
|
|
96
|
+
{
|
|
97
|
+
open: !!e,
|
|
98
|
+
onOpenChange: (r) => {
|
|
99
|
+
r || (l(""), h());
|
|
100
|
+
},
|
|
101
|
+
children: /* @__PURE__ */ f(D, { className: "sm:max-w-md", "data-record-header-action-dialog": "", children: [
|
|
102
|
+
/* @__PURE__ */ f(H, { children: [
|
|
103
|
+
/* @__PURE__ */ i(M, { children: e == null ? void 0 : e.label }),
|
|
104
|
+
/* @__PURE__ */ i(Q, { children: o ? "Say why — your justification is saved as a note on this record." : "Runs on this record. A justification, if you add one, is saved as a note." })
|
|
105
|
+
] }),
|
|
106
|
+
/* @__PURE__ */ f(_, { className: "space-y-1.5", children: [
|
|
107
|
+
/* @__PURE__ */ i("label", { htmlFor: "record-header-action-reason", className: "text-[12.5px] font-medium", children: o ? "Justification (required)" : "Justification (optional)" }),
|
|
108
|
+
/* @__PURE__ */ i(
|
|
109
|
+
J,
|
|
110
|
+
{
|
|
111
|
+
id: "record-header-action-reason",
|
|
112
|
+
autoFocus: !0,
|
|
113
|
+
rows: 4,
|
|
114
|
+
value: s,
|
|
115
|
+
onChange: (r) => l(r.target.value),
|
|
116
|
+
placeholder: "Why?"
|
|
117
|
+
}
|
|
118
|
+
)
|
|
119
|
+
] }),
|
|
120
|
+
/* @__PURE__ */ f(E, { children: [
|
|
121
|
+
/* @__PURE__ */ i(k, { variant: "outline", onClick: h, disabled: a.isPending, children: "Cancel" }),
|
|
122
|
+
/* @__PURE__ */ i(
|
|
123
|
+
k,
|
|
124
|
+
{
|
|
125
|
+
onClick: () => e && a.mutate(e),
|
|
126
|
+
disabled: !e || a.isPending || o && !s.trim(),
|
|
127
|
+
className: "bg-nvr-cyan text-white hover:bg-nvr-cyan/90",
|
|
128
|
+
children: a.isPending ? "Working…" : e == null ? void 0 : e.label
|
|
129
|
+
}
|
|
130
|
+
)
|
|
131
|
+
] })
|
|
132
|
+
] })
|
|
133
|
+
}
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
export {
|
|
137
|
+
ae as RecordHeaderActionButtons,
|
|
138
|
+
se as RecordHeaderActionDialog,
|
|
139
|
+
ie as useRecordHeaderActions
|
|
140
|
+
};
|