@parallelworks/tandem-web 0.144.0 → 0.145.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.
@@ -0,0 +1,230 @@
1
+ import { api as e, unwrap as t } from "../../../api/client.js";
2
+ import { meQuery as n, parallelWorksBucketsQuery as r, parallelWorksQuery as i } from "../../../api/queries.js";
3
+ import { useConfirm as a } from "../../../lib/confirm.js";
4
+ import { BucketIcon as o } from "../../../components/icons.js";
5
+ import { Route as s } from "./parallelworks.js";
6
+ import { useCan as c } from "../../../lib/roles.js";
7
+ import { AdminOnly as l, SettingsPage as u, useFormError as d } from "../../../components/settings.js";
8
+ import { Button as f, Callout as p, Input as m, Select as h, SettingRow as g, SettingsCard as _ } from "@parallelworks/ui";
9
+ import { useState as v } from "react";
10
+ import { useFormatter as y, useTranslations as b } from "use-intl";
11
+ import { jsx as x, jsxs as S } from "react/jsx-runtime";
12
+ import { useMutation as C, useQuery as w, useQueryClient as T, useSuspenseQuery as E } from "@tanstack/react-query";
13
+ // src/routes/$workspace/settings/parallelworks.tsx?tsr-split=component
14
+ function D() {
15
+ let { workspace: e } = s.useParams(), t = b("parallelWorks"), n = c(e, "manage_workspace");
16
+ return /* @__PURE__ */ S(u, {
17
+ title: t("title"),
18
+ description: t("description"),
19
+ children: [/* @__PURE__ */ x(l, { workspace: e }), n && /* @__PURE__ */ x(O, { workspace: e })]
20
+ });
21
+ }
22
+ function O({ workspace: e }) {
23
+ let { data: t } = E(i(e));
24
+ return t.connected ? /* @__PURE__ */ S("div", {
25
+ className: "space-y-10",
26
+ children: [/* @__PURE__ */ x(A, {
27
+ workspace: e,
28
+ conn: t
29
+ }), /* @__PURE__ */ x(M, {
30
+ workspace: e,
31
+ conn: t
32
+ })]
33
+ }) : /* @__PURE__ */ x(k, {
34
+ workspace: e,
35
+ conn: t
36
+ });
37
+ }
38
+ function k({ workspace: r, conn: a }) {
39
+ let o = b("parallelWorks"), s = T(), c = d(), { data: l } = w(n), [u, h] = v(a.url ?? (l?.mode === "platform" ? window.location.origin : "https://cloud.parallel.works")), [y, E] = v(""), D = C({
40
+ mutationFn: async () => t(await e.PUT("/api/v1/workspaces/{workspace}/parallelworks", {
41
+ params: { path: { workspace: r } },
42
+ body: {
43
+ url: u.trim(),
44
+ apiKey: y.trim()
45
+ }
46
+ })),
47
+ onMutate: c.clear,
48
+ onError: c.set,
49
+ onSuccess: (e) => s.setQueryData(i(r).queryKey, e)
50
+ });
51
+ return /* @__PURE__ */ S("form", {
52
+ onSubmit: (e) => {
53
+ e.preventDefault(), D.mutate();
54
+ },
55
+ children: [!a.canConnect && /* @__PURE__ */ x(p, {
56
+ tone: "warning",
57
+ className: "mb-6",
58
+ children: o("noKey")
59
+ }), /* @__PURE__ */ S(_, {
60
+ title: o("connect"),
61
+ description: o("connectDescription"),
62
+ action: /* @__PURE__ */ x(f, {
63
+ type: "submit",
64
+ variant: "primary",
65
+ loading: D.isPending,
66
+ disabled: !a.canConnect,
67
+ children: o("connectButton")
68
+ }),
69
+ actionAlign: "end",
70
+ error: c.error,
71
+ children: [/* @__PURE__ */ x(g, {
72
+ label: o("url"),
73
+ htmlFor: "pw-url",
74
+ helpText: o("urlHelp"),
75
+ fill: !0,
76
+ children: /* @__PURE__ */ x(m, {
77
+ id: "pw-url",
78
+ type: "url",
79
+ required: !0,
80
+ value: u,
81
+ onChange: (e) => h(e.target.value),
82
+ mono: !0
83
+ })
84
+ }), /* @__PURE__ */ x(g, {
85
+ label: o("apiKey"),
86
+ htmlFor: "pw-key",
87
+ helpText: o("apiKeyHelp"),
88
+ fill: !0,
89
+ children: /* @__PURE__ */ x(m, {
90
+ id: "pw-key",
91
+ type: "password",
92
+ autoComplete: "off",
93
+ required: !0,
94
+ placeholder: "pwt_…",
95
+ value: y,
96
+ onChange: (e) => E(e.target.value),
97
+ mono: !0
98
+ })
99
+ })]
100
+ })]
101
+ });
102
+ }
103
+ function A({ workspace: n, conn: r }) {
104
+ let o = b("parallelWorks"), s = y(), c = T(), { confirm: l, dialog: u } = a(), d = C({
105
+ mutationFn: async () => t(await e.DELETE("/api/v1/workspaces/{workspace}/parallelworks", { params: { path: { workspace: n } } })),
106
+ onSettled: () => c.invalidateQueries({ queryKey: i(n).queryKey })
107
+ });
108
+ return /* @__PURE__ */ S(_, {
109
+ title: o("account"),
110
+ action: /* @__PURE__ */ x(f, {
111
+ variant: "danger",
112
+ onClick: () => l({
113
+ title: o("disconnectTitle"),
114
+ description: o("disconnectDescription"),
115
+ confirmLabel: o("disconnect"),
116
+ onConfirm: () => d.mutateAsync()
117
+ }),
118
+ children: o("disconnect")
119
+ }),
120
+ actionAlign: "end",
121
+ children: [
122
+ /* @__PURE__ */ x(g, {
123
+ label: o("platform"),
124
+ children: /* @__PURE__ */ x("a", {
125
+ href: r.url,
126
+ className: "font-mono text-sm text-link hover:underline",
127
+ children: r.url
128
+ })
129
+ }),
130
+ /* @__PURE__ */ x(g, {
131
+ label: o("signedInAs"),
132
+ helpText: r.connectedAt && o("connectedBy", { date: s.dateTime(new Date(r.connectedAt), {
133
+ dateStyle: "medium",
134
+ timeStyle: "short"
135
+ }) }),
136
+ children: /* @__PURE__ */ x("span", {
137
+ className: "text-sm font-medium",
138
+ children: o("user", {
139
+ user: r.username ?? "",
140
+ organization: r.organization ?? ""
141
+ })
142
+ })
143
+ }),
144
+ u
145
+ ]
146
+ });
147
+ }
148
+ var j = (e) => `${e.user}/${e.name}`;
149
+ function M({ workspace: n, conn: a }) {
150
+ let s = b("parallelWorks"), c = T(), l = d(), u = w(r(n)), [p, m] = v(a.bucket ? j(a.bucket) : null), y = (e) => {
151
+ e ? c.setQueryData(i(n).queryKey, e) : c.invalidateQueries({ queryKey: i(n).queryKey });
152
+ }, E = C({
153
+ mutationFn: async (r) => t(await e.PUT("/api/v1/workspaces/{workspace}/parallelworks/bucket", {
154
+ params: { path: { workspace: n } },
155
+ body: {
156
+ user: r.user,
157
+ name: r.name
158
+ }
159
+ })),
160
+ onMutate: l.clear,
161
+ onError: l.set,
162
+ onSuccess: y
163
+ }), D = C({
164
+ mutationFn: async () => t(await e.DELETE("/api/v1/workspaces/{workspace}/parallelworks/bucket", { params: { path: { workspace: n } } })),
165
+ onMutate: l.clear,
166
+ onError: l.set,
167
+ onSuccess: () => {
168
+ m(null), y();
169
+ }
170
+ }), O = u.data?.find((e) => j(e) === p), k = a.bucket ? j(a.bucket) : null;
171
+ return /* @__PURE__ */ S(_, {
172
+ title: s("storage"),
173
+ description: s("storageDescription"),
174
+ error: l.error ?? (u.error && s("bucketsFailed")),
175
+ children: [
176
+ /* @__PURE__ */ x(g, {
177
+ label: s("filesGoTo"),
178
+ helpText: a.bucket ? s("filesInBucket") : s("filesOnServer"),
179
+ children: /* @__PURE__ */ S("span", {
180
+ className: "flex items-center gap-1.5 text-sm font-medium",
181
+ children: [a.bucket && /* @__PURE__ */ x(o, { className: "size-4 text-muted-foreground" }), a.bucket ? a.bucket.displayName || a.bucket.name : s("server")]
182
+ })
183
+ }),
184
+ /* @__PURE__ */ x(g, {
185
+ label: s("bucket"),
186
+ helpText: s("bucketHelp"),
187
+ children: /* @__PURE__ */ S("div", {
188
+ className: "flex items-center gap-2",
189
+ children: [/* @__PURE__ */ x("div", {
190
+ className: "w-60",
191
+ children: /* @__PURE__ */ x(h, {
192
+ width: "fill",
193
+ "aria-label": s("bucket"),
194
+ value: p,
195
+ placeholder: u.isPending ? s("loading") : s("pickBucket"),
196
+ disabled: !u.data?.length,
197
+ onValueChange: m,
198
+ items: (u.data ?? []).map((e) => ({
199
+ value: j(e),
200
+ label: e.displayName || e.name,
201
+ description: [
202
+ e.user,
203
+ e.type,
204
+ ...e.canWrite ? [] : [s("readOnly")]
205
+ ].join(" · "),
206
+ disabled: !e.canWrite,
207
+ icon: /* @__PURE__ */ x(o, {})
208
+ }))
209
+ })
210
+ }), /* @__PURE__ */ x(f, {
211
+ loading: E.isPending,
212
+ disabled: !O || p === k,
213
+ onClick: () => O && E.mutate(O),
214
+ children: s("use")
215
+ })]
216
+ })
217
+ }),
218
+ a.bucket && /* @__PURE__ */ x(g, {
219
+ label: s("stop"),
220
+ helpText: s("stopHelp"),
221
+ children: /* @__PURE__ */ x(f, {
222
+ loading: D.isPending,
223
+ onClick: () => D.mutate(),
224
+ children: s("stopButton")
225
+ })
226
+ })
227
+ ]
228
+ });
229
+ }
230
+ export { D as component };
@@ -0,0 +1,8 @@
1
+ import { meQuery as e, parallelWorksQuery as t } from "../../../api/queries.js";
2
+ import { may as n } from "../../../lib/roles.js";
3
+ // src/routes/$workspace/settings/parallelworks.tsx?tsr-split=loader
4
+ var r = async ({ context: { queryClient: r }, params: { workspace: i } }) => {
5
+ let a = await r.ensureQueryData(e);
6
+ n(a, i, "manage_workspace") && await r.ensureQueryData(t(i));
7
+ };
8
+ export { r as loader };