@nivaro/react 0.3.87 → 0.3.89

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.
@@ -0,0 +1,208 @@
1
+ import { jsxs as l, jsx as e } from "react/jsx-runtime";
2
+ import { ChevronsUpDown as x, Check as h, ChevronDown as b, ChevronRight as f } from "lucide-react";
3
+ import { useState as p } from "react";
4
+ import { cn as m } from "../../lib/utils.js";
5
+ import { Button as g } from "../ui/button.js";
6
+ import { Command as v, CommandInput as k, CommandList as N, CommandEmpty as w, CommandItem as y } from "../ui/command.js";
7
+ import { Popover as C, PopoverTrigger as S, PopoverContent as D } from "../ui/popover.js";
8
+ import { useDrill as P, Drillable as j } from "./drill.js";
9
+ function q({
10
+ id: a,
11
+ title: r,
12
+ gist: n,
13
+ empty: t,
14
+ defaultOpen: s,
15
+ children: u
16
+ }) {
17
+ const [i, o] = p(!!s && !t);
18
+ return /* @__PURE__ */ l(
19
+ "section",
20
+ {
21
+ "data-ops-section": a,
22
+ className: "rounded-lg border border-slate-200 bg-white dark:border-border dark:bg-card",
23
+ children: [
24
+ /* @__PURE__ */ l(
25
+ "button",
26
+ {
27
+ type: "button",
28
+ disabled: t,
29
+ "aria-expanded": t ? void 0 : i,
30
+ onClick: () => o((c) => !c),
31
+ className: "flex w-full items-center gap-2 rounded-lg px-3 py-2 text-left enabled:hover:bg-muted/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nvr-cyan/50",
32
+ children: [
33
+ t ? /* @__PURE__ */ e("span", { className: "w-3.5" }) : i ? /* @__PURE__ */ e(b, { className: "h-3.5 w-3.5 shrink-0 text-slate-400", "aria-hidden": !0 }) : /* @__PURE__ */ e(f, { className: "h-3.5 w-3.5 shrink-0 text-slate-400", "aria-hidden": !0 }),
34
+ /* @__PURE__ */ e(
35
+ "span",
36
+ {
37
+ className: m(
38
+ "text-[12.5px] font-semibold",
39
+ t ? "text-slate-400 dark:text-muted-foreground" : "text-slate-800 dark:text-foreground"
40
+ ),
41
+ children: r
42
+ }
43
+ ),
44
+ /* @__PURE__ */ e("span", { className: "min-w-0 flex-1 truncate text-right text-[11.5px] tabular-nums text-slate-500 dark:text-muted-foreground", children: t ? "Nothing recorded" : n })
45
+ ]
46
+ }
47
+ ),
48
+ i && !t && /* @__PURE__ */ e("div", { className: "space-y-3 border-t border-slate-100 px-3 py-3 dark:border-border", children: u })
49
+ ]
50
+ }
51
+ );
52
+ }
53
+ function I({ children: a }) {
54
+ return /* @__PURE__ */ e("h4", { className: "mb-1 text-[10.5px] font-semibold uppercase tracking-wide text-slate-500 dark:text-muted-foreground", children: a });
55
+ }
56
+ function z({
57
+ title: a,
58
+ rows: r,
59
+ cols: n,
60
+ limit: t = 15,
61
+ drill: s
62
+ }) {
63
+ const u = P();
64
+ if (!r.length) return null;
65
+ const i = r.slice(0, t);
66
+ return /* @__PURE__ */ l("div", { children: [
67
+ a && /* @__PURE__ */ e(I, { children: a }),
68
+ /* @__PURE__ */ e("div", { className: "overflow-x-auto", children: /* @__PURE__ */ l("table", { className: "w-full text-[12px]", children: [
69
+ /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ e("tr", { className: "border-b border-slate-200 text-left text-[10.5px] uppercase tracking-wide text-slate-500 dark:border-border dark:text-muted-foreground", children: n.map((o) => /* @__PURE__ */ e(
70
+ "th",
71
+ {
72
+ className: m("py-1 pr-3 font-medium last:pr-0", o.num && "text-right"),
73
+ children: o.h
74
+ },
75
+ o.h
76
+ )) }) }),
77
+ /* @__PURE__ */ e("tbody", { children: i.map((o, c) => /* @__PURE__ */ e(
78
+ "tr",
79
+ {
80
+ ...O(u, (s == null ? void 0 : s(o)) ?? null),
81
+ className: m(
82
+ "border-b border-slate-100 last:border-0 dark:border-border/60",
83
+ u && (s == null ? void 0 : s(o)) && "cursor-pointer hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-nvr-cyan/50"
84
+ ),
85
+ children: n.map((d) => /* @__PURE__ */ e(
86
+ "td",
87
+ {
88
+ className: m(
89
+ "py-1 pr-3 align-top text-slate-700 last:pr-0 dark:text-foreground",
90
+ d.num && "text-right tabular-nums",
91
+ d.className
92
+ ),
93
+ children: d.cell(o)
94
+ },
95
+ d.h
96
+ ))
97
+ },
98
+ c
99
+ )) })
100
+ ] }) }),
101
+ r.length > t && /* @__PURE__ */ l("p", { className: "mt-1 text-[11px] text-slate-500 dark:text-muted-foreground", children: [
102
+ "and ",
103
+ r.length - t,
104
+ " more"
105
+ ] })
106
+ ] });
107
+ }
108
+ function O(a, r) {
109
+ if (!a || !r) return {};
110
+ const n = () => a.open({ metric: r.metric, key: r.key, label: r.label });
111
+ return {
112
+ tabIndex: 0,
113
+ "data-ops-drill": r.metric,
114
+ onClick: n,
115
+ onKeyDown: (t) => {
116
+ (t.key === "Enter" || t.key === " ") && (t.preventDefault(), n());
117
+ }
118
+ };
119
+ }
120
+ function A({
121
+ label: a,
122
+ value: r,
123
+ tone: n,
124
+ drill: t
125
+ }) {
126
+ return /* @__PURE__ */ e(
127
+ j,
128
+ {
129
+ target: t ?? null,
130
+ className: "min-w-[84px] rounded-md px-1 py-0.5 -mx-1 -my-0.5 hover:bg-muted",
131
+ children: /* @__PURE__ */ l("div", { children: [
132
+ /* @__PURE__ */ e(
133
+ "div",
134
+ {
135
+ className: m(
136
+ "text-[15px] font-semibold tabular-nums",
137
+ n === "bad" ? "text-red-600 dark:text-red-400" : "text-slate-900 dark:text-foreground"
138
+ ),
139
+ children: r
140
+ }
141
+ ),
142
+ /* @__PURE__ */ e("div", { className: "text-[11px] text-slate-500 dark:text-muted-foreground", children: a })
143
+ ] })
144
+ }
145
+ );
146
+ }
147
+ function F({
148
+ value: a,
149
+ onChange: r,
150
+ options: n,
151
+ ariaLabel: t,
152
+ placeholder: s,
153
+ className: u
154
+ }) {
155
+ const [i, o] = p(!1), c = n.find((d) => d.value === a);
156
+ return /* @__PURE__ */ l(C, { open: i, onOpenChange: o, children: [
157
+ /* @__PURE__ */ e(S, { asChild: !0, children: /* @__PURE__ */ l(
158
+ g,
159
+ {
160
+ variant: "outline",
161
+ role: "combobox",
162
+ "aria-expanded": i,
163
+ "aria-label": t,
164
+ className: m(
165
+ "h-8 justify-between gap-2 rounded-md border-slate-200 bg-white px-2.5 text-[12.5px] font-normal dark:border-border dark:bg-background",
166
+ u
167
+ ),
168
+ children: [
169
+ /* @__PURE__ */ e("span", { className: m("truncate", !c && "text-muted-foreground"), children: (c == null ? void 0 : c.label) ?? s ?? "Select…" }),
170
+ /* @__PURE__ */ e(x, { className: "h-3 w-3 shrink-0 opacity-50", "aria-hidden": !0 })
171
+ ]
172
+ }
173
+ ) }),
174
+ /* @__PURE__ */ e(D, { className: "w-[260px] p-0", align: "start", children: /* @__PURE__ */ l(v, { children: [
175
+ /* @__PURE__ */ e(k, { placeholder: "Search…", className: "h-8 text-[12px]" }),
176
+ /* @__PURE__ */ l(N, { children: [
177
+ /* @__PURE__ */ e(w, { className: "py-3 text-center text-[12px] text-muted-foreground", children: "No results" }),
178
+ n.map((d) => /* @__PURE__ */ l(
179
+ y,
180
+ {
181
+ value: d.label,
182
+ onSelect: () => {
183
+ r(d.value), o(!1);
184
+ },
185
+ className: "text-[12px]",
186
+ children: [
187
+ /* @__PURE__ */ e(
188
+ h,
189
+ {
190
+ className: m("mr-2 h-3 w-3", d.value === a ? "opacity-100" : "opacity-0")
191
+ }
192
+ ),
193
+ d.label
194
+ ]
195
+ },
196
+ d.value
197
+ ))
198
+ ] })
199
+ ] }) })
200
+ ] });
201
+ }
202
+ export {
203
+ z as MiniTable,
204
+ F as Pick,
205
+ q as Section,
206
+ A as Stat,
207
+ I as SubTitle
208
+ };
@@ -0,0 +1,127 @@
1
+ import { jsxs as a, jsx as o } from "react/jsx-runtime";
2
+ import { useMutation as y } from "@tanstack/react-query";
3
+ import { MoveRight as C, Loader2 as w } from "lucide-react";
4
+ import { useState as l, useMemo as S } from "react";
5
+ import { toast as P } from "sonner";
6
+ import { useNivaroClient as R } from "../../context.js";
7
+ import { post as $ } from "../../lib/commands.js";
8
+ import { toastError as A } from "../../lib/error-toast.js";
9
+ import { Button as h } from "../ui/button.js";
10
+ import { SimpleSelect as E } from "../ui/SimpleSelect.js";
11
+ import { Textarea as O } from "../ui/textarea.js";
12
+ const x = 5;
13
+ function V({
14
+ collection: g,
15
+ item: v,
16
+ states: m,
17
+ currentStateId: c,
18
+ onMoved: b
19
+ }) {
20
+ const f = R(), [N, n] = l(!1), [i, d] = l(""), [r, p] = l(""), k = S(
21
+ () => [
22
+ { value: "", label: "Pick a state" },
23
+ ...m.filter((e) => String(e.id).toUpperCase() !== String(c ?? "").toUpperCase()).map((e) => ({ value: String(e.id), label: e.label }))
24
+ ],
25
+ [m, c]
26
+ ), s = y({
27
+ mutationFn: () => f.request(
28
+ $(`/pipelines/instance/${g}/${encodeURIComponent(String(v))}/move-state`, {
29
+ to_state: i,
30
+ reason: r.trim()
31
+ })
32
+ ),
33
+ onSuccess: (e) => {
34
+ const t = e == null ? void 0 : e.data;
35
+ P.success(
36
+ t != null && t.ended ? `Moved to ${t.to.label}, then an automatic rule took it to ${t.ended.label}` : `Moved to ${(t == null ? void 0 : t.to.label) ?? "the new state"}`
37
+ ), n(!1), d(""), p(""), b();
38
+ },
39
+ onError: (e) => A(e, "Could not move it")
40
+ }), u = r.trim().length >= x, M = !!i && u && !s.isPending;
41
+ return N ? /* @__PURE__ */ a(
42
+ "div",
43
+ {
44
+ className: "space-y-3 rounded-lg border border-amber-200 bg-amber-50/60 p-3 dark:border-amber-500/25 dark:bg-amber-500/[0.06]",
45
+ "data-move-to-state-form": !0,
46
+ children: [
47
+ /* @__PURE__ */ a("div", { className: "space-y-1", children: [
48
+ /* @__PURE__ */ o("p", { className: "text-[12px] font-medium text-slate-800 dark:text-slate-200", children: "Move to state" }),
49
+ /* @__PURE__ */ o("p", { className: "text-[11px] leading-relaxed text-slate-600 dark:text-slate-400", children: "Administrators only. Puts this record straight into the state you pick. No transition steps run: no Fusion or MWF pushes, emails or flows. Automatic rules are checked again afterwards, so it may move on by itself." })
50
+ ] }),
51
+ /* @__PURE__ */ a("div", { className: "grid gap-2 sm:grid-cols-[minmax(0,220px)_1fr]", children: [
52
+ /* @__PURE__ */ o(
53
+ E,
54
+ {
55
+ value: i,
56
+ onChange: d,
57
+ options: k,
58
+ ariaLabel: "New state",
59
+ disabled: s.isPending
60
+ }
61
+ ),
62
+ /* @__PURE__ */ o(
63
+ O,
64
+ {
65
+ value: r,
66
+ onChange: (e) => p(e.target.value),
67
+ placeholder: "Why? Saved in the history.",
68
+ rows: 2,
69
+ maxLength: 500,
70
+ disabled: s.isPending,
71
+ className: "min-h-[38px] text-[12px]",
72
+ "aria-label": "Reason"
73
+ }
74
+ )
75
+ ] }),
76
+ /* @__PURE__ */ a("div", { className: "flex items-center justify-end gap-2", children: [
77
+ !u && r.length > 0 && /* @__PURE__ */ a("span", { className: "mr-auto text-[11px] text-slate-500", children: [
78
+ "A few more words, please (",
79
+ x,
80
+ " characters or more)."
81
+ ] }),
82
+ /* @__PURE__ */ o(
83
+ h,
84
+ {
85
+ size: "sm",
86
+ variant: "ghost",
87
+ className: "h-7 text-[12px]",
88
+ onClick: () => n(!1),
89
+ disabled: s.isPending,
90
+ children: "Cancel"
91
+ }
92
+ ),
93
+ /* @__PURE__ */ a(
94
+ h,
95
+ {
96
+ size: "sm",
97
+ className: "h-7 gap-1.5 bg-nvr-cyan text-[12px] text-white hover:bg-nvr-cyan/90",
98
+ onClick: () => s.mutate(),
99
+ disabled: !M,
100
+ "data-move-to-state-submit": !0,
101
+ children: [
102
+ s.isPending && /* @__PURE__ */ o(w, { className: "h-3 w-3 animate-spin" }),
103
+ "Move"
104
+ ]
105
+ }
106
+ )
107
+ ] })
108
+ ]
109
+ }
110
+ ) : /* @__PURE__ */ a(
111
+ "button",
112
+ {
113
+ type: "button",
114
+ className: "flex items-center gap-1.5 text-[12px] text-slate-400 transition-colors hover:text-slate-600 dark:hover:text-slate-300",
115
+ onClick: () => n(!0),
116
+ "data-move-to-state-open": !0,
117
+ children: [
118
+ /* @__PURE__ */ o(C, { className: "h-3.5 w-3.5" }),
119
+ "Move to state…"
120
+ ]
121
+ }
122
+ );
123
+ }
124
+ export {
125
+ x as MOVE_REASON_MIN,
126
+ V as MoveToStatePanel
127
+ };