@rebasepro/studio 0.25.1 → 0.26.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/dist/BranchesView-Df00LXAI.js +1269 -0
- package/dist/BranchesView-Df00LXAI.js.map +1 -0
- package/dist/components/Branches/BranchDiffView.d.ts +10 -0
- package/dist/components/Branches/split-line-diff.d.ts +17 -0
- package/dist/index.es.js +1 -1
- package/package.json +9 -9
- package/dist/BranchesView-BHfwGTYc.js +0 -524
- package/dist/BranchesView-BHfwGTYc.js.map +0 -1
|
@@ -0,0 +1,1269 @@
|
|
|
1
|
+
import { t as classifyLoadFailure } from "./load-failure-Bd8lFIO7.js";
|
|
2
|
+
import { t as LoadFailureView } from "./load-failure-view-CBTB_h-h.js";
|
|
3
|
+
import { ConfirmationDialog, useApiBase, useApiConfig, useRebaseContext, useSnackbarController, useTranslation } from "@rebasepro/app";
|
|
4
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
5
|
+
import { Alert, Button, Checkbox, Chip, CircularProgress, CopyIcon, Dialog, DialogActions, DialogContent, DialogTitle, GitBranchIcon, GitMergeIcon, IconButton, Label, PlusIcon, RadioGroup, RadioGroupItem, RefreshCwIcon, Select, SelectItem, Tab, Table, TableBody, TableCell, TableHeader, TableRow, Tabs, TextField, Trash2Icon, Typography, cls, defaultBorderMixin, iconSize } from "@rebasepro/ui";
|
|
6
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { isBranchAdmin } from "@rebasepro/types";
|
|
8
|
+
import { formatRelativeTime } from "@rebasepro/utils";
|
|
9
|
+
//#region src/components/Branches/split-line-diff.ts
|
|
10
|
+
function splitLineDiff(before, after) {
|
|
11
|
+
const a = before === void 0 ? [] : before.split("\n");
|
|
12
|
+
const b = after === void 0 ? [] : after.split("\n");
|
|
13
|
+
const lcs = Array.from({ length: a.length + 1 }, () => new Array(b.length + 1).fill(0));
|
|
14
|
+
for (let i = a.length - 1; i >= 0; i -= 1) for (let j = b.length - 1; j >= 0; j -= 1) lcs[i][j] = a[i] === b[j] ? lcs[i + 1][j + 1] + 1 : Math.max(lcs[i + 1][j], lcs[i][j + 1]);
|
|
15
|
+
const rows = [];
|
|
16
|
+
let removed = [];
|
|
17
|
+
let added = [];
|
|
18
|
+
const flush = () => {
|
|
19
|
+
for (let k = 0; k < Math.max(removed.length, added.length); k += 1) rows.push({
|
|
20
|
+
left: removed[k] ?? null,
|
|
21
|
+
right: added[k] ?? null,
|
|
22
|
+
same: false
|
|
23
|
+
});
|
|
24
|
+
removed = [];
|
|
25
|
+
added = [];
|
|
26
|
+
};
|
|
27
|
+
let i = 0;
|
|
28
|
+
let j = 0;
|
|
29
|
+
while (i < a.length || j < b.length) if (i < a.length && j < b.length && a[i] === b[j]) {
|
|
30
|
+
flush();
|
|
31
|
+
rows.push({
|
|
32
|
+
left: a[i],
|
|
33
|
+
right: b[j],
|
|
34
|
+
same: true
|
|
35
|
+
});
|
|
36
|
+
i += 1;
|
|
37
|
+
j += 1;
|
|
38
|
+
} else if (j < b.length && (i >= a.length || lcs[i][j + 1] >= lcs[i + 1][j])) {
|
|
39
|
+
added.push(b[j]);
|
|
40
|
+
j += 1;
|
|
41
|
+
} else {
|
|
42
|
+
removed.push(a[i]);
|
|
43
|
+
i += 1;
|
|
44
|
+
}
|
|
45
|
+
flush();
|
|
46
|
+
return rows;
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/components/Branches/BranchDiffView.tsx
|
|
50
|
+
/** A refusal from the review routes, with the status `classifyLoadFailure` reads. */
|
|
51
|
+
var BranchReviewError = class extends Error {
|
|
52
|
+
status;
|
|
53
|
+
code;
|
|
54
|
+
constructor(message, status, code) {
|
|
55
|
+
super(message);
|
|
56
|
+
this.status = status;
|
|
57
|
+
this.code = code;
|
|
58
|
+
this.name = "BranchReviewError";
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
function isBranchDiff(value) {
|
|
62
|
+
return typeof value === "object" && value !== null && "fingerprint" in value && typeof value.fingerprint === "string" && "schema" in value && Array.isArray(value.schema) && "data" in value && Array.isArray(value.data);
|
|
63
|
+
}
|
|
64
|
+
function isMergeResult(value) {
|
|
65
|
+
return typeof value === "object" && value !== null && "tables" in value && Array.isArray(value.tables) && "targetDatabase" in value && typeof value.targetDatabase === "string";
|
|
66
|
+
}
|
|
67
|
+
async function requestJson(url, init, token) {
|
|
68
|
+
const response = await fetch(url, {
|
|
69
|
+
...init,
|
|
70
|
+
headers: {
|
|
71
|
+
...init.body ? { "Content-Type": "application/json" } : {},
|
|
72
|
+
...token ? { Authorization: `Bearer ${token}` } : {}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
const body = await response.json().catch(() => null);
|
|
76
|
+
if (!response.ok) {
|
|
77
|
+
const error = typeof body === "object" && body !== null && "error" in body && typeof body.error === "object" && body.error !== null ? body.error : null;
|
|
78
|
+
const message = error && "message" in error && typeof error.message === "string" ? error.message : `HTTP ${response.status}`;
|
|
79
|
+
const code = error && "code" in error && typeof error.code === "string" ? error.code : void 0;
|
|
80
|
+
throw new BranchReviewError(message, response.status, code);
|
|
81
|
+
}
|
|
82
|
+
return body;
|
|
83
|
+
}
|
|
84
|
+
var CHANGE_COLOR = {
|
|
85
|
+
added: "green",
|
|
86
|
+
dropped: "red",
|
|
87
|
+
altered: "yellow"
|
|
88
|
+
};
|
|
89
|
+
var ROW_COLOR = {
|
|
90
|
+
inserted: "green",
|
|
91
|
+
updated: "yellow",
|
|
92
|
+
deleted: "red",
|
|
93
|
+
conflict: "orange"
|
|
94
|
+
};
|
|
95
|
+
function BranchDiffView({ branch, details, onMerged }) {
|
|
96
|
+
const { t } = useTranslation();
|
|
97
|
+
const apiBase = useApiBase();
|
|
98
|
+
const apiConfig = useApiConfig();
|
|
99
|
+
const snackbar = useSnackbarController();
|
|
100
|
+
const snackbarRef = useRef(snackbar);
|
|
101
|
+
snackbarRef.current = snackbar;
|
|
102
|
+
const [tab, setTab] = useState("schema");
|
|
103
|
+
const [diff, setDiff] = useState(null);
|
|
104
|
+
const [loading, setLoading] = useState(true);
|
|
105
|
+
const [failure, setFailure] = useState(null);
|
|
106
|
+
const [mergeOpen, setMergeOpen] = useState(false);
|
|
107
|
+
const apiConfigRef = useRef(apiConfig);
|
|
108
|
+
apiConfigRef.current = apiConfig;
|
|
109
|
+
const tRef = useRef(t);
|
|
110
|
+
tRef.current = t;
|
|
111
|
+
const token = useCallback(async () => {
|
|
112
|
+
const config = apiConfigRef.current;
|
|
113
|
+
return config?.getAuthToken ? await config.getAuthToken() : null;
|
|
114
|
+
}, []);
|
|
115
|
+
const load = useCallback(async () => {
|
|
116
|
+
if (!apiBase) {
|
|
117
|
+
setLoading(false);
|
|
118
|
+
setFailure(classifyLoadFailure(new Error(tRef.current("studio_branch_diff_no_api"))));
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
setLoading(true);
|
|
122
|
+
try {
|
|
123
|
+
const body = await requestJson(`${apiBase}/admin/branches/${encodeURIComponent(branch.name)}/diff`, { method: "GET" }, await token());
|
|
124
|
+
if (!isBranchDiff(body)) throw new Error(tRef.current("studio_branch_diff_unreadable"));
|
|
125
|
+
setDiff(body);
|
|
126
|
+
setFailure(null);
|
|
127
|
+
} catch (e) {
|
|
128
|
+
setDiff(null);
|
|
129
|
+
setFailure(classifyLoadFailure(e));
|
|
130
|
+
} finally {
|
|
131
|
+
setLoading(false);
|
|
132
|
+
}
|
|
133
|
+
}, [
|
|
134
|
+
apiBase,
|
|
135
|
+
branch.name,
|
|
136
|
+
token
|
|
137
|
+
]);
|
|
138
|
+
useEffect(() => {
|
|
139
|
+
setDiff(null);
|
|
140
|
+
load();
|
|
141
|
+
}, [load]);
|
|
142
|
+
const canMerge = (diff?.data.filter((entry) => entry.inserted + entry.updated + entry.deleted + entry.conflicts > 0) ?? []).some((entry) => !entry.blocked);
|
|
143
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
144
|
+
className: "flex flex-col flex-1 min-h-0",
|
|
145
|
+
children: [
|
|
146
|
+
/* @__PURE__ */ jsxs("div", {
|
|
147
|
+
className: "flex items-end justify-between gap-3 px-5 pt-3",
|
|
148
|
+
children: [/* @__PURE__ */ jsxs(Tabs, {
|
|
149
|
+
value: tab,
|
|
150
|
+
onValueChange: (value) => setTab(value === "data" || value === "details" ? value : "schema"),
|
|
151
|
+
variant: "boxy",
|
|
152
|
+
className: "border-b border-hairline flex-1 min-w-0",
|
|
153
|
+
children: [
|
|
154
|
+
/* @__PURE__ */ jsxs(Tab, {
|
|
155
|
+
value: "schema",
|
|
156
|
+
innerClassName: "flex items-center gap-1.5",
|
|
157
|
+
children: [t("studio_branch_diff_tab_schema"), diff && diff.schema.length > 0 && /* @__PURE__ */ jsx(Chip, {
|
|
158
|
+
size: "smallest",
|
|
159
|
+
children: diff.schema.length
|
|
160
|
+
})]
|
|
161
|
+
}),
|
|
162
|
+
/* @__PURE__ */ jsxs(Tab, {
|
|
163
|
+
value: "data",
|
|
164
|
+
innerClassName: "flex items-center gap-1.5",
|
|
165
|
+
children: [t("studio_branch_diff_tab_data"), diff && diff.data.length > 0 && /* @__PURE__ */ jsx(Chip, {
|
|
166
|
+
size: "smallest",
|
|
167
|
+
children: diff.data.length
|
|
168
|
+
})]
|
|
169
|
+
}),
|
|
170
|
+
/* @__PURE__ */ jsx(Tab, {
|
|
171
|
+
value: "details",
|
|
172
|
+
children: t("studio_branch_diff_tab_details")
|
|
173
|
+
})
|
|
174
|
+
]
|
|
175
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
176
|
+
className: "flex items-center gap-2 pb-1.5 shrink-0",
|
|
177
|
+
children: [/* @__PURE__ */ jsx(IconButton, {
|
|
178
|
+
"aria-label": t("refresh"),
|
|
179
|
+
title: t("refresh"),
|
|
180
|
+
size: "small",
|
|
181
|
+
onClick: () => void load(),
|
|
182
|
+
disabled: loading,
|
|
183
|
+
children: /* @__PURE__ */ jsx(RefreshCwIcon, { size: iconSize.smallest })
|
|
184
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
185
|
+
size: "small",
|
|
186
|
+
color: "primary",
|
|
187
|
+
disabled: !diff || !canMerge || loading,
|
|
188
|
+
onClick: () => setMergeOpen(true),
|
|
189
|
+
startIcon: /* @__PURE__ */ jsx(GitMergeIcon, { size: iconSize.smallest }),
|
|
190
|
+
children: t("studio_branch_diff_merge", { target: branch.parentDatabase })
|
|
191
|
+
})]
|
|
192
|
+
})]
|
|
193
|
+
}),
|
|
194
|
+
/* @__PURE__ */ jsx("div", {
|
|
195
|
+
className: "flex-1 overflow-y-auto px-5 py-4",
|
|
196
|
+
children: tab === "details" ? details : loading && !diff ? /* @__PURE__ */ jsx("div", {
|
|
197
|
+
className: "flex items-center justify-center h-full",
|
|
198
|
+
children: /* @__PURE__ */ jsx(CircularProgress, {})
|
|
199
|
+
}) : failure ? /* @__PURE__ */ jsx(LoadFailureView, {
|
|
200
|
+
failure,
|
|
201
|
+
title: t("studio_branch_diff_failed"),
|
|
202
|
+
deniedTitle: t("studio_branch_diff_denied_title"),
|
|
203
|
+
deniedHint: t("studio_branch_diff_denied_hint"),
|
|
204
|
+
onRetry: () => void load()
|
|
205
|
+
}) : diff ? /* @__PURE__ */ jsxs("div", {
|
|
206
|
+
className: "space-y-4",
|
|
207
|
+
children: [!diff.forkPointKnown && /* @__PURE__ */ jsx(Alert, {
|
|
208
|
+
color: "warning",
|
|
209
|
+
children: /* @__PURE__ */ jsx(Typography, {
|
|
210
|
+
variant: "body2",
|
|
211
|
+
children: t("studio_branch_diff_fork_unknown", { target: diff.targetDatabase })
|
|
212
|
+
})
|
|
213
|
+
}), tab === "schema" ? /* @__PURE__ */ jsx(SchemaChanges, { diff }) : /* @__PURE__ */ jsx(DataChanges, { diff })]
|
|
214
|
+
}) : null
|
|
215
|
+
}),
|
|
216
|
+
diff && /* @__PURE__ */ jsx(MergeDialog, {
|
|
217
|
+
open: mergeOpen,
|
|
218
|
+
diff,
|
|
219
|
+
onClose: () => setMergeOpen(false),
|
|
220
|
+
merge: async (rule, skipBlocked) => {
|
|
221
|
+
if (!apiBase) return;
|
|
222
|
+
try {
|
|
223
|
+
const body = await requestJson(`${apiBase}/admin/branches/${encodeURIComponent(branch.name)}/merge`, {
|
|
224
|
+
method: "POST",
|
|
225
|
+
body: JSON.stringify({
|
|
226
|
+
expectedFingerprint: diff.fingerprint,
|
|
227
|
+
onConflict: rule,
|
|
228
|
+
skipBlocked
|
|
229
|
+
})
|
|
230
|
+
}, await token());
|
|
231
|
+
if (!isMergeResult(body)) throw new Error(t("studio_branch_diff_unreadable"));
|
|
232
|
+
const rows = body.tables.reduce((sum, table) => sum + table.inserted + table.updated + table.deleted, 0);
|
|
233
|
+
snackbarRef.current.open({
|
|
234
|
+
type: "success",
|
|
235
|
+
message: t("studio_branch_diff_merged", {
|
|
236
|
+
count: rows,
|
|
237
|
+
target: body.targetDatabase
|
|
238
|
+
})
|
|
239
|
+
});
|
|
240
|
+
for (const warning of body.warnings) snackbarRef.current.open({
|
|
241
|
+
type: "warning",
|
|
242
|
+
message: warning
|
|
243
|
+
});
|
|
244
|
+
setMergeOpen(false);
|
|
245
|
+
onMerged?.();
|
|
246
|
+
await load();
|
|
247
|
+
} catch (e) {
|
|
248
|
+
if (e instanceof BranchReviewError && e.code === "BRANCH_DIFF_STALE") {
|
|
249
|
+
snackbarRef.current.open({
|
|
250
|
+
type: "warning",
|
|
251
|
+
message: e.message
|
|
252
|
+
});
|
|
253
|
+
setMergeOpen(false);
|
|
254
|
+
await load();
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
throw e;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
})
|
|
261
|
+
]
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
function SchemaChanges({ diff }) {
|
|
265
|
+
const { t } = useTranslation();
|
|
266
|
+
if (diff.schema.length === 0) return /* @__PURE__ */ jsx(EmptyState, { text: t("studio_branch_diff_schema_empty", { target: diff.targetDatabase }) });
|
|
267
|
+
const objectLabel = {
|
|
268
|
+
table: t("studio_branch_diff_object_table"),
|
|
269
|
+
column: t("studio_branch_diff_object_column"),
|
|
270
|
+
policy: t("studio_branch_diff_object_policy"),
|
|
271
|
+
rls: t("studio_branch_diff_object_rls"),
|
|
272
|
+
constraint: t("studio_branch_diff_object_constraint"),
|
|
273
|
+
index: t("studio_branch_diff_object_index"),
|
|
274
|
+
trigger: t("studio_branch_diff_object_trigger"),
|
|
275
|
+
enum: t("studio_branch_diff_object_enum"),
|
|
276
|
+
view: t("studio_branch_diff_object_view"),
|
|
277
|
+
function: t("studio_branch_diff_object_function")
|
|
278
|
+
};
|
|
279
|
+
const changeLabel = {
|
|
280
|
+
added: t("studio_branch_diff_change_added"),
|
|
281
|
+
dropped: t("studio_branch_diff_change_dropped"),
|
|
282
|
+
altered: t("studio_branch_diff_change_altered")
|
|
283
|
+
};
|
|
284
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
285
|
+
className: "space-y-3",
|
|
286
|
+
children: [/* @__PURE__ */ jsx(Typography, {
|
|
287
|
+
variant: "body2",
|
|
288
|
+
color: "secondary",
|
|
289
|
+
children: t("studio_branch_diff_schema_not_merged")
|
|
290
|
+
}), diff.schema.map((change, index) => /* @__PURE__ */ jsxs("div", {
|
|
291
|
+
className: cls("rounded-xl border bg-surface-card overflow-hidden", defaultBorderMixin),
|
|
292
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
293
|
+
className: "flex items-center gap-2 px-3 py-2 min-w-0",
|
|
294
|
+
children: [
|
|
295
|
+
/* @__PURE__ */ jsx(Chip, {
|
|
296
|
+
size: "smallest",
|
|
297
|
+
colorScheme: CHANGE_COLOR[change.change],
|
|
298
|
+
children: changeLabel[change.change]
|
|
299
|
+
}),
|
|
300
|
+
/* @__PURE__ */ jsx(Typography, {
|
|
301
|
+
variant: "caption",
|
|
302
|
+
color: "secondary",
|
|
303
|
+
className: "shrink-0",
|
|
304
|
+
children: objectLabel[change.object]
|
|
305
|
+
}),
|
|
306
|
+
/* @__PURE__ */ jsx(Typography, {
|
|
307
|
+
variant: "body2",
|
|
308
|
+
className: "font-mono text-[12px] truncate",
|
|
309
|
+
children: `${change.schema}.${change.table}${change.name ? `.${change.name}` : ""}`
|
|
310
|
+
})
|
|
311
|
+
]
|
|
312
|
+
}), /* @__PURE__ */ jsx(SplitDiff, {
|
|
313
|
+
before: change.before,
|
|
314
|
+
after: change.after,
|
|
315
|
+
targetLabel: diff.targetDatabase,
|
|
316
|
+
branchLabel: diff.branchDatabase
|
|
317
|
+
})]
|
|
318
|
+
}, index))]
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
function SplitDiff({ before, after, targetLabel, branchLabel }) {
|
|
322
|
+
const rows = useMemo(() => splitLineDiff(before, after), [before, after]);
|
|
323
|
+
const line = "font-mono text-[12px] leading-5 whitespace-pre-wrap break-all px-3 min-h-5";
|
|
324
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
325
|
+
className: cls("grid grid-cols-2 border-t", defaultBorderMixin),
|
|
326
|
+
children: [
|
|
327
|
+
/* @__PURE__ */ jsx(Typography, {
|
|
328
|
+
variant: "caption",
|
|
329
|
+
color: "secondary",
|
|
330
|
+
className: cls("px-3 py-1 border-b border-r font-mono", defaultBorderMixin),
|
|
331
|
+
children: targetLabel
|
|
332
|
+
}),
|
|
333
|
+
/* @__PURE__ */ jsx(Typography, {
|
|
334
|
+
variant: "caption",
|
|
335
|
+
color: "secondary",
|
|
336
|
+
className: cls("px-3 py-1 border-b font-mono", defaultBorderMixin),
|
|
337
|
+
children: branchLabel
|
|
338
|
+
}),
|
|
339
|
+
rows.map((row, index) => /* @__PURE__ */ jsxs(React.Fragment, { children: [/* @__PURE__ */ jsx(Typography, {
|
|
340
|
+
component: "div",
|
|
341
|
+
variant: "body2",
|
|
342
|
+
className: cls(line, "border-r", defaultBorderMixin, row.left === null ? "bg-surface-field" : !row.same && "bg-red-500/10 text-red-700 dark:text-red-300"),
|
|
343
|
+
children: row.left ?? ""
|
|
344
|
+
}), /* @__PURE__ */ jsx(Typography, {
|
|
345
|
+
component: "div",
|
|
346
|
+
variant: "body2",
|
|
347
|
+
className: cls(line, row.right === null ? "bg-surface-field" : !row.same && "bg-emerald-500/10 text-emerald-700 dark:text-emerald-300"),
|
|
348
|
+
children: row.right ?? ""
|
|
349
|
+
})] }, index))
|
|
350
|
+
]
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
/** `public.posts (ON DELETE CASCADE, 1)`, for each foreign key into a row the branch deleted. */
|
|
354
|
+
function referencingText(found) {
|
|
355
|
+
return found.map((entry) => `${entry.schema}.${entry.table} (ON DELETE ${entry.onDelete.toUpperCase()}, ${entry.rows})`).join(", ");
|
|
356
|
+
}
|
|
357
|
+
/** Every foreign key, across the diff, through which the target's newer rows reference a row the branch deleted. */
|
|
358
|
+
function referencingRows(entries) {
|
|
359
|
+
return entries.flatMap((entry) => entry.referencedBy ?? []);
|
|
360
|
+
}
|
|
361
|
+
function DataChanges({ diff }) {
|
|
362
|
+
const { t } = useTranslation();
|
|
363
|
+
if (diff.data.length === 0) return /* @__PURE__ */ jsx(EmptyState, { text: t("studio_branch_diff_data_empty", { target: diff.targetDatabase }) });
|
|
364
|
+
const reached = /* @__PURE__ */ new Map();
|
|
365
|
+
for (const found of referencingRows(diff.data)) {
|
|
366
|
+
const key = `${found.schema}.${found.table}`;
|
|
367
|
+
reached.set(key, (reached.get(key) ?? 0) + found.rows);
|
|
368
|
+
}
|
|
369
|
+
return /* @__PURE__ */ jsx("div", {
|
|
370
|
+
className: "space-y-5",
|
|
371
|
+
children: diff.data.map((entry) => /* @__PURE__ */ jsx(TableChanges, {
|
|
372
|
+
entry,
|
|
373
|
+
target: diff.targetDatabase,
|
|
374
|
+
reached: reached.get(`${entry.schema}.${entry.table}`) ?? 0
|
|
375
|
+
}, `${entry.schema}.${entry.table}`))
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
function TableChanges({ entry, target, reached }) {
|
|
379
|
+
const { t } = useTranslation();
|
|
380
|
+
const rowLabel = {
|
|
381
|
+
inserted: t("studio_branch_diff_row_inserted"),
|
|
382
|
+
updated: t("studio_branch_diff_row_updated"),
|
|
383
|
+
deleted: t("studio_branch_diff_row_deleted"),
|
|
384
|
+
conflict: t("studio_branch_diff_row_conflict")
|
|
385
|
+
};
|
|
386
|
+
const total = entry.inserted + entry.updated + entry.deleted + entry.conflicts;
|
|
387
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
388
|
+
className: "space-y-2",
|
|
389
|
+
children: [
|
|
390
|
+
/* @__PURE__ */ jsxs("div", {
|
|
391
|
+
className: "flex flex-wrap items-center gap-2 min-w-0",
|
|
392
|
+
children: [
|
|
393
|
+
/* @__PURE__ */ jsx(Typography, {
|
|
394
|
+
variant: "subtitle2",
|
|
395
|
+
className: "font-mono truncate",
|
|
396
|
+
children: `${entry.schema}.${entry.table}`
|
|
397
|
+
}),
|
|
398
|
+
entry.collection && /* @__PURE__ */ jsx(Chip, {
|
|
399
|
+
size: "smallest",
|
|
400
|
+
children: entry.collection
|
|
401
|
+
}),
|
|
402
|
+
entry.inserted > 0 && /* @__PURE__ */ jsx(Chip, {
|
|
403
|
+
size: "smallest",
|
|
404
|
+
colorScheme: "green",
|
|
405
|
+
children: `+${entry.inserted} ${rowLabel.inserted}`
|
|
406
|
+
}),
|
|
407
|
+
entry.updated > 0 && /* @__PURE__ */ jsx(Chip, {
|
|
408
|
+
size: "smallest",
|
|
409
|
+
colorScheme: "yellow",
|
|
410
|
+
children: `~${entry.updated} ${rowLabel.updated}`
|
|
411
|
+
}),
|
|
412
|
+
entry.deleted > 0 && /* @__PURE__ */ jsx(Chip, {
|
|
413
|
+
size: "smallest",
|
|
414
|
+
colorScheme: "red",
|
|
415
|
+
children: `−${entry.deleted} ${rowLabel.deleted}`
|
|
416
|
+
}),
|
|
417
|
+
entry.conflicts > 0 && /* @__PURE__ */ jsx(Chip, {
|
|
418
|
+
size: "smallest",
|
|
419
|
+
colorScheme: "orange",
|
|
420
|
+
children: t("studio_branch_diff_conflicts", { count: entry.conflicts })
|
|
421
|
+
})
|
|
422
|
+
]
|
|
423
|
+
}),
|
|
424
|
+
entry.targetChanges > 0 && /* @__PURE__ */ jsx(Typography, {
|
|
425
|
+
variant: "caption",
|
|
426
|
+
color: "secondary",
|
|
427
|
+
className: "block",
|
|
428
|
+
children: reached > 0 ? t("studio_branch_diff_target_changes_referencing", {
|
|
429
|
+
count: entry.targetChanges,
|
|
430
|
+
reached: Math.min(reached, entry.targetChanges),
|
|
431
|
+
target
|
|
432
|
+
}) : t("studio_branch_diff_target_changes", {
|
|
433
|
+
count: entry.targetChanges,
|
|
434
|
+
target
|
|
435
|
+
})
|
|
436
|
+
}),
|
|
437
|
+
entry.referencedBy && entry.referencedBy.length > 0 && /* @__PURE__ */ jsx(Typography, {
|
|
438
|
+
variant: "caption",
|
|
439
|
+
color: "secondary",
|
|
440
|
+
className: "block",
|
|
441
|
+
children: t("studio_branch_diff_referenced_by", {
|
|
442
|
+
target,
|
|
443
|
+
tables: referencingText(entry.referencedBy)
|
|
444
|
+
})
|
|
445
|
+
}),
|
|
446
|
+
entry.blocked && /* @__PURE__ */ jsxs(Alert, {
|
|
447
|
+
color: "warning",
|
|
448
|
+
children: [/* @__PURE__ */ jsx(Typography, {
|
|
449
|
+
variant: "body2",
|
|
450
|
+
children: entry.blocked.message
|
|
451
|
+
}), entry.rowCounts && /* @__PURE__ */ jsx(Typography, {
|
|
452
|
+
variant: "caption",
|
|
453
|
+
color: "secondary",
|
|
454
|
+
className: "block mt-1",
|
|
455
|
+
children: t("studio_branch_diff_row_counts", {
|
|
456
|
+
target,
|
|
457
|
+
targetCount: entry.rowCounts.target,
|
|
458
|
+
branchCount: entry.rowCounts.branch
|
|
459
|
+
})
|
|
460
|
+
})]
|
|
461
|
+
}),
|
|
462
|
+
entry.samples.length > 0 && /* @__PURE__ */ jsx("div", {
|
|
463
|
+
className: cls("rounded-xl border overflow-hidden", defaultBorderMixin),
|
|
464
|
+
children: /* @__PURE__ */ jsxs(Table, {
|
|
465
|
+
className: "w-full",
|
|
466
|
+
children: [/* @__PURE__ */ jsxs(TableHeader, { children: [
|
|
467
|
+
/* @__PURE__ */ jsx(TableCell, {
|
|
468
|
+
header: true,
|
|
469
|
+
className: "w-28",
|
|
470
|
+
children: t("studio_branch_diff_column_change")
|
|
471
|
+
}),
|
|
472
|
+
/* @__PURE__ */ jsx(TableCell, {
|
|
473
|
+
header: true,
|
|
474
|
+
className: "w-32",
|
|
475
|
+
children: t("studio_branch_diff_column_key")
|
|
476
|
+
}),
|
|
477
|
+
/* @__PURE__ */ jsx(TableCell, {
|
|
478
|
+
header: true,
|
|
479
|
+
children: t("studio_branch_diff_column_values")
|
|
480
|
+
})
|
|
481
|
+
] }), /* @__PURE__ */ jsx(TableBody, { children: entry.samples.map((sample) => /* @__PURE__ */ jsxs(TableRow, { children: [
|
|
482
|
+
/* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(Chip, {
|
|
483
|
+
size: "smallest",
|
|
484
|
+
colorScheme: ROW_COLOR[sample.change],
|
|
485
|
+
children: rowLabel[sample.change]
|
|
486
|
+
}) }),
|
|
487
|
+
/* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(Typography, {
|
|
488
|
+
variant: "body2",
|
|
489
|
+
className: "font-mono text-[12px] break-all",
|
|
490
|
+
children: keyText(sample.key)
|
|
491
|
+
}) }),
|
|
492
|
+
/* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(RowValues, { sample }) })
|
|
493
|
+
] }, `${sample.change}:${sample.key}`)) })]
|
|
494
|
+
})
|
|
495
|
+
}),
|
|
496
|
+
total > entry.samples.length && entry.samples.length > 0 && /* @__PURE__ */ jsx(Typography, {
|
|
497
|
+
variant: "caption",
|
|
498
|
+
color: "disabled",
|
|
499
|
+
className: "block",
|
|
500
|
+
children: t("studio_branch_diff_samples_shown", {
|
|
501
|
+
shown: entry.samples.length,
|
|
502
|
+
total
|
|
503
|
+
})
|
|
504
|
+
})
|
|
505
|
+
]
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
/** `[42]` → `42`; a composite key keeps its commas. */
|
|
509
|
+
function keyText(key) {
|
|
510
|
+
return key.startsWith("[") && key.endsWith("]") ? key.slice(1, -1) : key;
|
|
511
|
+
}
|
|
512
|
+
var VALUES_SHOWN = 8;
|
|
513
|
+
function RowValues({ sample }) {
|
|
514
|
+
const mono = "font-mono text-[12px] break-all";
|
|
515
|
+
if (sample.change === "updated" || sample.change === "conflict" && sample.after) return /* @__PURE__ */ jsx("div", {
|
|
516
|
+
className: "space-y-0.5",
|
|
517
|
+
children: (sample.changedColumns ?? []).map((column) => /* @__PURE__ */ jsxs(Typography, {
|
|
518
|
+
variant: "body2",
|
|
519
|
+
className: mono,
|
|
520
|
+
children: [
|
|
521
|
+
/* @__PURE__ */ jsxs("span", {
|
|
522
|
+
className: "text-text-secondary dark:text-text-secondary-dark",
|
|
523
|
+
children: [column, ": "]
|
|
524
|
+
}),
|
|
525
|
+
/* @__PURE__ */ jsx("span", {
|
|
526
|
+
className: "bg-red-500/10 text-red-700 dark:text-red-300 rounded-md px-1",
|
|
527
|
+
children: display(sample.before?.[column])
|
|
528
|
+
}),
|
|
529
|
+
" → ",
|
|
530
|
+
/* @__PURE__ */ jsx("span", {
|
|
531
|
+
className: "bg-emerald-500/10 text-emerald-700 dark:text-emerald-300 rounded-md px-1",
|
|
532
|
+
children: display(sample.after?.[column])
|
|
533
|
+
})
|
|
534
|
+
]
|
|
535
|
+
}, column))
|
|
536
|
+
});
|
|
537
|
+
const values = Object.entries((sample.change === "inserted" ? sample.after : sample.before) ?? {});
|
|
538
|
+
return /* @__PURE__ */ jsxs(Typography, {
|
|
539
|
+
variant: "body2",
|
|
540
|
+
className: cls(mono, "text-text-secondary dark:text-text-secondary-dark"),
|
|
541
|
+
children: [values.slice(0, VALUES_SHOWN).map(([column, value]) => `${column}=${display(value)}`).join(" "), values.length > VALUES_SHOWN ? " …" : ""]
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
function display(value) {
|
|
545
|
+
if (value === null || value === void 0) return "NULL";
|
|
546
|
+
return value.length > 80 ? `${value.slice(0, 80)}…` : value;
|
|
547
|
+
}
|
|
548
|
+
function EmptyState({ text }) {
|
|
549
|
+
return /* @__PURE__ */ jsx("div", {
|
|
550
|
+
className: "flex items-center justify-center py-16",
|
|
551
|
+
children: /* @__PURE__ */ jsx(Typography, {
|
|
552
|
+
variant: "body2",
|
|
553
|
+
color: "disabled",
|
|
554
|
+
children: text
|
|
555
|
+
})
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
function MergeDialog({ open, diff, onClose, merge }) {
|
|
559
|
+
const { t } = useTranslation();
|
|
560
|
+
const [rule, setRule] = useState("abort");
|
|
561
|
+
const [skipBlocked, setSkipBlocked] = useState(false);
|
|
562
|
+
const [merging, setMerging] = useState(false);
|
|
563
|
+
const [error, setError] = useState(null);
|
|
564
|
+
useEffect(() => {
|
|
565
|
+
if (!open) return;
|
|
566
|
+
setRule("abort");
|
|
567
|
+
setSkipBlocked(false);
|
|
568
|
+
setError(null);
|
|
569
|
+
}, [open, diff.fingerprint]);
|
|
570
|
+
const mergeable = diff.data.filter((entry) => !entry.blocked);
|
|
571
|
+
const blocked = diff.data.filter((entry) => entry.blocked);
|
|
572
|
+
const sum = (key) => mergeable.reduce((total, entry) => total + entry[key], 0);
|
|
573
|
+
const conflicts = sum("conflicts");
|
|
574
|
+
const targetChanges = sum("targetChanges");
|
|
575
|
+
const target = diff.targetDatabase;
|
|
576
|
+
const referencing = referencingRows(mergeable);
|
|
577
|
+
const reached = referencing.reduce((total, found) => total + found.rows, 0);
|
|
578
|
+
const referencingTables = referencingText(referencing);
|
|
579
|
+
const ready = (conflicts === 0 || rule !== "abort") && (blocked.length === 0 || skipBlocked);
|
|
580
|
+
return /* @__PURE__ */ jsxs(Dialog, {
|
|
581
|
+
open,
|
|
582
|
+
onOpenChange: (next) => {
|
|
583
|
+
if (!next && !merging) onClose();
|
|
584
|
+
},
|
|
585
|
+
children: [
|
|
586
|
+
/* @__PURE__ */ jsx(DialogTitle, { children: t("studio_branch_diff_merge_title", {
|
|
587
|
+
branch: diff.branch,
|
|
588
|
+
target
|
|
589
|
+
}) }),
|
|
590
|
+
/* @__PURE__ */ jsxs(DialogContent, {
|
|
591
|
+
className: "space-y-4 sm:min-w-[420px] max-w-[560px]",
|
|
592
|
+
children: [
|
|
593
|
+
/* @__PURE__ */ jsx(Typography, {
|
|
594
|
+
variant: "body2",
|
|
595
|
+
children: t("studio_branch_diff_merge_writes", {
|
|
596
|
+
inserted: sum("inserted"),
|
|
597
|
+
updated: sum("updated"),
|
|
598
|
+
deleted: sum("deleted"),
|
|
599
|
+
target
|
|
600
|
+
})
|
|
601
|
+
}),
|
|
602
|
+
rule === "branch" && reached > 0 ? /* @__PURE__ */ jsx(Alert, {
|
|
603
|
+
color: "warning",
|
|
604
|
+
children: /* @__PURE__ */ jsx(Typography, {
|
|
605
|
+
variant: "body2",
|
|
606
|
+
children: t("studio_branch_diff_merge_referenced_reached", {
|
|
607
|
+
count: reached,
|
|
608
|
+
target,
|
|
609
|
+
tables: referencingTables
|
|
610
|
+
})
|
|
611
|
+
})
|
|
612
|
+
}) : /* @__PURE__ */ jsx(Typography, {
|
|
613
|
+
variant: "body2",
|
|
614
|
+
color: "secondary",
|
|
615
|
+
children: targetChanges > 0 ? t("studio_branch_diff_merge_target_kept_count", {
|
|
616
|
+
count: targetChanges,
|
|
617
|
+
target
|
|
618
|
+
}) : t("studio_branch_diff_merge_target_kept", { target })
|
|
619
|
+
}),
|
|
620
|
+
diff.schema.length > 0 && /* @__PURE__ */ jsx(Typography, {
|
|
621
|
+
variant: "body2",
|
|
622
|
+
color: "secondary",
|
|
623
|
+
children: t("studio_branch_diff_merge_schema_skipped", { count: diff.schema.length })
|
|
624
|
+
}),
|
|
625
|
+
conflicts > 0 && /* @__PURE__ */ jsxs("div", {
|
|
626
|
+
className: "space-y-2",
|
|
627
|
+
children: [
|
|
628
|
+
/* @__PURE__ */ jsx(Typography, {
|
|
629
|
+
variant: "body2",
|
|
630
|
+
className: "font-medium",
|
|
631
|
+
children: t("studio_branch_diff_merge_conflicts", { count: conflicts })
|
|
632
|
+
}),
|
|
633
|
+
reached > 0 && /* @__PURE__ */ jsx(Typography, {
|
|
634
|
+
variant: "body2",
|
|
635
|
+
color: "secondary",
|
|
636
|
+
children: t("studio_branch_diff_merge_referenced_conflicts", {
|
|
637
|
+
count: reached,
|
|
638
|
+
target,
|
|
639
|
+
tables: referencingTables
|
|
640
|
+
})
|
|
641
|
+
}),
|
|
642
|
+
/* @__PURE__ */ jsx(RadioGroup, {
|
|
643
|
+
value: rule,
|
|
644
|
+
onValueChange: (value) => setRule(value === "branch" || value === "target" ? value : "abort"),
|
|
645
|
+
children: [
|
|
646
|
+
["abort", t("studio_branch_diff_conflict_abort")],
|
|
647
|
+
["branch", t("studio_branch_diff_conflict_branch", { branch: diff.branch })],
|
|
648
|
+
["target", t("studio_branch_diff_conflict_target", { target })]
|
|
649
|
+
].map(([value, label]) => /* @__PURE__ */ jsxs("div", {
|
|
650
|
+
className: "flex items-center gap-2",
|
|
651
|
+
children: [/* @__PURE__ */ jsx(RadioGroupItem, {
|
|
652
|
+
id: `merge-conflict-${value}`,
|
|
653
|
+
value
|
|
654
|
+
}), /* @__PURE__ */ jsx(Label, {
|
|
655
|
+
htmlFor: `merge-conflict-${value}`,
|
|
656
|
+
children: label
|
|
657
|
+
})]
|
|
658
|
+
}, value))
|
|
659
|
+
})
|
|
660
|
+
]
|
|
661
|
+
}),
|
|
662
|
+
blocked.length > 0 && /* @__PURE__ */ jsxs(Alert, {
|
|
663
|
+
color: "warning",
|
|
664
|
+
children: [
|
|
665
|
+
/* @__PURE__ */ jsx(Typography, {
|
|
666
|
+
variant: "body2",
|
|
667
|
+
children: t("studio_branch_diff_merge_blocked", { count: blocked.length })
|
|
668
|
+
}),
|
|
669
|
+
/* @__PURE__ */ jsx("div", {
|
|
670
|
+
className: "mt-1 space-y-0.5",
|
|
671
|
+
children: blocked.map((entry) => /* @__PURE__ */ jsxs(Typography, {
|
|
672
|
+
variant: "caption",
|
|
673
|
+
className: "block",
|
|
674
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
675
|
+
className: "font-mono",
|
|
676
|
+
children: `${entry.schema}.${entry.table}`
|
|
677
|
+
}), ` — ${entry.blocked?.message ?? ""}`]
|
|
678
|
+
}, `${entry.schema}.${entry.table}`))
|
|
679
|
+
}),
|
|
680
|
+
/* @__PURE__ */ jsxs("div", {
|
|
681
|
+
className: "flex items-center gap-2 mt-2",
|
|
682
|
+
children: [/* @__PURE__ */ jsx(Checkbox, {
|
|
683
|
+
id: "merge-skip-blocked",
|
|
684
|
+
checked: skipBlocked,
|
|
685
|
+
onCheckedChange: setSkipBlocked,
|
|
686
|
+
size: "small"
|
|
687
|
+
}), /* @__PURE__ */ jsx(Label, {
|
|
688
|
+
htmlFor: "merge-skip-blocked",
|
|
689
|
+
children: t("studio_branch_diff_merge_skip_blocked")
|
|
690
|
+
})]
|
|
691
|
+
})
|
|
692
|
+
]
|
|
693
|
+
}),
|
|
694
|
+
/* @__PURE__ */ jsx(Typography, {
|
|
695
|
+
variant: "caption",
|
|
696
|
+
color: "secondary",
|
|
697
|
+
className: "block",
|
|
698
|
+
children: t("studio_branch_diff_merge_atomic", { target })
|
|
699
|
+
}),
|
|
700
|
+
error && /* @__PURE__ */ jsx(Alert, {
|
|
701
|
+
color: "error",
|
|
702
|
+
children: /* @__PURE__ */ jsx(Typography, {
|
|
703
|
+
variant: "body2",
|
|
704
|
+
children: error
|
|
705
|
+
})
|
|
706
|
+
})
|
|
707
|
+
]
|
|
708
|
+
}),
|
|
709
|
+
/* @__PURE__ */ jsxs(DialogActions, { children: [/* @__PURE__ */ jsx(Button, {
|
|
710
|
+
variant: "text",
|
|
711
|
+
onClick: onClose,
|
|
712
|
+
disabled: merging,
|
|
713
|
+
children: t("cancel")
|
|
714
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
715
|
+
color: "primary",
|
|
716
|
+
disabled: !ready || merging,
|
|
717
|
+
startIcon: merging ? /* @__PURE__ */ jsx(CircularProgress, { size: "smallest" }) : /* @__PURE__ */ jsx(GitMergeIcon, { size: iconSize.smallest }),
|
|
718
|
+
onClick: async () => {
|
|
719
|
+
setMerging(true);
|
|
720
|
+
setError(null);
|
|
721
|
+
try {
|
|
722
|
+
await merge(rule, skipBlocked);
|
|
723
|
+
} catch (e) {
|
|
724
|
+
setError(e instanceof Error ? e.message : String(e));
|
|
725
|
+
} finally {
|
|
726
|
+
setMerging(false);
|
|
727
|
+
}
|
|
728
|
+
},
|
|
729
|
+
children: t("studio_branch_diff_merge_confirm")
|
|
730
|
+
})] })
|
|
731
|
+
]
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
//#endregion
|
|
735
|
+
//#region src/components/Branches/BranchesView.tsx
|
|
736
|
+
/**
|
|
737
|
+
* The prefix the driver puts on every branch database.
|
|
738
|
+
*
|
|
739
|
+
* Stated here rather than derived from the row, because `BranchInfo` carries
|
|
740
|
+
* the *name* a person typed and not the database it became — and the detail
|
|
741
|
+
* pane used to print the name under "Database:", which is a connection string
|
|
742
|
+
* to nothing. Kept in step with `BranchService.BRANCH_DB_PREFIX` and the CLI's
|
|
743
|
+
* `branch-pointer.ts`, which say the same thing for the same reason.
|
|
744
|
+
*/
|
|
745
|
+
var BRANCH_DB_PREFIX = "rb_";
|
|
746
|
+
function formatSize(bytes) {
|
|
747
|
+
if (bytes === void 0 || bytes === null) return "—";
|
|
748
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
749
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
750
|
+
if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
751
|
+
return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
|
|
752
|
+
}
|
|
753
|
+
function formatRelative(date) {
|
|
754
|
+
if (!date) return "—";
|
|
755
|
+
const d = date instanceof Date ? date : new Date(date);
|
|
756
|
+
if (isNaN(d.getTime())) return "—";
|
|
757
|
+
return formatRelativeTime(d) ?? d.toLocaleDateString();
|
|
758
|
+
}
|
|
759
|
+
function BranchesView() {
|
|
760
|
+
const { databaseAdmin } = useRebaseContext();
|
|
761
|
+
const snackbar = useSnackbarController();
|
|
762
|
+
const { t } = useTranslation();
|
|
763
|
+
const [branches, setBranches] = useState([]);
|
|
764
|
+
const [loading, setLoading] = useState(true);
|
|
765
|
+
const [selectedBranch, setSelectedBranch] = useState(null);
|
|
766
|
+
const [createOpen, setCreateOpen] = useState(false);
|
|
767
|
+
const [newBranchName, setNewBranchName] = useState("");
|
|
768
|
+
/**
|
|
769
|
+
* The database to copy, when it is not the main one: a branch's own
|
|
770
|
+
* database, which is not its name.
|
|
771
|
+
*/
|
|
772
|
+
const [sourceDatabase, setSourceDatabase] = useState(void 0);
|
|
773
|
+
const [creating, setCreating] = useState(false);
|
|
774
|
+
/**
|
|
775
|
+
* Why the last create attempt was refused, kept on screen.
|
|
776
|
+
*
|
|
777
|
+
* The server refuses branching outright on the managed development
|
|
778
|
+
* database — PGlite serves one database, so the "branch" would be the
|
|
779
|
+
* parent. That refusal is the whole answer to what the reader just tried to
|
|
780
|
+
* do, and a snackbar is gone in four seconds; the same argument
|
|
781
|
+
* `load-failure.ts` makes for listings.
|
|
782
|
+
*/
|
|
783
|
+
const [createError, setCreateError] = useState(null);
|
|
784
|
+
const [deleteTarget, setDeleteTarget] = useState(null);
|
|
785
|
+
const [deleting, setDeleting] = useState(false);
|
|
786
|
+
/** Why the branch listing failed, classified — see `load-failure.ts`. */
|
|
787
|
+
const [failure, setFailure] = useState(null);
|
|
788
|
+
const snackbarRef = useRef(snackbar);
|
|
789
|
+
snackbarRef.current = snackbar;
|
|
790
|
+
const branchAdmin = isBranchAdmin(databaseAdmin) ? databaseAdmin : void 0;
|
|
791
|
+
const loadBranches = useCallback(async () => {
|
|
792
|
+
if (!branchAdmin) {
|
|
793
|
+
setLoading(false);
|
|
794
|
+
return;
|
|
795
|
+
}
|
|
796
|
+
try {
|
|
797
|
+
const result = await branchAdmin.listBranches();
|
|
798
|
+
setBranches(result);
|
|
799
|
+
setFailure(null);
|
|
800
|
+
} catch (e) {
|
|
801
|
+
setFailure(classifyLoadFailure(e));
|
|
802
|
+
} finally {
|
|
803
|
+
setLoading(false);
|
|
804
|
+
}
|
|
805
|
+
}, [branchAdmin]);
|
|
806
|
+
useEffect(() => {
|
|
807
|
+
loadBranches();
|
|
808
|
+
}, [loadBranches]);
|
|
809
|
+
const handleCreate = async () => {
|
|
810
|
+
if (!branchAdmin || !newBranchName.trim()) return;
|
|
811
|
+
setCreating(true);
|
|
812
|
+
setCreateError(null);
|
|
813
|
+
try {
|
|
814
|
+
await branchAdmin.createBranch(newBranchName.trim(), sourceDatabase ? { source: sourceDatabase } : void 0);
|
|
815
|
+
snackbarRef.current.open({
|
|
816
|
+
type: "success",
|
|
817
|
+
message: t("studio_branches_created_snackbar", { name: newBranchName.trim() })
|
|
818
|
+
});
|
|
819
|
+
setCreateOpen(false);
|
|
820
|
+
setNewBranchName("");
|
|
821
|
+
setSourceDatabase(void 0);
|
|
822
|
+
await loadBranches();
|
|
823
|
+
} catch (e) {
|
|
824
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
825
|
+
setCreateError(message);
|
|
826
|
+
snackbarRef.current.open({
|
|
827
|
+
type: "error",
|
|
828
|
+
message
|
|
829
|
+
});
|
|
830
|
+
} finally {
|
|
831
|
+
setCreating(false);
|
|
832
|
+
}
|
|
833
|
+
};
|
|
834
|
+
const handleDelete = async () => {
|
|
835
|
+
if (!branchAdmin || !deleteTarget) return;
|
|
836
|
+
setDeleting(true);
|
|
837
|
+
try {
|
|
838
|
+
await branchAdmin.deleteBranch(deleteTarget);
|
|
839
|
+
snackbarRef.current.open({
|
|
840
|
+
type: "success",
|
|
841
|
+
message: t("studio_branches_deleted_snackbar", { name: deleteTarget })
|
|
842
|
+
});
|
|
843
|
+
if (selectedBranch === deleteTarget) setSelectedBranch(null);
|
|
844
|
+
setDeleteTarget(null);
|
|
845
|
+
await loadBranches();
|
|
846
|
+
} catch (e) {
|
|
847
|
+
snackbarRef.current.open({
|
|
848
|
+
type: "error",
|
|
849
|
+
message: e instanceof Error ? e.message : String(e)
|
|
850
|
+
});
|
|
851
|
+
} finally {
|
|
852
|
+
setDeleting(false);
|
|
853
|
+
}
|
|
854
|
+
};
|
|
855
|
+
if (!branchAdmin) return /* @__PURE__ */ jsxs("div", {
|
|
856
|
+
className: "flex flex-col items-center justify-center h-full gap-4 text-center p-8",
|
|
857
|
+
children: [
|
|
858
|
+
/* @__PURE__ */ jsx(GitBranchIcon, {
|
|
859
|
+
size: iconSize.large,
|
|
860
|
+
className: "text-surface-300 dark:text-surface-600"
|
|
861
|
+
}),
|
|
862
|
+
/* @__PURE__ */ jsx(Typography, {
|
|
863
|
+
variant: "h6",
|
|
864
|
+
color: "secondary",
|
|
865
|
+
children: t("studio_branches_unavailable_title")
|
|
866
|
+
}),
|
|
867
|
+
/* @__PURE__ */ jsx(Typography, {
|
|
868
|
+
variant: "body2",
|
|
869
|
+
color: "disabled",
|
|
870
|
+
className: "max-w-md",
|
|
871
|
+
children: t("studio_branches_unavailable_body")
|
|
872
|
+
}),
|
|
873
|
+
/* @__PURE__ */ jsx("a", {
|
|
874
|
+
href: "https://rebase.pro/docs/backend/branching",
|
|
875
|
+
target: "_blank",
|
|
876
|
+
rel: "noreferrer",
|
|
877
|
+
className: "text-primary text-sm underline",
|
|
878
|
+
children: t("studio_read_the_docs")
|
|
879
|
+
})
|
|
880
|
+
]
|
|
881
|
+
});
|
|
882
|
+
if (loading) return /* @__PURE__ */ jsx("div", {
|
|
883
|
+
className: "flex items-center justify-center h-full",
|
|
884
|
+
children: /* @__PURE__ */ jsx(CircularProgress, {})
|
|
885
|
+
});
|
|
886
|
+
const selected = branches.find((b) => b.name === selectedBranch);
|
|
887
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
888
|
+
className: "flex h-full w-full overflow-hidden bg-surface-card",
|
|
889
|
+
children: [
|
|
890
|
+
/* @__PURE__ */ jsxs("div", {
|
|
891
|
+
className: cls("flex flex-col w-[340px] min-w-[280px] border-r h-full", defaultBorderMixin),
|
|
892
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
893
|
+
className: cls("flex items-center justify-between px-4 py-2.5 border-b bg-surface-sheet min-h-[48px]", defaultBorderMixin),
|
|
894
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
895
|
+
className: "flex items-center gap-2",
|
|
896
|
+
children: [
|
|
897
|
+
/* @__PURE__ */ jsx(GitBranchIcon, {
|
|
898
|
+
size: iconSize.small,
|
|
899
|
+
className: "text-primary"
|
|
900
|
+
}),
|
|
901
|
+
/* @__PURE__ */ jsx(Typography, {
|
|
902
|
+
variant: "subtitle2",
|
|
903
|
+
className: "font-semibold",
|
|
904
|
+
children: t("studio_tool_branches")
|
|
905
|
+
}),
|
|
906
|
+
/* @__PURE__ */ jsx(Chip, {
|
|
907
|
+
size: "smallest",
|
|
908
|
+
className: "bg-surface-raised text-surface-600 dark:text-surface-300",
|
|
909
|
+
children: branches.length
|
|
910
|
+
})
|
|
911
|
+
]
|
|
912
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
913
|
+
className: "flex items-center gap-1",
|
|
914
|
+
children: [/* @__PURE__ */ jsx(IconButton, {
|
|
915
|
+
"aria-label": t("refresh"),
|
|
916
|
+
size: "small",
|
|
917
|
+
onClick: loadBranches,
|
|
918
|
+
title: t("refresh"),
|
|
919
|
+
children: /* @__PURE__ */ jsx(RefreshCwIcon, { size: iconSize.smallest })
|
|
920
|
+
}), /* @__PURE__ */ jsx(IconButton, {
|
|
921
|
+
"aria-label": t("create_branch"),
|
|
922
|
+
size: "small",
|
|
923
|
+
onClick: () => setCreateOpen(true),
|
|
924
|
+
title: t("create_branch"),
|
|
925
|
+
className: "text-primary",
|
|
926
|
+
children: /* @__PURE__ */ jsx(PlusIcon, { size: iconSize.smallest })
|
|
927
|
+
})]
|
|
928
|
+
})]
|
|
929
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
930
|
+
className: "flex-1 overflow-y-auto p-2 space-y-1",
|
|
931
|
+
children: failure ? /* @__PURE__ */ jsx(LoadFailureView, {
|
|
932
|
+
failure,
|
|
933
|
+
title: t("studio_branches_read_failed"),
|
|
934
|
+
deniedTitle: t("studio_branches_denied_title"),
|
|
935
|
+
deniedHint: t("studio_branches_denied_hint"),
|
|
936
|
+
onRetry: loadBranches
|
|
937
|
+
}) : branches.length === 0 ? /* @__PURE__ */ jsxs("div", {
|
|
938
|
+
className: "flex flex-col items-center justify-center h-full gap-3 text-center px-4",
|
|
939
|
+
children: [
|
|
940
|
+
/* @__PURE__ */ jsx(CopyIcon, {
|
|
941
|
+
size: iconSize.small,
|
|
942
|
+
className: "text-surface-300 dark:text-surface-600"
|
|
943
|
+
}),
|
|
944
|
+
/* @__PURE__ */ jsx(Typography, {
|
|
945
|
+
variant: "body2",
|
|
946
|
+
color: "disabled",
|
|
947
|
+
className: "text-[13px]",
|
|
948
|
+
children: t("studio_branches_empty")
|
|
949
|
+
}),
|
|
950
|
+
/* @__PURE__ */ jsx(Button, {
|
|
951
|
+
size: "small",
|
|
952
|
+
variant: "outlined",
|
|
953
|
+
onClick: () => setCreateOpen(true),
|
|
954
|
+
startIcon: /* @__PURE__ */ jsx(PlusIcon, { size: iconSize.smallest }),
|
|
955
|
+
children: t("studio_branches_create_action")
|
|
956
|
+
})
|
|
957
|
+
]
|
|
958
|
+
}) : branches.map((branch) => /* @__PURE__ */ jsxs("div", {
|
|
959
|
+
onClick: () => setSelectedBranch(branch.name),
|
|
960
|
+
className: cls("flex items-center gap-3 px-3 py-2.5 rounded-lg cursor-pointer transition-all", selectedBranch === branch.name ? "bg-primary/10 dark:bg-primary/15 ring-1 ring-primary/30" : "hover:bg-surface-hover"),
|
|
961
|
+
children: [
|
|
962
|
+
/* @__PURE__ */ jsx("div", { className: "w-2 h-2 rounded-full shrink-0 bg-emerald-500" }),
|
|
963
|
+
/* @__PURE__ */ jsxs("div", {
|
|
964
|
+
className: "flex-1 min-w-0",
|
|
965
|
+
children: [/* @__PURE__ */ jsx(Typography, {
|
|
966
|
+
variant: "body2",
|
|
967
|
+
className: "truncate font-medium text-[13px]",
|
|
968
|
+
children: branch.name
|
|
969
|
+
}), /* @__PURE__ */ jsx(Typography, {
|
|
970
|
+
variant: "caption",
|
|
971
|
+
color: "secondary",
|
|
972
|
+
className: "truncate text-[11px]",
|
|
973
|
+
children: t("studio_branches_list_from", {
|
|
974
|
+
parent: branch.parentDatabase,
|
|
975
|
+
when: formatRelative(branch.createdAt)
|
|
976
|
+
})
|
|
977
|
+
})]
|
|
978
|
+
}),
|
|
979
|
+
branch.sizeBytes !== void 0 && /* @__PURE__ */ jsx(Typography, {
|
|
980
|
+
variant: "caption",
|
|
981
|
+
color: "disabled",
|
|
982
|
+
className: "font-mono text-[10px] shrink-0",
|
|
983
|
+
children: formatSize(branch.sizeBytes)
|
|
984
|
+
})
|
|
985
|
+
]
|
|
986
|
+
}, branch.name))
|
|
987
|
+
})]
|
|
988
|
+
}),
|
|
989
|
+
/* @__PURE__ */ jsx("div", {
|
|
990
|
+
className: "flex-1 flex flex-col min-w-0 h-full overflow-hidden",
|
|
991
|
+
children: !selected ? /* @__PURE__ */ jsxs("div", {
|
|
992
|
+
className: "flex flex-col items-center justify-center h-full gap-3",
|
|
993
|
+
children: [/* @__PURE__ */ jsx(GitBranchIcon, {
|
|
994
|
+
size: iconSize.large,
|
|
995
|
+
className: "text-surface-200 dark:text-surface-700"
|
|
996
|
+
}), /* @__PURE__ */ jsx(Typography, {
|
|
997
|
+
variant: "body2",
|
|
998
|
+
color: "disabled",
|
|
999
|
+
children: branches.length === 0 ? t("studio_branches_empty_detail") : t("studio_branches_select_prompt")
|
|
1000
|
+
})]
|
|
1001
|
+
}) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
|
|
1002
|
+
className: cls("flex items-center justify-between px-5 py-3 border-b bg-surface-card min-h-[56px]", defaultBorderMixin),
|
|
1003
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
1004
|
+
className: "flex items-center gap-3 min-w-0",
|
|
1005
|
+
children: [/* @__PURE__ */ jsx("div", { className: "w-2.5 h-2.5 rounded-full bg-emerald-500" }), /* @__PURE__ */ jsxs("div", {
|
|
1006
|
+
className: "min-w-0",
|
|
1007
|
+
children: [/* @__PURE__ */ jsx(Typography, {
|
|
1008
|
+
variant: "subtitle1",
|
|
1009
|
+
className: "font-semibold truncate",
|
|
1010
|
+
children: selected.name
|
|
1011
|
+
}), /* @__PURE__ */ jsxs(Typography, {
|
|
1012
|
+
variant: "caption",
|
|
1013
|
+
color: "secondary",
|
|
1014
|
+
className: "truncate",
|
|
1015
|
+
children: [
|
|
1016
|
+
t("studio_branches_created_from"),
|
|
1017
|
+
" ",
|
|
1018
|
+
/* @__PURE__ */ jsx(Typography, {
|
|
1019
|
+
variant: "mono",
|
|
1020
|
+
component: "span",
|
|
1021
|
+
className: "text-[11px]",
|
|
1022
|
+
children: selected.parentDatabase
|
|
1023
|
+
})
|
|
1024
|
+
]
|
|
1025
|
+
})]
|
|
1026
|
+
})]
|
|
1027
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
1028
|
+
className: "flex items-center gap-2 shrink-0",
|
|
1029
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
1030
|
+
size: "small",
|
|
1031
|
+
color: "error",
|
|
1032
|
+
variant: "outlined",
|
|
1033
|
+
onClick: () => setDeleteTarget(selected.name),
|
|
1034
|
+
startIcon: /* @__PURE__ */ jsx(Trash2Icon, { size: iconSize.smallest }),
|
|
1035
|
+
children: t("delete")
|
|
1036
|
+
})
|
|
1037
|
+
})]
|
|
1038
|
+
}), /* @__PURE__ */ jsx(BranchDiffView, {
|
|
1039
|
+
branch: selected,
|
|
1040
|
+
onMerged: loadBranches,
|
|
1041
|
+
details: /* @__PURE__ */ jsxs("div", {
|
|
1042
|
+
className: "space-y-4",
|
|
1043
|
+
children: [
|
|
1044
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1045
|
+
className: "grid grid-cols-2 md:grid-cols-4 gap-3",
|
|
1046
|
+
children: [
|
|
1047
|
+
/* @__PURE__ */ jsx(StatCard, {
|
|
1048
|
+
label: t("studio_branches_branch_name"),
|
|
1049
|
+
value: selected.name,
|
|
1050
|
+
mono: true
|
|
1051
|
+
}),
|
|
1052
|
+
/* @__PURE__ */ jsx(StatCard, {
|
|
1053
|
+
label: t("studio_branches_source_database"),
|
|
1054
|
+
value: selected.parentDatabase,
|
|
1055
|
+
mono: true
|
|
1056
|
+
}),
|
|
1057
|
+
/* @__PURE__ */ jsx(StatCard, {
|
|
1058
|
+
label: t("studio_branches_created"),
|
|
1059
|
+
value: formatRelative(selected.createdAt)
|
|
1060
|
+
}),
|
|
1061
|
+
/* @__PURE__ */ jsx(StatCard, {
|
|
1062
|
+
label: t("studio_branches_size"),
|
|
1063
|
+
value: formatSize(selected.sizeBytes)
|
|
1064
|
+
})
|
|
1065
|
+
]
|
|
1066
|
+
}),
|
|
1067
|
+
/* @__PURE__ */ jsx(Alert, {
|
|
1068
|
+
color: "info",
|
|
1069
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
1070
|
+
className: "space-y-1.5",
|
|
1071
|
+
children: [
|
|
1072
|
+
/* @__PURE__ */ jsx(Typography, {
|
|
1073
|
+
variant: "body2",
|
|
1074
|
+
className: "text-[13px] font-medium",
|
|
1075
|
+
children: t("studio_branches_usage_title")
|
|
1076
|
+
}),
|
|
1077
|
+
/* @__PURE__ */ jsx(Typography, {
|
|
1078
|
+
variant: "body2",
|
|
1079
|
+
className: "text-[13px]",
|
|
1080
|
+
children: t("studio_branches_usage_switch")
|
|
1081
|
+
}),
|
|
1082
|
+
/* @__PURE__ */ jsx(UsageCommand, { command: `rebase db branch switch ${selected.name}` }),
|
|
1083
|
+
/* @__PURE__ */ jsx(Typography, {
|
|
1084
|
+
variant: "body2",
|
|
1085
|
+
className: "text-[13px]",
|
|
1086
|
+
children: t("studio_branches_usage_off")
|
|
1087
|
+
}),
|
|
1088
|
+
/* @__PURE__ */ jsx(UsageCommand, { command: "rebase db branch switch --off" }),
|
|
1089
|
+
/* @__PURE__ */ jsx(Typography, {
|
|
1090
|
+
variant: "body2",
|
|
1091
|
+
className: "text-[13px]",
|
|
1092
|
+
children: t("studio_branches_usage_isolated")
|
|
1093
|
+
})
|
|
1094
|
+
]
|
|
1095
|
+
})
|
|
1096
|
+
}),
|
|
1097
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1098
|
+
className: "p-4 rounded-lg border bg-surface-sheet border-hairline-strong",
|
|
1099
|
+
children: [/* @__PURE__ */ jsx(Typography, {
|
|
1100
|
+
variant: "caption",
|
|
1101
|
+
className: "text-[10px] uppercase tracking-wider text-surface-400 mb-2 block font-medium",
|
|
1102
|
+
children: t("studio_branches_connection_details")
|
|
1103
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
1104
|
+
className: "space-y-2",
|
|
1105
|
+
children: [
|
|
1106
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1107
|
+
className: "flex items-center gap-2",
|
|
1108
|
+
children: [/* @__PURE__ */ jsx(Typography, {
|
|
1109
|
+
variant: "caption",
|
|
1110
|
+
color: "secondary",
|
|
1111
|
+
className: "w-24 shrink-0 text-[11px]",
|
|
1112
|
+
children: t("studio_branches_row_database")
|
|
1113
|
+
}), /* @__PURE__ */ jsx(Typography, {
|
|
1114
|
+
variant: "body2",
|
|
1115
|
+
className: "font-mono text-[12px]",
|
|
1116
|
+
children: `${BRANCH_DB_PREFIX}${selected.name}`
|
|
1117
|
+
})]
|
|
1118
|
+
}),
|
|
1119
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1120
|
+
className: "flex items-start gap-2",
|
|
1121
|
+
children: [/* @__PURE__ */ jsx(Typography, {
|
|
1122
|
+
variant: "caption",
|
|
1123
|
+
color: "secondary",
|
|
1124
|
+
className: "w-24 shrink-0 text-[11px]",
|
|
1125
|
+
children: t("studio_branches_row_connect")
|
|
1126
|
+
}), /* @__PURE__ */ jsx(Typography, {
|
|
1127
|
+
variant: "body2",
|
|
1128
|
+
className: "font-mono text-[12px] break-all",
|
|
1129
|
+
children: `DATABASE_URL=…/${BRANCH_DB_PREFIX}${selected.name}`
|
|
1130
|
+
})]
|
|
1131
|
+
}),
|
|
1132
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1133
|
+
className: "flex items-center gap-2",
|
|
1134
|
+
children: [/* @__PURE__ */ jsx(Typography, {
|
|
1135
|
+
variant: "caption",
|
|
1136
|
+
color: "secondary",
|
|
1137
|
+
className: "w-24 shrink-0 text-[11px]",
|
|
1138
|
+
children: t("studio_branches_row_branched_from")
|
|
1139
|
+
}), /* @__PURE__ */ jsx(Typography, {
|
|
1140
|
+
variant: "body2",
|
|
1141
|
+
className: "font-mono text-[12px]",
|
|
1142
|
+
children: selected.parentDatabase
|
|
1143
|
+
})]
|
|
1144
|
+
}),
|
|
1145
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1146
|
+
className: "flex items-center gap-2",
|
|
1147
|
+
children: [/* @__PURE__ */ jsx(Typography, {
|
|
1148
|
+
variant: "caption",
|
|
1149
|
+
color: "secondary",
|
|
1150
|
+
className: "w-24 shrink-0 text-[11px]",
|
|
1151
|
+
children: t("studio_branches_row_created_at")
|
|
1152
|
+
}), /* @__PURE__ */ jsx(Typography, {
|
|
1153
|
+
variant: "body2",
|
|
1154
|
+
className: "font-mono text-[12px]",
|
|
1155
|
+
children: selected.createdAt instanceof Date ? selected.createdAt.toLocaleString() : new Date(selected.createdAt).toLocaleString()
|
|
1156
|
+
})]
|
|
1157
|
+
})
|
|
1158
|
+
]
|
|
1159
|
+
})]
|
|
1160
|
+
})
|
|
1161
|
+
]
|
|
1162
|
+
})
|
|
1163
|
+
}, selected.name)] })
|
|
1164
|
+
}),
|
|
1165
|
+
/* @__PURE__ */ jsxs(Dialog, {
|
|
1166
|
+
open: createOpen,
|
|
1167
|
+
onOpenChange: (open) => {
|
|
1168
|
+
setCreateOpen(open);
|
|
1169
|
+
if (!open) setCreateError(null);
|
|
1170
|
+
},
|
|
1171
|
+
children: [
|
|
1172
|
+
/* @__PURE__ */ jsx(DialogTitle, { children: t("studio_branches_create_title") }),
|
|
1173
|
+
/* @__PURE__ */ jsxs(DialogContent, {
|
|
1174
|
+
className: "space-y-4 sm:min-w-[400px]",
|
|
1175
|
+
children: [
|
|
1176
|
+
/* @__PURE__ */ jsx(Typography, {
|
|
1177
|
+
variant: "body2",
|
|
1178
|
+
color: "secondary",
|
|
1179
|
+
className: "text-[13px]",
|
|
1180
|
+
children: t("studio_branches_create_body")
|
|
1181
|
+
}),
|
|
1182
|
+
createError && /* @__PURE__ */ jsx(Alert, {
|
|
1183
|
+
color: "error",
|
|
1184
|
+
children: /* @__PURE__ */ jsx(Typography, {
|
|
1185
|
+
variant: "body2",
|
|
1186
|
+
className: "text-[13px]",
|
|
1187
|
+
children: createError
|
|
1188
|
+
})
|
|
1189
|
+
}),
|
|
1190
|
+
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(TextField, {
|
|
1191
|
+
label: t("studio_branches_branch_name"),
|
|
1192
|
+
value: newBranchName,
|
|
1193
|
+
onChange: (e) => setNewBranchName(e.target.value),
|
|
1194
|
+
placeholder: t("studio_branches_name_placeholder"),
|
|
1195
|
+
size: "small",
|
|
1196
|
+
autoFocus: true
|
|
1197
|
+
}) }),
|
|
1198
|
+
branches.length > 0 && /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(Select, {
|
|
1199
|
+
label: t("studio_branches_source_database"),
|
|
1200
|
+
value: sourceDatabase ?? "__main__",
|
|
1201
|
+
onValueChange: (v) => setSourceDatabase(v === "__main__" ? void 0 : v),
|
|
1202
|
+
placeholder: t("studio_branches_source_main"),
|
|
1203
|
+
size: "small",
|
|
1204
|
+
children: [/* @__PURE__ */ jsx(SelectItem, {
|
|
1205
|
+
value: "__main__",
|
|
1206
|
+
children: t("studio_branches_source_main")
|
|
1207
|
+
}), branches.map((b) => /* @__PURE__ */ jsx(SelectItem, {
|
|
1208
|
+
value: b.database,
|
|
1209
|
+
children: b.name
|
|
1210
|
+
}, b.name))]
|
|
1211
|
+
}) })
|
|
1212
|
+
]
|
|
1213
|
+
}),
|
|
1214
|
+
/* @__PURE__ */ jsxs(DialogActions, { children: [/* @__PURE__ */ jsx(Button, {
|
|
1215
|
+
variant: "text",
|
|
1216
|
+
onClick: () => setCreateOpen(false),
|
|
1217
|
+
disabled: creating,
|
|
1218
|
+
children: t("cancel")
|
|
1219
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
1220
|
+
color: "primary",
|
|
1221
|
+
onClick: handleCreate,
|
|
1222
|
+
disabled: !newBranchName.trim() || creating,
|
|
1223
|
+
startIcon: creating ? /* @__PURE__ */ jsx(CircularProgress, { size: "smallest" }) : /* @__PURE__ */ jsx(PlusIcon, { size: iconSize.smallest }),
|
|
1224
|
+
children: creating ? t("studio_branches_creating") : t("studio_branches_create_action")
|
|
1225
|
+
})] })
|
|
1226
|
+
]
|
|
1227
|
+
}),
|
|
1228
|
+
/* @__PURE__ */ jsx(ConfirmationDialog, {
|
|
1229
|
+
open: !!deleteTarget,
|
|
1230
|
+
onAccept: handleDelete,
|
|
1231
|
+
onCancel: () => setDeleteTarget(null),
|
|
1232
|
+
title: t("studio_branches_delete_title"),
|
|
1233
|
+
body: /* @__PURE__ */ jsx(Typography, {
|
|
1234
|
+
variant: "body2",
|
|
1235
|
+
children: t("studio_branches_delete_body", { name: deleteTarget ?? "" })
|
|
1236
|
+
}),
|
|
1237
|
+
loading: deleting
|
|
1238
|
+
})
|
|
1239
|
+
]
|
|
1240
|
+
});
|
|
1241
|
+
}
|
|
1242
|
+
/** A command the usage alert tells the reader to run, set apart from the prose. */
|
|
1243
|
+
function UsageCommand({ command }) {
|
|
1244
|
+
return /* @__PURE__ */ jsx(Typography, {
|
|
1245
|
+
variant: "mono",
|
|
1246
|
+
component: "div",
|
|
1247
|
+
className: "px-2 py-1 rounded bg-surface-well text-[12px] break-all",
|
|
1248
|
+
children: command
|
|
1249
|
+
});
|
|
1250
|
+
}
|
|
1251
|
+
function StatCard({ label, value, mono }) {
|
|
1252
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1253
|
+
className: cls("px-3 py-2 rounded-lg border bg-surface-card", defaultBorderMixin),
|
|
1254
|
+
children: [/* @__PURE__ */ jsx(Typography, {
|
|
1255
|
+
variant: "caption",
|
|
1256
|
+
color: "secondary",
|
|
1257
|
+
className: "text-[10px] uppercase tracking-wider font-medium",
|
|
1258
|
+
children: label
|
|
1259
|
+
}), /* @__PURE__ */ jsx(Typography, {
|
|
1260
|
+
variant: "body2",
|
|
1261
|
+
className: cls("mt-0.5 font-semibold text-[13px] truncate", mono && "font-mono"),
|
|
1262
|
+
children: value
|
|
1263
|
+
})]
|
|
1264
|
+
});
|
|
1265
|
+
}
|
|
1266
|
+
//#endregion
|
|
1267
|
+
export { BranchesView };
|
|
1268
|
+
|
|
1269
|
+
//# sourceMappingURL=BranchesView-Df00LXAI.js.map
|