@parallelworks/tandem-web 0.164.1 → 0.166.0

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/lib/issueMenu.js CHANGED
@@ -6,159 +6,183 @@ import { cyclesQuery as o, issueQuery as s, labelsQuery as c, projectsQuery as l
6
6
  import { invalidateIssueViews as f } from "../api/mutations.js";
7
7
  import { useFavorites as p } from "./favorites.js";
8
8
  import { copyItem as m } from "./menus.js";
9
- import { CalendarIcon as ee, CycleIcon as h, EstimateIcon as g, FolderIcon as _, PriorityIcon as v, ProjectIcon as y, StatusIcon as b, TagIcon as x, UserIcon as te, usePriorityNames as S } from "../components/icons.js";
10
- import { addDays as C, today as w } from "./time.js";
11
- import { ProjectStatusIcon as T, scalePoints as E, useEstimateLabel as D } from "../components/Planning.js";
12
- import { assigneeKey as O, parseAssigneeKey as k, useAssigneeOptions as A } from "./assignees.js";
13
- import { menuDivider as j } from "@parallelworks/ui";
14
- import { useCallback as M } from "react";
15
- import { useTranslations as N } from "use-intl";
16
- import { jsx as P } from "react/jsx-runtime";
17
- import { useQueries as F, useQuery as I, useQueryClient as L } from "@tanstack/react-query";
9
+ import { CalendarIcon as h, CycleIcon as ee, EstimateIcon as te, FolderIcon as ne, PriorityIcon as g, ProjectIcon as re, StatusIcon as _, TagIcon as v, UserIcon as y, usePriorityNames as b } from "../components/icons.js";
10
+ import { addDays as x, today as S } from "./time.js";
11
+ import { ProjectStatusIcon as C, scalePoints as w, useEstimateLabel as T } from "../components/Planning.js";
12
+ import { assigneeKey as E, parseAssigneeKey as ie, useAssigneeOptions as D } from "./assignees.js";
13
+ import { eachLimited as O } from "./eachLimited.js";
14
+ import { menuDivider as k, toast as ae } from "@parallelworks/ui";
15
+ import { useCallback as A } from "react";
16
+ import { useErrorMessage as j } from "@parallelworks/problem/react";
17
+ import { useTranslations as M } from "use-intl";
18
+ import { jsx as N } from "react/jsx-runtime";
19
+ import { useQueries as P, useQuery as F, useQueryClient as I } from "@tanstack/react-query";
18
20
  // src/lib/issueMenu.tsx
19
- function R(t, n) {
21
+ function L(t, n) {
20
22
  return e(i(t, n));
21
23
  }
22
- function z(e) {
23
- let i = L(), z = a(), { data: B = [] } = I(d(e)), { data: V = [] } = I(c(e)), H = A(e), U = p(e), W = S(), G = N("issueMenu"), K = N("common"), q = N("favorites"), J = F({ queries: B.map((t) => u(e, t.key)) }), Y = N("planning"), X = D(), { data: Z = [] } = I(l(e)), Q = F({ queries: B.map((t) => ({
24
+ function R(e) {
25
+ let i = I(), R = a(), { data: z = [] } = F(d(e)), { data: B = [] } = F(c(e)), V = D(e), H = p(e), U = b(), W = M("issueMenu"), G = j(), K = M("common"), q = M("favorites"), J = P({ queries: z.map((t) => u(e, t.key)) }), Y = M("planning"), X = T(), { data: Z = [] } = F(l(e)), Q = P({ queries: z.map((t) => ({
24
26
  ...o(e, t.key),
25
27
  enabled: t.cyclesEnabled
26
28
  })) });
27
- return M((a) => {
29
+ return A((a) => {
28
30
  let o = a[0];
29
31
  if (!o) return [];
30
32
  let c = (e) => {
31
- let t = B.findIndex((t) => t.id === e);
33
+ let t = z.findIndex((t) => t.id === e);
32
34
  return J[t]?.data ?? [];
33
- }, l = (e) => a.every(e), u = async (r) => {
34
- await Promise.all(a.map(async (a) => {
35
- let o = r(a);
36
- if (!o) return;
37
- let c = n(await t.PATCH("/api/v1/workspaces/{workspace}/issues/{identifier}", {
38
- params: { path: {
39
- workspace: e,
40
- identifier: a.identifier
41
- } },
42
- body: o
43
- }));
44
- i.setQueryData(s(e, a.identifier).queryKey, c), f(i, e, a.identifier);
35
+ }, l = (e) => a.every(e), u = (e) => {
36
+ e.length > 0 && ae.error(W("bulkFailed", {
37
+ count: e.length,
38
+ reason: G(e[0])
45
39
  }));
46
40
  }, d = async (r) => {
47
- await Promise.all(a.filter((e) => e.identifier.split("-")[0] !== r).map(async (a) => {
48
- let o = n(await t.POST("/api/v1/workspaces/{workspace}/issues/{identifier}/move", {
49
- params: { path: {
41
+ let o = [];
42
+ try {
43
+ u(await O(a, async (a) => {
44
+ let c = r(a);
45
+ if (!c) return;
46
+ let l = n(await t.PATCH("/api/v1/workspaces/{workspace}/issues/{identifier}", {
47
+ params: { path: {
48
+ workspace: e,
49
+ identifier: a.identifier
50
+ } },
51
+ body: c
52
+ }));
53
+ i.setQueryData(s(e, a.identifier).queryKey, l), o.push(a.identifier);
54
+ }));
55
+ } finally {
56
+ f(i, e, o);
57
+ }
58
+ }, p = async (r) => {
59
+ let o = [];
60
+ try {
61
+ u(await O(a.filter((e) => e.identifier.split("-")[0] !== r), async (a) => {
62
+ let c = n(await t.POST("/api/v1/workspaces/{workspace}/issues/{identifier}/move", {
63
+ params: { path: {
64
+ workspace: e,
65
+ identifier: a.identifier
66
+ } },
67
+ body: { team: r }
68
+ }));
69
+ i.setQueryData(s(e, c.identifier).queryKey, c), o.push(a.identifier), window.location.pathname.toLowerCase().includes(a.identifier.toLowerCase()) && R({
70
+ to: "/$workspace/issues/$identifier",
71
+ params: {
72
+ workspace: e,
73
+ identifier: c.identifier
74
+ },
75
+ replace: !0
76
+ });
77
+ }));
78
+ } finally {
79
+ f(i, e, o);
80
+ }
81
+ }, b = async (r) => {
82
+ let o = [];
83
+ try {
84
+ u(await O(a.filter((e) => !!e.archivedAt !== r), async (a) => {
85
+ let c = { params: { path: {
50
86
  workspace: e,
51
87
  identifier: a.identifier
52
- } },
53
- body: { team: r }
88
+ } } }, l = n(r ? await t.POST("/api/v1/workspaces/{workspace}/issues/{identifier}/archive", c) : await t.POST("/api/v1/workspaces/{workspace}/issues/{identifier}/restore", c));
89
+ i.setQueryData(s(e, a.identifier).queryKey, l), o.push(a.identifier);
54
90
  }));
55
- i.setQueryData(s(e, o.identifier).queryKey, o), f(i, e, a.identifier), window.location.pathname.toLowerCase().includes(a.identifier.toLowerCase()) && z({
56
- to: "/$workspace/issues/$identifier",
57
- params: {
58
- workspace: e,
59
- identifier: o.identifier
60
- },
61
- replace: !0
62
- });
63
- }));
64
- }, p = async (r) => {
65
- await Promise.all(a.filter((e) => !!e.archivedAt !== r).map(async (a) => {
66
- let o = { params: { path: {
67
- workspace: e,
68
- identifier: a.identifier
69
- } } }, c = n(r ? await t.POST("/api/v1/workspaces/{workspace}/issues/{identifier}/archive", o) : await t.POST("/api/v1/workspaces/{workspace}/issues/{identifier}/restore", o));
70
- i.setQueryData(s(e, a.identifier).queryKey, c), f(i, e, a.identifier);
71
- }));
72
- }, S = (e, t) => {
91
+ } finally {
92
+ f(i, e, o);
93
+ }
94
+ }, T = (e, t) => {
73
95
  let n = c(t.teamId);
74
96
  return (n.find((t) => t.name === e.name) ?? n.find((t) => t.category === e.category))?.id;
75
- }, D = a.length === 1, A = l((e) => e.teamId === o.teamId) ? B.findIndex((e) => e.id === o.teamId) : -1, M = B[A], N = (M?.cyclesEnabled ? Q[A]?.data ?? [] : []).filter((e) => e.state !== "past"), F = M?.estimateScale ?? "none", I = l((e) => e.project?.id === o.project?.id) ? o.project?.id : void 0, L = Z.find((e) => e.id === I)?.milestones ?? [], ne = (e) => e.name ? Y("cycleNamed", {
97
+ }, D = a.length === 1, A = l((e) => e.teamId === o.teamId) ? z.findIndex((e) => e.id === o.teamId) : -1, j = z[A], M = (j?.cyclesEnabled ? Q[A]?.data ?? [] : []).filter((e) => e.state !== "past"), P = j?.estimateScale ?? "none", F = l((e) => e.project?.id === o.project?.id) ? o.project?.id : void 0, I = Z.find((e) => e.id === F)?.milestones ?? [], oe = (e) => e.name ? Y("cycleNamed", {
76
98
  number: e.number,
77
99
  name: e.name
78
- }) : Y("cycle", { number: e.number }), $ = w(), re = [
100
+ }) : Y("cycle", { number: e.number }), $ = S(), se = [
79
101
  {
80
102
  label: Y("dueToday"),
81
103
  date: $
82
104
  },
83
105
  {
84
106
  label: Y("dueTomorrow"),
85
- date: C($, 1)
107
+ date: x($, 1)
86
108
  },
87
109
  {
88
110
  label: Y("dueInAWeek"),
89
- date: C($, 7)
111
+ date: x($, 7)
90
112
  },
91
113
  {
92
114
  label: Y("dueInTwoWeeks"),
93
- date: C($, 14)
115
+ date: x($, 14)
94
116
  }
95
- ], ie = [
117
+ ], ce = [
96
118
  {
97
119
  label: Y("project"),
98
- icon: /* @__PURE__ */ P(y, { className: "size-4" }),
120
+ icon: /* @__PURE__ */ N(re, { className: "size-4" }),
121
+ shortcut: "M",
99
122
  disabled: Z.length === 0,
100
123
  items: [{
101
124
  label: Y("noProject"),
102
125
  checked: l((e) => !e.project),
103
- onClick: () => u((e) => e.project ? { projectId: "" } : null)
126
+ onClick: () => d((e) => e.project ? { projectId: "" } : null)
104
127
  }, ...Z.map((e) => ({
105
128
  label: e.name,
106
- icon: /* @__PURE__ */ P(T, { status: e.status }),
129
+ icon: /* @__PURE__ */ N(C, { status: e.status }),
107
130
  checked: l((t) => t.project?.id === e.id),
108
- onClick: () => u((t) => t.project?.id === e.id ? null : { projectId: e.id })
131
+ onClick: () => d((t) => t.project?.id === e.id ? null : { projectId: e.id })
109
132
  }))]
110
133
  },
111
- ...L.length > 0 ? [{
134
+ ...I.length > 0 ? [{
112
135
  label: Y("milestone"),
113
136
  items: [{
114
137
  label: Y("noMilestone"),
115
138
  checked: l((e) => !e.milestone),
116
- onClick: () => u((e) => e.milestone ? { milestoneId: "" } : null)
117
- }, ...L.map((e) => ({
139
+ onClick: () => d((e) => e.milestone ? { milestoneId: "" } : null)
140
+ }, ...I.map((e) => ({
118
141
  label: e.name,
119
142
  checked: l((t) => t.milestone?.id === e.id),
120
- onClick: () => u((t) => t.milestone?.id === e.id ? null : { milestoneId: e.id })
143
+ onClick: () => d((t) => t.milestone?.id === e.id ? null : { milestoneId: e.id })
121
144
  }))]
122
145
  }] : [],
123
- ...M?.cyclesEnabled ? [{
146
+ ...j?.cyclesEnabled ? [{
124
147
  label: Y("cycleLabel"),
125
- icon: /* @__PURE__ */ P(h, { className: "size-4" }),
148
+ icon: /* @__PURE__ */ N(ee, { className: "size-4" }),
126
149
  items: [{
127
150
  label: Y("noCycle"),
128
151
  checked: l((e) => !e.cycle),
129
- onClick: () => u((e) => e.cycle ? { cycleId: "" } : null)
130
- }, ...N.map((e) => ({
152
+ onClick: () => d((e) => e.cycle ? { cycleId: "" } : null)
153
+ }, ...M.map((e) => ({
131
154
  label: Y("cycleWithState", {
132
- cycle: ne(e),
155
+ cycle: oe(e),
133
156
  state: Y(`states.${e.state}`)
134
157
  }),
135
158
  checked: l((t) => t.cycle?.id === e.id),
136
- onClick: () => u((t) => t.cycle?.id === e.id ? null : { cycleId: e.id })
159
+ onClick: () => d((t) => t.cycle?.id === e.id ? null : { cycleId: e.id })
137
160
  }))]
138
161
  }] : [],
139
- ...F === "none" ? [] : [{
162
+ ...P === "none" ? [] : [{
140
163
  label: Y("estimate"),
141
- icon: /* @__PURE__ */ P(g, { className: "size-4" }),
142
- items: [0, ...E(F)].map((e) => ({
143
- label: e ? X(e, F) : Y("noEstimate"),
164
+ icon: /* @__PURE__ */ N(te, { className: "size-4" }),
165
+ items: [0, ...w(P)].map((e) => ({
166
+ label: e ? X(e, P) : Y("noEstimate"),
144
167
  checked: l((t) => (t.estimate ?? 0) === e),
145
- onClick: () => u((t) => (t.estimate ?? 0) === e ? null : { estimate: e })
168
+ onClick: () => d((t) => (t.estimate ?? 0) === e ? null : { estimate: e })
146
169
  }))
147
170
  }],
148
171
  {
149
172
  label: Y("dueDate"),
150
- icon: /* @__PURE__ */ P(ee, { className: "size-4" }),
173
+ shortcut: "D",
174
+ icon: /* @__PURE__ */ N(h, { className: "size-4" }),
151
175
  items: [
152
- ...re.map((e) => ({
176
+ ...se.map((e) => ({
153
177
  label: e.label,
154
178
  checked: l((t) => t.dueDate === e.date),
155
- onClick: () => u((t) => t.dueDate === e.date ? null : { dueDate: e.date })
179
+ onClick: () => d((t) => t.dueDate === e.date ? null : { dueDate: e.date })
156
180
  })),
157
- j,
181
+ k,
158
182
  {
159
183
  label: Y("noDueDate"),
160
184
  checked: l((e) => !e.dueDate),
161
- onClick: () => u((e) => e.dueDate ? { dueDate: "" } : null)
185
+ onClick: () => d((e) => e.dueDate ? { dueDate: "" } : null)
162
186
  }
163
187
  ]
164
188
  }
@@ -166,27 +190,27 @@ function z(e) {
166
190
  return [
167
191
  {
168
192
  label: K("status"),
169
- icon: /* @__PURE__ */ P(b, {
193
+ icon: /* @__PURE__ */ N(_, {
170
194
  category: o.status.category,
171
195
  step: o.status.step
172
196
  }),
173
197
  shortcut: "S",
174
198
  items: c(o.teamId).map((e) => ({
175
199
  label: e.name,
176
- icon: /* @__PURE__ */ P(b, {
200
+ icon: /* @__PURE__ */ N(_, {
177
201
  category: e.category,
178
202
  step: e.step
179
203
  }),
180
204
  checked: l((t) => t.status.name === e.name),
181
- onClick: () => u((t) => {
182
- let n = S(e, t);
205
+ onClick: () => d((t) => {
206
+ let n = T(e, t);
183
207
  return n && n !== t.status.id ? { statusId: n } : null;
184
208
  })
185
209
  }))
186
210
  },
187
211
  {
188
212
  label: K("priority"),
189
- icon: /* @__PURE__ */ P(v, { priority: o.priority }),
213
+ icon: /* @__PURE__ */ N(g, { priority: o.priority }),
190
214
  shortcut: "P",
191
215
  items: [
192
216
  1,
@@ -195,60 +219,60 @@ function z(e) {
195
219
  4,
196
220
  0
197
221
  ].map((e) => ({
198
- label: W[e] ?? "",
199
- icon: /* @__PURE__ */ P(v, { priority: e }),
222
+ label: U[e] ?? "",
223
+ icon: /* @__PURE__ */ N(g, { priority: e }),
200
224
  checked: l((t) => t.priority === e),
201
- onClick: () => u((t) => t.priority === e ? null : { priority: e })
225
+ onClick: () => d((t) => t.priority === e ? null : { priority: e })
202
226
  }))
203
227
  },
204
228
  {
205
229
  label: K("assignee"),
206
- icon: /* @__PURE__ */ P(te, {}),
230
+ icon: /* @__PURE__ */ N(y, {}),
207
231
  shortcut: "A",
208
- items: H.map((e) => {
209
- let t = k(e.value), n = (t) => t.assignees.some((t) => O(t) === e.value), r = l(n);
232
+ items: V.map((e) => {
233
+ let t = ie(e.value), n = (t) => t.assignees.some((t) => E(t) === e.value), r = l(n);
210
234
  return {
211
235
  label: e.label,
212
236
  icon: e.icon,
213
237
  checked: r,
214
- onClick: () => u((e) => r ? { removeAssignees: [t] } : n(e) ? null : { addAssignees: [t] })
238
+ onClick: () => d((e) => r ? { removeAssignees: [t] } : n(e) ? null : { addAssignees: [t] })
215
239
  };
216
240
  })
217
241
  },
218
242
  {
219
243
  label: K("labels"),
220
- icon: /* @__PURE__ */ P(x, {}),
244
+ icon: /* @__PURE__ */ N(v, {}),
221
245
  shortcut: "L",
222
- disabled: V.length === 0,
223
- items: V.map((e) => {
246
+ disabled: B.length === 0,
247
+ items: B.map((e) => {
224
248
  let t = (t) => t.labels.some((t) => t.id === e.id), n = l(t);
225
249
  return {
226
250
  label: e.name,
227
- icon: /* @__PURE__ */ P("span", {
251
+ icon: /* @__PURE__ */ N("span", {
228
252
  className: "size-2.5 rounded-full",
229
253
  style: { background: e.color }
230
254
  }),
231
255
  checked: n,
232
- onClick: () => u((r) => n ? { removeLabels: [e.id] } : t(r) ? null : { addLabels: [e.id] })
256
+ onClick: () => d((r) => n ? { removeLabels: [e.id] } : t(r) ? null : { addLabels: [e.id] })
233
257
  };
234
258
  })
235
259
  },
236
- ...ie,
260
+ ...ce,
237
261
  {
238
- label: G("moveToTeam"),
239
- icon: /* @__PURE__ */ P(_, {}),
240
- disabled: B.length < 2,
241
- items: B.filter((e) => !e.archivedAt).map((e) => ({
262
+ label: W("moveToTeam"),
263
+ icon: /* @__PURE__ */ N(ne, {}),
264
+ disabled: z.length < 2,
265
+ items: z.filter((e) => !e.archivedAt).map((e) => ({
242
266
  label: e.name,
243
267
  checked: l((t) => t.teamId === e.id),
244
- onClick: () => d(e.key)
268
+ onClick: () => p(e.key)
245
269
  }))
246
270
  },
247
- j,
271
+ k,
248
272
  ...D ? [
249
273
  {
250
274
  label: K("open"),
251
- onClick: () => z({
275
+ onClick: () => R({
252
276
  to: "/$workspace/issues/$identifier",
253
277
  params: {
254
278
  workspace: e,
@@ -258,32 +282,33 @@ function z(e) {
258
282
  },
259
283
  {
260
284
  label: K("openInNewTab"),
261
- href: R(e, o.identifier),
285
+ href: L(e, o.identifier),
262
286
  target: "_blank"
263
287
  },
264
- j
288
+ k
265
289
  ] : [],
266
- m(G("copyLinks", { count: a.length }), a.map((t) => R(e, t.identifier)).join("\n")),
267
- m(G("copyIds", { count: a.length }), a.map((e) => e.identifier).join(", ")),
268
- ...D ? [m(G("copyTitle"), o.title), m(G("copyBranch"), r(o.identifier, o.title))] : [],
269
- ...D ? [j, {
270
- label: U.find("issue", o.id) ? q("remove") : q("add"),
271
- onClick: () => U.toggle("issue", o.id)
290
+ m(W("copyLinks", { count: a.length }), a.map((t) => L(e, t.identifier)).join("\n")),
291
+ m(W("copyIds", { count: a.length }), a.map((e) => e.identifier).join(", ")),
292
+ ...D ? [m(W("copyTitle"), o.title), m(W("copyBranch"), r(o.identifier, o.title))] : [],
293
+ ...D ? [k, {
294
+ label: H.find("issue", o.id) ? q("remove") : q("add"),
295
+ onClick: () => H.toggle("issue", o.id)
272
296
  }] : [],
273
- j,
297
+ k,
274
298
  l((e) => !!e.archivedAt) ? {
275
- label: G("restore"),
276
- onClick: () => p(!1)
299
+ label: W("restore"),
300
+ onClick: () => b(!1)
277
301
  } : {
278
- label: G("archive"),
279
- onClick: () => p(!0)
302
+ label: W("archive"),
303
+ shortcut: "⌫",
304
+ onClick: () => b(!0)
280
305
  }
281
306
  ];
282
307
  }, [
308
+ z,
283
309
  B,
284
310
  V,
285
311
  H,
286
- U,
287
312
  J,
288
313
  Q,
289
314
  Z,
@@ -291,11 +316,12 @@ function z(e) {
291
316
  X,
292
317
  e,
293
318
  i,
294
- z,
319
+ R,
320
+ U,
295
321
  W,
296
- G,
297
322
  K,
298
- q
323
+ q,
324
+ G
299
325
  ]);
300
326
  }
301
- export { R as issueURL, z as useIssueMenu };
327
+ export { L as issueURL, R as useIssueMenu };
@@ -0,0 +1,22 @@
1
+ // src/lib/notificationRead.ts
2
+ function e(e, t, n, r) {
3
+ let i = 0, a = e.notifications.map((e) => {
4
+ if (t && !t.includes(e.id)) return e;
5
+ if (n && !e.readAt) return i--, {
6
+ ...e,
7
+ readAt: r
8
+ };
9
+ if (!n && e.readAt) {
10
+ i++;
11
+ let { readAt: t, ...n } = e;
12
+ return n;
13
+ }
14
+ return e;
15
+ });
16
+ return {
17
+ ...e,
18
+ notifications: a,
19
+ unread: n && !t ? 0 : Math.max(0, e.unread + i)
20
+ };
21
+ }
22
+ export { e as markRead };