@parallelworks/tandem-web 0.182.1 → 0.184.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.
@@ -1,17 +1,17 @@
1
- import { docPropertiesQuery as e, propertyKinds as t, spaceScope as n, useDocPropertyActions as r } from "../lib/docProperties.js";
2
- import { usePeople as i } from "../lib/people.js";
3
- import { useCan as a } from "../lib/roles.js";
4
- import { AddIcon as o } from "./icons.js";
5
- import { Button as s, Checkbox as c, ErrorText as l, IconButton as u, Input as d, Popover as f, Select as p, Textarea as m, menuDivider as h, useOpenMenu as g } from "@parallelworks/ui";
6
- import { Link as _ } from "@tanstack/react-router";
7
- import { useEffect as v, useState as y } from "react";
8
- import { useErrorMessage as b } from "@parallelworks/problem/react";
9
- import { useTranslations as x } from "use-intl";
10
- import { jsx as S, jsxs as C } from "react/jsx-runtime";
11
- import { useQuery as w } from "@tanstack/react-query";
1
+ import { docPropertiesQuery as e, hasValue as t, propertyKinds as n, spaceScope as r, useDocPropertyActions as i } from "../lib/docProperties.js";
2
+ import { usePeople as a } from "../lib/people.js";
3
+ import { useCan as o } from "../lib/roles.js";
4
+ import { AddIcon as s } from "./icons.js";
5
+ import { Button as c, Checkbox as l, ErrorText as u, IconButton as d, Input as f, Popover as p, Select as m, Textarea as h, menuDivider as g, useOpenMenu as _ } from "@parallelworks/ui";
6
+ import { Link as v } from "@tanstack/react-router";
7
+ import { useEffect as y, useState as b } from "react";
8
+ import { useErrorMessage as x } from "@parallelworks/problem/react";
9
+ import { useTranslations as S } from "use-intl";
10
+ import { Fragment as C, jsx as w, jsxs as T } from "react/jsx-runtime";
11
+ import { useQuery as E } from "@tanstack/react-query";
12
12
  // src/components/DocProperties.tsx
