@nivaro/react 0.3.38 → 0.3.39
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.
|
@@ -1,86 +1,92 @@
|
|
|
1
1
|
import { jsxs as n, jsx as t } from "react/jsx-runtime";
|
|
2
|
-
import { useQueryClient as D, useQuery as
|
|
3
|
-
import { Loader2 as
|
|
4
|
-
import { useState as
|
|
5
|
-
import { toast as
|
|
2
|
+
import { useQueryClient as D, useQuery as L, useMutation as F } from "@tanstack/react-query";
|
|
3
|
+
import { Loader2 as j, EyeOff as I, CalendarClock as Q, ChevronsUpDown as R, Check as B } from "lucide-react";
|
|
4
|
+
import { useState as m, useId as K, useMemo as M } from "react";
|
|
5
|
+
import { toast as g } from "sonner";
|
|
6
6
|
import { useNivaroClient as $ } from "../../context.js";
|
|
7
7
|
import { get as V, post as q } from "../../lib/commands.js";
|
|
8
8
|
import { titleCase as W, cn as z } from "../../lib/utils.js";
|
|
9
9
|
import { Button as w } from "../ui/button.js";
|
|
10
10
|
import { Command as A, CommandInput as H, CommandList as U, CommandEmpty as G, CommandItem as J } from "../ui/command.js";
|
|
11
11
|
import { Input as S } from "../ui/input.js";
|
|
12
|
-
import { Popover as
|
|
12
|
+
import { Popover as E, PopoverTrigger as P, PopoverContent as _ } from "../ui/popover.js";
|
|
13
13
|
function O(l, r) {
|
|
14
14
|
return l instanceof Error && l.message ? l.message : r;
|
|
15
15
|
}
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}) {
|
|
21
|
-
const u = $(), x = D(), m = ["picker-exclusion", l, r], { data: s } = j({
|
|
22
|
-
queryKey: m,
|
|
23
|
-
queryFn: () => u.request(
|
|
16
|
+
function X(l, r, i = {}) {
|
|
17
|
+
const s = $(), c = D(), h = ["picker-exclusion", l, r], { data: o, isLoading: p } = L({
|
|
18
|
+
queryKey: h,
|
|
19
|
+
queryFn: () => s.request(
|
|
24
20
|
V(`/picker-exclusions/status/${l}/${r}`)
|
|
25
21
|
).then((a) => a.data),
|
|
22
|
+
enabled: i.enabled ?? !0,
|
|
26
23
|
staleTime: 6e4
|
|
27
|
-
}),
|
|
24
|
+
}), d = (o == null ? void 0 : o.excluded) ?? !1, u = F({
|
|
28
25
|
mutationFn: () => {
|
|
29
|
-
const a = { collection: l, item_id: r, layout:
|
|
30
|
-
return
|
|
31
|
-
|
|
26
|
+
const a = { collection: l, item_id: r, layout: i.layoutSlug ?? null };
|
|
27
|
+
return s.request(
|
|
28
|
+
d ? { _method: "DELETE", _path: "/picker-exclusions", _body: a } : q("/picker-exclusions", a)
|
|
32
29
|
);
|
|
33
30
|
},
|
|
34
31
|
onSuccess: () => {
|
|
35
|
-
|
|
32
|
+
var a;
|
|
33
|
+
c.invalidateQueries({ queryKey: h }), g.success(d ? "Record re-enabled in pickers" : "Record excluded from pickers"), (a = i.onDone) == null || a.call(i);
|
|
36
34
|
},
|
|
37
|
-
onError: (a) =>
|
|
35
|
+
onError: (a) => g.error(O(a, "Could not change picker visibility"))
|
|
38
36
|
});
|
|
37
|
+
return { excluded: d, isLoading: p, toggle: u };
|
|
38
|
+
}
|
|
39
|
+
function de({
|
|
40
|
+
collection: l,
|
|
41
|
+
itemId: r,
|
|
42
|
+
layoutSlug: i
|
|
43
|
+
}) {
|
|
44
|
+
const { excluded: s, toggle: c } = X(l, r, { layoutSlug: i });
|
|
39
45
|
return /* @__PURE__ */ n(
|
|
40
46
|
"button",
|
|
41
47
|
{
|
|
42
48
|
type: "button",
|
|
43
49
|
"data-record-picker-exclusion": !0,
|
|
44
|
-
"data-excluded":
|
|
45
|
-
disabled:
|
|
46
|
-
onClick: () =>
|
|
47
|
-
"data-tip":
|
|
50
|
+
"data-excluded": s ? "true" : "false",
|
|
51
|
+
disabled: c.isPending,
|
|
52
|
+
onClick: () => c.mutate(),
|
|
53
|
+
"data-tip": s ? "This record is hidden from pickers — click to offer it again" : "Hide this record from every picker that would offer it",
|
|
48
54
|
className: "inline-flex items-center",
|
|
49
55
|
children: [
|
|
50
|
-
|
|
51
|
-
|
|
56
|
+
c.isPending ? /* @__PURE__ */ t(j, { className: "animate-spin" }) : /* @__PURE__ */ t(I, {}),
|
|
57
|
+
s ? "Re-enable in pickers" : "Disable in pickers"
|
|
52
58
|
]
|
|
53
59
|
}
|
|
54
60
|
);
|
|
55
61
|
}
|
|
56
|
-
function
|
|
62
|
+
function ue({
|
|
57
63
|
collection: l,
|
|
58
64
|
itemId: r,
|
|
59
|
-
fields:
|
|
60
|
-
layoutSlug:
|
|
65
|
+
fields: i,
|
|
66
|
+
layoutSlug: s
|
|
61
67
|
}) {
|
|
62
|
-
const
|
|
63
|
-
() =>
|
|
64
|
-
[
|
|
65
|
-
),
|
|
66
|
-
mutationFn: () =>
|
|
68
|
+
const c = $(), [h, o] = m(!1), [p, d] = m(!1), [u, a] = m(""), [b, v] = m(""), [f, k] = m(""), x = K(), C = M(
|
|
69
|
+
() => i.filter((e) => !e.field.startsWith("__") && !e.field.includes(".")).map((e) => ({ field: e.field, label: e.label || W(e.field) })),
|
|
70
|
+
[i]
|
|
71
|
+
), y = C.find((e) => e.field === u), N = F({
|
|
72
|
+
mutationFn: () => c.request(
|
|
67
73
|
q("/scheduled-changes", {
|
|
68
74
|
collection: l,
|
|
69
75
|
item_id: r,
|
|
70
76
|
change_type: "field_update",
|
|
71
|
-
changes: { [
|
|
77
|
+
changes: { [u]: b },
|
|
72
78
|
// datetime-local is the viewer's local time; the API stores UTC.
|
|
73
|
-
scheduled_at: new Date(
|
|
74
|
-
layout:
|
|
79
|
+
scheduled_at: new Date(f).toISOString(),
|
|
80
|
+
layout: s ?? null
|
|
75
81
|
})
|
|
76
82
|
),
|
|
77
83
|
onSuccess: () => {
|
|
78
|
-
|
|
84
|
+
o(!1), a(""), v(""), k(""), g.success("Change scheduled");
|
|
79
85
|
},
|
|
80
|
-
onError: (e) =>
|
|
81
|
-
}), T =
|
|
82
|
-
return /* @__PURE__ */ n(
|
|
83
|
-
/* @__PURE__ */ t(
|
|
86
|
+
onError: (e) => g.error(O(e, "Could not schedule the change"))
|
|
87
|
+
}), T = f !== "" && !Number.isNaN(new Date(f).getTime());
|
|
88
|
+
return /* @__PURE__ */ n(E, { open: h, onOpenChange: o, children: [
|
|
89
|
+
/* @__PURE__ */ t(P, { asChild: !0, children: /* @__PURE__ */ n(
|
|
84
90
|
"button",
|
|
85
91
|
{
|
|
86
92
|
type: "button",
|
|
@@ -93,37 +99,37 @@ function de({
|
|
|
93
99
|
]
|
|
94
100
|
}
|
|
95
101
|
) }),
|
|
96
|
-
/* @__PURE__ */ n(
|
|
102
|
+
/* @__PURE__ */ n(_, { side: "left", align: "start", className: "w-80 p-4", "data-schedule-change-panel": !0, children: [
|
|
97
103
|
/* @__PURE__ */ t("p", { className: "mb-3 text-[13px] font-medium", children: "Schedule a field change" }),
|
|
98
104
|
/* @__PURE__ */ n("div", { className: "space-y-3", children: [
|
|
99
105
|
/* @__PURE__ */ n("div", { children: [
|
|
100
106
|
/* @__PURE__ */ t("span", { className: "mb-1 block text-[11px] font-medium text-muted-foreground", children: "Field" }),
|
|
101
|
-
/* @__PURE__ */ n(
|
|
102
|
-
/* @__PURE__ */ t(
|
|
107
|
+
/* @__PURE__ */ n(E, { open: p, onOpenChange: d, children: [
|
|
108
|
+
/* @__PURE__ */ t(P, { asChild: !0, children: /* @__PURE__ */ n(
|
|
103
109
|
w,
|
|
104
110
|
{
|
|
105
111
|
type: "button",
|
|
106
112
|
variant: "outline",
|
|
107
113
|
role: "combobox",
|
|
108
|
-
"aria-expanded":
|
|
114
|
+
"aria-expanded": p,
|
|
109
115
|
"aria-label": "Field",
|
|
110
116
|
className: "h-8 w-full justify-between text-[12px] font-normal",
|
|
111
117
|
children: [
|
|
112
|
-
/* @__PURE__ */ t("span", { className: "truncate", children: (
|
|
118
|
+
/* @__PURE__ */ t("span", { className: "truncate", children: (y == null ? void 0 : y.label) ?? "Select a field…" }),
|
|
113
119
|
/* @__PURE__ */ t(R, { className: "ml-1 h-3 w-3 shrink-0 opacity-50" })
|
|
114
120
|
]
|
|
115
121
|
}
|
|
116
122
|
) }),
|
|
117
|
-
/* @__PURE__ */ t(
|
|
123
|
+
/* @__PURE__ */ t(_, { className: "w-[--radix-popover-trigger-width] p-0", align: "start", children: /* @__PURE__ */ n(A, { children: [
|
|
118
124
|
/* @__PURE__ */ t(H, { placeholder: "Search fields…", className: "h-8 text-[12px]" }),
|
|
119
125
|
/* @__PURE__ */ n(U, { children: [
|
|
120
126
|
/* @__PURE__ */ t(G, { className: "py-3 text-center text-[12px] text-muted-foreground", children: "No field matches" }),
|
|
121
|
-
|
|
127
|
+
C.map((e) => /* @__PURE__ */ n(
|
|
122
128
|
J,
|
|
123
129
|
{
|
|
124
130
|
value: `${e.label} ${e.field}`,
|
|
125
131
|
onSelect: () => {
|
|
126
|
-
|
|
132
|
+
a(e.field), d(!1);
|
|
127
133
|
},
|
|
128
134
|
className: "text-[12px]",
|
|
129
135
|
children: [
|
|
@@ -132,7 +138,7 @@ function de({
|
|
|
132
138
|
{
|
|
133
139
|
className: z(
|
|
134
140
|
"mr-2 h-3.5 w-3.5",
|
|
135
|
-
|
|
141
|
+
u === e.field ? "opacity-100" : "opacity-0"
|
|
136
142
|
)
|
|
137
143
|
}
|
|
138
144
|
),
|
|
@@ -150,7 +156,7 @@ function de({
|
|
|
150
156
|
/* @__PURE__ */ t(
|
|
151
157
|
"label",
|
|
152
158
|
{
|
|
153
|
-
htmlFor: `${
|
|
159
|
+
htmlFor: `${x}-value`,
|
|
154
160
|
className: "mb-1 block text-[11px] font-medium text-muted-foreground",
|
|
155
161
|
children: "New value"
|
|
156
162
|
}
|
|
@@ -158,8 +164,8 @@ function de({
|
|
|
158
164
|
/* @__PURE__ */ t(
|
|
159
165
|
S,
|
|
160
166
|
{
|
|
161
|
-
id: `${
|
|
162
|
-
value:
|
|
167
|
+
id: `${x}-value`,
|
|
168
|
+
value: b,
|
|
163
169
|
onChange: (e) => v(e.target.value),
|
|
164
170
|
className: "h-8 text-[12px]"
|
|
165
171
|
}
|
|
@@ -169,7 +175,7 @@ function de({
|
|
|
169
175
|
/* @__PURE__ */ t(
|
|
170
176
|
"label",
|
|
171
177
|
{
|
|
172
|
-
htmlFor: `${
|
|
178
|
+
htmlFor: `${x}-at`,
|
|
173
179
|
className: "mb-1 block text-[11px] font-medium text-muted-foreground",
|
|
174
180
|
children: "When"
|
|
175
181
|
}
|
|
@@ -177,10 +183,10 @@ function de({
|
|
|
177
183
|
/* @__PURE__ */ t(
|
|
178
184
|
S,
|
|
179
185
|
{
|
|
180
|
-
id: `${
|
|
186
|
+
id: `${x}-at`,
|
|
181
187
|
type: "datetime-local",
|
|
182
|
-
value:
|
|
183
|
-
onChange: (e) =>
|
|
188
|
+
value: f,
|
|
189
|
+
onChange: (e) => k(e.target.value),
|
|
184
190
|
className: "h-8 text-[12px]"
|
|
185
191
|
}
|
|
186
192
|
)
|
|
@@ -191,9 +197,9 @@ function de({
|
|
|
191
197
|
type: "button",
|
|
192
198
|
size: "sm",
|
|
193
199
|
className: "h-8 w-full bg-nvr-cyan text-[12px] text-white hover:bg-nvr-cyan/90",
|
|
194
|
-
disabled: !
|
|
195
|
-
onClick: () =>
|
|
196
|
-
children:
|
|
200
|
+
disabled: !u || !b || !T || N.isPending,
|
|
201
|
+
onClick: () => N.mutate(),
|
|
202
|
+
children: N.isPending ? "Scheduling…" : "Schedule change"
|
|
197
203
|
}
|
|
198
204
|
)
|
|
199
205
|
] })
|
|
@@ -201,6 +207,7 @@ function de({
|
|
|
201
207
|
] });
|
|
202
208
|
}
|
|
203
209
|
export {
|
|
204
|
-
|
|
205
|
-
|
|
210
|
+
de as PickerExclusionToggle,
|
|
211
|
+
ue as ScheduleChangeButton,
|
|
212
|
+
X as usePickerExclusion
|
|
206
213
|
};
|