@nivaro/react 0.3.15 → 0.3.17
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 +127 -6
- package/dist/index.js +736 -734
- package/dist/shared/components/CollectionBrowserView.js +2344 -2309
- package/dist/shared/components/ItemEditForm.js +3773 -3604
- package/dist/shared/components/RecordGridEditor.js +319 -282
- package/dist/shared/components/RecordReadView.js +202 -200
- package/dist/shared/components/cbv/unknown-fields.js +18 -8
- package/dist/shared/components/chat/ChatAnalyticsView.js +2 -2
- package/dist/shared/components/import/DocumentAutofillButton.js +148 -142
- package/dist/shared/components/item-edit/CatalogPickerField.js +264 -276
- package/dist/shared/components/item-edit/FieldRenderer.js +136 -133
- package/dist/shared/components/item-edit/FieldRow.js +198 -184
- package/dist/shared/components/item-edit/HeaderTools.js +107 -99
- package/dist/shared/components/item-edit/InlineTableField.js +138 -136
- package/dist/shared/components/item-edit/RecordLiveSync.js +1 -0
- package/dist/shared/components/item-edit/RelationCombobox.js +30 -23
- package/dist/shared/components/item-edit/SummaryPanel.js +334 -294
- package/dist/shared/components/item-edit/column-length.js +12 -0
- package/dist/shared/components/panels/AccessDeniedPanel.js +47 -37
- package/dist/shared/components/panels/ItemLockBanner.js +307 -285
- package/dist/shared/components/panels/PipelinePanel.js +486 -465
- package/dist/shared/components/panels/RevisionsPanel.js +210 -204
- package/dist/shared/components/pipeline/PipelineEditorView.js +1672 -1568
- package/dist/shared/components/profile/DelegationCard.js +178 -121
- package/dist/shared/components/profile/PersonActivity.js +152 -139
- package/dist/shared/components/queue/QueueWorklist.js +668 -659
- package/dist/shared/components/queue/transition-note.js +90 -0
- package/dist/shared/components/support/SupportRequestDialog.js +100 -89
- package/dist/shared/components/support/TicketDetailSheet.js +104 -91
- package/dist/shared/lib/autofill-runs.js +33 -26
- package/dist/shared/lib/draft-store.js +40 -24
- package/dist/shared/lib/live-queries.js +10 -9
- package/dist/shared/lib/request-gate.js +140 -127
- package/dist/shared/lib/restore-skipped.js +10 -0
- package/package.json +1 -1
|
@@ -1,197 +1,219 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { jsxs as y, jsx as k } from "react/jsx-runtime";
|
|
2
|
+
import { QueryClientContext as Le } from "@tanstack/react-query";
|
|
3
|
+
import { Lock as H, LockOpen as ne } from "lucide-react";
|
|
4
|
+
import { useContext as Ee, useState as _, useRef as A, useCallback as w, useEffect as N } from "react";
|
|
4
5
|
import { toast as u } from "sonner";
|
|
5
|
-
import { useNivaroClient as
|
|
6
|
-
import { post as
|
|
7
|
-
import { idleState as
|
|
8
|
-
import { useOptionalRealtime as
|
|
9
|
-
import { announceRecordTabs as
|
|
10
|
-
import { Button as
|
|
11
|
-
import { Popover as
|
|
12
|
-
const
|
|
13
|
-
function
|
|
14
|
-
const [t, r] =
|
|
6
|
+
import { useNivaroClient as Re, useItemEditAuth as Ce } from "../../context.js";
|
|
7
|
+
import { post as C, get as Se, del as K } from "../../lib/commands.js";
|
|
8
|
+
import { idleState as qe } from "../../lib/idle.js";
|
|
9
|
+
import { useOptionalRealtime as ae, updateTouches as Ae } from "../../lib/realtime.js";
|
|
10
|
+
import { announceRecordTabs as se, useRecordTabsSignal as Te } from "../../lib/record-tabs.js";
|
|
11
|
+
import { Button as O } from "../ui/button.js";
|
|
12
|
+
import { Popover as oe, PopoverTrigger as ie, PopoverContent as le } from "../ui/popover.js";
|
|
13
|
+
const Ie = 6e4, Ye = 2 * 6e4, Oe = 3e4, De = 6e4, Me = 15e3;
|
|
14
|
+
function je() {
|
|
15
|
+
const [t, r] = _(
|
|
15
16
|
() => typeof document > "u" || document.visibilityState !== "hidden"
|
|
16
17
|
);
|
|
17
|
-
return
|
|
18
|
-
const
|
|
19
|
-
return document.addEventListener("visibilitychange",
|
|
18
|
+
return N(() => {
|
|
19
|
+
const i = () => r(document.visibilityState !== "hidden");
|
|
20
|
+
return document.addEventListener("visibilitychange", i), () => document.removeEventListener("visibilitychange", i);
|
|
20
21
|
}, []), t;
|
|
21
22
|
}
|
|
22
|
-
function
|
|
23
|
-
const { lazy:
|
|
24
|
-
|
|
25
|
-
}, []),
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
function Xe(t, r, i, S = {}) {
|
|
24
|
+
const { lazy: L = !1, active: T = !0 } = S, s = Re(), { isAdmin: E, userId: g } = Ce(), v = Ee(Le), [p, h] = _(null), [F, $] = _(!1), [D, J] = _(!1), [ce, ue] = _([]), [de, M] = _(null), [fe, G] = _(!1), [ke, X] = _(""), [me, P] = _(!1), [he, Z] = _(!1), j = A(null), l = A(!1), R = A(!1), Q = A(!1), V = A(0), q = A(!1), z = A(null), m = w(() => {
|
|
25
|
+
j.current && (clearInterval(j.current), j.current = null);
|
|
26
|
+
}, []), U = w(
|
|
27
|
+
(a) => {
|
|
28
|
+
var e, c;
|
|
29
|
+
const n = a, f = n.status ?? ((e = n.response) == null ? void 0 : e.status), o = ((c = n.response) == null ? void 0 : c.data) ?? n.response;
|
|
30
|
+
return f !== 403 || (o == null ? void 0 : o.code) !== "EDIT_LOCKED" ? !1 : (m(), l.current = !1, $(!1), u.warning(o.error || "You can no longer edit this record — your edit lock was let go"), v == null || v.invalidateQueries({ queryKey: ["pipeline-instance-lock", t, r] }), v == null || v.invalidateQueries({ queryKey: ["pipeline-instance", t, r] }), !0);
|
|
31
|
+
},
|
|
32
|
+
[v, t, r, m]
|
|
33
|
+
), d = w(async () => {
|
|
34
|
+
var a, n;
|
|
35
|
+
if (!t || !r || q.current) return !1;
|
|
36
|
+
z.current = null;
|
|
29
37
|
try {
|
|
30
|
-
return await s.request(
|
|
31
|
-
const
|
|
38
|
+
return await s.request(C(`/item-locks/${t}/${r}/lock`, {})), l.current = !0, $(!0), P(!1), h(null), m(), j.current = setInterval(() => {
|
|
39
|
+
const f = Math.max(
|
|
32
40
|
0,
|
|
33
|
-
Math.floor((Date.now() - new Date(
|
|
41
|
+
Math.floor((Date.now() - new Date(qe().last_active).getTime()) / 1e3)
|
|
34
42
|
);
|
|
35
|
-
s.request(
|
|
36
|
-
if (!(
|
|
37
|
-
|
|
43
|
+
s.request(C(`/item-locks/${t}/${r}/heartbeat`, { idle_seconds: f })).then((o) => {
|
|
44
|
+
if (!(o != null && o.idle_released)) return;
|
|
45
|
+
m(), l.current = !1, $(!1), u.info(
|
|
38
46
|
"Your edit lock was released after inactivity — it re-locks when you resume."
|
|
39
47
|
);
|
|
40
48
|
const e = () => {
|
|
41
|
-
window.removeEventListener("pointerdown", e, !0), window.removeEventListener("keydown", e, !0),
|
|
49
|
+
window.removeEventListener("pointerdown", e, !0), window.removeEventListener("keydown", e, !0), d();
|
|
42
50
|
};
|
|
43
51
|
window.addEventListener("pointerdown", e, !0), window.addEventListener("keydown", e, !0);
|
|
44
|
-
}).catch((
|
|
45
|
-
var
|
|
46
|
-
const e =
|
|
47
|
-
if (
|
|
48
|
-
const
|
|
49
|
-
if (
|
|
50
|
-
|
|
52
|
+
}).catch((o) => {
|
|
53
|
+
var te, re;
|
|
54
|
+
const e = o, c = e.status ?? ((te = e.response) == null ? void 0 : te.status);
|
|
55
|
+
if (U(o) || c !== 404 && c !== 409) return;
|
|
56
|
+
const x = ((re = e.response) == null ? void 0 : re.data) ?? e.response;
|
|
57
|
+
if (c === 404 && !(x != null && x.locked_by)) {
|
|
58
|
+
d();
|
|
51
59
|
return;
|
|
52
60
|
}
|
|
53
|
-
|
|
54
|
-
locked_by:
|
|
55
|
-
locked_by_name:
|
|
61
|
+
m(), l.current = !1, $(!1), x != null && x.locked_by && (h({
|
|
62
|
+
locked_by: x.locked_by,
|
|
63
|
+
locked_by_name: x.locked_by_name ?? null
|
|
56
64
|
}), u.warning(
|
|
57
|
-
`${
|
|
65
|
+
`${x.locked_by_name ?? "Another user"} took over editing — your changes are no longer being saved`
|
|
58
66
|
));
|
|
59
67
|
});
|
|
60
|
-
},
|
|
61
|
-
} catch (
|
|
62
|
-
const
|
|
63
|
-
return
|
|
64
|
-
locked_by:
|
|
65
|
-
locked_by_name:
|
|
66
|
-
...typeof
|
|
68
|
+
}, Ie), !0;
|
|
69
|
+
} catch (f) {
|
|
70
|
+
const o = f, e = o.status ?? ((a = o.response) == null ? void 0 : a.status), c = ((n = o.response) == null ? void 0 : n.data) ?? o.response;
|
|
71
|
+
return z.current = e ?? null, U(f) ? !1 : e === 404 ? (q.current = !0, m(), l.current = !1, $(!1), !1) : (e === 409 && (c != null && c.locked_by) && (l.current = !1, $(!1), h({
|
|
72
|
+
locked_by: c.locked_by,
|
|
73
|
+
locked_by_name: c.locked_by_name ?? null,
|
|
74
|
+
...typeof c.may_take_over == "boolean" ? { may_take_over: c.may_take_over } : {}
|
|
67
75
|
})), !1);
|
|
68
76
|
}
|
|
69
|
-
}, [s, t, r,
|
|
77
|
+
}, [s, t, r, m, U]), b = w(async () => {
|
|
70
78
|
if (!(!t || !r))
|
|
71
79
|
try {
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
76
|
-
if (!(
|
|
77
|
-
|
|
80
|
+
const a = await s.request(Se(`/item-locks/${t}/${r}/lock`)), n = a == null ? void 0 : a.data;
|
|
81
|
+
ue(Array.isArray(n == null ? void 0 : n.queue) ? n.queue : []), M(typeof (n == null ? void 0 : n.my_position) == "number" ? n.my_position : null);
|
|
82
|
+
const f = (n == null ? void 0 : n.is_mine) === !0 || !!g && String((n == null ? void 0 : n.locked_by) ?? "").toLowerCase() === g.toLowerCase(), o = typeof (n == null ? void 0 : n.may_take_over) == "boolean" ? { may_take_over: n.may_take_over } : {};
|
|
83
|
+
if (l.current) return;
|
|
84
|
+
if (!(n != null && n.locked_by) || f) {
|
|
85
|
+
h(null);
|
|
78
86
|
return;
|
|
79
87
|
}
|
|
80
|
-
|
|
81
|
-
(e) => e && e.locked_by === String(
|
|
88
|
+
h(
|
|
89
|
+
(e) => e && e.locked_by === String(n.locked_by) ? {
|
|
82
90
|
...e,
|
|
83
|
-
note:
|
|
84
|
-
idle_minutes:
|
|
85
|
-
...
|
|
91
|
+
note: n.note ?? e.note ?? null,
|
|
92
|
+
idle_minutes: n.locked_by_idle_minutes ?? e.idle_minutes ?? null,
|
|
93
|
+
...o
|
|
86
94
|
} : {
|
|
87
|
-
locked_by: String(
|
|
88
|
-
locked_by_name:
|
|
89
|
-
note:
|
|
90
|
-
idle_minutes:
|
|
91
|
-
...
|
|
95
|
+
locked_by: String(n.locked_by),
|
|
96
|
+
locked_by_name: n.locked_by_name ?? null,
|
|
97
|
+
note: n.note ?? null,
|
|
98
|
+
idle_minutes: n.locked_by_idle_minutes ?? null,
|
|
99
|
+
...o
|
|
92
100
|
}
|
|
93
|
-
),
|
|
94
|
-
} catch (
|
|
95
|
-
(
|
|
101
|
+
), P(!1);
|
|
102
|
+
} catch (a) {
|
|
103
|
+
(a == null ? void 0 : a.status) === 404 && (q.current = !0);
|
|
96
104
|
}
|
|
97
|
-
}, [s, t, r,
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}, [
|
|
101
|
-
if (!
|
|
102
|
-
const
|
|
103
|
-
return () => clearInterval(
|
|
104
|
-
}, [
|
|
105
|
-
if (!(!
|
|
106
|
-
return
|
|
107
|
-
|
|
105
|
+
}, [s, t, r, g]), I = (p == null ? void 0 : p.locked_by) ?? null;
|
|
106
|
+
N(() => {
|
|
107
|
+
I && b();
|
|
108
|
+
}, [I, b]), N(() => {
|
|
109
|
+
if (!I) return;
|
|
110
|
+
const a = setInterval(() => void b(), Oe);
|
|
111
|
+
return () => clearInterval(a);
|
|
112
|
+
}, [I, b]), N(() => {
|
|
113
|
+
if (!(!i || !t || !r))
|
|
114
|
+
return R.current = !1, q.current = !1, L ? b() : d(), () => {
|
|
115
|
+
m(), R.current = !1, l.current && (l.current = !1, s.request(K(`/item-locks/${t}/${r}/lock`)).then(() => se(g, "lock-released", t, r)).catch(() => {
|
|
108
116
|
}));
|
|
109
117
|
};
|
|
110
|
-
}, [
|
|
111
|
-
const
|
|
112
|
-
if (!(!
|
|
113
|
-
|
|
118
|
+
}, [i, t, r, d, s, m, g, L, b]);
|
|
119
|
+
const be = w(async () => {
|
|
120
|
+
if (!(!i || l.current || Q.current) && !(Date.now() < V.current)) {
|
|
121
|
+
Q.current = !0;
|
|
114
122
|
try {
|
|
115
|
-
|
|
123
|
+
const a = await d();
|
|
124
|
+
!a && z.current === 409 && u.warning("Someone else is editing this record — your change can’t be saved yet"), !a && z.current !== 409 && !q.current && (V.current = Date.now() + Me);
|
|
116
125
|
} finally {
|
|
117
|
-
|
|
126
|
+
Q.current = !1;
|
|
118
127
|
}
|
|
119
128
|
}
|
|
120
|
-
}, [
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
129
|
+
}, [i, d]);
|
|
130
|
+
N(() => {
|
|
131
|
+
const a = () => {
|
|
132
|
+
V.current = 0;
|
|
133
|
+
};
|
|
134
|
+
return window.addEventListener("online", a), () => window.removeEventListener("online", a);
|
|
135
|
+
}, []);
|
|
136
|
+
const ye = je(), B = T && ye;
|
|
137
|
+
N(() => {
|
|
138
|
+
if (!i || !t || !r) return;
|
|
139
|
+
if (B) {
|
|
140
|
+
R.current && (R.current = !1, d());
|
|
125
141
|
return;
|
|
126
142
|
}
|
|
127
|
-
const
|
|
128
|
-
|
|
143
|
+
const a = setTimeout(() => {
|
|
144
|
+
l.current && (m(), l.current = !1, $(!1), R.current = !0, s.request(K(`/item-locks/${t}/${r}/lock`)).then(() => se(g, "lock-released", t, r)).catch(() => {
|
|
129
145
|
}));
|
|
130
|
-
},
|
|
131
|
-
return () => clearTimeout(
|
|
132
|
-
}, [
|
|
133
|
-
if (!
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
146
|
+
}, Ye);
|
|
147
|
+
return () => clearTimeout(a);
|
|
148
|
+
}, [i, B, t, r, d, s, m, g]), N(() => {
|
|
149
|
+
if (!i || !L || !t || !r || I || !B) return;
|
|
150
|
+
const a = setInterval(() => {
|
|
151
|
+
!l.current && !q.current && b();
|
|
152
|
+
}, De);
|
|
153
|
+
return () => clearInterval(a);
|
|
154
|
+
}, [i, L, t, r, I, B, b]), N(() => {
|
|
155
|
+
if (!i || !t || !r) return;
|
|
156
|
+
const a = () => {
|
|
157
|
+
var f;
|
|
158
|
+
if (l.current) {
|
|
159
|
+
m(), l.current = !1, R.current = !0;
|
|
138
160
|
try {
|
|
139
|
-
const
|
|
161
|
+
const o = (f = s.getToken) == null ? void 0 : f.call(s), e = s.url ?? "";
|
|
140
162
|
fetch(
|
|
141
163
|
`${e}/api/item-locks/${encodeURIComponent(t)}/${encodeURIComponent(r)}/lock/release`,
|
|
142
164
|
{
|
|
143
165
|
method: "POST",
|
|
144
166
|
keepalive: !0,
|
|
145
|
-
credentials:
|
|
146
|
-
headers:
|
|
167
|
+
credentials: o ? "omit" : "include",
|
|
168
|
+
headers: o ? { Authorization: `Bearer ${o}` } : {}
|
|
147
169
|
}
|
|
148
170
|
).catch(() => {
|
|
149
171
|
});
|
|
150
172
|
} catch {
|
|
151
173
|
}
|
|
152
174
|
}
|
|
153
|
-
},
|
|
154
|
-
|
|
175
|
+
}, n = (f) => {
|
|
176
|
+
f.persisted && R.current && (R.current = !1, d());
|
|
155
177
|
};
|
|
156
|
-
return window.addEventListener("pagehide",
|
|
157
|
-
window.removeEventListener("pagehide",
|
|
178
|
+
return window.addEventListener("pagehide", a), window.addEventListener("pageshow", n), () => {
|
|
179
|
+
window.removeEventListener("pagehide", a), window.removeEventListener("pageshow", n);
|
|
158
180
|
};
|
|
159
|
-
}, [
|
|
160
|
-
|
|
181
|
+
}, [i, t, r, s, m, d]), Te(g, "lock-released", t, r, () => {
|
|
182
|
+
i && l.current && d();
|
|
161
183
|
});
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
if (!(!
|
|
165
|
-
return
|
|
166
|
-
var
|
|
167
|
-
|
|
184
|
+
const W = ae();
|
|
185
|
+
N(() => {
|
|
186
|
+
if (!(!i || !W || !t || !r))
|
|
187
|
+
return W.subscribeCollections([t], (a) => {
|
|
188
|
+
var n;
|
|
189
|
+
l.current || q.current || !((n = a.changed_fields) != null && n.includes("$lock")) || !Ae(a, r) || b();
|
|
168
190
|
});
|
|
169
|
-
}, [
|
|
170
|
-
const
|
|
191
|
+
}, [i, W, t, r, b]);
|
|
192
|
+
const Y = ae(), [ge, ee] = _(!1), ve = w(async () => {
|
|
171
193
|
if (!(!t || !r)) {
|
|
172
|
-
|
|
194
|
+
ee(!0);
|
|
173
195
|
try {
|
|
174
|
-
await s.request(
|
|
196
|
+
await s.request(C(`/item-locks/${t}/${r}/lock/request`, {})), u.success("Asked the current editor to release the lock");
|
|
175
197
|
} catch {
|
|
176
198
|
u.error("Could not send the lock request");
|
|
177
199
|
} finally {
|
|
178
|
-
|
|
200
|
+
ee(!1);
|
|
179
201
|
}
|
|
180
202
|
}
|
|
181
203
|
}, [s, t, r]);
|
|
182
|
-
|
|
183
|
-
if (!
|
|
184
|
-
const
|
|
185
|
-
if ((e == null ? void 0 : e.collection) !== t || String(e == null ? void 0 : e.item) !== String(r) || !
|
|
186
|
-
const
|
|
187
|
-
u(`${
|
|
204
|
+
N(() => {
|
|
205
|
+
if (!Y || !t || !r) return;
|
|
206
|
+
const a = Y.on("lock:requested", (e) => {
|
|
207
|
+
if ((e == null ? void 0 : e.collection) !== t || String(e == null ? void 0 : e.item) !== String(r) || !l.current) return;
|
|
208
|
+
const c = (e == null ? void 0 : e.from) ?? {};
|
|
209
|
+
u(`${c.name ?? "Someone"} is asking you to release this record`, {
|
|
188
210
|
duration: 3e4,
|
|
189
211
|
action: {
|
|
190
212
|
label: "Release",
|
|
191
213
|
onClick: () => {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
to:
|
|
214
|
+
m(), l.current = !1, $(!1), s.request(
|
|
215
|
+
C(`/item-locks/${t}/${r}/lock/respond`, {
|
|
216
|
+
to: c.id,
|
|
195
217
|
action: "release"
|
|
196
218
|
})
|
|
197
219
|
).then(() => u.success("Lock released")).catch(() => u.error("Failed to release the lock"));
|
|
@@ -201,8 +223,8 @@ function Ke(t, r, o, C = {}) {
|
|
|
201
223
|
label: "Keep editing",
|
|
202
224
|
onClick: () => {
|
|
203
225
|
s.request(
|
|
204
|
-
|
|
205
|
-
to:
|
|
226
|
+
C(`/item-locks/${t}/${r}/lock/respond`, {
|
|
227
|
+
to: c.id,
|
|
206
228
|
action: "decline"
|
|
207
229
|
})
|
|
208
230
|
).catch(() => {
|
|
@@ -210,125 +232,125 @@ function Ke(t, r, o, C = {}) {
|
|
|
210
232
|
}
|
|
211
233
|
}
|
|
212
234
|
});
|
|
213
|
-
}),
|
|
214
|
-
var
|
|
215
|
-
(e == null ? void 0 : e.collection) !== t || String(e == null ? void 0 : e.item) !== String(r) ||
|
|
216
|
-
`${((
|
|
235
|
+
}), n = Y.on("lock:response", (e) => {
|
|
236
|
+
var c, x;
|
|
237
|
+
(e == null ? void 0 : e.collection) !== t || String(e == null ? void 0 : e.item) !== String(r) || l.current || ((e == null ? void 0 : e.action) === "release" ? (u.success(`${((c = e == null ? void 0 : e.from) == null ? void 0 : c.name) ?? "The editor"} released the lock — it's yours`), d()) : u.warning(
|
|
238
|
+
`${((x = e == null ? void 0 : e.from) == null ? void 0 : x.name) ?? "The editor"} is keeping the lock${e != null && e.note ? `: "${e.note}"` : ""}`
|
|
217
239
|
));
|
|
218
|
-
}),
|
|
219
|
-
(e == null ? void 0 : e.collection) !== t || String(e == null ? void 0 : e.item) !== String(r) ||
|
|
220
|
-
}),
|
|
221
|
-
(e == null ? void 0 : e.collection) !== t || String(e == null ? void 0 : e.item) !== String(r) || (
|
|
240
|
+
}), f = Y.on("lock:available", (e) => {
|
|
241
|
+
(e == null ? void 0 : e.collection) !== t || String(e == null ? void 0 : e.item) !== String(r) || l.current || (u.success("Your turn — the edit lock is yours"), M(null), d());
|
|
242
|
+
}), o = Y.on("lock:queued", (e) => {
|
|
243
|
+
(e == null ? void 0 : e.collection) !== t || String(e == null ? void 0 : e.item) !== String(r) || (l.current && u(`${(e == null ? void 0 : e.user_name) ?? "Someone"} is waiting to edit this record`, { duration: 8e3 }), b());
|
|
222
244
|
});
|
|
223
245
|
return () => {
|
|
224
|
-
|
|
246
|
+
a(), n(), f(), o();
|
|
225
247
|
};
|
|
226
|
-
}, [
|
|
227
|
-
const
|
|
248
|
+
}, [Y, t, r, s, d, m, b]);
|
|
249
|
+
const xe = w(async () => {
|
|
228
250
|
if (!(!t || !r)) {
|
|
229
|
-
|
|
251
|
+
G(!0);
|
|
230
252
|
try {
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
),
|
|
234
|
-
if (
|
|
235
|
-
|
|
253
|
+
const a = await s.request(
|
|
254
|
+
C(`/item-locks/${t}/${r}/lock/queue`, {})
|
|
255
|
+
), n = a == null ? void 0 : a.data;
|
|
256
|
+
if (n != null && n.free) {
|
|
257
|
+
M(null), h(null), u.success("Nobody is editing this record now — go ahead");
|
|
236
258
|
return;
|
|
237
259
|
}
|
|
238
|
-
const
|
|
239
|
-
|
|
260
|
+
const f = n == null ? void 0 : n.position;
|
|
261
|
+
M(typeof f == "number" ? f : 1), u.success("You are in line — the lock comes to you automatically when it frees up"), b();
|
|
240
262
|
} catch {
|
|
241
263
|
u.error("Could not join the queue");
|
|
242
264
|
} finally {
|
|
243
|
-
|
|
265
|
+
G(!1);
|
|
244
266
|
}
|
|
245
267
|
}
|
|
246
|
-
}, [s, t, r,
|
|
268
|
+
}, [s, t, r, b]), we = w(async () => {
|
|
247
269
|
if (!(!t || !r))
|
|
248
270
|
try {
|
|
249
|
-
await s.request(
|
|
271
|
+
await s.request(K(`/item-locks/${t}/${r}/lock/queue`)), M(null), b();
|
|
250
272
|
} catch {
|
|
251
273
|
}
|
|
252
|
-
}, [s, t, r,
|
|
253
|
-
async (
|
|
254
|
-
if (!(!t || !r || !
|
|
255
|
-
|
|
274
|
+
}, [s, t, r, b]), _e = w(
|
|
275
|
+
async (a) => {
|
|
276
|
+
if (!(!t || !r || !l.current)) {
|
|
277
|
+
X(a);
|
|
256
278
|
try {
|
|
257
|
-
await s.request(
|
|
279
|
+
await s.request(C(`/item-locks/${t}/${r}/lock/note`, { note: a }));
|
|
258
280
|
} catch {
|
|
259
281
|
}
|
|
260
282
|
}
|
|
261
283
|
},
|
|
262
284
|
[s, t, r]
|
|
263
|
-
),
|
|
264
|
-
if (!(!t || !r || !
|
|
265
|
-
|
|
285
|
+
), pe = w(async () => {
|
|
286
|
+
if (!(!t || !r || !l.current)) {
|
|
287
|
+
Z(!0), m(), l.current = !1, $(!1);
|
|
266
288
|
try {
|
|
267
|
-
await s.request(
|
|
289
|
+
await s.request(K(`/item-locks/${t}/${r}/lock`)), P(!0), X(""), u.success("Lock released — anyone can edit this record now");
|
|
268
290
|
} catch {
|
|
269
|
-
u.error("Failed to release the lock"),
|
|
291
|
+
u.error("Failed to release the lock"), d();
|
|
270
292
|
} finally {
|
|
271
|
-
|
|
293
|
+
Z(!1);
|
|
272
294
|
}
|
|
273
295
|
}
|
|
274
|
-
}, [s, t, r,
|
|
275
|
-
if (
|
|
276
|
-
const
|
|
277
|
-
return
|
|
278
|
-
}, [
|
|
279
|
-
var
|
|
296
|
+
}, [s, t, r, m, d]), $e = w(async () => {
|
|
297
|
+
if (l.current) return !0;
|
|
298
|
+
const a = await d();
|
|
299
|
+
return a && u.success("You hold the edit lock again"), a;
|
|
300
|
+
}, [d]), Ne = w(async () => {
|
|
301
|
+
var a;
|
|
280
302
|
if (!(!t || !r)) {
|
|
281
|
-
|
|
303
|
+
J(!0);
|
|
282
304
|
try {
|
|
283
|
-
await s.request(
|
|
284
|
-
} catch (
|
|
285
|
-
const
|
|
286
|
-
u.error(
|
|
305
|
+
await s.request(C(`/item-locks/${t}/${r}/lock/force`, {})), u.success("You now hold the edit lock"), await d();
|
|
306
|
+
} catch (n) {
|
|
307
|
+
const f = ((a = n == null ? void 0 : n.response) == null ? void 0 : a.error) ?? "Failed to take over the lock";
|
|
308
|
+
u.error(f), (n == null ? void 0 : n.status) === 403 && h((o) => o && { ...o, may_take_over: !1 });
|
|
287
309
|
} finally {
|
|
288
|
-
|
|
310
|
+
J(!1);
|
|
289
311
|
}
|
|
290
312
|
}
|
|
291
|
-
}, [s, t, r,
|
|
313
|
+
}, [s, t, r, d]);
|
|
292
314
|
return {
|
|
293
|
-
lockHolder:
|
|
294
|
-
acquired:
|
|
295
|
-
isReadOnly: !!
|
|
296
|
-
takeOver:
|
|
297
|
-
takingOver:
|
|
298
|
-
isAdmin:
|
|
299
|
-
requestLock:
|
|
300
|
-
requesting:
|
|
301
|
-
queue:
|
|
302
|
-
myPosition:
|
|
303
|
-
joinQueue:
|
|
304
|
-
leaveQueue:
|
|
305
|
-
joining:
|
|
306
|
-
myNote:
|
|
307
|
-
saveNote:
|
|
308
|
-
release:
|
|
309
|
-
releasing:
|
|
310
|
-
released:
|
|
311
|
-
relock:
|
|
312
|
-
claim:
|
|
315
|
+
lockHolder: p,
|
|
316
|
+
acquired: F,
|
|
317
|
+
isReadOnly: !!p,
|
|
318
|
+
takeOver: Ne,
|
|
319
|
+
takingOver: D,
|
|
320
|
+
isAdmin: E,
|
|
321
|
+
requestLock: ve,
|
|
322
|
+
requesting: ge,
|
|
323
|
+
queue: ce,
|
|
324
|
+
myPosition: de,
|
|
325
|
+
joinQueue: xe,
|
|
326
|
+
leaveQueue: we,
|
|
327
|
+
joining: fe,
|
|
328
|
+
myNote: ke,
|
|
329
|
+
saveNote: _e,
|
|
330
|
+
release: pe,
|
|
331
|
+
releasing: he,
|
|
332
|
+
released: me,
|
|
333
|
+
relock: $e,
|
|
334
|
+
claim: be
|
|
313
335
|
};
|
|
314
336
|
}
|
|
315
|
-
function
|
|
337
|
+
function Ze({
|
|
316
338
|
note: t,
|
|
317
339
|
onSave: r,
|
|
318
|
-
waiting:
|
|
319
|
-
onRelease:
|
|
320
|
-
releasing:
|
|
321
|
-
released:
|
|
340
|
+
waiting: i,
|
|
341
|
+
onRelease: S,
|
|
342
|
+
releasing: L,
|
|
343
|
+
released: T,
|
|
322
344
|
onRelock: s
|
|
323
345
|
}) {
|
|
324
|
-
var
|
|
325
|
-
const [
|
|
326
|
-
|
|
327
|
-
const
|
|
328
|
-
|
|
346
|
+
var p;
|
|
347
|
+
const [E, g] = _(t);
|
|
348
|
+
N(() => g(t), [t]);
|
|
349
|
+
const v = () => {
|
|
350
|
+
E.trim() !== t && r(E.trim());
|
|
329
351
|
};
|
|
330
|
-
return
|
|
331
|
-
/* @__PURE__ */
|
|
352
|
+
return T ? /* @__PURE__ */ y(oe, { children: [
|
|
353
|
+
/* @__PURE__ */ k(ie, { asChild: !0, children: /* @__PURE__ */ k(
|
|
332
354
|
"button",
|
|
333
355
|
{
|
|
334
356
|
type: "button",
|
|
@@ -336,14 +358,14 @@ function Qe({
|
|
|
336
358
|
title: "Lock released — anyone can edit this record",
|
|
337
359
|
"data-lock-released": !0,
|
|
338
360
|
className: "relative inline-flex h-8 w-8 items-center justify-center text-slate-400 transition-colors hover:bg-accent hover:text-accent-foreground dark:text-slate-500",
|
|
339
|
-
children: /* @__PURE__ */
|
|
361
|
+
children: /* @__PURE__ */ k(ne, { className: "h-4 w-4", strokeWidth: 2 })
|
|
340
362
|
}
|
|
341
363
|
) }),
|
|
342
|
-
/* @__PURE__ */
|
|
343
|
-
/* @__PURE__ */
|
|
344
|
-
/* @__PURE__ */
|
|
345
|
-
/* @__PURE__ */
|
|
346
|
-
|
|
364
|
+
/* @__PURE__ */ y(le, { align: "end", sideOffset: 6, className: "w-[300px] p-3", children: [
|
|
365
|
+
/* @__PURE__ */ k("p", { className: "text-[12px] font-semibold text-slate-700 dark:text-slate-200", children: "You released the edit lock" }),
|
|
366
|
+
/* @__PURE__ */ k("p", { className: "mt-0.5 text-[11px] text-slate-500 dark:text-slate-400", children: "Anyone can edit this record now. Your next edit locks it again — or lock it now." }),
|
|
367
|
+
/* @__PURE__ */ y(
|
|
368
|
+
O,
|
|
347
369
|
{
|
|
348
370
|
type: "button",
|
|
349
371
|
size: "sm",
|
|
@@ -351,102 +373,102 @@ function Qe({
|
|
|
351
373
|
onClick: s,
|
|
352
374
|
"data-lock-relock": !0,
|
|
353
375
|
children: [
|
|
354
|
-
/* @__PURE__ */
|
|
376
|
+
/* @__PURE__ */ k(H, { className: "mr-1.5 h-3.5 w-3.5" }),
|
|
355
377
|
" Lock again"
|
|
356
378
|
]
|
|
357
379
|
}
|
|
358
380
|
)
|
|
359
381
|
] })
|
|
360
|
-
] }) : /* @__PURE__ */
|
|
361
|
-
/* @__PURE__ */
|
|
382
|
+
] }) : /* @__PURE__ */ y(oe, { children: [
|
|
383
|
+
/* @__PURE__ */ k(ie, { asChild: !0, children: /* @__PURE__ */ y(
|
|
362
384
|
"button",
|
|
363
385
|
{
|
|
364
386
|
type: "button",
|
|
365
387
|
"aria-label": "You hold the edit lock — add a note for others",
|
|
366
|
-
title:
|
|
388
|
+
title: i.length > 0 ? `You hold the edit lock · ${i.length} waiting` : "You hold the edit lock",
|
|
367
389
|
"data-lock-holder": !0,
|
|
368
390
|
className: "relative inline-flex h-8 w-8 items-center justify-center text-[#0e7490] transition-colors hover:bg-accent hover:text-accent-foreground dark:text-nvr-cyan",
|
|
369
391
|
children: [
|
|
370
|
-
/* @__PURE__ */
|
|
371
|
-
|
|
392
|
+
/* @__PURE__ */ k(H, { className: "h-4 w-4", strokeWidth: 2 }),
|
|
393
|
+
i.length > 0 && /* @__PURE__ */ k("span", { className: "absolute right-1 top-1 h-1.5 w-1.5 rounded-full bg-amber-500 ring-2 ring-background" })
|
|
372
394
|
]
|
|
373
395
|
}
|
|
374
396
|
) }),
|
|
375
|
-
/* @__PURE__ */
|
|
376
|
-
/* @__PURE__ */
|
|
377
|
-
/* @__PURE__ */
|
|
378
|
-
/* @__PURE__ */
|
|
397
|
+
/* @__PURE__ */ y(le, { align: "end", sideOffset: 6, className: "w-[300px] p-3", children: [
|
|
398
|
+
/* @__PURE__ */ k("p", { className: "text-[12px] font-semibold text-slate-700 dark:text-slate-200", children: "You hold the edit lock" }),
|
|
399
|
+
/* @__PURE__ */ k("p", { className: "mt-0.5 text-[11px] text-slate-500 dark:text-slate-400", children: "Others see this record read-only. A note tells them what you’re doing." }),
|
|
400
|
+
/* @__PURE__ */ k(
|
|
379
401
|
"input",
|
|
380
402
|
{
|
|
381
|
-
value:
|
|
382
|
-
onChange: (
|
|
383
|
-
onBlur:
|
|
384
|
-
onKeyDown: (
|
|
385
|
-
|
|
403
|
+
value: E,
|
|
404
|
+
onChange: (h) => g(h.target.value.slice(0, 300)),
|
|
405
|
+
onBlur: v,
|
|
406
|
+
onKeyDown: (h) => {
|
|
407
|
+
h.key === "Enter" && (h.preventDefault(), v());
|
|
386
408
|
},
|
|
387
409
|
placeholder: "“editing lines, ~15 min”",
|
|
388
410
|
"aria-label": "Lock note",
|
|
389
411
|
className: "mt-2 h-7 w-full rounded-md border border-slate-200 bg-white px-2 text-[12px] dark:border-border dark:bg-card"
|
|
390
412
|
}
|
|
391
413
|
),
|
|
392
|
-
|
|
393
|
-
/* @__PURE__ */
|
|
394
|
-
|
|
414
|
+
i.length > 0 && /* @__PURE__ */ y("div", { className: "mt-2 rounded-md bg-amber-50 px-2 py-1.5 text-[11px] text-amber-800 dark:bg-amber-500/10 dark:text-amber-200", children: [
|
|
415
|
+
/* @__PURE__ */ y("span", { className: "font-semibold", children: [
|
|
416
|
+
i.length,
|
|
395
417
|
" waiting for the lock:"
|
|
396
418
|
] }),
|
|
397
419
|
" ",
|
|
398
|
-
|
|
420
|
+
i.map((h) => h.name ?? "someone").join(", ")
|
|
399
421
|
] }),
|
|
400
|
-
|
|
401
|
-
|
|
422
|
+
S && /* @__PURE__ */ y(
|
|
423
|
+
O,
|
|
402
424
|
{
|
|
403
425
|
type: "button",
|
|
404
426
|
variant: "outline",
|
|
405
427
|
size: "sm",
|
|
406
428
|
className: "mt-2 h-7 w-full text-[12px]",
|
|
407
|
-
onClick:
|
|
408
|
-
disabled:
|
|
429
|
+
onClick: S,
|
|
430
|
+
disabled: L,
|
|
409
431
|
"data-lock-release": !0,
|
|
410
432
|
children: [
|
|
411
|
-
/* @__PURE__ */
|
|
412
|
-
|
|
433
|
+
/* @__PURE__ */ k(ne, { className: "mr-1.5 h-3.5 w-3.5" }),
|
|
434
|
+
L ? "Releasing…" : i.length > 0 ? `Release lock to ${((p = i[0]) == null ? void 0 : p.name) ?? "the next person"}` : "Release lock"
|
|
413
435
|
]
|
|
414
436
|
}
|
|
415
437
|
)
|
|
416
438
|
] })
|
|
417
439
|
] });
|
|
418
440
|
}
|
|
419
|
-
function
|
|
441
|
+
function et({
|
|
420
442
|
lockHolder: t,
|
|
421
443
|
onTakeOver: r,
|
|
422
|
-
takingOver:
|
|
423
|
-
isAdmin:
|
|
424
|
-
onRequestLock:
|
|
425
|
-
requesting:
|
|
444
|
+
takingOver: i,
|
|
445
|
+
isAdmin: S,
|
|
446
|
+
onRequestLock: L,
|
|
447
|
+
requesting: T,
|
|
426
448
|
queue: s,
|
|
427
|
-
myPosition:
|
|
428
|
-
onJoinQueue:
|
|
429
|
-
onLeaveQueue:
|
|
430
|
-
joining:
|
|
431
|
-
noun:
|
|
432
|
-
readOnlyText:
|
|
449
|
+
myPosition: E,
|
|
450
|
+
onJoinQueue: g,
|
|
451
|
+
onLeaveQueue: v,
|
|
452
|
+
joining: p,
|
|
453
|
+
noun: h = "this item",
|
|
454
|
+
readOnlyText: F = "fields are read-only"
|
|
433
455
|
}) {
|
|
434
456
|
if (!t) return null;
|
|
435
|
-
const
|
|
436
|
-
return /* @__PURE__ */
|
|
457
|
+
const $ = t.locked_by_name || "Another user", D = (s == null ? void 0 : s.length) ?? 0;
|
|
458
|
+
return /* @__PURE__ */ y(
|
|
437
459
|
"div",
|
|
438
460
|
{
|
|
439
461
|
className: "mb-4 flex flex-wrap items-center gap-3 rounded-lg border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-900 dark:border-amber-500/30 dark:bg-amber-500/10 dark:text-amber-100",
|
|
440
462
|
"data-lock-banner": !0,
|
|
441
463
|
children: [
|
|
442
|
-
/* @__PURE__ */
|
|
443
|
-
/* @__PURE__ */
|
|
444
|
-
/* @__PURE__ */
|
|
464
|
+
/* @__PURE__ */ k(H, { className: "h-4 w-4 shrink-0 text-amber-500" }),
|
|
465
|
+
/* @__PURE__ */ y("span", { className: "min-w-0 flex-1", children: [
|
|
466
|
+
/* @__PURE__ */ k("span", { className: "font-medium", children: $ }),
|
|
445
467
|
" is editing ",
|
|
446
|
-
|
|
468
|
+
h,
|
|
447
469
|
" — ",
|
|
448
|
-
|
|
449
|
-
t.idle_minutes != null && t.idle_minutes >= 2 && /* @__PURE__ */
|
|
470
|
+
F,
|
|
471
|
+
t.idle_minutes != null && t.idle_minutes >= 2 && /* @__PURE__ */ y(
|
|
450
472
|
"span",
|
|
451
473
|
{
|
|
452
474
|
className: "ml-1.5 rounded bg-amber-100 px-1 py-px text-[10px] font-semibold text-amber-700 dark:bg-amber-500/20 dark:text-amber-200",
|
|
@@ -461,67 +483,67 @@ function Ve({
|
|
|
461
483
|
),
|
|
462
484
|
" ",
|
|
463
485
|
"until the lock is released.",
|
|
464
|
-
t.note && /* @__PURE__ */
|
|
486
|
+
t.note && /* @__PURE__ */ y("span", { className: "mt-0.5 block text-[12.5px] text-amber-800/90 dark:text-amber-200/90", children: [
|
|
465
487
|
"“",
|
|
466
488
|
t.note,
|
|
467
489
|
"”"
|
|
468
490
|
] }),
|
|
469
|
-
|
|
470
|
-
|
|
491
|
+
D > 0 && E == null && /* @__PURE__ */ y("span", { className: "mt-0.5 block text-[11.5px] text-amber-700/80 dark:text-amber-300/80", children: [
|
|
492
|
+
D,
|
|
471
493
|
" ",
|
|
472
|
-
|
|
494
|
+
D === 1 ? "person is" : "people are",
|
|
473
495
|
" already waiting."
|
|
474
496
|
] })
|
|
475
497
|
] }),
|
|
476
|
-
|
|
477
|
-
|
|
498
|
+
g && (E != null ? /* @__PURE__ */ y(
|
|
499
|
+
O,
|
|
478
500
|
{
|
|
479
501
|
size: "sm",
|
|
480
502
|
variant: "outline",
|
|
481
503
|
className: "h-7 shrink-0 border-amber-300 bg-white text-[12px] text-amber-800 hover:bg-amber-100 dark:border-amber-500/40 dark:bg-transparent dark:text-amber-200 dark:hover:bg-amber-500/15",
|
|
482
|
-
onClick:
|
|
504
|
+
onClick: v,
|
|
483
505
|
"data-lock-queue-leave": !0,
|
|
484
506
|
children: [
|
|
485
507
|
"You’re #",
|
|
486
|
-
|
|
508
|
+
E,
|
|
487
509
|
" in line · Leave"
|
|
488
510
|
]
|
|
489
511
|
}
|
|
490
|
-
) : /* @__PURE__ */
|
|
491
|
-
|
|
512
|
+
) : /* @__PURE__ */ k(
|
|
513
|
+
O,
|
|
492
514
|
{
|
|
493
515
|
size: "sm",
|
|
494
516
|
variant: "outline",
|
|
495
517
|
className: "h-7 shrink-0 border-amber-300 bg-white text-[12px] text-amber-800 hover:bg-amber-100 dark:border-amber-500/40 dark:bg-transparent dark:text-amber-200 dark:hover:bg-amber-500/15",
|
|
496
|
-
onClick:
|
|
497
|
-
disabled:
|
|
518
|
+
onClick: g,
|
|
519
|
+
disabled: p,
|
|
498
520
|
"data-lock-queue-join": !0,
|
|
499
|
-
children:
|
|
521
|
+
children: p ? "Joining…" : "Ask to be next"
|
|
500
522
|
}
|
|
501
523
|
)),
|
|
502
|
-
|
|
503
|
-
|
|
524
|
+
L && /* @__PURE__ */ k(
|
|
525
|
+
O,
|
|
504
526
|
{
|
|
505
527
|
size: "sm",
|
|
506
528
|
variant: "outline",
|
|
507
529
|
className: "h-7 shrink-0 border-amber-300 bg-white text-[12px] text-amber-800 hover:bg-amber-100 dark:border-amber-500/40 dark:bg-transparent dark:text-amber-200 dark:hover:bg-amber-500/15",
|
|
508
|
-
onClick:
|
|
509
|
-
disabled:
|
|
510
|
-
children:
|
|
530
|
+
onClick: L,
|
|
531
|
+
disabled: T,
|
|
532
|
+
children: T ? "Asking…" : "Ask them to wrap up"
|
|
511
533
|
}
|
|
512
534
|
),
|
|
513
535
|
// Admins always; other roles only when the server says they may (the
|
|
514
536
|
// takeover-role allowlist, #256) — unknown = offered, and a 403 then
|
|
515
537
|
// hides it. A Take over that can only fail was a dead end.
|
|
516
|
-
(
|
|
517
|
-
|
|
538
|
+
(S || t.may_take_over !== !1) && /* @__PURE__ */ k(
|
|
539
|
+
O,
|
|
518
540
|
{
|
|
519
541
|
size: "sm",
|
|
520
542
|
variant: "outline",
|
|
521
|
-
className:
|
|
543
|
+
className: S ? "h-7 shrink-0 border-amber-300 bg-white text-[12px] text-amber-800 hover:bg-amber-100 dark:border-amber-500/40 dark:bg-transparent dark:text-amber-200 dark:hover:bg-amber-500/15" : "h-7 shrink-0 border-amber-200 bg-white/60 text-[12px] text-amber-700/80 hover:bg-amber-100 dark:border-amber-500/30 dark:bg-transparent dark:text-amber-200/80 dark:hover:bg-amber-500/15",
|
|
522
544
|
onClick: r,
|
|
523
|
-
disabled:
|
|
524
|
-
children:
|
|
545
|
+
disabled: i,
|
|
546
|
+
children: i ? "Taking over…" : "Take over"
|
|
525
547
|
}
|
|
526
548
|
)
|
|
527
549
|
]
|
|
@@ -529,7 +551,7 @@ function Ve({
|
|
|
529
551
|
);
|
|
530
552
|
}
|
|
531
553
|
export {
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
554
|
+
et as ItemLockBanner,
|
|
555
|
+
Ze as LockHolderButton,
|
|
556
|
+
Xe as useItemLock
|
|
535
557
|
};
|