13
- function T(e) {
14
- let { nameOf: t } = i(e), n = x("docProperties");
13
+ function D(e) {
14
+ let { nameOf: t } = a(e), n = S("docProperties");
15
15
  return (e, r) => {
16
16
  if (r == null) return "";
17
17
  let i = (t) => e.options.find((e) => e.id === t)?.name ?? String(t);
@@ -24,67 +24,76 @@ function T(e) {
24
24
  }
25
25
  };
26
26
  }
27
- function E({ workspace: t, doc: i, space: o, editable: s }) {
28
- let c = x("docProperties"), u = b(), { data: d = [] } = w(e(t, o)), f = a(t, "manage_labels", n(o)), p = r(t), m = i.properties ?? {};
29
- if (d.length === 0 && !(s && f)) return null;
30
- let h = (e, t) => p.setValues.mutate({
31
- doc: i.key,
27
+ function O({ workspace: n, doc: a, space: s, editable: c }) {
28
+ let l = S("docProperties"), d = x(), { data: f = [] } = E(e(n, s)), p = o(n, "manage_labels", r(s)), m = i(n), h = a.properties ?? {}, [g, _] = b({
29
+ doc: a.key,
30
+ ids: []
31
+ }), v = g.doc === a.key ? g.ids : [], y = f.filter((e) => t(h[e.id]) || v.includes(e.id)), C = f.filter((e) => !y.includes(e)), D = c && (C.length > 0 || p);
32
+ if (y.length === 0 && !D) return null;
33
+ let O = (e, t) => m.setValues.mutate({
34
+ doc: a.key,
32
35
  values: { [e]: t }
33
36
  });
34
- return /* @__PURE__ */ C("section", {
35
- "aria-label": c("title"),
37
+ return /* @__PURE__ */ T("section", {
38
+ "aria-label": l("title"),
36
39
  className: "mt-3 space-y-0.5 text-sm",
37
40
  children: [
38
- d.map((e) => /* @__PURE__ */ C("div", {
41
+ y.map((e) => /* @__PURE__ */ T("div", {
39
42
  className: "flex min-h-8 items-center gap-2",
40
- children: [/* @__PURE__ */ S(D, {
41
- workspace: t,
43
+ children: [/* @__PURE__ */ w(k, {
44
+ workspace: n,
42
45
  property: e,
43
- admin: s && f
44
- }), /* @__PURE__ */ S("div", {
46
+ admin: c && p
47
+ }), /* @__PURE__ */ w("div", {
45
48
  className: "min-w-0 flex-1",
46
- children: /* @__PURE__ */ S(O, {
47
- workspace: t,
49
+ children: /* @__PURE__ */ w(A, {
50
+ workspace: n,
48
51
  property: e,
49
- value: m[e.id],
50
- editable: s,
51
- onChange: (t) => h(e.id, t)
52
+ value: h[e.id],
53
+ editable: c,
54
+ onChange: (t) => O(e.id, t)
52
55
  })
53
56
  })]
54
57
  }, e.id)),
55
- s && f && /* @__PURE__ */ S(A, {
56
- workspace: t,
57
- space: o
58
+ D && /* @__PURE__ */ w(M, {
59
+ workspace: n,
60
+ space: s,
61
+ unset: C,
62
+ admin: p,
63
+ onPick: (e) => _({
64
+ doc: a.key,
65
+ ids: [...v, e]
66
+ })
58
67
  }),
59
- p.setValues.error && /* @__PURE__ */ S(l, { children: u(p.setValues.error) })
68
+ m.setValues.error && /* @__PURE__ */ w(u, { children: d(m.setValues.error) })
60
69
  ]
61
70
  });
62
71
  }
63
- function D({ workspace: e, property: t, admin: n }) {
64
- let i = x("docProperties"), a = g(), o = r(e), [s, c] = y(!1), l = /* @__PURE__ */ S("span", {
72
+ function k({ workspace: e, property: t, admin: n }) {
73
+ let r = S("docProperties"), a = _(), o = i(e), [s, c] = b(!1), l = /* @__PURE__ */ w("span", {
65
74
  className: "truncate",
66
75
  children: t.name
67
76
  });
68
- if (!n) return /* @__PURE__ */ S("span", {
77
+ if (!n) return /* @__PURE__ */ w("span", {
69
78
  className: "flex w-36 shrink-0 text-muted-foreground",
70
79
  children: l
71
80
  });
72
81
  let u = () => [
73
82
  {
74
- label: i("edit"),
83
+ label: r("edit"),
75
84
  onClick: () => c(!0)
76
85
  },
77
- h,
86
+ g,
78
87
  {
79
- label: i("remove"),
88
+ label: r("remove"),
80
89
  destructive: !0,
81
90
  onClick: () => o.remove.mutate(t.id)
82
91
  }
83
92
  ];
84
- return /* @__PURE__ */ S(f, {
93
+ return /* @__PURE__ */ w(p, {
85
94
  open: s,
86
95
  onOpenChange: c,
87
- trigger: /* @__PURE__ */ S("button", {
96
+ trigger: /* @__PURE__ */ w("button", {
88
97
  type: "button",
89
98
  onContextMenu: (e) => a(e, u()),
90
99
  className: "flex h-7 w-36 shrink-0 items-center rounded-md px-1.5 text-left text-muted-foreground hover:bg-muted",
@@ -93,8 +102,8 @@ function D({ workspace: e, property: t, admin: n }) {
93
102
  align: "start",
94
103
  className: "w-72",
95
104
  initialFocus: "first-control",
96
- "aria-label": i("edit"),
97
- children: /* @__PURE__ */ S(j, {
105
+ "aria-label": r("edit"),
106
+ children: /* @__PURE__ */ w(N, {
98
107
  workspace: e,
99
108
  property: t,
100
109
  onDone: () => c(!1),
@@ -104,11 +113,11 @@ function D({ workspace: e, property: t, admin: n }) {
104
113
  })
105
114
  });
106
115
  }
107
- function O({ workspace: e, property: t, value: n, editable: r, onChange: a }) {
108
- let o = x("docProperties"), { members: s } = i(e), l = T(e), u = o("empty");
116
+ function A({ workspace: e, property: t, value: n, editable: r, onChange: i }) {
117
+ let o = S("docProperties"), { members: s } = a(e), c = D(e), u = o("empty");
109
118
  if (!r) {
110
- let r = l(t, n);
111
- return t.kind === "issue" && r ? /* @__PURE__ */ S(_, {
119
+ let r = c(t, n);
120
+ return t.kind === "issue" && r ? /* @__PURE__ */ w(v, {
112
121
  to: "/$workspace/issues/$identifier",
113
122
  params: {
114
123
  workspace: e,
@@ -116,19 +125,19 @@ function O({ workspace: e, property: t, value: n, editable: r, onChange: a }) {
116
125
  },
117
126
  className: "text-primary hover:underline",
118
127
  children: r
119
- }) : t.kind === "url" && r ? /* @__PURE__ */ S("a", {
128
+ }) : t.kind === "url" && r ? /* @__PURE__ */ w("a", {
120
129
  href: r,
121
130
  target: "_blank",
122
131
  rel: "noopener noreferrer",
123
132
  className: "truncate text-primary hover:underline",
124
133
  children: r
125
- }) : /* @__PURE__ */ S("span", {
134
+ }) : /* @__PURE__ */ w("span", {
126
135
  className: r ? "" : "text-muted-foreground",
127
136
  children: r || u
128
137
  });
129
138
  }
130
139
  switch (t.kind) {
131
- case "select": return /* @__PURE__ */ S(p, {
140
+ case "select": return /* @__PURE__ */ w(m, {
132
141
  value: typeof n == "string" ? n : "",
133
142
  items: [{
134
143
  value: "",
@@ -137,25 +146,25 @@ function O({ workspace: e, property: t, value: n, editable: r, onChange: a }) {
137
146
  value: e.id ?? "",
138
147
  label: e.name
139
148
  }))],
140
- onValueChange: (e) => a(e || null),
149
+ onValueChange: (e) => i(e || null),
141
150
  "aria-label": t.name,
142
151
  size: "sm",
143
152
  width: "content"
144
153
  });
145
- case "multi_select": return /* @__PURE__ */ S(p, {
154
+ case "multi_select": return /* @__PURE__ */ w(m, {
146
155
  multiple: !0,
147
156
  value: Array.isArray(n) ? n : [],
148
157
  items: t.options.map((e) => ({
149
158
  value: e.id ?? "",
150
159
  label: e.name
151
160
  })),
152
- onValueChange: (e) => a(e),
161
+ onValueChange: (e) => i(e),
153
162
  placeholder: u,
154
163
  "aria-label": t.name,
155
164
  size: "sm",
156
165
  width: "content"
157
166
  });
158
- case "person": return /* @__PURE__ */ S(p, {
167
+ case "person": return /* @__PURE__ */ w(m, {
159
168
  value: typeof n == "string" ? n : "",
160
169
  items: [{
161
170
  value: "",
@@ -164,37 +173,37 @@ function O({ workspace: e, property: t, value: n, editable: r, onChange: a }) {
164
173
  value: e.user.username,
165
174
  label: e.user.name
166
175
  }))],
167
- onValueChange: (e) => a(e || null),
176
+ onValueChange: (e) => i(e || null),
168
177
  "aria-label": t.name,
169
178
  size: "sm",
170
179
  width: "content"
171
180
  });
172
- case "checkbox": return /* @__PURE__ */ S(c, {
181
+ case "checkbox": return /* @__PURE__ */ w(l, {
173
182
  checked: n === !0,
174
- onCheckedChange: (e) => a(e === !0),
183
+ onCheckedChange: (e) => i(e === !0),
175
184
  "aria-label": t.name
176
185
  });
177
- case "date": return /* @__PURE__ */ S(d, {
186
+ case "date": return /* @__PURE__ */ w(f, {
178
187
  type: "date",
179
188
  value: typeof n == "string" ? n : "",
180
- onChange: (e) => a(e.target.value || null),
189
+ onChange: (e) => i(e.target.value || null),
181
190
  "aria-label": t.name,
182
191
  className: "h-7 px-1.5 w-40"
183
192
  });
184
- default: return /* @__PURE__ */ S(k, {
193
+ default: return /* @__PURE__ */ w(j, {
185
194
  property: t,
186
195
  value: n,
187
- onChange: a
196
+ onChange: i
188
197
  });
189
198
  }
190
199
  }
191
- function k({ property: e, value: t, onChange: n }) {
192
- let r = x("docProperties"), i = t == null ? "" : String(t), [a, o] = y(i);
193
- v(() => o(i), [i]);
200
+ function j({ property: e, value: t, onChange: n }) {
201
+ let r = S("docProperties"), i = t == null ? "" : String(t), [a, o] = b(i);
202
+ y(() => o(i), [i]);
194
203
  let s = () => {
195
204
  a !== i && (a.trim() ? n(e.kind === "number" ? Number(a) : a) : n(null));
196
205
  };
197
- return /* @__PURE__ */ S(d, {
206
+ return /* @__PURE__ */ w(f, {
198
207
  type: e.kind === "number" ? "number" : e.kind === "url" ? "url" : "text",
199
208
  value: a,
200
209
  onChange: (e) => o(e.target.value),
@@ -205,45 +214,59 @@ function k({ property: e, value: t, onChange: n }) {
205
214
  className: "h-7 border-transparent px-1.5 shadow-none hover:border-border"
206
215
  });
207
216
  }
208
- function A({ workspace: e, space: t }) {
209
- let n = x("docProperties"), [r, i] = y(!1);
210
- return /* @__PURE__ */ S(f, {
211
- open: r,
212
- onOpenChange: i,
213
- trigger: /* @__PURE__ */ S(s, {
214
- size: "xs",
215
- variant: "ghost",
216
- icon: /* @__PURE__ */ S(o, {}),
217
- className: "mt-1 text-muted-foreground",
218
- children: n("add")
219
- }),
217
+ function M({ workspace: e, space: t, unset: n, admin: r, onPick: i }) {
218
+ let a = S("docProperties"), o = _(), [l, u] = b(null), d = (e) => {
219
+ if (n.length === 0) {
220
+ u(e);
221
+ return;
222
+ }
223
+ let t = n.map((e) => ({
224
+ label: e.name,
225
+ onClick: () => i(e.id)
226
+ }));
227
+ r && t.push(g, {
228
+ label: a("new"),
229
+ onClick: () => u(e)
230
+ }), o(e, t);
231
+ };
232
+ return /* @__PURE__ */ T(C, { children: [/* @__PURE__ */ w(c, {
233
+ size: "xs",
234
+ variant: "ghost",
235
+ icon: /* @__PURE__ */ w(s, {}),
236
+ className: "mt-1 text-muted-foreground",
237
+ onClick: (e) => d(e.currentTarget),
238
+ children: a("add")
239
+ }), l && /* @__PURE__ */ w(p, {
240
+ open: !0,
241
+ onOpenChange: (e) => !e && u(null),
242
+ at: l,
220
243
  align: "start",
221
244
  className: "w-72",
222
245
  initialFocus: "first-control",
223
- "aria-label": n("add"),
224
- children: /* @__PURE__ */ S(j, {
246
+ "aria-label": a("new"),
247
+ children: /* @__PURE__ */ w(N, {
225
248
  workspace: e,
226
249
  space: t,
227
- onDone: () => i(!1)
250
+ onDone: () => u(null)
228
251
  })
229
- });
252
+ })] });
230
253
  }
231
- function j({ workspace: e, space: n, property: i, onDone: a, onRemove: o }) {
232
- let c = x("docProperties"), f = b(), h = r(e), [g, _] = y(i?.name ?? ""), [v, w] = y(i?.kind ?? "text"), [T, E] = y((i?.options ?? []).map((e) => e.name).join("\n")), D = v === "select" || v === "multi_select", O = () => T.split("\n").map((e) => e.trim()).filter(Boolean).map((e) => {
233
- let t = i?.options.find((t) => t.name === e)?.id;
254
+ function N({ workspace: e, space: t, property: r, onDone: a, onRemove: o }) {
255
+ let s = S("docProperties"), l = x(), p = i(e), [g, _] = b(r?.name ?? ""), [v, y] = b(r?.kind ?? "text"), [C, E] = b((r?.options ?? []).map((e) => e.name).join("\n")), D = v === "select" || v === "multi_select", O = () => C.split("\n").map((e) => e.trim()).filter(Boolean).map((e) => {
256
+ let t = r?.options.find((t) => t.name === e)?.id;
234
257
  return {
235
258
  name: e,
236
259
  ...t && { id: t }
237
260
  };
238
- }), k = i ? h.update : h.create;
239
- return /* @__PURE__ */ C("form", {
261
+ }), k = r ? p.update : p.create;
262
+ return /* @__PURE__ */ T("form", {
240
263
  onSubmit: (e) => {
241
- e.preventDefault(), i ? h.update.mutate({
242
- id: i.id,
264
+ e.preventDefault(), r ? p.update.mutate({
265
+ id: r.id,
243
266
  name: g,
244
267
  ...D && { options: O() }
245
- }, { onSuccess: a }) : h.create.mutate({
246
- ...n && { space: n },
268
+ }, { onSuccess: a }) : p.create.mutate({
269
+ ...t && { space: t },
247
270
  name: g,
248
271
  kind: v,
249
272
  ...D && { options: O() }
@@ -251,9 +274,9 @@ function j({ workspace: e, space: n, property: i, onDone: a, onRemove: o }) {
251
274
  },
252
275
  className: "space-y-3 text-sm",
253
276
  children: [
254
- /* @__PURE__ */ C("label", {
277
+ /* @__PURE__ */ T("label", {
255
278
  className: "block text-xs font-medium text-muted-foreground",
256
- children: [c("name"), /* @__PURE__ */ S(d, {
279
+ children: [s("name"), /* @__PURE__ */ w(f, {
257
280
  value: g,
258
281
  onChange: (e) => _(e.target.value),
259
282
  required: !0,
@@ -261,60 +284,60 @@ function j({ workspace: e, space: n, property: i, onDone: a, onRemove: o }) {
261
284
  className: "mt-1"
262
285
  })]
263
286
  }),
264
- !i && /* @__PURE__ */ C("div", {
287
+ !r && /* @__PURE__ */ T("div", {
265
288
  className: "text-xs font-medium text-muted-foreground",
266
- children: [c("kind"), /* @__PURE__ */ S("div", {
289
+ children: [s("kind"), /* @__PURE__ */ w("div", {
267
290
  className: "mt-1",
268
- children: /* @__PURE__ */ S(p, {
291
+ children: /* @__PURE__ */ w(m, {
269
292
  value: v,
270
- items: t.map((e) => ({
293
+ items: n.map((e) => ({
271
294
  value: e,
272
- label: c(`kinds.${e}`)
295
+ label: s(`kinds.${e}`)
273
296
  })),
274
- onValueChange: w,
275
- "aria-label": c("kind"),
297
+ onValueChange: y,
298
+ "aria-label": s("kind"),
276
299
  width: "fill"
277
300
  })
278
301
  })]
279
302
  }),
280
- D && /* @__PURE__ */ C("label", {
303
+ D && /* @__PURE__ */ T("label", {
281
304
  className: "block text-xs font-medium text-muted-foreground",
282
305
  children: [
283
- c("options"),
284
- /* @__PURE__ */ S(m, {
285
- value: T,
306
+ s("options"),
307
+ /* @__PURE__ */ w(h, {
308
+ value: C,
286
309
  onChange: (e) => E(e.target.value),
287
310
  rows: 4,
288
311
  className: "mt-1"
289
312
  }),
290
- /* @__PURE__ */ S("span", {
313
+ /* @__PURE__ */ w("span", {
291
314
  className: "mt-1 block font-normal",
292
- children: c("optionsHint")
315
+ children: s("optionsHint")
293
316
  })
294
317
  ]
295
318
  }),
296
- k.error && /* @__PURE__ */ S(l, { children: f(k.error) }),
297
- /* @__PURE__ */ C("div", {
319
+ k.error && /* @__PURE__ */ w(u, { children: l(k.error) }),
320
+ /* @__PURE__ */ T("div", {
298
321
  className: "flex justify-between gap-2",
299
- children: [o ? /* @__PURE__ */ S(u, {
322
+ children: [o ? /* @__PURE__ */ w(d, {
300
323
  variant: "ghost",
301
324
  size: "sm",
302
- label: c("remove"),
303
- icon: /* @__PURE__ */ S("span", {
325
+ label: s("remove"),
326
+ icon: /* @__PURE__ */ w("span", {
304
327
  "aria-hidden": !0,
305
328
  children: "×"
306
329
  }),
307
330
  onClick: o
308
- }) : /* @__PURE__ */ S("span", {}), /* @__PURE__ */ S(s, {
331
+ }) : /* @__PURE__ */ w("span", {}), /* @__PURE__ */ w(c, {
309
332
  type: "submit",
310
333
  size: "sm",
311
334
  variant: "primary",
312
335
  loading: k.isPending,
313
336
  disabled: !g.trim(),
314
- children: c(i ? "save" : "add")
337
+ children: s(r ? "save" : "add")
315
338
  })]
316
339
  })
317
340
  ]
318
341
  });
319
342
  }
320
- export { E as DocProperties, O as PropertyField, T as usePropertyText };
343
+ export { O as DocProperties, A as PropertyField, D as usePropertyText };