@rebasepro/studio 0.35.1 → 0.37.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.
Files changed (93) hide show
  1. package/README.md +1 -1
  2. package/dist/{ApiExplorer-C61w8gCc.js → ApiExplorer-BVQHAjHB.js} +3 -2
  3. package/dist/{ApiExplorer-C61w8gCc.js.map → ApiExplorer-BVQHAjHB.js.map} +1 -1
  4. package/dist/{useRunAsUsers-CF7tkGzj.js → AuthSimulationSelector-XogpkeXC.js} +4 -68
  5. package/dist/AuthSimulationSelector-XogpkeXC.js.map +1 -0
  6. package/dist/{CronJobsView-DUuyzkJK.js → CronJobsView-DyX9MINh.js} +2 -2
  7. package/dist/{CronJobsView-DUuyzkJK.js.map → CronJobsView-DyX9MINh.js.map} +1 -1
  8. package/dist/DatabaseView-Bi0NZS90.js +1897 -0
  9. package/dist/DatabaseView-Bi0NZS90.js.map +1 -0
  10. package/dist/{JSEditor-Bi2Aol-Y.js → JSEditor-B4Lazm-z.js} +4 -3
  11. package/dist/{JSEditor-Bi2Aol-Y.js.map → JSEditor-B4Lazm-z.js.map} +1 -1
  12. package/dist/RLSEditor-CcHkWFNg.js +973 -0
  13. package/dist/RLSEditor-CcHkWFNg.js.map +1 -0
  14. package/dist/{SQLEditor-DRo5kW1h.js → SQLEditorRoute-f5j_ZKdj.js} +1472 -320
  15. package/dist/SQLEditorRoute-f5j_ZKdj.js.map +1 -0
  16. package/dist/SchemaDiagramView-CckQobIZ.js +98 -0
  17. package/dist/SchemaDiagramView-CckQobIZ.js.map +1 -0
  18. package/dist/{StorageView-D0D8z4lI.js → StorageView-DQEIDFvO.js} +592 -447
  19. package/dist/StorageView-DQEIDFvO.js.map +1 -0
  20. package/dist/TableEditorView-BRZNvD6U.js +3615 -0
  21. package/dist/TableEditorView-BRZNvD6U.js.map +1 -0
  22. package/dist/TablePolicies-C1-tbC8x.js +1740 -0
  23. package/dist/TablePolicies-C1-tbC8x.js.map +1 -0
  24. package/dist/{SchemaVisualizer-Dy4kWKT5.js → TablesDiagram-RTJfwVEN.js} +651 -489
  25. package/dist/TablesDiagram-RTJfwVEN.js.map +1 -0
  26. package/dist/{UsersAndRolesView-CKw4SJPj.js → UsersAndRolesView-Cx6xtMVH.js} +2 -2
  27. package/dist/{UsersAndRolesView-CKw4SJPj.js.map → UsersAndRolesView-Cx6xtMVH.js.map} +1 -1
  28. package/dist/{WebhooksView-CFPY-N9h.js → WebhooksView-Bn9KB7xG.js} +2 -2
  29. package/dist/{WebhooksView-CFPY-N9h.js.map → WebhooksView-Bn9KB7xG.js.map} +1 -1
  30. package/dist/{adminFetch-BfOnfRgU.js → adminFetch-C7Ra8rpP.js} +26 -1
  31. package/dist/{adminFetch-BfOnfRgU.js.map → adminFetch-C7Ra8rpP.js.map} +1 -1
  32. package/dist/components/Database/ActivitySection.d.ts +9 -0
  33. package/dist/components/Database/AdvisorsSection.d.ts +17 -0
  34. package/dist/components/Database/DatabaseView.d.ts +13 -0
  35. package/dist/components/Database/ExtensionsSection.d.ts +2 -0
  36. package/dist/components/Database/FunctionsSection.d.ts +2 -0
  37. package/dist/components/Database/QueriesSection.d.ts +3 -0
  38. package/dist/components/Database/TriggersSection.d.ts +2 -0
  39. package/dist/components/Database/TypesSection.d.ts +2 -0
  40. package/dist/components/Database/format.d.ts +6 -0
  41. package/dist/components/Database/links.d.ts +11 -0
  42. package/dist/components/Database/shared.d.ts +35 -0
  43. package/dist/components/Database/source.d.ts +12 -0
  44. package/dist/components/Database/useCatalogList.d.ts +13 -0
  45. package/dist/components/RLSEditor/RLSEditor.d.ts +2 -0
  46. package/dist/components/RLSEditor/TablePolicies.d.ts +54 -0
  47. package/dist/components/SQLEditor/ExplainVisualizer.d.ts +8 -20
  48. package/dist/components/SQLEditor/ResultChart.d.ts +18 -0
  49. package/dist/components/SQLEditor/SQLEditor.d.ts +13 -1
  50. package/dist/components/SQLEditor/SQLEditorRoute.d.ts +13 -0
  51. package/dist/components/SQLEditor/SQLEditorSidebar.d.ts +7 -1
  52. package/dist/components/SQLEditor/SqlParamsPanel.d.ts +16 -0
  53. package/dist/components/SQLEditor/useSqlSnippets.d.ts +47 -0
  54. package/dist/components/SchemaVisualizer/SchemaDiagramView.d.ts +12 -0
  55. package/dist/components/SchemaVisualizer/TablesDiagram.d.ts +23 -0
  56. package/dist/components/SchemaVisualizer/useSchemaGraph.d.ts +32 -1
  57. package/dist/components/StorageView/StorageView.d.ts +5 -0
  58. package/dist/components/TableEditor/CreateTableDialog.d.ts +8 -0
  59. package/dist/components/TableEditor/DdlConfirm.d.ts +23 -0
  60. package/dist/components/TableEditor/SqlBlock.d.ts +7 -0
  61. package/dist/components/TableEditor/TableDdlSheet.d.ts +9 -0
  62. package/dist/components/TableEditor/TableEditorView.d.ts +7 -0
  63. package/dist/components/TableEditor/tableModel.d.ts +210 -0
  64. package/dist/components/TableEditor/tabs/DataTab.d.ts +12 -0
  65. package/dist/components/TableEditor/tabs/PoliciesTab.d.ts +8 -0
  66. package/dist/components/TableEditor/tabs/RelationsTab.d.ts +8 -0
  67. package/dist/components/TableEditor/tabs/SettingsTab.d.ts +11 -0
  68. package/dist/components/TableEditor/tabs/StatsTab.d.ts +8 -0
  69. package/dist/components/TableEditor/tabs/StructureTab.d.ts +12 -0
  70. package/dist/index.es.js +29 -15
  71. package/dist/index.es.js.map +1 -1
  72. package/dist/{sql_utils-CYcgpgam.js → sql_utils-DkMYltfq.js} +27 -3
  73. package/dist/sql_utils-DkMYltfq.js.map +1 -0
  74. package/dist/useRunAsUsers-GPFCxcBC.js +69 -0
  75. package/dist/useRunAsUsers-GPFCxcBC.js.map +1 -0
  76. package/dist/utils/adminFetch.d.ts +1 -0
  77. package/dist/utils/csv_parse.d.ts +11 -0
  78. package/dist/utils/explain_plan.d.ts +70 -0
  79. package/dist/utils/sql_params.d.ts +51 -0
  80. package/dist/utils/sql_utils.d.ts +16 -0
  81. package/package.json +11 -9
  82. package/dist/RLSEditor-CTG3jLE7.js +0 -2572
  83. package/dist/RLSEditor-CTG3jLE7.js.map +0 -1
  84. package/dist/SQLEditor-DRo5kW1h.js.map +0 -1
  85. package/dist/SchemaVisualizer-Dy4kWKT5.js.map +0 -1
  86. package/dist/StorageView-D0D8z4lI.js.map +0 -1
  87. package/dist/TableEditorView-BKhSBG-K.js +0 -1694
  88. package/dist/TableEditorView-BKhSBG-K.js.map +0 -1
  89. package/dist/components/SchemaVisualizer/SchemaVisualizer.d.ts +0 -3
  90. package/dist/policy-presets-CJKzAvQp.js +0 -167
  91. package/dist/policy-presets-CJKzAvQp.js.map +0 -1
  92. package/dist/sql_utils-CYcgpgam.js.map +0 -1
  93. package/dist/useRunAsUsers-CF7tkGzj.js.map +0 -1
@@ -0,0 +1,3615 @@
1
+ import { a as asStringArray, o as isRecord, r as asNumber, s as useAdminFetch } from "./adminFetch-C7Ra8rpP.js";
2
+ import { t as useRunAsUsers } from "./useRunAsUsers-GPFCxcBC.js";
3
+ import { a as SIGNED_IN_SQL, t as TablePolicies } from "./TablePolicies-C1-tbC8x.js";
4
+ import { t as FixedEditorOverlay } from "./FixedEditorOverlay-DtgPBSjq.js";
5
+ import { _ as tablesLink, a as TABLE_PARAM, c as formatBytes, d as notServedReasonKey, f as parseFilterParam, g as sqlDraftLink, h as parseTablesResponse, i as TABLE_FILTER_PARAM, l as formatCount, m as parseTableDetails, n as ROW_FILTER_OPERATORS, o as TABLE_TAB_PARAM, p as parseRowsPage, r as TABLES_VIEW_PARAM, s as asPostgresPolicies, t as TablesDiagram, u as isInspectorTab } from "./TablesDiagram-RTJfwVEN.js";
6
+ import { ConfirmationDialog, UserSelectPopover, useSnackbarController, useTranslation } from "@rebasepro/app";
7
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
8
+ import { Alert, ArrowRightIcon, BooleanSwitch, BooleanSwitchWithLabel, Button, Card, Checkbox, ChevronLeftIcon, ChevronRightIcon, Chip, CircularProgress, CodeIcon, CopyIcon, DatabaseIcon, Dialog, DialogActions, DialogContent, DialogTitle, DownloadIcon, EyeIcon, FilterChip, FilterIcon, IconButton, LucideIconByName, Maximize2Icon, MultiSelect, MultiSelectItem, PencilIcon, PlusIcon, Popover, RefreshCwIcon, SearchBar, Select, SelectItem, Sheet, ShieldIcon, StatusDot, Tab, Table, TableBody, TableCell, TableHeader, TableIcon, TableRow, Tabs, TerminalIcon, TextField, ToggleButtonGroup, Tooltip, Trash2Icon, Typography, UploadIcon, VirtualTable, XIcon, cls, defaultBorderMixin, iconSize } from "@rebasepro/ui";
9
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
10
+ import { useNavigate, useSearchParams } from "react-router";
11
+ import { IMPERSONATE_HEADER, policy } from "@rebasepro/types";
12
+ import { compilePolicyExpression } from "@rebasepro/common";
13
+ //#region src/components/TableEditor/SqlBlock.tsx
14
+ /** SQL to read and copy: a well with the statements in the mono face and a copy button. */
15
+ function SqlBlock({ sql, className, maxHeight = "max-h-80" }) {
16
+ const { t } = useTranslation();
17
+ const snackbar = useSnackbarController();
18
+ return /* @__PURE__ */ jsxs("div", {
19
+ className: cls("relative rounded-lg bg-surface-field", className),
20
+ children: [/* @__PURE__ */ jsx("div", {
21
+ className: "absolute right-1.5 top-1.5",
22
+ children: /* @__PURE__ */ jsx(Tooltip, {
23
+ title: t("copy"),
24
+ children: /* @__PURE__ */ jsx(IconButton, {
25
+ size: "small",
26
+ "aria-label": t("copy"),
27
+ onClick: () => {
28
+ navigator.clipboard.writeText(sql).then(() => snackbar.open({
29
+ type: "success",
30
+ message: t("copied")
31
+ }));
32
+ },
33
+ children: /* @__PURE__ */ jsx(CopyIcon, { size: iconSize.smallest })
34
+ })
35
+ })
36
+ }), /* @__PURE__ */ jsx(Typography, {
37
+ variant: "mono",
38
+ component: "div",
39
+ className: cls("p-3 pr-10 text-xs whitespace-pre-wrap break-words overflow-auto", maxHeight),
40
+ children: sql
41
+ })]
42
+ });
43
+ }
44
+ //#endregion
45
+ //#region src/components/TableEditor/DdlConfirm.tsx
46
+ /**
47
+ * A schema change, shown as the SQL it will run before it runs: the route is
48
+ * asked with `dryRun: true` first, the statements are shown, and only "Run"
49
+ * sends it for real. Every DDL route under `/api/admin/db` answers a dry run.
50
+ */
51
+ function useDdlConfirm() {
52
+ const { t } = useTranslation();
53
+ const { requestJson } = useAdminFetch();
54
+ const snackbar = useSnackbarController();
55
+ const [pending, setPending] = useState(null);
56
+ const [running, setRunning] = useState(false);
57
+ const confirm = useCallback(async (change) => {
58
+ try {
59
+ const preview = await requestJson(change.path, {
60
+ method: change.method,
61
+ body: {
62
+ ...change.body,
63
+ dryRun: true
64
+ }
65
+ });
66
+ const statements = isRecord(preview) ? asStringArray(preview.statements) : [];
67
+ setPending({
68
+ ...change,
69
+ destructive: change.destructive ?? false,
70
+ statements
71
+ });
72
+ } catch (err) {
73
+ snackbar.open({
74
+ type: "error",
75
+ message: err instanceof Error ? err.message : String(err)
76
+ });
77
+ }
78
+ }, [requestJson, snackbar]);
79
+ const run = async () => {
80
+ if (!pending) return;
81
+ setRunning(true);
82
+ try {
83
+ await requestJson(pending.path, {
84
+ method: pending.method,
85
+ body: pending.body
86
+ });
87
+ snackbar.open({
88
+ type: "success",
89
+ message: pending.done
90
+ });
91
+ pending.onDone?.();
92
+ setPending(null);
93
+ } catch (err) {
94
+ snackbar.open({
95
+ type: "error",
96
+ message: err instanceof Error ? err.message : String(err)
97
+ });
98
+ } finally {
99
+ setRunning(false);
100
+ }
101
+ };
102
+ return {
103
+ confirm,
104
+ dialog: /* @__PURE__ */ jsxs(Dialog, {
105
+ open: pending !== null,
106
+ onOpenChange: (open) => {
107
+ if (!open && !running) setPending(null);
108
+ },
109
+ maxWidth: "2xl",
110
+ fullWidth: true,
111
+ children: [
112
+ /* @__PURE__ */ jsx(DialogTitle, { children: pending?.title }),
113
+ /* @__PURE__ */ jsxs(DialogContent, {
114
+ className: "flex flex-col gap-3",
115
+ children: [/* @__PURE__ */ jsx(Typography, {
116
+ variant: "body2",
117
+ color: "secondary",
118
+ children: t("studio_tables_ddl_preview_intro")
119
+ }), /* @__PURE__ */ jsx(SqlBlock, { sql: pending?.statements.join("\n") ?? "" })]
120
+ }),
121
+ /* @__PURE__ */ jsxs(DialogActions, { children: [/* @__PURE__ */ jsx(Button, {
122
+ variant: "text",
123
+ disabled: running,
124
+ onClick: () => setPending(null),
125
+ children: t("cancel")
126
+ }), /* @__PURE__ */ jsx(Button, {
127
+ variant: "filled",
128
+ color: pending?.destructive ? "error" : "primary",
129
+ disabled: running,
130
+ onClick: () => void run(),
131
+ children: running ? t("studio_tables_ddl_running") : t("studio_tables_ddl_run")
132
+ })] })
133
+ ]
134
+ })
135
+ };
136
+ }
137
+ //#endregion
138
+ //#region src/components/TableEditor/tabs/StructureTab.tsx
139
+ var SQL_TYPES = [
140
+ "text",
141
+ "varchar(255)",
142
+ "integer",
143
+ "bigint",
144
+ "smallint",
145
+ "numeric",
146
+ "double precision",
147
+ "real",
148
+ "boolean",
149
+ "uuid",
150
+ "timestamptz",
151
+ "timestamp",
152
+ "date",
153
+ "time",
154
+ "jsonb",
155
+ "json",
156
+ "bytea",
157
+ "text[]",
158
+ "integer[]",
159
+ "uuid[]"
160
+ ];
161
+ var FK_ACTIONS = [
162
+ "NO ACTION",
163
+ "RESTRICT",
164
+ "CASCADE",
165
+ "SET NULL",
166
+ "SET DEFAULT"
167
+ ];
168
+ var INDEX_METHODS = [
169
+ "btree",
170
+ "gin",
171
+ "gist",
172
+ "hash",
173
+ "brin"
174
+ ];
175
+ function SectionHeader({ title, action }) {
176
+ return /* @__PURE__ */ jsxs("div", {
177
+ className: "flex items-center justify-between gap-3",
178
+ children: [/* @__PURE__ */ jsx(Typography, {
179
+ variant: "subtitle2",
180
+ children: title
181
+ }), action]
182
+ });
183
+ }
184
+ function Section({ children }) {
185
+ return /* @__PURE__ */ jsx("div", {
186
+ className: cls("overflow-x-auto rounded-lg border", defaultBorderMixin),
187
+ children
188
+ });
189
+ }
190
+ /** Columns, indexes, constraints and triggers: everything the table is made of. */
191
+ function StructureTab({ table, tables, details, onChanged }) {
192
+ const { t } = useTranslation();
193
+ const navigate = useNavigate();
194
+ const { confirm, dialog } = useDdlConfirm();
195
+ const [columnDialog, setColumnDialog] = useState(null);
196
+ const [indexOpen, setIndexOpen] = useState(false);
197
+ const [constraintOpen, setConstraintOpen] = useState(false);
198
+ const base = `/admin/db/tables/${encodeURIComponent(table.name)}`;
199
+ const isView = table.kind === "view";
200
+ const columns = details?.columns ?? table.columns.map((column) => ({
201
+ name: column.name,
202
+ type: column.dataType,
203
+ udt: column.udtName,
204
+ category: "S",
205
+ notNull: !column.nullable,
206
+ default: column.defaultExpr,
207
+ identity: null,
208
+ generated: null,
209
+ primaryKey: column.primaryKey,
210
+ comment: null
211
+ }));
212
+ const uniqueColumns = new Set(table.columns.filter((column) => column.unique).map((column) => column.name));
213
+ const constraints = (details?.constraints ?? []).filter((constraint) => constraint.kind !== "primary_key");
214
+ const triggerTemplate = `CREATE OR REPLACE FUNCTION ${table.schema}.${table.name}_before_update()
215
+ RETURNS trigger LANGUAGE plpgsql AS $$
216
+ BEGIN
217
+ -- NEW.updated_at := now();
218
+ RETURN NEW;
219
+ END $$;
220
+
221
+ CREATE TRIGGER ${table.name}_before_update
222
+ BEFORE UPDATE ON ${table.schema}.${table.name}
223
+ FOR EACH ROW EXECUTE FUNCTION ${table.schema}.${table.name}_before_update();`;
224
+ return /* @__PURE__ */ jsxs("div", {
225
+ className: "flex flex-col gap-7",
226
+ children: [
227
+ /* @__PURE__ */ jsxs("div", {
228
+ className: "flex flex-col gap-2",
229
+ children: [/* @__PURE__ */ jsx(SectionHeader, {
230
+ title: t("studio_tables_columns_heading", { count: columns.length }),
231
+ action: !isView && /* @__PURE__ */ jsxs(Button, {
232
+ size: "small",
233
+ variant: "outlined",
234
+ onClick: () => setColumnDialog({ mode: "add" }),
235
+ children: [/* @__PURE__ */ jsx(PlusIcon, { size: iconSize.smallest }), t("studio_tables_add_column")]
236
+ })
237
+ }), /* @__PURE__ */ jsx(Section, { children: /* @__PURE__ */ jsxs(Table, {
238
+ className: "w-full",
239
+ children: [/* @__PURE__ */ jsxs(TableHeader, { children: [
240
+ /* @__PURE__ */ jsx(TableCell, {
241
+ header: true,
242
+ children: t("studio_branch_diff_object_column")
243
+ }),
244
+ /* @__PURE__ */ jsx(TableCell, {
245
+ header: true,
246
+ children: t("type")
247
+ }),
248
+ /* @__PURE__ */ jsx(TableCell, {
249
+ header: true,
250
+ children: t("studio_tables_constraints")
251
+ }),
252
+ /* @__PURE__ */ jsx(TableCell, {
253
+ header: true,
254
+ children: t("studio_tables_default")
255
+ }),
256
+ /* @__PURE__ */ jsx(TableCell, {
257
+ header: true,
258
+ className: "text-right",
259
+ children: t("actions")
260
+ })
261
+ ] }), /* @__PURE__ */ jsx(TableBody, { children: columns.map((column) => /* @__PURE__ */ jsxs(TableRow, { children: [
262
+ /* @__PURE__ */ jsxs(TableCell, { children: [/* @__PURE__ */ jsx(Typography, {
263
+ variant: "mono",
264
+ className: "text-sm font-medium",
265
+ children: column.name
266
+ }), column.comment && /* @__PURE__ */ jsx(Typography, {
267
+ variant: "caption",
268
+ color: "secondary",
269
+ className: "block",
270
+ children: column.comment
271
+ })] }),
272
+ /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(Typography, {
273
+ variant: "mono",
274
+ className: "text-xs",
275
+ color: "secondary",
276
+ children: column.type
277
+ }) }),
278
+ /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsxs("div", {
279
+ className: "flex items-center gap-1.5 flex-wrap",
280
+ children: [
281
+ column.primaryKey && /* @__PURE__ */ jsx(Chip, {
282
+ size: "smallest",
283
+ colorScheme: "blueLight",
284
+ children: "PK"
285
+ }),
286
+ column.notNull && !column.primaryKey && /* @__PURE__ */ jsx(Chip, {
287
+ size: "smallest",
288
+ children: "NOT NULL"
289
+ }),
290
+ uniqueColumns.has(column.name) && !column.primaryKey && /* @__PURE__ */ jsx(Chip, {
291
+ size: "smallest",
292
+ colorScheme: "purpleLight",
293
+ children: "UNIQUE"
294
+ }),
295
+ column.identity && /* @__PURE__ */ jsx(Chip, {
296
+ size: "smallest",
297
+ children: "IDENTITY"
298
+ }),
299
+ column.generated && /* @__PURE__ */ jsx(Chip, {
300
+ size: "smallest",
301
+ children: "GENERATED"
302
+ }),
303
+ table.foreignKeys.some((fk) => fk.fromColumns.includes(column.name)) && /* @__PURE__ */ jsx(Chip, {
304
+ size: "smallest",
305
+ colorScheme: "tealLight",
306
+ children: "FK"
307
+ })
308
+ ]
309
+ }) }),
310
+ /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(Typography, {
311
+ variant: "mono",
312
+ className: "text-xs",
313
+ color: "secondary",
314
+ children: column.default ?? "—"
315
+ }) }),
316
+ /* @__PURE__ */ jsx(TableCell, {
317
+ className: "text-right whitespace-nowrap",
318
+ children: !isView && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Tooltip, {
319
+ title: t("studio_tables_edit_column", { name: column.name }),
320
+ children: /* @__PURE__ */ jsx(IconButton, {
321
+ size: "small",
322
+ "aria-label": t("studio_tables_edit_column", { name: column.name }),
323
+ onClick: () => setColumnDialog({
324
+ mode: "edit",
325
+ column
326
+ }),
327
+ children: /* @__PURE__ */ jsx(PencilIcon, { size: iconSize.smallest })
328
+ })
329
+ }), !column.primaryKey && /* @__PURE__ */ jsx(Tooltip, {
330
+ title: t("studio_tables_drop_column", { name: column.name }),
331
+ children: /* @__PURE__ */ jsx(IconButton, {
332
+ size: "small",
333
+ "aria-label": t("studio_tables_drop_column", { name: column.name }),
334
+ onClick: () => void confirm({
335
+ title: t("studio_tables_drop_column", { name: column.name }),
336
+ path: `${base}/columns/${encodeURIComponent(column.name)}`,
337
+ method: "DELETE",
338
+ body: {
339
+ schema: table.schema,
340
+ confirm: column.name
341
+ },
342
+ destructive: true,
343
+ done: t("studio_tables_column_dropped", { name: column.name }),
344
+ onDone: onChanged
345
+ }),
346
+ children: /* @__PURE__ */ jsx(Trash2Icon, { size: iconSize.smallest })
347
+ })
348
+ })] })
349
+ })
350
+ ] }, column.name)) })]
351
+ }) })]
352
+ }),
353
+ /* @__PURE__ */ jsxs("div", {
354
+ className: "flex flex-col gap-2",
355
+ children: [/* @__PURE__ */ jsx(SectionHeader, {
356
+ title: t("studio_tables_indexes_heading", { count: details?.indexes.length ?? table.indexes.length }),
357
+ action: table.kind === "table" && /* @__PURE__ */ jsxs(Button, {
358
+ size: "small",
359
+ variant: "outlined",
360
+ onClick: () => setIndexOpen(true),
361
+ children: [/* @__PURE__ */ jsx(PlusIcon, { size: iconSize.smallest }), t("studio_tables_add_index")]
362
+ })
363
+ }), /* @__PURE__ */ jsx(Section, { children: /* @__PURE__ */ jsxs(Table, {
364
+ className: "w-full",
365
+ children: [/* @__PURE__ */ jsxs(TableHeader, { children: [
366
+ /* @__PURE__ */ jsx(TableCell, {
367
+ header: true,
368
+ children: t("name")
369
+ }),
370
+ /* @__PURE__ */ jsx(TableCell, {
371
+ header: true,
372
+ children: t("studio_tables_definition")
373
+ }),
374
+ /* @__PURE__ */ jsx(TableCell, {
375
+ header: true,
376
+ className: "text-right",
377
+ children: t("studio_tables_index_size")
378
+ }),
379
+ /* @__PURE__ */ jsx(TableCell, {
380
+ header: true,
381
+ className: "text-right",
382
+ children: t("studio_tables_index_scans")
383
+ }),
384
+ /* @__PURE__ */ jsx(TableCell, {
385
+ header: true,
386
+ className: "text-right",
387
+ children: t("actions")
388
+ })
389
+ ] }), /* @__PURE__ */ jsx(TableBody, { children: (details?.indexes ?? table.indexes.map((index) => ({
390
+ ...index,
391
+ method: "",
392
+ valid: true,
393
+ backsConstraint: index.primary,
394
+ bytes: null,
395
+ scans: null,
396
+ tuplesRead: null,
397
+ tuplesFetched: null
398
+ }))).map((index) => /* @__PURE__ */ jsxs(TableRow, { children: [
399
+ /* @__PURE__ */ jsx(TableCell, {
400
+ className: "whitespace-nowrap",
401
+ children: /* @__PURE__ */ jsxs("div", {
402
+ className: "flex items-center gap-1.5",
403
+ children: [
404
+ /* @__PURE__ */ jsx(Typography, {
405
+ variant: "mono",
406
+ className: "text-xs",
407
+ children: index.name
408
+ }),
409
+ index.primary && /* @__PURE__ */ jsx(Chip, {
410
+ size: "smallest",
411
+ colorScheme: "blueLight",
412
+ children: "PK"
413
+ }),
414
+ index.unique && !index.primary && /* @__PURE__ */ jsx(Chip, {
415
+ size: "smallest",
416
+ colorScheme: "purpleLight",
417
+ children: "UNIQUE"
418
+ }),
419
+ !index.valid && /* @__PURE__ */ jsx(Chip, {
420
+ size: "smallest",
421
+ colorScheme: "redLight",
422
+ children: t("studio_tables_index_invalid")
423
+ })
424
+ ]
425
+ })
426
+ }),
427
+ /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(Typography, {
428
+ variant: "mono",
429
+ className: "text-xs",
430
+ color: "secondary",
431
+ children: index.definition
432
+ }) }),
433
+ /* @__PURE__ */ jsx(TableCell, {
434
+ className: "text-right",
435
+ children: /* @__PURE__ */ jsx(Typography, {
436
+ variant: "body2",
437
+ className: "tabular-nums",
438
+ children: formatBytes(index.bytes)
439
+ })
440
+ }),
441
+ /* @__PURE__ */ jsx(TableCell, {
442
+ className: "text-right",
443
+ children: /* @__PURE__ */ jsx(Typography, {
444
+ variant: "body2",
445
+ className: "tabular-nums",
446
+ children: formatCount(index.scans)
447
+ })
448
+ }),
449
+ /* @__PURE__ */ jsx(TableCell, {
450
+ className: "text-right",
451
+ children: !index.backsConstraint && /* @__PURE__ */ jsx(IconButton, {
452
+ size: "small",
453
+ "aria-label": t("studio_tables_drop_index", { name: index.name }),
454
+ onClick: () => void confirm({
455
+ title: t("studio_tables_drop_index", { name: index.name }),
456
+ path: `${base}/indexes/${encodeURIComponent(index.name)}`,
457
+ method: "DELETE",
458
+ body: { schema: table.schema },
459
+ destructive: true,
460
+ done: t("studio_tables_index_dropped", { name: index.name }),
461
+ onDone: onChanged
462
+ }),
463
+ children: /* @__PURE__ */ jsx(Trash2Icon, { size: iconSize.smallest })
464
+ })
465
+ })
466
+ ] }, index.name)) })]
467
+ }) })]
468
+ }),
469
+ details && table.kind === "table" && /* @__PURE__ */ jsxs("div", {
470
+ className: "flex flex-col gap-2",
471
+ children: [/* @__PURE__ */ jsx(SectionHeader, {
472
+ title: t("studio_tables_constraints_heading", { count: constraints.length }),
473
+ action: /* @__PURE__ */ jsxs(Button, {
474
+ size: "small",
475
+ variant: "outlined",
476
+ onClick: () => setConstraintOpen(true),
477
+ children: [/* @__PURE__ */ jsx(PlusIcon, { size: iconSize.smallest }), t("studio_tables_add_constraint")]
478
+ })
479
+ }), constraints.length === 0 ? /* @__PURE__ */ jsx(Typography, {
480
+ variant: "body2",
481
+ color: "secondary",
482
+ children: t("studio_tables_no_constraints")
483
+ }) : /* @__PURE__ */ jsx(Section, { children: /* @__PURE__ */ jsxs(Table, {
484
+ className: "w-full",
485
+ children: [/* @__PURE__ */ jsxs(TableHeader, { children: [
486
+ /* @__PURE__ */ jsx(TableCell, {
487
+ header: true,
488
+ children: t("name")
489
+ }),
490
+ /* @__PURE__ */ jsx(TableCell, {
491
+ header: true,
492
+ children: t("type")
493
+ }),
494
+ /* @__PURE__ */ jsx(TableCell, {
495
+ header: true,
496
+ children: t("studio_tables_definition")
497
+ }),
498
+ /* @__PURE__ */ jsx(TableCell, {
499
+ header: true,
500
+ className: "text-right",
501
+ children: t("actions")
502
+ })
503
+ ] }), /* @__PURE__ */ jsx(TableBody, { children: constraints.map((constraint) => /* @__PURE__ */ jsxs(TableRow, { children: [
504
+ /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(Typography, {
505
+ variant: "mono",
506
+ className: "text-xs",
507
+ children: constraint.name
508
+ }) }),
509
+ /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(Typography, {
510
+ variant: "body2",
511
+ children: t(`studio_tables_constraint_${constraint.kind}`)
512
+ }) }),
513
+ /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(Typography, {
514
+ variant: "mono",
515
+ className: "text-xs",
516
+ color: "secondary",
517
+ children: constraint.definition
518
+ }) }),
519
+ /* @__PURE__ */ jsx(TableCell, {
520
+ className: "text-right",
521
+ children: /* @__PURE__ */ jsx(IconButton, {
522
+ size: "small",
523
+ "aria-label": t("studio_tables_drop_constraint", { name: constraint.name }),
524
+ onClick: () => void confirm({
525
+ title: t("studio_tables_drop_constraint", { name: constraint.name }),
526
+ path: `${base}/constraints/${encodeURIComponent(constraint.name)}`,
527
+ method: "DELETE",
528
+ body: { schema: table.schema },
529
+ destructive: true,
530
+ done: t("studio_tables_constraint_dropped", { name: constraint.name }),
531
+ onDone: onChanged
532
+ }),
533
+ children: /* @__PURE__ */ jsx(Trash2Icon, { size: iconSize.smallest })
534
+ })
535
+ })
536
+ ] }, constraint.name)) })]
537
+ }) })]
538
+ }),
539
+ details && table.kind === "table" && /* @__PURE__ */ jsxs("div", {
540
+ className: "flex flex-col gap-2",
541
+ children: [/* @__PURE__ */ jsx(SectionHeader, {
542
+ title: t("studio_tables_triggers_heading", { count: details.triggers.length }),
543
+ action: /* @__PURE__ */ jsxs(Button, {
544
+ size: "small",
545
+ variant: "outlined",
546
+ onClick: () => navigate(sqlDraftLink(triggerTemplate)),
547
+ children: [/* @__PURE__ */ jsx(PlusIcon, { size: iconSize.smallest }), t("studio_tables_new_trigger")]
548
+ })
549
+ }), details.triggers.length === 0 ? /* @__PURE__ */ jsx(Typography, {
550
+ variant: "body2",
551
+ color: "secondary",
552
+ children: t("studio_tables_no_triggers")
553
+ }) : /* @__PURE__ */ jsx(Section, { children: /* @__PURE__ */ jsxs(Table, {
554
+ className: "w-full",
555
+ children: [/* @__PURE__ */ jsxs(TableHeader, { children: [
556
+ /* @__PURE__ */ jsx(TableCell, {
557
+ header: true,
558
+ children: t("name")
559
+ }),
560
+ /* @__PURE__ */ jsx(TableCell, {
561
+ header: true,
562
+ children: t("studio_tables_definition")
563
+ }),
564
+ /* @__PURE__ */ jsx(TableCell, {
565
+ header: true,
566
+ children: t("studio_tables_trigger_enabled")
567
+ }),
568
+ /* @__PURE__ */ jsx(TableCell, {
569
+ header: true,
570
+ className: "text-right",
571
+ children: t("actions")
572
+ })
573
+ ] }), /* @__PURE__ */ jsx(TableBody, { children: details.triggers.map((trigger) => /* @__PURE__ */ jsxs(TableRow, { children: [
574
+ /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(Typography, {
575
+ variant: "mono",
576
+ className: "text-xs",
577
+ children: trigger.name
578
+ }) }),
579
+ /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(Typography, {
580
+ variant: "mono",
581
+ className: "text-xs",
582
+ color: "secondary",
583
+ children: trigger.definition
584
+ }) }),
585
+ /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(BooleanSwitch, {
586
+ size: "small",
587
+ value: trigger.enabled,
588
+ onValueChange: (enabled) => void confirm({
589
+ title: t(enabled ? "studio_tables_enable_trigger" : "studio_tables_disable_trigger", { name: trigger.name }),
590
+ path: `${base}/triggers/${encodeURIComponent(trigger.name)}`,
591
+ method: "PATCH",
592
+ body: {
593
+ schema: table.schema,
594
+ enabled
595
+ },
596
+ done: t(enabled ? "studio_tables_trigger_enabled_done" : "studio_tables_trigger_disabled_done", { name: trigger.name }),
597
+ onDone: onChanged
598
+ })
599
+ }) }),
600
+ /* @__PURE__ */ jsx(TableCell, {
601
+ className: "text-right",
602
+ children: /* @__PURE__ */ jsx(IconButton, {
603
+ size: "small",
604
+ "aria-label": t("studio_tables_drop_trigger", { name: trigger.name }),
605
+ onClick: () => void confirm({
606
+ title: t("studio_tables_drop_trigger", { name: trigger.name }),
607
+ path: `${base}/triggers/${encodeURIComponent(trigger.name)}`,
608
+ method: "DELETE",
609
+ body: { schema: table.schema },
610
+ destructive: true,
611
+ done: t("studio_tables_trigger_dropped", { name: trigger.name }),
612
+ onDone: onChanged
613
+ }),
614
+ children: /* @__PURE__ */ jsx(Trash2Icon, { size: iconSize.smallest })
615
+ })
616
+ })
617
+ ] }, trigger.name)) })]
618
+ }) })]
619
+ }),
620
+ columnDialog && /* @__PURE__ */ jsx(ColumnDialog, {
621
+ table,
622
+ tables,
623
+ column: columnDialog.mode === "edit" ? columnDialog.column : null,
624
+ onClose: () => setColumnDialog(null),
625
+ onSubmit: (change) => {
626
+ setColumnDialog(null);
627
+ confirm({
628
+ ...change,
629
+ onDone: onChanged
630
+ });
631
+ }
632
+ }),
633
+ indexOpen && /* @__PURE__ */ jsx(IndexDialog, {
634
+ table,
635
+ columns,
636
+ onClose: () => setIndexOpen(false),
637
+ onSubmit: (change) => {
638
+ setIndexOpen(false);
639
+ confirm({
640
+ ...change,
641
+ onDone: onChanged
642
+ });
643
+ }
644
+ }),
645
+ constraintOpen && /* @__PURE__ */ jsx(ConstraintDialog, {
646
+ table,
647
+ tables,
648
+ columns,
649
+ onClose: () => setConstraintOpen(false),
650
+ onSubmit: (change) => {
651
+ setConstraintOpen(false);
652
+ confirm({
653
+ ...change,
654
+ onDone: onChanged
655
+ });
656
+ }
657
+ }),
658
+ dialog
659
+ ]
660
+ });
661
+ }
662
+ function ColumnDialog({ table, tables, column, onClose, onSubmit }) {
663
+ const { t } = useTranslation();
664
+ const [name, setName] = useState(column?.name ?? "");
665
+ const [type, setType] = useState(column?.type ?? "text");
666
+ const [nullable, setNullable] = useState(column ? !column.notNull : true);
667
+ const [unique, setUnique] = useState(false);
668
+ const [defaultExpr, setDefaultExpr] = useState(column?.default ?? "");
669
+ const [using, setUsing] = useState("");
670
+ const [refTable, setRefTable] = useState("");
671
+ const [refColumn, setRefColumn] = useState("");
672
+ const [onDelete, setOnDelete] = useState("NO ACTION");
673
+ const types = useMemo(() => column && !SQL_TYPES.some((candidate) => candidate === column.type) ? [column.type, ...SQL_TYPES] : [...SQL_TYPES], [column]);
674
+ const target = tables.find((candidate) => candidate.key === refTable);
675
+ const typeChanged = column !== null && type !== column.type;
676
+ const base = `/admin/db/tables/${encodeURIComponent(table.name)}`;
677
+ const submit = () => {
678
+ if (column) {
679
+ const body = { schema: table.schema };
680
+ if (name.trim() && name.trim() !== column.name) body.renameTo = name.trim();
681
+ if (typeChanged) {
682
+ body.type = type;
683
+ if (using.trim()) body.using = using.trim();
684
+ }
685
+ if (nullable !== !column.notNull) body.nullable = nullable;
686
+ if ((defaultExpr.trim() || null) !== (column.default ?? null)) body.default = defaultExpr.trim() || null;
687
+ if (Object.keys(body).length === 1) {
688
+ onClose();
689
+ return;
690
+ }
691
+ onSubmit({
692
+ title: t("studio_tables_edit_column", { name: column.name }),
693
+ path: `${base}/columns/${encodeURIComponent(column.name)}`,
694
+ method: "PATCH",
695
+ body,
696
+ done: t("studio_tables_column_updated", { name: name.trim() || column.name })
697
+ });
698
+ return;
699
+ }
700
+ onSubmit({
701
+ title: t("studio_tables_add_column_to", { name: table.name }),
702
+ path: `${base}/columns`,
703
+ method: "POST",
704
+ body: {
705
+ schema: table.schema,
706
+ name: name.trim(),
707
+ type,
708
+ nullable,
709
+ unique,
710
+ ...defaultExpr.trim() ? { default: defaultExpr.trim() } : {},
711
+ ...target && refColumn ? { references: {
712
+ schema: target.schema,
713
+ table: target.name,
714
+ column: refColumn,
715
+ onDelete
716
+ } } : {}
717
+ },
718
+ done: t("studio_tables_column_added", { name: name.trim() })
719
+ });
720
+ };
721
+ return /* @__PURE__ */ jsxs(Dialog, {
722
+ open: true,
723
+ onOpenChange: (open) => {
724
+ if (!open) onClose();
725
+ },
726
+ maxWidth: "md",
727
+ fullWidth: true,
728
+ children: [
729
+ /* @__PURE__ */ jsx(DialogTitle, { children: column ? t("studio_tables_edit_column", { name: column.name }) : t("studio_tables_add_column_to", { name: table.name }) }),
730
+ /* @__PURE__ */ jsxs(DialogContent, {
731
+ className: "flex flex-col gap-3",
732
+ children: [
733
+ /* @__PURE__ */ jsx(TextField, {
734
+ label: t("studio_tables_column_name"),
735
+ value: name,
736
+ onChange: (event) => setName(event.target.value),
737
+ placeholder: "status"
738
+ }),
739
+ /* @__PURE__ */ jsx(Select, {
740
+ label: t("studio_tables_sql_type"),
741
+ value: type,
742
+ onValueChange: (value) => setType(String(value)),
743
+ children: types.map((candidate) => /* @__PURE__ */ jsx(SelectItem, {
744
+ value: candidate,
745
+ children: candidate
746
+ }, candidate))
747
+ }),
748
+ typeChanged && /* @__PURE__ */ jsx(TextField, {
749
+ label: t("studio_tables_type_using"),
750
+ value: using,
751
+ onChange: (event) => setUsing(event.target.value),
752
+ placeholder: `${column?.name ?? "column"}::${type}`
753
+ }),
754
+ /* @__PURE__ */ jsx(TextField, {
755
+ label: t("studio_tables_default_expr"),
756
+ value: defaultExpr,
757
+ onChange: (event) => setDefaultExpr(event.target.value),
758
+ placeholder: "'draft'"
759
+ }),
760
+ /* @__PURE__ */ jsx(BooleanSwitchWithLabel, {
761
+ label: t("studio_tables_nullable"),
762
+ value: nullable,
763
+ onValueChange: setNullable
764
+ }),
765
+ !column && /* @__PURE__ */ jsx(BooleanSwitchWithLabel, {
766
+ label: t("unique"),
767
+ value: unique,
768
+ onValueChange: setUnique
769
+ }),
770
+ !column && /* @__PURE__ */ jsxs("div", {
771
+ className: "grid grid-cols-1 sm:grid-cols-3 gap-2",
772
+ children: [
773
+ /* @__PURE__ */ jsx(Select, {
774
+ label: t("studio_tables_references_table"),
775
+ value: refTable,
776
+ onValueChange: (value) => {
777
+ setRefTable(String(value));
778
+ setRefColumn("");
779
+ },
780
+ children: tables.filter((candidate) => candidate.kind === "table").map((candidate) => /* @__PURE__ */ jsx(SelectItem, {
781
+ value: candidate.key,
782
+ children: candidate.name
783
+ }, candidate.key))
784
+ }),
785
+ /* @__PURE__ */ jsx(Select, {
786
+ label: t("studio_tables_references_column"),
787
+ value: refColumn,
788
+ disabled: !target,
789
+ onValueChange: (value) => setRefColumn(String(value)),
790
+ children: (target?.columns ?? []).map((candidate) => /* @__PURE__ */ jsx(SelectItem, {
791
+ value: candidate.name,
792
+ children: candidate.name
793
+ }, candidate.name))
794
+ }),
795
+ /* @__PURE__ */ jsx(Select, {
796
+ label: t("studio_tables_on_delete"),
797
+ value: onDelete,
798
+ disabled: !target,
799
+ onValueChange: (value) => setOnDelete(String(value)),
800
+ children: FK_ACTIONS.map((action) => /* @__PURE__ */ jsx(SelectItem, {
801
+ value: action,
802
+ children: action
803
+ }, action))
804
+ })
805
+ ]
806
+ })
807
+ ]
808
+ }),
809
+ /* @__PURE__ */ jsxs(DialogActions, { children: [/* @__PURE__ */ jsx(Button, {
810
+ variant: "text",
811
+ onClick: onClose,
812
+ children: t("cancel")
813
+ }), /* @__PURE__ */ jsx(Button, {
814
+ variant: "filled",
815
+ color: "primary",
816
+ disabled: !name.trim(),
817
+ onClick: submit,
818
+ children: t("studio_tables_review_sql")
819
+ })] })
820
+ ]
821
+ });
822
+ }
823
+ function IndexDialog({ table, columns, onClose, onSubmit }) {
824
+ const { t } = useTranslation();
825
+ const [selected, setSelected] = useState([]);
826
+ const [unique, setUnique] = useState(false);
827
+ const [method, setMethod] = useState("btree");
828
+ const [name, setName] = useState("");
829
+ return /* @__PURE__ */ jsxs(Dialog, {
830
+ open: true,
831
+ onOpenChange: (open) => {
832
+ if (!open) onClose();
833
+ },
834
+ maxWidth: "md",
835
+ fullWidth: true,
836
+ children: [
837
+ /* @__PURE__ */ jsx(DialogTitle, { children: t("studio_tables_create_index_on", { name: table.name }) }),
838
+ /* @__PURE__ */ jsxs(DialogContent, {
839
+ className: "flex flex-col gap-3",
840
+ children: [
841
+ /* @__PURE__ */ jsx(MultiSelect, {
842
+ label: t("studio_tables_index_columns"),
843
+ value: selected,
844
+ onValueChange: setSelected,
845
+ children: columns.map((column) => /* @__PURE__ */ jsx(MultiSelectItem, {
846
+ value: column.name,
847
+ children: column.name
848
+ }, column.name))
849
+ }),
850
+ /* @__PURE__ */ jsx(Select, {
851
+ label: t("studio_tables_index_method"),
852
+ value: method,
853
+ onValueChange: (value) => setMethod(String(value)),
854
+ children: INDEX_METHODS.map((candidate) => /* @__PURE__ */ jsx(SelectItem, {
855
+ value: candidate,
856
+ children: candidate
857
+ }, candidate))
858
+ }),
859
+ /* @__PURE__ */ jsx(TextField, {
860
+ label: t("studio_tables_index_name_optional"),
861
+ value: name,
862
+ onChange: (event) => setName(event.target.value)
863
+ }),
864
+ /* @__PURE__ */ jsx(BooleanSwitchWithLabel, {
865
+ label: t("studio_tables_unique_index"),
866
+ value: unique,
867
+ onValueChange: setUnique
868
+ })
869
+ ]
870
+ }),
871
+ /* @__PURE__ */ jsxs(DialogActions, { children: [/* @__PURE__ */ jsx(Button, {
872
+ variant: "text",
873
+ onClick: onClose,
874
+ children: t("cancel")
875
+ }), /* @__PURE__ */ jsx(Button, {
876
+ variant: "filled",
877
+ color: "primary",
878
+ disabled: selected.length === 0,
879
+ onClick: () => onSubmit({
880
+ title: t("studio_tables_create_index_on", { name: table.name }),
881
+ path: `/admin/db/tables/${encodeURIComponent(table.name)}/indexes`,
882
+ method: "POST",
883
+ body: {
884
+ schema: table.schema,
885
+ columns: selected,
886
+ unique,
887
+ method,
888
+ ...name.trim() ? { name: name.trim() } : {}
889
+ },
890
+ done: t("studio_tables_index_created")
891
+ }),
892
+ children: t("studio_tables_review_sql")
893
+ })] })
894
+ ]
895
+ });
896
+ }
897
+ function ConstraintDialog({ table, tables, columns, onClose, onSubmit }) {
898
+ const { t } = useTranslation();
899
+ const [kind, setKind] = useState("foreign_key");
900
+ const [selected, setSelected] = useState([]);
901
+ const [refTable, setRefTable] = useState("");
902
+ const [refColumns, setRefColumns] = useState([]);
903
+ const [onDelete, setOnDelete] = useState("NO ACTION");
904
+ const [expression, setExpression] = useState("");
905
+ const [name, setName] = useState("");
906
+ const target = tables.find((candidate) => candidate.key === refTable);
907
+ const ready = kind === "check" ? expression.trim() !== "" : selected.length > 0 && (kind !== "foreign_key" || target !== void 0 && refColumns.length === selected.length);
908
+ const submit = () => {
909
+ const body = {
910
+ schema: table.schema,
911
+ kind,
912
+ ...name.trim() ? { name: name.trim() } : {}
913
+ };
914
+ if (kind === "check") body.expression = expression.trim();
915
+ else body.columns = selected;
916
+ if (kind === "foreign_key" && target) body.references = {
917
+ schema: target.schema,
918
+ table: target.name,
919
+ columns: refColumns,
920
+ onDelete
921
+ };
922
+ onSubmit({
923
+ title: t("studio_tables_add_constraint"),
924
+ path: `/admin/db/tables/${encodeURIComponent(table.name)}/constraints`,
925
+ method: "POST",
926
+ body,
927
+ done: t("studio_tables_constraint_added")
928
+ });
929
+ };
930
+ return /* @__PURE__ */ jsxs(Dialog, {
931
+ open: true,
932
+ onOpenChange: (open) => {
933
+ if (!open) onClose();
934
+ },
935
+ maxWidth: "md",
936
+ fullWidth: true,
937
+ children: [
938
+ /* @__PURE__ */ jsx(DialogTitle, { children: t("studio_tables_add_constraint") }),
939
+ /* @__PURE__ */ jsxs(DialogContent, {
940
+ className: "flex flex-col gap-3",
941
+ children: [
942
+ /* @__PURE__ */ jsxs(Select, {
943
+ label: t("type"),
944
+ value: kind,
945
+ onValueChange: (value) => {
946
+ if (value === "foreign_key" || value === "unique" || value === "check") setKind(value);
947
+ },
948
+ children: [
949
+ /* @__PURE__ */ jsx(SelectItem, {
950
+ value: "foreign_key",
951
+ children: t("studio_tables_constraint_foreign_key")
952
+ }),
953
+ /* @__PURE__ */ jsx(SelectItem, {
954
+ value: "unique",
955
+ children: t("studio_tables_constraint_unique")
956
+ }),
957
+ /* @__PURE__ */ jsx(SelectItem, {
958
+ value: "check",
959
+ children: t("studio_tables_constraint_check")
960
+ })
961
+ ]
962
+ }),
963
+ kind !== "check" && /* @__PURE__ */ jsx(MultiSelect, {
964
+ label: t("studio_columns"),
965
+ value: selected,
966
+ onValueChange: setSelected,
967
+ children: columns.map((column) => /* @__PURE__ */ jsx(MultiSelectItem, {
968
+ value: column.name,
969
+ children: column.name
970
+ }, column.name))
971
+ }),
972
+ kind === "foreign_key" && /* @__PURE__ */ jsxs(Fragment, { children: [
973
+ /* @__PURE__ */ jsx(Select, {
974
+ label: t("studio_tables_references_table"),
975
+ value: refTable,
976
+ onValueChange: (value) => {
977
+ setRefTable(String(value));
978
+ setRefColumns([]);
979
+ },
980
+ children: tables.filter((candidate) => candidate.kind === "table").map((candidate) => /* @__PURE__ */ jsx(SelectItem, {
981
+ value: candidate.key,
982
+ children: candidate.name
983
+ }, candidate.key))
984
+ }),
985
+ /* @__PURE__ */ jsx(MultiSelect, {
986
+ label: t("studio_tables_references_columns"),
987
+ value: refColumns,
988
+ onValueChange: setRefColumns,
989
+ disabled: !target,
990
+ children: (target?.columns ?? []).map((column) => /* @__PURE__ */ jsx(MultiSelectItem, {
991
+ value: column.name,
992
+ children: column.name
993
+ }, column.name))
994
+ }),
995
+ /* @__PURE__ */ jsx(Select, {
996
+ label: t("studio_tables_on_delete"),
997
+ value: onDelete,
998
+ onValueChange: (value) => setOnDelete(String(value)),
999
+ children: FK_ACTIONS.map((action) => /* @__PURE__ */ jsx(SelectItem, {
1000
+ value: action,
1001
+ children: action
1002
+ }, action))
1003
+ })
1004
+ ] }),
1005
+ kind === "check" && /* @__PURE__ */ jsx(TextField, {
1006
+ label: t("studio_tables_check_expression"),
1007
+ value: expression,
1008
+ onChange: (event) => setExpression(event.target.value),
1009
+ placeholder: "price >= 0"
1010
+ }),
1011
+ /* @__PURE__ */ jsx(TextField, {
1012
+ label: t("studio_tables_constraint_name_optional"),
1013
+ value: name,
1014
+ onChange: (event) => setName(event.target.value)
1015
+ })
1016
+ ]
1017
+ }),
1018
+ /* @__PURE__ */ jsxs(DialogActions, { children: [/* @__PURE__ */ jsx(Button, {
1019
+ variant: "text",
1020
+ onClick: onClose,
1021
+ children: t("cancel")
1022
+ }), /* @__PURE__ */ jsx(Button, {
1023
+ variant: "filled",
1024
+ color: "primary",
1025
+ disabled: !ready,
1026
+ onClick: submit,
1027
+ children: t("studio_tables_review_sql")
1028
+ })] })
1029
+ ]
1030
+ });
1031
+ }
1032
+ //#endregion
1033
+ //#region src/components/TableEditor/CreateTableDialog.tsx
1034
+ /**
1035
+ * The "Owner only" preset's condition: the row's `user_id` is the signed-in
1036
+ * user. Compiled, as `SIGNED_IN_SQL` is, rather than written out: the
1037
+ * hand-written `user_id = rebase.uid()` compared a uuid column with text and
1038
+ * Postgres refused the table, and the old "signed in" clause — a bare
1039
+ * `rebase.uid() IS NOT NULL` — let anonymous visitors through.
1040
+ */
1041
+ var OWNS_ROW_BY_USER_ID_SQL = compilePolicyExpression(policy.compare(policy.field("user_id"), "eq", policy.authUid()));
1042
+ var RLS_PRESETS = [
1043
+ {
1044
+ value: "authenticated",
1045
+ labelKey: "studio_tables_preset_authenticated"
1046
+ },
1047
+ {
1048
+ value: "public-read",
1049
+ labelKey: "studio_tables_preset_public_read"
1050
+ },
1051
+ {
1052
+ value: "owner",
1053
+ labelKey: "studio_tables_preset_owner"
1054
+ },
1055
+ {
1056
+ value: "admin-only",
1057
+ labelKey: "studio_tables_preset_admin_only"
1058
+ }
1059
+ ];
1060
+ var INITIAL_COLUMNS = [
1061
+ {
1062
+ name: "id",
1063
+ type: "uuid",
1064
+ primaryKey: true,
1065
+ nullable: false,
1066
+ unique: false,
1067
+ defaultExpr: "gen_random_uuid()"
1068
+ },
1069
+ {
1070
+ name: "title",
1071
+ type: "text",
1072
+ primaryKey: false,
1073
+ nullable: false,
1074
+ unique: false,
1075
+ defaultExpr: ""
1076
+ },
1077
+ {
1078
+ name: "created_at",
1079
+ type: "timestamptz",
1080
+ primaryKey: false,
1081
+ nullable: false,
1082
+ unique: false,
1083
+ defaultExpr: "now()"
1084
+ }
1085
+ ];
1086
+ function CreateTableDialog({ open, onOpenChange, schema, onCreated }) {
1087
+ const { t } = useTranslation();
1088
+ const { requestJson } = useAdminFetch();
1089
+ const snackbar = useSnackbarController();
1090
+ const [name, setName] = useState("");
1091
+ const [rlsPreset, setRlsPreset] = useState("authenticated");
1092
+ const [columns, setColumns] = useState(INITIAL_COLUMNS);
1093
+ const [previewSql, setPreviewSql] = useState(null);
1094
+ const [creating, setCreating] = useState(false);
1095
+ const payload = (dryRun) => {
1096
+ const policies = [];
1097
+ if (rlsPreset === "authenticated") policies.push({
1098
+ name: "authenticated_all",
1099
+ operation: "ALL",
1100
+ using: SIGNED_IN_SQL,
1101
+ withCheck: SIGNED_IN_SQL
1102
+ });
1103
+ else if (rlsPreset === "public-read") {
1104
+ policies.push({
1105
+ name: "public_read",
1106
+ operation: "SELECT",
1107
+ using: "true"
1108
+ });
1109
+ policies.push({
1110
+ name: "authenticated_write",
1111
+ operation: "ALL",
1112
+ using: SIGNED_IN_SQL,
1113
+ withCheck: SIGNED_IN_SQL
1114
+ });
1115
+ } else if (rlsPreset === "owner") policies.push({
1116
+ name: "owner_all",
1117
+ operation: "ALL",
1118
+ using: OWNS_ROW_BY_USER_ID_SQL,
1119
+ withCheck: OWNS_ROW_BY_USER_ID_SQL
1120
+ });
1121
+ return {
1122
+ schema,
1123
+ name: name.trim(),
1124
+ columns: columns.filter((column) => column.name.trim() !== "").map((column) => ({
1125
+ name: column.name.trim(),
1126
+ type: column.type,
1127
+ primaryKey: column.primaryKey,
1128
+ nullable: column.nullable,
1129
+ unique: column.unique,
1130
+ ...column.defaultExpr.trim() ? { default: column.defaultExpr.trim() } : {}
1131
+ })),
1132
+ enableRls: true,
1133
+ policies,
1134
+ dryRun
1135
+ };
1136
+ };
1137
+ const preview = async () => {
1138
+ try {
1139
+ const raw = await requestJson("/admin/db/tables", {
1140
+ method: "POST",
1141
+ body: payload(true)
1142
+ });
1143
+ setPreviewSql(isRecord(raw) ? asStringArray(raw.statements ?? raw.sql) : []);
1144
+ } catch (err) {
1145
+ snackbar.open({
1146
+ type: "error",
1147
+ message: err instanceof Error ? err.message : t("studio_tables_sql_preview_failed")
1148
+ });
1149
+ }
1150
+ };
1151
+ const create = async () => {
1152
+ setCreating(true);
1153
+ try {
1154
+ const created = name.trim();
1155
+ await requestJson("/admin/db/tables", {
1156
+ method: "POST",
1157
+ body: payload(false)
1158
+ });
1159
+ onOpenChange(false);
1160
+ setName("");
1161
+ setPreviewSql(null);
1162
+ setColumns(INITIAL_COLUMNS);
1163
+ onCreated(created);
1164
+ } catch (err) {
1165
+ snackbar.open({
1166
+ type: "error",
1167
+ message: err instanceof Error ? err.message : t("studio_tables_create_failed")
1168
+ });
1169
+ } finally {
1170
+ setCreating(false);
1171
+ }
1172
+ };
1173
+ const update = (index, change) => setColumns((prev) => prev.map((column, i) => i === index ? {
1174
+ ...column,
1175
+ ...change
1176
+ } : column));
1177
+ return /* @__PURE__ */ jsxs(Dialog, {
1178
+ open,
1179
+ onOpenChange,
1180
+ maxWidth: "2xl",
1181
+ fullWidth: true,
1182
+ children: [
1183
+ /* @__PURE__ */ jsx(DialogTitle, { children: t("studio_tables_create_table") }),
1184
+ /* @__PURE__ */ jsxs(DialogContent, {
1185
+ className: "flex flex-col gap-4",
1186
+ children: [
1187
+ /* @__PURE__ */ jsxs("div", {
1188
+ className: "grid grid-cols-1 md:grid-cols-2 gap-3",
1189
+ children: [/* @__PURE__ */ jsx(TextField, {
1190
+ label: t("studio_tables_name_label"),
1191
+ value: name,
1192
+ onChange: (event) => setName(event.target.value),
1193
+ placeholder: "projects"
1194
+ }), /* @__PURE__ */ jsx(Select, {
1195
+ label: t("studio_tables_initial_rls"),
1196
+ value: rlsPreset,
1197
+ onValueChange: (value) => setRlsPreset(String(value)),
1198
+ children: RLS_PRESETS.map((preset) => /* @__PURE__ */ jsx(SelectItem, {
1199
+ value: preset.value,
1200
+ children: t(preset.labelKey)
1201
+ }, preset.value))
1202
+ })]
1203
+ }),
1204
+ /* @__PURE__ */ jsxs("div", {
1205
+ className: "flex flex-col gap-2",
1206
+ children: [/* @__PURE__ */ jsxs("div", {
1207
+ className: "flex items-center justify-between",
1208
+ children: [/* @__PURE__ */ jsx(Typography, {
1209
+ variant: "subtitle2",
1210
+ children: t("studio_columns")
1211
+ }), /* @__PURE__ */ jsxs(Button, {
1212
+ size: "small",
1213
+ variant: "outlined",
1214
+ onClick: () => setColumns((prev) => [...prev, {
1215
+ name: "",
1216
+ type: "text",
1217
+ primaryKey: false,
1218
+ nullable: true,
1219
+ unique: false,
1220
+ defaultExpr: ""
1221
+ }]),
1222
+ children: [/* @__PURE__ */ jsx(PlusIcon, { size: iconSize.small }), t("studio_tables_add_column")]
1223
+ })]
1224
+ }), /* @__PURE__ */ jsx("div", {
1225
+ className: "flex flex-col gap-2 max-h-64 overflow-y-auto pr-1",
1226
+ children: columns.map((column, index) => /* @__PURE__ */ jsxs("div", {
1227
+ className: cls("grid grid-cols-12 gap-2 items-center p-2 rounded-md border", defaultBorderMixin),
1228
+ children: [
1229
+ /* @__PURE__ */ jsx("div", {
1230
+ className: "col-span-3",
1231
+ children: /* @__PURE__ */ jsx(TextField, {
1232
+ size: "small",
1233
+ placeholder: "column_name",
1234
+ value: column.name,
1235
+ onChange: (event) => update(index, { name: event.target.value })
1236
+ })
1237
+ }),
1238
+ /* @__PURE__ */ jsx("div", {
1239
+ className: "col-span-3",
1240
+ children: /* @__PURE__ */ jsx(Select, {
1241
+ size: "small",
1242
+ value: column.type,
1243
+ onValueChange: (value) => update(index, { type: String(value) }),
1244
+ children: SQL_TYPES.map((type) => /* @__PURE__ */ jsx(SelectItem, {
1245
+ value: type,
1246
+ children: type
1247
+ }, type))
1248
+ })
1249
+ }),
1250
+ /* @__PURE__ */ jsx("div", {
1251
+ className: "col-span-3",
1252
+ children: /* @__PURE__ */ jsx(TextField, {
1253
+ size: "small",
1254
+ placeholder: t("studio_tables_default_optional_placeholder"),
1255
+ value: column.defaultExpr,
1256
+ onChange: (event) => update(index, { defaultExpr: event.target.value })
1257
+ })
1258
+ }),
1259
+ /* @__PURE__ */ jsxs("div", {
1260
+ className: "col-span-2 flex items-center gap-1",
1261
+ children: [/* @__PURE__ */ jsx(Chip, {
1262
+ size: "small",
1263
+ colorScheme: column.primaryKey ? "blueLight" : "grayLight",
1264
+ onClick: () => update(index, {
1265
+ primaryKey: !column.primaryKey,
1266
+ nullable: !column.primaryKey ? false : column.nullable
1267
+ }),
1268
+ children: "PK"
1269
+ }), /* @__PURE__ */ jsx(Chip, {
1270
+ size: "small",
1271
+ colorScheme: !column.nullable ? "orangeLight" : "grayLight",
1272
+ onClick: () => update(index, { nullable: !column.nullable }),
1273
+ children: "NN"
1274
+ })]
1275
+ }),
1276
+ /* @__PURE__ */ jsx("div", {
1277
+ className: "col-span-1 flex justify-end",
1278
+ children: /* @__PURE__ */ jsx(IconButton, {
1279
+ size: "small",
1280
+ "aria-label": t("studio_tables_remove_draft_column"),
1281
+ onClick: () => setColumns((prev) => prev.filter((_, i) => i !== index)),
1282
+ children: /* @__PURE__ */ jsx(Trash2Icon, { size: iconSize.small })
1283
+ })
1284
+ })
1285
+ ]
1286
+ }, index))
1287
+ })]
1288
+ }),
1289
+ previewSql && previewSql.length > 0 && /* @__PURE__ */ jsx(SqlBlock, { sql: previewSql.join("\n") })
1290
+ ]
1291
+ }),
1292
+ /* @__PURE__ */ jsxs(DialogActions, { children: [
1293
+ /* @__PURE__ */ jsx(Button, {
1294
+ variant: "text",
1295
+ onClick: () => onOpenChange(false),
1296
+ children: t("cancel")
1297
+ }),
1298
+ /* @__PURE__ */ jsx(Button, {
1299
+ variant: "outlined",
1300
+ disabled: !name.trim(),
1301
+ onClick: () => void preview(),
1302
+ children: t("studio_tables_preview_sql")
1303
+ }),
1304
+ /* @__PURE__ */ jsx(Button, {
1305
+ variant: "filled",
1306
+ color: "primary",
1307
+ disabled: creating || !name.trim(),
1308
+ onClick: () => void create(),
1309
+ children: creating ? t("studio_tables_creating") : t("studio_tables_create_table")
1310
+ })
1311
+ ] })
1312
+ ]
1313
+ });
1314
+ }
1315
+ //#endregion
1316
+ //#region src/components/TableEditor/TableDdlSheet.tsx
1317
+ /** The table's definition as one SQL script, to read, copy, or take to the SQL editor. */
1318
+ function TableDdlSheet({ open, onOpenChange, title, ddl, loading }) {
1319
+ const { t } = useTranslation();
1320
+ const navigate = useNavigate();
1321
+ return /* @__PURE__ */ jsx(Sheet, {
1322
+ open,
1323
+ onOpenChange,
1324
+ title: t("studio_tables_ddl_title", { name: title }),
1325
+ children: /* @__PURE__ */ jsxs("div", {
1326
+ className: "w-[min(720px,100vw)] h-full flex flex-col gap-4 p-5 bg-surface-card",
1327
+ children: [
1328
+ /* @__PURE__ */ jsxs("div", {
1329
+ className: "flex items-center justify-between gap-2",
1330
+ children: [/* @__PURE__ */ jsx(Typography, {
1331
+ variant: "subtitle1",
1332
+ className: "font-mono truncate",
1333
+ children: t("studio_tables_ddl_title", { name: title })
1334
+ }), /* @__PURE__ */ jsx(IconButton, {
1335
+ size: "small",
1336
+ "aria-label": t("close"),
1337
+ onClick: () => onOpenChange(false),
1338
+ children: /* @__PURE__ */ jsx(XIcon, { size: iconSize.smallest })
1339
+ })]
1340
+ }),
1341
+ /* @__PURE__ */ jsx(Typography, {
1342
+ variant: "body2",
1343
+ color: "secondary",
1344
+ children: t("studio_tables_ddl_body")
1345
+ }),
1346
+ loading || ddl === null ? /* @__PURE__ */ jsx(Typography, {
1347
+ variant: "body2",
1348
+ color: "secondary",
1349
+ children: t("loading")
1350
+ }) : /* @__PURE__ */ jsx(SqlBlock, {
1351
+ sql: ddl,
1352
+ className: "flex-1 min-h-0",
1353
+ maxHeight: "max-h-full h-full"
1354
+ }),
1355
+ /* @__PURE__ */ jsx("div", {
1356
+ className: "flex justify-end",
1357
+ children: /* @__PURE__ */ jsxs(Button, {
1358
+ variant: "outlined",
1359
+ disabled: !ddl,
1360
+ onClick: () => ddl && navigate(sqlDraftLink(ddl)),
1361
+ children: [/* @__PURE__ */ jsx(TerminalIcon, { size: iconSize.smallest }), t("studio_tables_ddl_open_in_sql")]
1362
+ })
1363
+ })
1364
+ ]
1365
+ })
1366
+ });
1367
+ }
1368
+ //#endregion
1369
+ //#region src/utils/csv_parse.ts
1370
+ /**
1371
+ * RFC 4180 CSV, read back: quoted fields may hold commas, line breaks and
1372
+ * doubled quotes; a record ends at CRLF or LF. An empty unquoted field is
1373
+ * `null` (the export writes NULL as nothing), an empty quoted one `""`.
1374
+ */
1375
+ function parseCsv(text) {
1376
+ const records = [];
1377
+ let record = [];
1378
+ let field = "";
1379
+ let quoted = false;
1380
+ let wasQuoted = false;
1381
+ let i = 0;
1382
+ const source = text.charCodeAt(0) === 65279 ? text.slice(1) : text;
1383
+ const endField = () => {
1384
+ record.push(field === "" && !wasQuoted ? null : field);
1385
+ field = "";
1386
+ wasQuoted = false;
1387
+ };
1388
+ const endRecord = () => {
1389
+ endField();
1390
+ if (!(record.length === 1 && record[0] === null)) records.push(record);
1391
+ record = [];
1392
+ };
1393
+ while (i < source.length) {
1394
+ const ch = source[i];
1395
+ if (quoted) {
1396
+ if (ch === "\"") {
1397
+ if (source[i + 1] === "\"") {
1398
+ field += "\"";
1399
+ i += 2;
1400
+ continue;
1401
+ }
1402
+ quoted = false;
1403
+ i++;
1404
+ continue;
1405
+ }
1406
+ field += ch;
1407
+ i++;
1408
+ continue;
1409
+ }
1410
+ if (ch === "\"" && field === "") {
1411
+ quoted = true;
1412
+ wasQuoted = true;
1413
+ i++;
1414
+ } else if (ch === ",") {
1415
+ endField();
1416
+ i++;
1417
+ } else if (ch === "\r" && source[i + 1] === "\n") {
1418
+ endRecord();
1419
+ i += 2;
1420
+ } else if (ch === "\n") {
1421
+ endRecord();
1422
+ i++;
1423
+ } else {
1424
+ field += ch;
1425
+ i++;
1426
+ }
1427
+ }
1428
+ if (field !== "" || wasQuoted || record.length > 0) endRecord();
1429
+ return records;
1430
+ }
1431
+ /** The first record as column names, the rest as rows keyed by them. */
1432
+ function parseCsvWithHeader(text) {
1433
+ const [header, ...body] = parseCsv(text);
1434
+ const columns = (header ?? []).map((name) => (name ?? "").trim());
1435
+ return {
1436
+ columns,
1437
+ rows: body.map((record) => {
1438
+ const row = {};
1439
+ columns.forEach((column, index) => {
1440
+ if (column) row[column] = record[index] ?? null;
1441
+ });
1442
+ return row;
1443
+ })
1444
+ };
1445
+ }
1446
+ //#endregion
1447
+ //#region src/components/TableEditor/tabs/DataTab.tsx
1448
+ var PAGE_SIZES = [
1449
+ 50,
1450
+ 100,
1451
+ 500
1452
+ ];
1453
+ /** One empty list each, so a page not loaded yet hands the memos the same arrays every render. */
1454
+ var NO_COLUMNS = [];
1455
+ var NO_ROWS = [];
1456
+ var NO_KEY = [];
1457
+ var SELECT_COLUMN = "__select__";
1458
+ var ACTIONS_COLUMN = "__actions__";
1459
+ var IMPORT_CHUNK = 500;
1460
+ var ROW_ACTION_ICON = "text-text-secondary dark:text-text-secondary-dark hover:text-text-primary dark:hover:text-text-primary-dark transition-colors";
1461
+ var OPERATOR_LABEL = {
1462
+ eq: "=",
1463
+ neq: "≠",
1464
+ lt: "<",
1465
+ lte: "≤",
1466
+ gt: ">",
1467
+ gte: "≥",
1468
+ like: "LIKE",
1469
+ ilike: "ILIKE",
1470
+ in: "IN",
1471
+ is_null: "IS NULL",
1472
+ not_null: "IS NOT NULL"
1473
+ };
1474
+ /** A starting width wide enough for the column's usual values; the grid lets it be resized. */
1475
+ function columnWidth(column) {
1476
+ const udt = column.udt.toLowerCase();
1477
+ if (udt === "uuid") return 300;
1478
+ if (udt === "timestamptz" || udt === "timestamp") return 240;
1479
+ if (udt === "date" || udt === "bool") return 120;
1480
+ if (column.category === "N") return 130;
1481
+ if (udt === "json" || udt === "jsonb") return 280;
1482
+ return 200;
1483
+ }
1484
+ function isMonospace(column) {
1485
+ return column.primaryKey || column.category === "N" || column.category === "D" || column.udt === "uuid" || column.udt === "json" || column.udt === "jsonb";
1486
+ }
1487
+ /** The text a long or structured value is shown with in the viewer: JSON pretty-printed when it parses. */
1488
+ function prettyValue(value, column) {
1489
+ if (column && (column.udt === "json" || column.udt === "jsonb")) try {
1490
+ return JSON.stringify(JSON.parse(value), null, 2);
1491
+ } catch {
1492
+ return value;
1493
+ }
1494
+ return value;
1495
+ }
1496
+ /** A row's key: its primary key columns' text, which the admin API casts back to their types. */
1497
+ function rowKey(row, primaryKey) {
1498
+ const key = {};
1499
+ for (const column of primaryKey) key[column] = row[column] ?? null;
1500
+ return key;
1501
+ }
1502
+ function rowKeyString(row, primaryKey) {
1503
+ return JSON.stringify(primaryKey.map((column) => row[column]));
1504
+ }
1505
+ /** A data-API value as the text the admin API would have printed. */
1506
+ function apiValueText(value) {
1507
+ if (value === null || value === void 0) return null;
1508
+ return typeof value === "object" ? JSON.stringify(value) : String(value);
1509
+ }
1510
+ /**
1511
+ * The table's rows, read as the database owner through `/api/admin/db`
1512
+ * (unserved tables and views included), or — "View as" — through the data
1513
+ * API as one user, under the row level security that user gets.
1514
+ */
1515
+ function DataTab({ table }) {
1516
+ const { t, i18n } = useTranslation();
1517
+ const { requestJson, requestRaw } = useAdminFetch();
1518
+ const snackbar = useSnackbarController();
1519
+ const navigate = useNavigate();
1520
+ const [searchParams, setSearchParams] = useSearchParams();
1521
+ const filters = useMemo(() => parseFilterParam(searchParams.get(TABLE_FILTER_PARAM)), [searchParams]);
1522
+ const setFilters = useCallback((next) => {
1523
+ setSearchParams((prev) => {
1524
+ const params = new URLSearchParams(prev);
1525
+ if (next.length > 0) params.set(TABLE_FILTER_PARAM, JSON.stringify(next));
1526
+ else params.delete(TABLE_FILTER_PARAM);
1527
+ return params;
1528
+ }, { replace: true });
1529
+ }, [setSearchParams]);
1530
+ const [sort, setSort] = useState(null);
1531
+ const [pageSize, setPageSize] = useState(100);
1532
+ const [offset, setOffset] = useState(0);
1533
+ const [page, setPage] = useState(null);
1534
+ const [loading, setLoading] = useState(true);
1535
+ const [error, setError] = useState(null);
1536
+ const [selected, setSelected] = useState(/* @__PURE__ */ new Set());
1537
+ const [editingCell, setEditingCell] = useState(null);
1538
+ const [viewing, setViewing] = useState(null);
1539
+ const [rowDialog, setRowDialog] = useState(null);
1540
+ const [confirmDelete, setConfirmDelete] = useState(null);
1541
+ const [deleting, setDeleting] = useState(false);
1542
+ const [importOpen, setImportOpen] = useState(false);
1543
+ const [readAs, setReadAs] = useState("owner");
1544
+ const [viewAsUser, setViewAsUser] = useState(null);
1545
+ const runAs = useRunAsUsers();
1546
+ const throughApi = readAs === "api";
1547
+ const loadRequest = useRef(0);
1548
+ const filterKey = JSON.stringify(filters);
1549
+ useEffect(() => {
1550
+ setOffset(0);
1551
+ setSelected(/* @__PURE__ */ new Set());
1552
+ }, [
1553
+ filterKey,
1554
+ sort,
1555
+ pageSize,
1556
+ readAs,
1557
+ viewAsUser
1558
+ ]);
1559
+ const load = useCallback(async () => {
1560
+ const request = ++loadRequest.current;
1561
+ setLoading(true);
1562
+ setError(null);
1563
+ try {
1564
+ let next;
1565
+ if (throughApi) {
1566
+ const headers = {};
1567
+ if (viewAsUser && viewAsUser.uid !== runAs.currentUser?.uid) headers[IMPERSONATE_HEADER] = viewAsUser.uid;
1568
+ const raw = await requestJson(`/data/${encodeURIComponent(table.slug)}?limit=${pageSize}&offset=${offset}`, { headers });
1569
+ const records = isRecord(raw) && Array.isArray(raw.data) ? raw.data.filter(isRecord) : [];
1570
+ const byKey = new Map(table.columns.map((column) => [column.key, column.name]));
1571
+ const rows = records.map((record) => {
1572
+ const row = {};
1573
+ for (const [key, value] of Object.entries(record)) row[byKey.get(key) ?? key] = apiValueText(value);
1574
+ return row;
1575
+ });
1576
+ const total = isRecord(raw) && isRecord(raw.meta) && typeof raw.meta.total === "number" ? raw.meta.total : null;
1577
+ next = {
1578
+ columns: page?.columns ?? [],
1579
+ rows,
1580
+ count: {
1581
+ value: total ?? offset + rows.length,
1582
+ exact: total !== null
1583
+ },
1584
+ primaryKey: page?.primaryKey ?? [],
1585
+ readOnly: true,
1586
+ readOnlyReason: null
1587
+ };
1588
+ } else {
1589
+ const params = new URLSearchParams({
1590
+ schema: table.schema,
1591
+ limit: String(pageSize),
1592
+ offset: String(offset)
1593
+ });
1594
+ if (sort) {
1595
+ params.set("orderBy", sort.column);
1596
+ params.set("direction", sort.direction);
1597
+ }
1598
+ if (filters.length > 0) params.set("filters", JSON.stringify(filters));
1599
+ next = parseRowsPage(await requestJson(`/admin/db/tables/${encodeURIComponent(table.name)}/rows?${params.toString()}`));
1600
+ }
1601
+ if (request === loadRequest.current) setPage(next);
1602
+ } catch (err) {
1603
+ if (request === loadRequest.current) setError(err instanceof Error ? err : new Error(t("studio_tables_rows_load_failed")));
1604
+ } finally {
1605
+ if (request === loadRequest.current) setLoading(false);
1606
+ }
1607
+ }, [
1608
+ throughApi,
1609
+ viewAsUser,
1610
+ runAs.currentUser?.uid,
1611
+ requestJson,
1612
+ table,
1613
+ pageSize,
1614
+ offset,
1615
+ sort,
1616
+ filterKey,
1617
+ t
1618
+ ]);
1619
+ useEffect(() => {
1620
+ load();
1621
+ }, [load]);
1622
+ const columns = page?.columns ?? NO_COLUMNS;
1623
+ const rows = page?.rows ?? NO_ROWS;
1624
+ const primaryKey = page?.primaryKey ?? NO_KEY;
1625
+ const writable = !throughApi && page !== null && !page.readOnly;
1626
+ const columnByName = useMemo(() => new Map(columns.map((column) => [column.name, column])), [columns]);
1627
+ /** A column that is the whole of a foreign key opens the row it points at. */
1628
+ const foreignKeyByColumn = useMemo(() => {
1629
+ const map = /* @__PURE__ */ new Map();
1630
+ for (const fk of table.foreignKeys) if (fk.fromColumns.length === 1) map.set(fk.fromColumns[0], fk);
1631
+ return map;
1632
+ }, [table.foreignKeys]);
1633
+ const openForeignRow = useCallback((fk, value) => {
1634
+ navigate(tablesLink(`${fk.toSchema}.${fk.toTable}`, "data", [{
1635
+ column: fk.toColumns[0],
1636
+ op: "eq",
1637
+ value
1638
+ }]));
1639
+ }, [navigate]);
1640
+ const saveCell = useCallback(async (text, row, column, rowIndex) => {
1641
+ const editing = editingCell;
1642
+ setEditingCell(null);
1643
+ if (!editing || text === editing.initialValue) return;
1644
+ const value = text === "" && !column.notNull ? null : text;
1645
+ try {
1646
+ const saved = await requestJson(`/admin/db/tables/${encodeURIComponent(table.name)}/rows`, {
1647
+ method: "PATCH",
1648
+ body: {
1649
+ schema: table.schema,
1650
+ key: rowKey(row, primaryKey),
1651
+ values: { [column.name]: value }
1652
+ }
1653
+ });
1654
+ const savedRow = isRecord(saved) && isRecord(saved.row) ? parseRowsPage({ rows: [saved.row] }).rows[0] : null;
1655
+ setPage((prev) => {
1656
+ if (!prev || !savedRow) return prev;
1657
+ const nextRows = [...prev.rows];
1658
+ if (rowKeyString(nextRows[rowIndex] ?? {}, primaryKey) !== rowKeyString(row, primaryKey)) return prev;
1659
+ nextRows[rowIndex] = savedRow;
1660
+ return {
1661
+ ...prev,
1662
+ rows: nextRows
1663
+ };
1664
+ });
1665
+ snackbar.open({
1666
+ type: "success",
1667
+ message: t("studio_tables_row_updated")
1668
+ });
1669
+ } catch (err) {
1670
+ snackbar.open({
1671
+ type: "error",
1672
+ message: err instanceof Error ? err.message : t("studio_tables_row_save_failed")
1673
+ });
1674
+ }
1675
+ }, [
1676
+ editingCell,
1677
+ requestJson,
1678
+ table,
1679
+ primaryKey,
1680
+ snackbar,
1681
+ t
1682
+ ]);
1683
+ const deleteRows = async () => {
1684
+ if (!confirmDelete) return;
1685
+ setDeleting(true);
1686
+ try {
1687
+ const result = await requestJson(`/admin/db/tables/${encodeURIComponent(table.name)}/rows`, {
1688
+ method: "DELETE",
1689
+ body: {
1690
+ schema: table.schema,
1691
+ keys: confirmDelete.map((row) => rowKey(row, primaryKey))
1692
+ }
1693
+ });
1694
+ const count = isRecord(result) && typeof result.deleted === "number" ? result.deleted : confirmDelete.length;
1695
+ snackbar.open({
1696
+ type: "success",
1697
+ message: t("studio_tables_rows_deleted", { count })
1698
+ });
1699
+ setConfirmDelete(null);
1700
+ setSelected(/* @__PURE__ */ new Set());
1701
+ await load();
1702
+ } catch (err) {
1703
+ snackbar.open({
1704
+ type: "error",
1705
+ message: err instanceof Error ? err.message : t("studio_tables_row_delete_failed")
1706
+ });
1707
+ } finally {
1708
+ setDeleting(false);
1709
+ }
1710
+ };
1711
+ const exportCsv = async () => {
1712
+ try {
1713
+ const params = new URLSearchParams({
1714
+ schema: table.schema,
1715
+ format: "csv"
1716
+ });
1717
+ if (sort) {
1718
+ params.set("orderBy", sort.column);
1719
+ params.set("direction", sort.direction);
1720
+ }
1721
+ if (filters.length > 0) params.set("filters", JSON.stringify(filters));
1722
+ const blob = await (await requestRaw(`/admin/db/tables/${encodeURIComponent(table.name)}/rows?${params.toString()}`)).blob();
1723
+ const url = URL.createObjectURL(blob);
1724
+ const link = document.createElement("a");
1725
+ link.href = url;
1726
+ link.download = `${table.schema}.${table.name}.csv`;
1727
+ link.click();
1728
+ URL.revokeObjectURL(url);
1729
+ } catch (err) {
1730
+ snackbar.open({
1731
+ type: "error",
1732
+ message: err instanceof Error ? err.message : t("studio_tables_export_failed")
1733
+ });
1734
+ }
1735
+ };
1736
+ const sortBy = useMemo(() => sort ? [[sort.column, sort.direction]] : void 0, [sort]);
1737
+ const gridColumns = useMemo(() => [...writable ? [{
1738
+ key: SELECT_COLUMN,
1739
+ title: "",
1740
+ width: 40,
1741
+ sortable: false,
1742
+ resizable: false
1743
+ }, {
1744
+ key: ACTIONS_COLUMN,
1745
+ title: "",
1746
+ width: 76,
1747
+ sortable: false,
1748
+ resizable: false
1749
+ }] : [], ...columns.map((column) => ({
1750
+ key: column.name,
1751
+ title: column.name,
1752
+ width: columnWidth(column),
1753
+ sortable: !throughApi,
1754
+ resizable: true
1755
+ }))], [
1756
+ columns,
1757
+ writable,
1758
+ throughApi
1759
+ ]);
1760
+ const pageKeys = useMemo(() => rows.map((row) => rowKeyString(row, primaryKey)), [rows, primaryKey]);
1761
+ const allSelected = pageKeys.length > 0 && pageKeys.every((key) => selected.has(key));
1762
+ const renderCell = useCallback(({ rowData, column, rowIndex }) => {
1763
+ if (!rowData) return null;
1764
+ if (column.key === SELECT_COLUMN) {
1765
+ const key = rowKeyString(rowData, primaryKey);
1766
+ return /* @__PURE__ */ jsx("div", {
1767
+ className: "h-full flex items-center justify-center",
1768
+ children: /* @__PURE__ */ jsx(Checkbox, {
1769
+ size: "smallest",
1770
+ checked: selected.has(key),
1771
+ onCheckedChange: (checked) => setSelected((prev) => {
1772
+ const next = new Set(prev);
1773
+ if (checked) next.add(key);
1774
+ else next.delete(key);
1775
+ return next;
1776
+ })
1777
+ })
1778
+ });
1779
+ }
1780
+ if (column.key === ACTIONS_COLUMN) return /* @__PURE__ */ jsxs("div", {
1781
+ className: "h-full flex items-center justify-center gap-0.5",
1782
+ children: [/* @__PURE__ */ jsx(Tooltip, {
1783
+ title: t("studio_tables_edit_row"),
1784
+ children: /* @__PURE__ */ jsx(IconButton, {
1785
+ size: "small",
1786
+ "aria-label": t("studio_tables_edit_row"),
1787
+ className: ROW_ACTION_ICON,
1788
+ onClick: () => setRowDialog({
1789
+ mode: "edit",
1790
+ row: rowData
1791
+ }),
1792
+ children: /* @__PURE__ */ jsx(PencilIcon, { size: iconSize.smallest })
1793
+ })
1794
+ }), /* @__PURE__ */ jsx(Tooltip, {
1795
+ title: t("delete_row"),
1796
+ children: /* @__PURE__ */ jsx(IconButton, {
1797
+ size: "small",
1798
+ "aria-label": t("delete_row"),
1799
+ className: ROW_ACTION_ICON,
1800
+ onClick: () => setConfirmDelete([rowData]),
1801
+ children: /* @__PURE__ */ jsx(Trash2Icon, { size: iconSize.smallest })
1802
+ })
1803
+ })]
1804
+ });
1805
+ const catalogColumn = columnByName.get(column.key);
1806
+ const value = rowData[column.key] ?? null;
1807
+ if (editingCell && editingCell.rowIndex === rowIndex && editingCell.column === column.key && catalogColumn) return /* @__PURE__ */ jsx(FixedEditorOverlay, {
1808
+ displayValue: editingCell.initialValue,
1809
+ onSave: (text) => void saveCell(text, rowData, catalogColumn, rowIndex),
1810
+ onCancel: () => setEditingCell(null)
1811
+ });
1812
+ const fk = foreignKeyByColumn.get(column.key);
1813
+ const long = value !== null && (value.length > 60 || value.includes("\n") || catalogColumn?.udt === "json" || catalogColumn?.udt === "jsonb");
1814
+ const editable = writable && catalogColumn && !catalogColumn.generated && !catalogColumn.primaryKey;
1815
+ return /* @__PURE__ */ jsxs("div", {
1816
+ className: cls("group px-3 h-full flex items-center gap-1 whitespace-nowrap min-w-0", editable && "cursor-text"),
1817
+ title: value ?? "NULL",
1818
+ onDoubleClick: () => {
1819
+ if (!editable) return;
1820
+ setEditingCell({
1821
+ rowIndex,
1822
+ column: column.key,
1823
+ initialValue: value ?? ""
1824
+ });
1825
+ },
1826
+ children: [/* @__PURE__ */ jsx("div", {
1827
+ className: "min-w-0 flex-1 truncate",
1828
+ children: value === null ? /* @__PURE__ */ jsx(Typography, {
1829
+ variant: "caption",
1830
+ color: "disabled",
1831
+ className: "italic",
1832
+ children: "NULL"
1833
+ }) : fk ? /* @__PURE__ */ jsx("button", {
1834
+ type: "button",
1835
+ className: "text-primary hover:underline truncate font-mono text-xs",
1836
+ onClick: () => openForeignRow(fk, value),
1837
+ children: value
1838
+ }) : catalogColumn && isMonospace(catalogColumn) ? /* @__PURE__ */ jsx(Typography, {
1839
+ variant: "mono",
1840
+ className: "truncate text-xs text-text-secondary dark:text-text-secondary-dark",
1841
+ children: value
1842
+ }) : /* @__PURE__ */ jsx(Typography, {
1843
+ variant: "body2",
1844
+ className: "truncate text-[13px]",
1845
+ children: value
1846
+ })
1847
+ }), long && value !== null && /* @__PURE__ */ jsx(IconButton, {
1848
+ size: "smallest",
1849
+ "aria-label": t("studio_tables_view_value"),
1850
+ className: ROW_ACTION_ICON,
1851
+ onClick: () => setViewing({
1852
+ column: column.key,
1853
+ value
1854
+ }),
1855
+ children: /* @__PURE__ */ jsx(Maximize2Icon, { size: 12 })
1856
+ })]
1857
+ });
1858
+ }, [
1859
+ primaryKey,
1860
+ selected,
1861
+ t,
1862
+ columnByName,
1863
+ editingCell,
1864
+ saveCell,
1865
+ foreignKeyByColumn,
1866
+ writable,
1867
+ openForeignRow
1868
+ ]);
1869
+ const count = page?.count ?? {
1870
+ value: 0,
1871
+ exact: true
1872
+ };
1873
+ const firstRow = rows.length === 0 ? 0 : offset + 1;
1874
+ const lastRow = offset + rows.length;
1875
+ const formatter = new Intl.NumberFormat(i18n?.language);
1876
+ const totalLabel = count.exact ? formatter.format(count.value) : `~${formatter.format(count.value)}`;
1877
+ const hasNext = count.exact ? lastRow < count.value : rows.length === pageSize;
1878
+ const selectedRows = rows.filter((row) => selected.has(rowKeyString(row, primaryKey)));
1879
+ return /* @__PURE__ */ jsxs("div", {
1880
+ className: "flex-1 flex flex-col min-h-0 min-w-0",
1881
+ children: [
1882
+ /* @__PURE__ */ jsxs("div", {
1883
+ className: "px-4 py-2 flex items-center justify-between gap-3 flex-wrap shrink-0",
1884
+ children: [/* @__PURE__ */ jsxs("div", {
1885
+ className: "flex items-center gap-2 flex-wrap min-w-0",
1886
+ children: [!throughApi && /* @__PURE__ */ jsx(FilterBar, {
1887
+ columns,
1888
+ filters,
1889
+ onChange: setFilters
1890
+ }), throughApi && /* @__PURE__ */ jsx(Typography, {
1891
+ variant: "caption",
1892
+ color: "secondary",
1893
+ children: t("studio_tables_view_as_hint")
1894
+ })]
1895
+ }), /* @__PURE__ */ jsxs("div", {
1896
+ className: "flex items-center gap-2 shrink-0",
1897
+ children: [
1898
+ table.served && /* @__PURE__ */ jsxs("div", {
1899
+ className: "flex items-center gap-2",
1900
+ children: [/* @__PURE__ */ jsx(ToggleButtonGroup, {
1901
+ "aria-label": t("studio_tables_view_as"),
1902
+ value: readAs,
1903
+ onValueChange: setReadAs,
1904
+ options: [{
1905
+ value: "owner",
1906
+ label: t("studio_tables_view_as_owner")
1907
+ }, {
1908
+ value: "api",
1909
+ label: t("studio_tables_view_as_user")
1910
+ }]
1911
+ }), throughApi && /* @__PURE__ */ jsx(UserSelectPopover, {
1912
+ selectedUser: viewAsUser,
1913
+ onUserSelected: setViewAsUser,
1914
+ users: runAs.users,
1915
+ loading: runAs.loading,
1916
+ onSearchTextChange: runAs.onSearchTextChange,
1917
+ totalCount: runAs.totalCount,
1918
+ currentUser: runAs.currentUser
1919
+ })]
1920
+ }),
1921
+ writable && selectedRows.length > 0 && /* @__PURE__ */ jsxs(Button, {
1922
+ size: "small",
1923
+ variant: "outlined",
1924
+ color: "error",
1925
+ onClick: () => setConfirmDelete(selectedRows),
1926
+ children: [/* @__PURE__ */ jsx(Trash2Icon, { size: iconSize.smallest }), t("studio_tables_delete_selected", { count: selectedRows.length })]
1927
+ }),
1928
+ /* @__PURE__ */ jsx(Tooltip, {
1929
+ title: t("studio_tables_refresh_rows"),
1930
+ children: /* @__PURE__ */ jsx(IconButton, {
1931
+ size: "small",
1932
+ "aria-label": t("studio_tables_refresh_rows"),
1933
+ onClick: () => void load(),
1934
+ children: /* @__PURE__ */ jsx(RefreshCwIcon, { size: iconSize.smallest })
1935
+ })
1936
+ }),
1937
+ !throughApi && /* @__PURE__ */ jsx(Tooltip, {
1938
+ title: t("studio_tables_export_csv"),
1939
+ children: /* @__PURE__ */ jsx(IconButton, {
1940
+ size: "small",
1941
+ "aria-label": t("studio_tables_export_csv"),
1942
+ onClick: () => void exportCsv(),
1943
+ children: /* @__PURE__ */ jsx(DownloadIcon, { size: iconSize.smallest })
1944
+ })
1945
+ }),
1946
+ writable && /* @__PURE__ */ jsx(Tooltip, {
1947
+ title: t("studio_tables_import_csv"),
1948
+ children: /* @__PURE__ */ jsx(IconButton, {
1949
+ size: "small",
1950
+ "aria-label": t("studio_tables_import_csv"),
1951
+ onClick: () => setImportOpen(true),
1952
+ children: /* @__PURE__ */ jsx(UploadIcon, { size: iconSize.smallest })
1953
+ })
1954
+ }),
1955
+ writable && /* @__PURE__ */ jsxs(Button, {
1956
+ size: "small",
1957
+ color: "primary",
1958
+ variant: "filled",
1959
+ onClick: () => setRowDialog({ mode: "insert" }),
1960
+ children: [/* @__PURE__ */ jsx(PlusIcon, { size: iconSize.smallest }), t("studio_tables_add_row")]
1961
+ })
1962
+ ]
1963
+ })]
1964
+ }),
1965
+ page?.readOnlyReason === "no_primary_key" && !throughApi && /* @__PURE__ */ jsx("div", {
1966
+ className: "px-4 pb-2 shrink-0",
1967
+ children: /* @__PURE__ */ jsx(Alert, {
1968
+ color: "info",
1969
+ size: "small",
1970
+ children: t("studio_tables_read_only_no_pk")
1971
+ })
1972
+ }),
1973
+ /* @__PURE__ */ jsx("div", {
1974
+ className: "flex-1 relative min-h-0 min-w-0",
1975
+ children: /* @__PURE__ */ jsx(VirtualTable, {
1976
+ data: rows,
1977
+ columns: gridColumns,
1978
+ rowHeight: 32,
1979
+ headerHeight: 32,
1980
+ loading,
1981
+ error: error ?? void 0,
1982
+ extraData: {
1983
+ editingCell,
1984
+ selected
1985
+ },
1986
+ cellRenderer: renderCell,
1987
+ sortBy,
1988
+ onSortByUpdate: (next) => {
1989
+ const first = next?.[0];
1990
+ setSort(first ? {
1991
+ column: first[0],
1992
+ direction: first[1]
1993
+ } : null);
1994
+ },
1995
+ emptyComponent: /* @__PURE__ */ jsxs("div", {
1996
+ className: "flex flex-col items-center gap-3 text-center",
1997
+ children: [/* @__PURE__ */ jsx(Typography, {
1998
+ variant: "body2",
1999
+ color: "secondary",
2000
+ children: filters.length > 0 ? t("studio_tables_no_matching_rows") : t("studio_tables_no_rows", { name: table.name })
2001
+ }), writable && filters.length === 0 && /* @__PURE__ */ jsxs(Button, {
2002
+ size: "small",
2003
+ variant: "outlined",
2004
+ onClick: () => setRowDialog({ mode: "insert" }),
2005
+ children: [/* @__PURE__ */ jsx(PlusIcon, { size: iconSize.small }), t("studio_tables_insert_first_row")]
2006
+ })]
2007
+ })
2008
+ })
2009
+ }),
2010
+ /* @__PURE__ */ jsxs("div", {
2011
+ className: "px-4 h-10 flex items-center justify-between gap-3 shrink-0",
2012
+ children: [/* @__PURE__ */ jsxs("div", {
2013
+ className: "flex items-center gap-2",
2014
+ children: [writable && /* @__PURE__ */ jsx(Checkbox, {
2015
+ size: "smallest",
2016
+ checked: allSelected,
2017
+ indeterminate: !allSelected && selectedRows.length > 0,
2018
+ onCheckedChange: (checked) => setSelected(checked ? new Set(pageKeys) : /* @__PURE__ */ new Set())
2019
+ }), /* @__PURE__ */ jsx(Typography, {
2020
+ variant: "caption",
2021
+ color: "secondary",
2022
+ children: t("studio_tables_rows_range", {
2023
+ first: formatter.format(firstRow),
2024
+ last: formatter.format(lastRow),
2025
+ total: totalLabel
2026
+ })
2027
+ })]
2028
+ }), /* @__PURE__ */ jsxs("div", {
2029
+ className: "flex items-center gap-2",
2030
+ children: [
2031
+ /* @__PURE__ */ jsx(Select, {
2032
+ size: "smallest",
2033
+ value: String(pageSize),
2034
+ onValueChange: (value) => setPageSize(Number(value)),
2035
+ renderValue: (value) => t("studio_tables_page_size", { count: Number(value) }),
2036
+ children: PAGE_SIZES.map((size) => /* @__PURE__ */ jsx(SelectItem, {
2037
+ value: String(size),
2038
+ children: t("studio_tables_page_size", { count: size })
2039
+ }, size))
2040
+ }),
2041
+ /* @__PURE__ */ jsx(IconButton, {
2042
+ size: "small",
2043
+ "aria-label": t("studio_tables_previous_page"),
2044
+ disabled: offset === 0 || loading,
2045
+ onClick: () => setOffset(Math.max(0, offset - pageSize)),
2046
+ children: /* @__PURE__ */ jsx(ChevronLeftIcon, { size: iconSize.smallest })
2047
+ }),
2048
+ /* @__PURE__ */ jsx(IconButton, {
2049
+ size: "small",
2050
+ "aria-label": t("studio_tables_next_page"),
2051
+ disabled: !hasNext || loading,
2052
+ onClick: () => setOffset(offset + pageSize),
2053
+ children: /* @__PURE__ */ jsx(ChevronRightIcon, { size: iconSize.smallest })
2054
+ })
2055
+ ]
2056
+ })]
2057
+ }),
2058
+ /* @__PURE__ */ jsx(Sheet, {
2059
+ open: viewing !== null,
2060
+ onOpenChange: (open) => {
2061
+ if (!open) setViewing(null);
2062
+ },
2063
+ title: viewing?.column,
2064
+ children: /* @__PURE__ */ jsxs("div", {
2065
+ className: "w-[min(640px,100vw)] h-full flex flex-col gap-3 p-5 bg-surface-card",
2066
+ children: [/* @__PURE__ */ jsxs("div", {
2067
+ className: "flex items-center justify-between gap-2",
2068
+ children: [/* @__PURE__ */ jsx(Typography, {
2069
+ variant: "subtitle2",
2070
+ className: "font-mono",
2071
+ children: viewing?.column
2072
+ }), /* @__PURE__ */ jsx(IconButton, {
2073
+ size: "small",
2074
+ "aria-label": t("close"),
2075
+ onClick: () => setViewing(null),
2076
+ children: /* @__PURE__ */ jsx(XIcon, { size: iconSize.smallest })
2077
+ })]
2078
+ }), /* @__PURE__ */ jsx("pre", {
2079
+ className: "flex-1 overflow-auto rounded-lg bg-surface-field p-3 font-mono text-xs whitespace-pre-wrap break-all",
2080
+ children: viewing ? prettyValue(viewing.value, columnByName.get(viewing.column)) : ""
2081
+ })]
2082
+ })
2083
+ }),
2084
+ rowDialog && /* @__PURE__ */ jsx(RowDialog, {
2085
+ table,
2086
+ columns,
2087
+ primaryKey,
2088
+ row: rowDialog.mode === "edit" ? rowDialog.row : null,
2089
+ onClose: () => setRowDialog(null),
2090
+ onSaved: () => {
2091
+ setRowDialog(null);
2092
+ load();
2093
+ }
2094
+ }),
2095
+ importOpen && /* @__PURE__ */ jsx(ImportDialog, {
2096
+ table,
2097
+ columns,
2098
+ onClose: () => setImportOpen(false),
2099
+ onImported: () => {
2100
+ setImportOpen(false);
2101
+ load();
2102
+ }
2103
+ }),
2104
+ /* @__PURE__ */ jsx(ConfirmationDialog, {
2105
+ open: confirmDelete !== null,
2106
+ loading: deleting,
2107
+ onAccept: () => void deleteRows(),
2108
+ onCancel: () => setConfirmDelete(null),
2109
+ title: t("studio_tables_delete_rows_title", { count: confirmDelete?.length ?? 0 }),
2110
+ body: t("studio_tables_delete_rows_body", {
2111
+ count: confirmDelete?.length ?? 0,
2112
+ name: table.name
2113
+ })
2114
+ })
2115
+ ]
2116
+ });
2117
+ }
2118
+ function FilterBar({ columns, filters, onChange }) {
2119
+ const { t } = useTranslation();
2120
+ const [open, setOpen] = useState(false);
2121
+ const [column, setColumn] = useState("");
2122
+ const [op, setOp] = useState("eq");
2123
+ const [value, setValue] = useState("");
2124
+ useEffect(() => {
2125
+ if (open && !column && columns[0]) setColumn(columns[0].name);
2126
+ }, [
2127
+ open,
2128
+ column,
2129
+ columns
2130
+ ]);
2131
+ const needsValue = op !== "is_null" && op !== "not_null";
2132
+ const add = () => {
2133
+ if (!column || needsValue && value === "") return;
2134
+ const filter = op === "in" ? {
2135
+ column,
2136
+ op,
2137
+ value: value.split(",").map((item) => item.trim()).filter(Boolean)
2138
+ } : needsValue ? {
2139
+ column,
2140
+ op,
2141
+ value
2142
+ } : {
2143
+ column,
2144
+ op
2145
+ };
2146
+ onChange([...filters, filter]);
2147
+ setValue("");
2148
+ setOpen(false);
2149
+ };
2150
+ const describe = (filter) => {
2151
+ const shown = Array.isArray(filter.value) ? `(${filter.value.join(", ")})` : filter.value ?? "";
2152
+ return `${filter.column} ${OPERATOR_LABEL[filter.op]} ${shown}`.trim();
2153
+ };
2154
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
2155
+ filters.map((filter, index) => /* @__PURE__ */ jsx(FilterChip, {
2156
+ active: true,
2157
+ size: "small",
2158
+ icon: /* @__PURE__ */ jsx(XIcon, { size: 12 }),
2159
+ "aria-label": t("studio_tables_remove_filter", { filter: describe(filter) }),
2160
+ onClick: () => onChange(filters.filter((_, i) => i !== index)),
2161
+ children: /* @__PURE__ */ jsx("span", {
2162
+ className: "font-mono",
2163
+ children: describe(filter)
2164
+ })
2165
+ }, `${filter.column}-${index}`)),
2166
+ /* @__PURE__ */ jsx(Popover, {
2167
+ open,
2168
+ onOpenChange: setOpen,
2169
+ align: "start",
2170
+ trigger: /* @__PURE__ */ jsxs(Button, {
2171
+ size: "small",
2172
+ variant: "text",
2173
+ children: [/* @__PURE__ */ jsx(FilterIcon, { size: iconSize.smallest }), t("studio_tables_add_filter")]
2174
+ }),
2175
+ children: /* @__PURE__ */ jsxs("div", {
2176
+ className: "p-3 flex flex-col gap-2 w-72",
2177
+ children: [
2178
+ /* @__PURE__ */ jsx(Select, {
2179
+ size: "small",
2180
+ label: t("studio_branch_diff_object_column"),
2181
+ value: column,
2182
+ onValueChange: (next) => setColumn(String(next)),
2183
+ children: columns.map((candidate) => /* @__PURE__ */ jsx(SelectItem, {
2184
+ value: candidate.name,
2185
+ children: candidate.name
2186
+ }, candidate.name))
2187
+ }),
2188
+ /* @__PURE__ */ jsx(Select, {
2189
+ size: "small",
2190
+ label: t("studio_tables_filter_operator"),
2191
+ value: op,
2192
+ onValueChange: (next) => {
2193
+ const found = ROW_FILTER_OPERATORS.find((candidate) => candidate === next);
2194
+ if (found) setOp(found);
2195
+ },
2196
+ children: ROW_FILTER_OPERATORS.map((candidate) => /* @__PURE__ */ jsx(SelectItem, {
2197
+ value: candidate,
2198
+ children: OPERATOR_LABEL[candidate]
2199
+ }, candidate))
2200
+ }),
2201
+ needsValue && /* @__PURE__ */ jsx(TextField, {
2202
+ size: "small",
2203
+ label: op === "in" ? t("studio_tables_filter_values") : t("studio_tables_filter_value"),
2204
+ value,
2205
+ onChange: (event) => setValue(event.target.value),
2206
+ onKeyDown: (event) => {
2207
+ if (event.key === "Enter") {
2208
+ event.preventDefault();
2209
+ add();
2210
+ }
2211
+ }
2212
+ }),
2213
+ /* @__PURE__ */ jsx("div", {
2214
+ className: "flex justify-end",
2215
+ children: /* @__PURE__ */ jsx(Button, {
2216
+ size: "small",
2217
+ variant: "outlined",
2218
+ onClick: add,
2219
+ disabled: !column || needsValue && value === "",
2220
+ children: t("studio_tables_apply_filter")
2221
+ })
2222
+ })
2223
+ ]
2224
+ })
2225
+ }),
2226
+ filters.length > 0 && /* @__PURE__ */ jsx(Button, {
2227
+ size: "small",
2228
+ variant: "text",
2229
+ onClick: () => onChange([]),
2230
+ children: t("studio_tables_clear_filters")
2231
+ })
2232
+ ] });
2233
+ }
2234
+ function RowDialog({ table, columns, primaryKey, row, onClose, onSaved }) {
2235
+ const { t } = useTranslation();
2236
+ const { requestJson } = useAdminFetch();
2237
+ const snackbar = useSnackbarController();
2238
+ const editable = columns.filter((column) => !column.generated);
2239
+ const [values, setValues] = useState(() => {
2240
+ const initial = {};
2241
+ for (const column of editable) initial[column.name] = row ? row[column.name] ?? "" : "";
2242
+ return initial;
2243
+ });
2244
+ /** Columns the user explicitly set to NULL (an empty box otherwise means "default" on insert). */
2245
+ const [nulls, setNulls] = useState(() => new Set(row ? editable.filter((column) => row[column.name] === null).map((column) => column.name) : []));
2246
+ const [saving, setSaving] = useState(false);
2247
+ const save = async () => {
2248
+ setSaving(true);
2249
+ try {
2250
+ const payload = {};
2251
+ for (const column of editable) {
2252
+ const text = values[column.name] ?? "";
2253
+ const isNull = nulls.has(column.name);
2254
+ if (row) {
2255
+ const before = row[column.name] ?? null;
2256
+ const after = isNull ? null : text;
2257
+ if (after !== before && !column.primaryKey) payload[column.name] = after;
2258
+ } else if (isNull) payload[column.name] = null;
2259
+ else if (text !== "") payload[column.name] = text;
2260
+ }
2261
+ if (row) {
2262
+ if (Object.keys(payload).length === 0) {
2263
+ onClose();
2264
+ return;
2265
+ }
2266
+ await requestJson(`/admin/db/tables/${encodeURIComponent(table.name)}/rows`, {
2267
+ method: "PATCH",
2268
+ body: {
2269
+ schema: table.schema,
2270
+ key: rowKey(row, primaryKey),
2271
+ values: payload
2272
+ }
2273
+ });
2274
+ snackbar.open({
2275
+ type: "success",
2276
+ message: t("studio_tables_row_updated")
2277
+ });
2278
+ } else {
2279
+ await requestJson(`/admin/db/tables/${encodeURIComponent(table.name)}/rows`, {
2280
+ method: "POST",
2281
+ body: {
2282
+ schema: table.schema,
2283
+ rows: [payload]
2284
+ }
2285
+ });
2286
+ snackbar.open({
2287
+ type: "success",
2288
+ message: t("studio_tables_row_inserted")
2289
+ });
2290
+ }
2291
+ onSaved();
2292
+ } catch (err) {
2293
+ snackbar.open({
2294
+ type: "error",
2295
+ message: err instanceof Error ? err.message : t("studio_tables_row_save_failed")
2296
+ });
2297
+ } finally {
2298
+ setSaving(false);
2299
+ }
2300
+ };
2301
+ return /* @__PURE__ */ jsxs(Dialog, {
2302
+ open: true,
2303
+ onOpenChange: (open) => {
2304
+ if (!open) onClose();
2305
+ },
2306
+ maxWidth: "lg",
2307
+ fullWidth: true,
2308
+ children: [
2309
+ /* @__PURE__ */ jsx(DialogTitle, { children: row ? t("studio_tables_edit_row_title", { id: primaryKey.map((column) => row[column]).join(", ") }) : t("studio_tables_insert_row_into", { name: table.name }) }),
2310
+ /* @__PURE__ */ jsx(DialogContent, {
2311
+ className: "flex flex-col gap-3 max-h-[60vh] overflow-y-auto",
2312
+ children: editable.map((column) => {
2313
+ const isNull = nulls.has(column.name);
2314
+ const locked = Boolean(row && column.primaryKey) || column.identity === "always" && !row;
2315
+ const placeholder = column.identity ? t("studio_tables_identity_placeholder") : column.default ? t("studio_tables_default_placeholder", { value: column.default }) : "";
2316
+ return /* @__PURE__ */ jsxs("div", {
2317
+ className: "flex items-start gap-2",
2318
+ children: [/* @__PURE__ */ jsx(TextField, {
2319
+ className: "flex-1",
2320
+ label: `${column.name} · ${column.type}${column.notNull ? " *" : ""}`,
2321
+ value: isNull ? "" : values[column.name] ?? "",
2322
+ disabled: locked || isNull,
2323
+ multiline: column.udt === "json" || column.udt === "jsonb" || column.udt === "text",
2324
+ placeholder: isNull ? "NULL" : placeholder,
2325
+ onChange: (event) => setValues((prev) => ({
2326
+ ...prev,
2327
+ [column.name]: event.target.value
2328
+ }))
2329
+ }), !column.notNull && !locked && /* @__PURE__ */ jsx(FilterChip, {
2330
+ size: "small",
2331
+ active: isNull,
2332
+ className: "mt-5",
2333
+ onClick: () => setNulls((prev) => {
2334
+ const next = new Set(prev);
2335
+ if (next.has(column.name)) next.delete(column.name);
2336
+ else next.add(column.name);
2337
+ return next;
2338
+ }),
2339
+ children: "NULL"
2340
+ })]
2341
+ }, column.name);
2342
+ })
2343
+ }),
2344
+ /* @__PURE__ */ jsxs(DialogActions, { children: [/* @__PURE__ */ jsx(Button, {
2345
+ variant: "text",
2346
+ onClick: onClose,
2347
+ children: t("cancel")
2348
+ }), /* @__PURE__ */ jsx(Button, {
2349
+ variant: "filled",
2350
+ color: "primary",
2351
+ disabled: saving,
2352
+ onClick: () => void save(),
2353
+ children: saving ? t("saving") : row ? t("studio_save_changes") : t("studio_tables_insert_row")
2354
+ })] })
2355
+ ]
2356
+ });
2357
+ }
2358
+ function ImportDialog({ table, columns, onClose, onImported }) {
2359
+ const { t } = useTranslation();
2360
+ const { requestJson } = useAdminFetch();
2361
+ const snackbar = useSnackbarController();
2362
+ const [parsed, setParsed] = useState(null);
2363
+ const [fileName, setFileName] = useState(null);
2364
+ const [importing, setImporting] = useState(false);
2365
+ const [progress, setProgress] = useState(0);
2366
+ const [failure, setFailure] = useState(null);
2367
+ const known = new Set(columns.filter((column) => !column.generated).map((column) => column.name));
2368
+ const matched = parsed ? parsed.columns.filter((column) => known.has(column)) : [];
2369
+ const ignored = parsed ? parsed.columns.filter((column) => column && !known.has(column)) : [];
2370
+ const readFile = async (file) => {
2371
+ setFailure(null);
2372
+ setFileName(file.name);
2373
+ setParsed(parseCsvWithHeader(await file.text()));
2374
+ };
2375
+ const run = async () => {
2376
+ if (!parsed) return;
2377
+ setImporting(true);
2378
+ setFailure(null);
2379
+ let done = 0;
2380
+ try {
2381
+ for (let start = 0; start < parsed.rows.length; start += IMPORT_CHUNK) {
2382
+ const chunk = parsed.rows.slice(start, start + IMPORT_CHUNK).map((row) => {
2383
+ const out = {};
2384
+ for (const column of matched) out[column] = row[column] ?? null;
2385
+ return out;
2386
+ });
2387
+ try {
2388
+ await requestJson(`/admin/db/tables/${encodeURIComponent(table.name)}/rows`, {
2389
+ method: "POST",
2390
+ body: {
2391
+ schema: table.schema,
2392
+ rows: chunk
2393
+ }
2394
+ });
2395
+ } catch (err) {
2396
+ const message = err instanceof Error ? err.message : String(err);
2397
+ setFailure(t("studio_tables_import_failed_at", {
2398
+ first: start + 1,
2399
+ last: start + chunk.length,
2400
+ done,
2401
+ message
2402
+ }));
2403
+ return;
2404
+ }
2405
+ done += chunk.length;
2406
+ setProgress(done);
2407
+ }
2408
+ snackbar.open({
2409
+ type: "success",
2410
+ message: t("studio_tables_imported_rows", { count: done })
2411
+ });
2412
+ onImported();
2413
+ } finally {
2414
+ setImporting(false);
2415
+ }
2416
+ };
2417
+ return /* @__PURE__ */ jsxs(Dialog, {
2418
+ open: true,
2419
+ onOpenChange: (open) => {
2420
+ if (!open && !importing) onClose();
2421
+ },
2422
+ maxWidth: "lg",
2423
+ fullWidth: true,
2424
+ children: [
2425
+ /* @__PURE__ */ jsx(DialogTitle, { children: t("studio_tables_import_into", { name: table.name }) }),
2426
+ /* @__PURE__ */ jsxs(DialogContent, {
2427
+ className: "flex flex-col gap-3",
2428
+ children: [
2429
+ /* @__PURE__ */ jsx(Typography, {
2430
+ variant: "body2",
2431
+ color: "secondary",
2432
+ children: t("studio_tables_import_help")
2433
+ }),
2434
+ /* @__PURE__ */ jsxs(Button, {
2435
+ variant: "outlined",
2436
+ component: "label",
2437
+ className: "self-start",
2438
+ children: [
2439
+ /* @__PURE__ */ jsx(UploadIcon, { size: iconSize.smallest }),
2440
+ fileName ?? t("studio_tables_import_choose"),
2441
+ /* @__PURE__ */ jsx("input", {
2442
+ type: "file",
2443
+ accept: ".csv,text/csv",
2444
+ className: "hidden",
2445
+ onChange: (event) => {
2446
+ const file = event.target.files?.[0];
2447
+ if (file) readFile(file);
2448
+ }
2449
+ })
2450
+ ]
2451
+ }),
2452
+ parsed && /* @__PURE__ */ jsxs("div", {
2453
+ className: "flex flex-col gap-2",
2454
+ children: [
2455
+ /* @__PURE__ */ jsx(Typography, {
2456
+ variant: "body2",
2457
+ children: t("studio_tables_import_summary", {
2458
+ rows: parsed.rows.length,
2459
+ columns: matched.length
2460
+ })
2461
+ }),
2462
+ matched.length > 0 && /* @__PURE__ */ jsx(Typography, {
2463
+ variant: "caption",
2464
+ color: "secondary",
2465
+ className: "font-mono",
2466
+ children: matched.join(", ")
2467
+ }),
2468
+ ignored.length > 0 && /* @__PURE__ */ jsx(Alert, {
2469
+ color: "warning",
2470
+ size: "small",
2471
+ children: t("studio_tables_import_ignored", { columns: ignored.join(", ") })
2472
+ })
2473
+ ]
2474
+ }),
2475
+ importing && /* @__PURE__ */ jsx(Typography, {
2476
+ variant: "caption",
2477
+ color: "secondary",
2478
+ children: t("studio_tables_import_progress", {
2479
+ done: progress,
2480
+ total: parsed?.rows.length ?? 0
2481
+ })
2482
+ }),
2483
+ failure && /* @__PURE__ */ jsx(Alert, {
2484
+ color: "error",
2485
+ children: failure
2486
+ })
2487
+ ]
2488
+ }),
2489
+ /* @__PURE__ */ jsxs(DialogActions, { children: [/* @__PURE__ */ jsx(Button, {
2490
+ variant: "text",
2491
+ disabled: importing,
2492
+ onClick: onClose,
2493
+ children: t("cancel")
2494
+ }), /* @__PURE__ */ jsx(Button, {
2495
+ variant: "filled",
2496
+ color: "primary",
2497
+ disabled: importing || !parsed || parsed.rows.length === 0 || matched.length === 0,
2498
+ onClick: () => void run(),
2499
+ children: importing ? t("studio_tables_importing") : t("studio_tables_import_rows", { count: parsed?.rows.length ?? 0 })
2500
+ })] })
2501
+ ]
2502
+ });
2503
+ }
2504
+ //#endregion
2505
+ //#region src/components/TableEditor/tabs/PoliciesTab.tsx
2506
+ /** Row level security for the table — the same editor as the RLS view — and who holds which privilege on it. */
2507
+ function PoliciesTab({ table, details, onChanged }) {
2508
+ const { t } = useTranslation();
2509
+ const grantsByRole = /* @__PURE__ */ new Map();
2510
+ for (const grant of details?.grants ?? []) {
2511
+ const entry = grantsByRole.get(grant.grantee) ?? {
2512
+ privileges: [],
2513
+ grantable: []
2514
+ };
2515
+ entry.privileges.push(grant.privilege);
2516
+ if (grant.grantable) entry.grantable.push(grant.privilege);
2517
+ grantsByRole.set(grant.grantee, entry);
2518
+ }
2519
+ return /* @__PURE__ */ jsxs("div", {
2520
+ className: "flex flex-col gap-8 max-w-5xl",
2521
+ children: [/* @__PURE__ */ jsx(TablePolicies, {
2522
+ schemaName: table.schema,
2523
+ tableName: table.name,
2524
+ rlsEnabled: table.rlsEnabled,
2525
+ policies: asPostgresPolicies(table),
2526
+ onChanged
2527
+ }, table.key), details && /* @__PURE__ */ jsxs("div", {
2528
+ className: "flex flex-col gap-2",
2529
+ children: [
2530
+ /* @__PURE__ */ jsx(Typography, {
2531
+ variant: "subtitle2",
2532
+ children: t("studio_tables_privileges_heading")
2533
+ }),
2534
+ /* @__PURE__ */ jsx(Typography, {
2535
+ variant: "body2",
2536
+ color: "secondary",
2537
+ children: details.relation.defaultPrivileges ? t("studio_tables_privileges_default", { owner: details.relation.owner }) : t("studio_tables_privileges_owner", { owner: details.relation.owner })
2538
+ }),
2539
+ grantsByRole.size > 0 && /* @__PURE__ */ jsx("div", {
2540
+ className: cls("overflow-x-auto rounded-lg border", defaultBorderMixin),
2541
+ children: /* @__PURE__ */ jsxs(Table, {
2542
+ className: "w-full",
2543
+ children: [/* @__PURE__ */ jsxs(TableHeader, { children: [/* @__PURE__ */ jsx(TableCell, {
2544
+ header: true,
2545
+ children: t("studio_tables_privileges_role")
2546
+ }), /* @__PURE__ */ jsx(TableCell, {
2547
+ header: true,
2548
+ children: t("studio_tables_privileges_granted")
2549
+ })] }), /* @__PURE__ */ jsx(TableBody, { children: [...grantsByRole.entries()].map(([role, entry]) => /* @__PURE__ */ jsxs(TableRow, { children: [/* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(Typography, {
2550
+ variant: "mono",
2551
+ className: "text-xs",
2552
+ children: role
2553
+ }) }), /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(Typography, {
2554
+ variant: "mono",
2555
+ className: "text-xs",
2556
+ color: "secondary",
2557
+ children: entry.privileges.map((privilege) => entry.grantable.includes(privilege) ? `${privilege}*` : privilege).join(", ")
2558
+ }) })] }, role)) })]
2559
+ })
2560
+ }),
2561
+ grantsByRole.size > 0 && /* @__PURE__ */ jsx(Typography, {
2562
+ variant: "caption",
2563
+ color: "secondary",
2564
+ children: t("studio_tables_privileges_grantable_note")
2565
+ })
2566
+ ]
2567
+ })]
2568
+ });
2569
+ }
2570
+ //#endregion
2571
+ //#region src/components/TableEditor/tabs/RelationsTab.tsx
2572
+ function ForeignKeyTable({ title, foreignKeys, direction, empty }) {
2573
+ const { t } = useTranslation();
2574
+ const navigate = useNavigate();
2575
+ return /* @__PURE__ */ jsxs("div", {
2576
+ className: "flex flex-col gap-2",
2577
+ children: [/* @__PURE__ */ jsx(Typography, {
2578
+ variant: "subtitle2",
2579
+ children: title
2580
+ }), foreignKeys.length === 0 ? /* @__PURE__ */ jsx(Typography, {
2581
+ variant: "body2",
2582
+ color: "secondary",
2583
+ children: empty
2584
+ }) : /* @__PURE__ */ jsx("div", {
2585
+ className: cls("overflow-x-auto rounded-lg border", defaultBorderMixin),
2586
+ children: /* @__PURE__ */ jsxs(Table, {
2587
+ className: "w-full",
2588
+ children: [/* @__PURE__ */ jsxs(TableHeader, { children: [
2589
+ /* @__PURE__ */ jsx(TableCell, {
2590
+ header: true,
2591
+ children: direction === "outgoing" ? t("studio_columns") : t("studio_tables_relations_from")
2592
+ }),
2593
+ /* @__PURE__ */ jsx(TableCell, {
2594
+ header: true,
2595
+ children: direction === "outgoing" ? t("studio_tables_relations_references") : t("studio_columns")
2596
+ }),
2597
+ /* @__PURE__ */ jsx(TableCell, {
2598
+ header: true,
2599
+ children: t("studio_tables_on_delete")
2600
+ }),
2601
+ /* @__PURE__ */ jsx(TableCell, {
2602
+ header: true,
2603
+ children: t("name")
2604
+ })
2605
+ ] }), /* @__PURE__ */ jsx(TableBody, { children: foreignKeys.map((fk) => {
2606
+ const otherKey = direction === "outgoing" ? `${fk.toSchema}.${fk.toTable}` : `${fk.fromSchema}.${fk.fromTable}`;
2607
+ const otherLabel = direction === "outgoing" ? `${fk.toTable}(${fk.toColumns.join(", ")})` : `${fk.fromTable}(${fk.fromColumns.join(", ")})`;
2608
+ return /* @__PURE__ */ jsxs(TableRow, { children: [
2609
+ /* @__PURE__ */ jsx(TableCell, { children: direction === "outgoing" ? /* @__PURE__ */ jsx(Typography, {
2610
+ variant: "mono",
2611
+ className: "text-xs",
2612
+ children: fk.fromColumns.join(", ")
2613
+ }) : /* @__PURE__ */ jsx(Button, {
2614
+ size: "small",
2615
+ variant: "text",
2616
+ onClick: () => navigate(tablesLink(otherKey, "relations")),
2617
+ children: /* @__PURE__ */ jsx(Typography, {
2618
+ variant: "mono",
2619
+ className: "text-xs",
2620
+ children: otherLabel
2621
+ })
2622
+ }) }),
2623
+ /* @__PURE__ */ jsx(TableCell, { children: direction === "outgoing" ? /* @__PURE__ */ jsxs(Button, {
2624
+ size: "small",
2625
+ variant: "text",
2626
+ onClick: () => navigate(tablesLink(otherKey, "relations")),
2627
+ children: [/* @__PURE__ */ jsx(ArrowRightIcon, { size: iconSize.smallest }), /* @__PURE__ */ jsx(Typography, {
2628
+ variant: "mono",
2629
+ className: "text-xs",
2630
+ children: otherLabel
2631
+ })]
2632
+ }) : /* @__PURE__ */ jsx(Typography, {
2633
+ variant: "mono",
2634
+ className: "text-xs",
2635
+ children: fk.toColumns.join(", ")
2636
+ }) }),
2637
+ /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(Typography, {
2638
+ variant: "mono",
2639
+ className: "text-xs",
2640
+ color: "secondary",
2641
+ children: fk.onDelete
2642
+ }) }),
2643
+ /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(Typography, {
2644
+ variant: "mono",
2645
+ className: "text-xs",
2646
+ color: "secondary",
2647
+ children: fk.name
2648
+ }) })
2649
+ ] }, `${fk.fromTable}.${fk.name}`);
2650
+ }) })]
2651
+ })
2652
+ })]
2653
+ });
2654
+ }
2655
+ /** What the table points at and what points at it: the foreign keys both ways, and its neighbourhood drawn. */
2656
+ function RelationsTab({ table, tables, details }) {
2657
+ const { t } = useTranslation();
2658
+ const navigate = useNavigate();
2659
+ const outgoing = details?.foreignKeys.outgoing ?? table.foreignKeys;
2660
+ const incoming = details?.foreignKeys.incoming ?? tables.flatMap((other) => other.foreignKeys.filter((fk) => fk.toTable === table.name && fk.toSchema === table.schema));
2661
+ return /* @__PURE__ */ jsxs("div", {
2662
+ className: "flex flex-col gap-6",
2663
+ children: [
2664
+ /* @__PURE__ */ jsxs("div", {
2665
+ className: "flex flex-col gap-2",
2666
+ children: [/* @__PURE__ */ jsxs("div", {
2667
+ className: "flex items-center justify-between gap-3",
2668
+ children: [/* @__PURE__ */ jsx(Typography, {
2669
+ variant: "subtitle2",
2670
+ children: t("studio_tables_relations_diagram")
2671
+ }), /* @__PURE__ */ jsx(Button, {
2672
+ size: "small",
2673
+ variant: "text",
2674
+ onClick: () => navigate(`/tables?${new URLSearchParams({
2675
+ [TABLES_VIEW_PARAM]: "diagram",
2676
+ [TABLE_PARAM]: table.key
2677
+ }).toString()}`),
2678
+ children: t("studio_tables_relations_open_diagram")
2679
+ })]
2680
+ }), /* @__PURE__ */ jsx("div", {
2681
+ className: cls("h-[420px] rounded-lg border overflow-hidden", defaultBorderMixin),
2682
+ children: /* @__PURE__ */ jsx(TablesDiagram, {
2683
+ catalog: tables,
2684
+ focusTable: table.name,
2685
+ alwaysFocus: true,
2686
+ compact: true,
2687
+ onOpenTable: (name) => {
2688
+ if (name !== table.name) navigate(tablesLink(`${table.schema}.${name}`, "relations"));
2689
+ }
2690
+ })
2691
+ })]
2692
+ }),
2693
+ /* @__PURE__ */ jsx(ForeignKeyTable, {
2694
+ title: t("studio_tables_relations_outgoing", { count: outgoing.length }),
2695
+ foreignKeys: outgoing,
2696
+ direction: "outgoing",
2697
+ empty: t("studio_tables_relations_outgoing_none")
2698
+ }),
2699
+ /* @__PURE__ */ jsx(ForeignKeyTable, {
2700
+ title: t("studio_tables_relations_incoming", { count: incoming.length }),
2701
+ foreignKeys: incoming,
2702
+ direction: "incoming",
2703
+ empty: t("studio_tables_relations_incoming_none")
2704
+ })
2705
+ ]
2706
+ });
2707
+ }
2708
+ //#endregion
2709
+ //#region src/components/TableEditor/tabs/StatsTab.tsx
2710
+ function Tile({ label, value, hint }) {
2711
+ return /* @__PURE__ */ jsxs(Card, {
2712
+ className: "p-3 flex flex-col gap-1 min-w-0",
2713
+ children: [
2714
+ /* @__PURE__ */ jsx(Typography, {
2715
+ variant: "caption",
2716
+ color: "secondary",
2717
+ children: label
2718
+ }),
2719
+ /* @__PURE__ */ jsx(Typography, {
2720
+ variant: "h6",
2721
+ className: "tabular-nums truncate",
2722
+ children: value
2723
+ }),
2724
+ hint && /* @__PURE__ */ jsx(Typography, {
2725
+ variant: "caption",
2726
+ color: "secondary",
2727
+ className: "truncate",
2728
+ children: hint
2729
+ })
2730
+ ]
2731
+ });
2732
+ }
2733
+ /** Storage and access statistics, and the maintenance that keeps them honest. */
2734
+ function StatsTab({ table, details, onChanged }) {
2735
+ const { t, i18n } = useTranslation();
2736
+ const { confirm, dialog } = useDdlConfirm();
2737
+ const stats = details?.stats ?? null;
2738
+ const locale = i18n?.language;
2739
+ const when = (value) => value ? new Date(value).toLocaleString(locale) : t("studio_tables_stats_never");
2740
+ const deadRatio = stats && stats.liveTuples !== null && stats.deadTuples !== null && stats.liveTuples + stats.deadTuples > 0 ? stats.deadTuples / (stats.liveTuples + stats.deadTuples) : null;
2741
+ const base = `/admin/db/tables/${encodeURIComponent(table.name)}`;
2742
+ if (!details) return null;
2743
+ if (!stats) return /* @__PURE__ */ jsx(Typography, {
2744
+ variant: "body2",
2745
+ color: "secondary",
2746
+ children: t("studio_tables_stats_unavailable")
2747
+ });
2748
+ return /* @__PURE__ */ jsxs("div", {
2749
+ className: "flex flex-col gap-6 max-w-5xl",
2750
+ children: [
2751
+ /* @__PURE__ */ jsxs("div", {
2752
+ className: "grid grid-cols-2 lg:grid-cols-4 gap-3",
2753
+ children: [
2754
+ /* @__PURE__ */ jsx(Tile, {
2755
+ label: t("studio_tables_stats_rows"),
2756
+ value: formatCount(stats.rowEstimate, locale),
2757
+ hint: t("studio_tables_stats_estimate")
2758
+ }),
2759
+ /* @__PURE__ */ jsx(Tile, {
2760
+ label: t("studio_tables_stats_total_size"),
2761
+ value: formatBytes(stats.totalBytes)
2762
+ }),
2763
+ /* @__PURE__ */ jsx(Tile, {
2764
+ label: t("studio_tables_stats_table_size"),
2765
+ value: formatBytes(stats.tableBytes),
2766
+ hint: t("studio_tables_stats_toast", { size: formatBytes(stats.toastBytes) })
2767
+ }),
2768
+ /* @__PURE__ */ jsx(Tile, {
2769
+ label: t("studio_tables_stats_index_size"),
2770
+ value: formatBytes(stats.indexBytes)
2771
+ }),
2772
+ /* @__PURE__ */ jsx(Tile, {
2773
+ label: t("studio_tables_stats_seq_scans"),
2774
+ value: formatCount(stats.seqScans, locale),
2775
+ hint: t("studio_tables_stats_rows_read", { count: formatCount(stats.seqTuplesRead, locale) })
2776
+ }),
2777
+ /* @__PURE__ */ jsx(Tile, {
2778
+ label: t("studio_tables_stats_index_scans"),
2779
+ value: formatCount(stats.indexScans, locale),
2780
+ hint: t("studio_tables_stats_rows_fetched", { count: formatCount(stats.indexTuplesFetched, locale) })
2781
+ }),
2782
+ /* @__PURE__ */ jsx(Tile, {
2783
+ label: t("studio_tables_stats_dead_rows"),
2784
+ value: formatCount(stats.deadTuples, locale),
2785
+ hint: deadRatio !== null ? t("studio_tables_stats_dead_ratio", { percent: (deadRatio * 100).toFixed(1) }) : void 0
2786
+ }),
2787
+ /* @__PURE__ */ jsx(Tile, {
2788
+ label: t("studio_tables_stats_writes"),
2789
+ value: formatCount((stats.inserts ?? 0) + (stats.updates ?? 0) + (stats.deletes ?? 0), locale),
2790
+ hint: t("studio_tables_stats_writes_hint", {
2791
+ inserts: formatCount(stats.inserts, locale),
2792
+ updates: formatCount(stats.updates, locale),
2793
+ deletes: formatCount(stats.deletes, locale)
2794
+ })
2795
+ })
2796
+ ]
2797
+ }),
2798
+ table.kind === "table" && /* @__PURE__ */ jsxs(Card, {
2799
+ className: "p-4 flex flex-col gap-3",
2800
+ children: [
2801
+ /* @__PURE__ */ jsx(Typography, {
2802
+ variant: "subtitle2",
2803
+ children: t("studio_tables_maintenance_heading")
2804
+ }),
2805
+ /* @__PURE__ */ jsxs("div", {
2806
+ className: "grid grid-cols-1 sm:grid-cols-2 gap-2",
2807
+ children: [/* @__PURE__ */ jsx(Typography, {
2808
+ variant: "body2",
2809
+ color: "secondary",
2810
+ children: t("studio_tables_stats_last_vacuum", {
2811
+ manual: when(stats.lastVacuum),
2812
+ auto: when(stats.lastAutovacuum)
2813
+ })
2814
+ }), /* @__PURE__ */ jsx(Typography, {
2815
+ variant: "body2",
2816
+ color: "secondary",
2817
+ children: t("studio_tables_stats_last_analyze", {
2818
+ manual: when(stats.lastAnalyze),
2819
+ auto: when(stats.lastAutoanalyze)
2820
+ })
2821
+ })]
2822
+ }),
2823
+ /* @__PURE__ */ jsxs("div", {
2824
+ className: "flex gap-2",
2825
+ children: [/* @__PURE__ */ jsx(Button, {
2826
+ size: "small",
2827
+ variant: "outlined",
2828
+ onClick: () => void confirm({
2829
+ title: t("studio_tables_analyze"),
2830
+ path: `${base}/maintenance`,
2831
+ method: "POST",
2832
+ body: {
2833
+ schema: table.schema,
2834
+ action: "analyze"
2835
+ },
2836
+ done: t("studio_tables_analyze_done", { name: table.name }),
2837
+ onDone: onChanged
2838
+ }),
2839
+ children: t("studio_tables_analyze")
2840
+ }), /* @__PURE__ */ jsx(Button, {
2841
+ size: "small",
2842
+ variant: "outlined",
2843
+ onClick: () => void confirm({
2844
+ title: t("studio_tables_vacuum"),
2845
+ path: `${base}/maintenance`,
2846
+ method: "POST",
2847
+ body: {
2848
+ schema: table.schema,
2849
+ action: "vacuum"
2850
+ },
2851
+ done: t("studio_tables_vacuum_done", { name: table.name }),
2852
+ onDone: onChanged
2853
+ }),
2854
+ children: t("studio_tables_vacuum")
2855
+ })]
2856
+ })
2857
+ ]
2858
+ }),
2859
+ table.materialized && /* @__PURE__ */ jsxs(Card, {
2860
+ className: "p-4 flex items-center justify-between gap-3",
2861
+ children: [/* @__PURE__ */ jsx(Typography, {
2862
+ variant: "body2",
2863
+ color: "secondary",
2864
+ children: t("studio_tables_matview_refresh_hint")
2865
+ }), /* @__PURE__ */ jsx(Button, {
2866
+ size: "small",
2867
+ variant: "outlined",
2868
+ onClick: () => void confirm({
2869
+ title: t("studio_tables_matview_refresh"),
2870
+ path: `${base}/refresh`,
2871
+ method: "POST",
2872
+ body: { schema: table.schema },
2873
+ done: t("studio_tables_matview_refreshed", { name: table.name }),
2874
+ onDone: onChanged
2875
+ }),
2876
+ children: t("studio_tables_matview_refresh")
2877
+ })]
2878
+ }),
2879
+ dialog
2880
+ ]
2881
+ });
2882
+ }
2883
+ //#endregion
2884
+ //#region src/components/TableEditor/tabs/SettingsTab.tsx
2885
+ /** How the API serves the table (`rebase.table_meta`), its name, and dropping it. */
2886
+ function SettingsTab({ table, onChanged, onTableReplaced }) {
2887
+ const { t } = useTranslation();
2888
+ const { requestJson } = useAdminFetch();
2889
+ const snackbar = useSnackbarController();
2890
+ const { confirm, dialog } = useDdlConfirm();
2891
+ const base = `/admin/db/tables/${encodeURIComponent(table.name)}`;
2892
+ const [slug, setSlug] = useState("");
2893
+ const [description, setDescription] = useState("");
2894
+ const [exposed, setExposed] = useState(true);
2895
+ const [softDelete, setSoftDelete] = useState(false);
2896
+ const [history, setHistory] = useState(false);
2897
+ const [readOnly, setReadOnly] = useState(false);
2898
+ const [saving, setSaving] = useState(false);
2899
+ const [rename, setRename] = useState(table.name);
2900
+ const [dropOpen, setDropOpen] = useState(false);
2901
+ const [dropConfirm, setDropConfirm] = useState("");
2902
+ const [dropping, setDropping] = useState(false);
2903
+ useEffect(() => {
2904
+ setSlug(table.meta?.slug ?? table.slug);
2905
+ setDescription(table.meta?.description ?? "");
2906
+ setExposed(table.meta?.exposed ?? table.exposed);
2907
+ setSoftDelete(table.meta?.softDelete ?? false);
2908
+ setHistory(table.meta?.history ?? false);
2909
+ setReadOnly(table.meta?.readOnly ?? false);
2910
+ setRename(table.name);
2911
+ }, [table]);
2912
+ const saveMeta = async () => {
2913
+ setSaving(true);
2914
+ try {
2915
+ const nonPkColumns = table.columns.filter((column) => !column.primaryKey).map((column) => column.name);
2916
+ await requestJson(base, {
2917
+ method: "PATCH",
2918
+ body: {
2919
+ schema: table.schema,
2920
+ meta: {
2921
+ slug: slug.trim() || null,
2922
+ description: description.trim() || null,
2923
+ exposed,
2924
+ softDeleteColumn: softDelete ? table.meta?.softDeleteColumn ?? "deleted_at" : null,
2925
+ historyEnabled: history,
2926
+ readonlyColumns: readOnly ? nonPkColumns : []
2927
+ }
2928
+ }
2929
+ });
2930
+ snackbar.open({
2931
+ type: "success",
2932
+ message: t("studio_tables_meta_saved")
2933
+ });
2934
+ onChanged();
2935
+ } catch (err) {
2936
+ snackbar.open({
2937
+ type: "error",
2938
+ message: err instanceof Error ? err.message : t("studio_tables_meta_save_failed")
2939
+ });
2940
+ } finally {
2941
+ setSaving(false);
2942
+ }
2943
+ };
2944
+ const drop = async () => {
2945
+ setDropping(true);
2946
+ try {
2947
+ await requestJson(base, {
2948
+ method: "DELETE",
2949
+ body: {
2950
+ schema: table.schema,
2951
+ confirm: dropConfirm
2952
+ }
2953
+ });
2954
+ snackbar.open({
2955
+ type: "success",
2956
+ message: t("studio_tables_table_dropped", { name: table.name })
2957
+ });
2958
+ setDropOpen(false);
2959
+ onTableReplaced(null);
2960
+ } catch (err) {
2961
+ snackbar.open({
2962
+ type: "error",
2963
+ message: err instanceof Error ? err.message : t("studio_tables_drop_failed")
2964
+ });
2965
+ } finally {
2966
+ setDropping(false);
2967
+ }
2968
+ };
2969
+ return /* @__PURE__ */ jsxs("div", {
2970
+ className: "max-w-2xl flex flex-col gap-5",
2971
+ children: [
2972
+ /* @__PURE__ */ jsxs(Card, {
2973
+ className: "p-4 flex flex-col gap-4",
2974
+ children: [
2975
+ /* @__PURE__ */ jsx(Typography, {
2976
+ variant: "subtitle1",
2977
+ children: t("studio_tables_meta_heading")
2978
+ }),
2979
+ /* @__PURE__ */ jsx(TextField, {
2980
+ label: t("studio_tables_slug_label"),
2981
+ value: slug,
2982
+ onChange: (event) => setSlug(event.target.value),
2983
+ placeholder: table.name
2984
+ }),
2985
+ /* @__PURE__ */ jsx(TextField, {
2986
+ label: t("description"),
2987
+ value: description,
2988
+ onChange: (event) => setDescription(event.target.value),
2989
+ placeholder: t("studio_tables_description_placeholder")
2990
+ }),
2991
+ /* @__PURE__ */ jsx(BooleanSwitchWithLabel, {
2992
+ label: t("studio_tables_expose_label"),
2993
+ value: exposed,
2994
+ onValueChange: setExposed
2995
+ }),
2996
+ /* @__PURE__ */ jsx(BooleanSwitchWithLabel, {
2997
+ label: t("studio_tables_read_only_label"),
2998
+ value: readOnly,
2999
+ onValueChange: setReadOnly
3000
+ }),
3001
+ /* @__PURE__ */ jsx(BooleanSwitchWithLabel, {
3002
+ label: t("studio_tables_soft_delete_label"),
3003
+ value: softDelete,
3004
+ onValueChange: setSoftDelete
3005
+ }),
3006
+ /* @__PURE__ */ jsx(BooleanSwitchWithLabel, {
3007
+ label: t("studio_tables_history_label"),
3008
+ value: history,
3009
+ onValueChange: setHistory
3010
+ }),
3011
+ /* @__PURE__ */ jsx("div", {
3012
+ className: "flex justify-end",
3013
+ children: /* @__PURE__ */ jsx(Button, {
3014
+ variant: "filled",
3015
+ color: "primary",
3016
+ disabled: saving,
3017
+ onClick: () => void saveMeta(),
3018
+ children: saving ? t("saving") : t("studio_tables_save_settings")
3019
+ })
3020
+ })
3021
+ ]
3022
+ }),
3023
+ table.kind === "table" && /* @__PURE__ */ jsxs(Card, {
3024
+ className: "p-4 flex flex-col gap-3",
3025
+ children: [/* @__PURE__ */ jsx(Typography, {
3026
+ variant: "subtitle1",
3027
+ children: t("studio_tables_rename_heading")
3028
+ }), /* @__PURE__ */ jsxs("div", {
3029
+ className: "flex items-end gap-2",
3030
+ children: [/* @__PURE__ */ jsx(TextField, {
3031
+ className: "flex-1",
3032
+ label: t("studio_tables_name_label"),
3033
+ value: rename,
3034
+ onChange: (event) => setRename(event.target.value)
3035
+ }), /* @__PURE__ */ jsx(Button, {
3036
+ variant: "outlined",
3037
+ disabled: !rename.trim() || rename.trim() === table.name,
3038
+ onClick: () => void confirm({
3039
+ title: t("studio_tables_rename_heading"),
3040
+ path: base,
3041
+ method: "PATCH",
3042
+ body: {
3043
+ schema: table.schema,
3044
+ renameTo: rename.trim()
3045
+ },
3046
+ done: t("studio_tables_renamed", {
3047
+ from: table.name,
3048
+ to: rename.trim()
3049
+ }),
3050
+ onDone: () => onTableReplaced(`${table.schema}.${rename.trim()}`)
3051
+ }),
3052
+ children: t("studio_tables_rename")
3053
+ })]
3054
+ })]
3055
+ }),
3056
+ table.kind === "table" && /* @__PURE__ */ jsxs(Card, {
3057
+ className: "p-4 flex items-center justify-between gap-4",
3058
+ children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx(Typography, {
3059
+ variant: "subtitle2",
3060
+ children: t("studio_tables_danger_zone")
3061
+ }), /* @__PURE__ */ jsx(Typography, {
3062
+ variant: "body2",
3063
+ color: "secondary",
3064
+ children: t("studio_tables_drop_description", { name: table.name })
3065
+ })] }), /* @__PURE__ */ jsx(Button, {
3066
+ variant: "outlined",
3067
+ color: "error",
3068
+ onClick: () => setDropOpen(true),
3069
+ children: t("studio_tables_drop_table")
3070
+ })]
3071
+ }),
3072
+ /* @__PURE__ */ jsxs(Dialog, {
3073
+ open: dropOpen,
3074
+ onOpenChange: setDropOpen,
3075
+ maxWidth: "sm",
3076
+ fullWidth: true,
3077
+ children: [
3078
+ /* @__PURE__ */ jsx(DialogTitle, { children: t("studio_tables_drop_table") }),
3079
+ /* @__PURE__ */ jsxs(DialogContent, {
3080
+ className: "flex flex-col gap-3",
3081
+ children: [/* @__PURE__ */ jsx(Alert, {
3082
+ color: "error",
3083
+ children: t("studio_tables_drop_warning", { name: table.name })
3084
+ }), /* @__PURE__ */ jsx(TextField, {
3085
+ label: t("studio_tables_drop_confirm_label", { name: table.name }),
3086
+ value: dropConfirm,
3087
+ onChange: (event) => setDropConfirm(event.target.value)
3088
+ })]
3089
+ }),
3090
+ /* @__PURE__ */ jsxs(DialogActions, { children: [/* @__PURE__ */ jsx(Button, {
3091
+ variant: "text",
3092
+ onClick: () => setDropOpen(false),
3093
+ children: t("cancel")
3094
+ }), /* @__PURE__ */ jsx(Button, {
3095
+ variant: "filled",
3096
+ color: "error",
3097
+ disabled: dropping || dropConfirm !== table.name,
3098
+ onClick: () => void drop(),
3099
+ children: dropping ? t("studio_tables_dropping") : t("studio_tables_drop_table")
3100
+ })] })
3101
+ ]
3102
+ }),
3103
+ dialog
3104
+ ]
3105
+ });
3106
+ }
3107
+ //#endregion
3108
+ //#region src/components/TableEditor/TableEditorView.tsx
3109
+ /** The tabs that read the table's catalog details. */
3110
+ var DETAIL_TABS = /* @__PURE__ */ new Set([
3111
+ "structure",
3112
+ "policies",
3113
+ "relations",
3114
+ "stats"
3115
+ ]);
3116
+ /**
3117
+ * The Tables view: every table of the schema, and for the one selected its
3118
+ * rows, structure, policies, relations, statistics and settings — or the
3119
+ * whole schema as a diagram. The selection, tab and mode live in the URL
3120
+ * (`?table=schema.name&tableTab=…`, `?tablesView=diagram`), so any view can
3121
+ * link straight to them.
3122
+ */
3123
+ function TableEditorView() {
3124
+ const { requestJson } = useAdminFetch();
3125
+ const snackbar = useSnackbarController();
3126
+ const { t, i18n } = useTranslation();
3127
+ const [searchParams, setSearchParams] = useSearchParams();
3128
+ const [tables, setTables] = useState([]);
3129
+ const [loading, setLoading] = useState(true);
3130
+ const [error, setError] = useState(null);
3131
+ const [search, setSearch] = useState("");
3132
+ const [createOpen, setCreateOpen] = useState(false);
3133
+ const [ddlOpen, setDdlOpen] = useState(false);
3134
+ const [details, setDetails] = useState(null);
3135
+ const [detailsLoading, setDetailsLoading] = useState(false);
3136
+ const [detailsVersion, setDetailsVersion] = useState(0);
3137
+ const linkedKey = searchParams.get(TABLE_PARAM);
3138
+ const rawTab = searchParams.get(TABLE_TAB_PARAM);
3139
+ const activeTab = isInspectorTab(rawTab) ? rawTab : "data";
3140
+ const diagramMode = searchParams.get(TABLES_VIEW_PARAM) === "diagram";
3141
+ /** Changes this view's own parameters only: the hosted console keeps its own (`?tab=`) in the same query string. */
3142
+ const updateParams = useCallback((change) => {
3143
+ setSearchParams((prev) => {
3144
+ const params = new URLSearchParams(prev);
3145
+ for (const [key, value] of Object.entries(change)) if (value === null) params.delete(key);
3146
+ else params.set(key, value);
3147
+ return params;
3148
+ }, { replace: true });
3149
+ }, [setSearchParams]);
3150
+ /** Reads the tables again; resolves to the list read, or `null` when the read failed. */
3151
+ const loadTables = useCallback(async () => {
3152
+ setLoading(true);
3153
+ setError(null);
3154
+ try {
3155
+ const list = parseTablesResponse(await requestJson("/admin/db/tables"));
3156
+ setTables(list);
3157
+ return list;
3158
+ } catch (err) {
3159
+ setError(err instanceof Error ? err.message : t("studio_tables_load_failed"));
3160
+ return null;
3161
+ } finally {
3162
+ setLoading(false);
3163
+ }
3164
+ }, [requestJson, t]);
3165
+ useEffect(() => {
3166
+ loadTables();
3167
+ }, [loadTables]);
3168
+ useEffect(() => {
3169
+ if (loading || diagramMode) return;
3170
+ if (linkedKey && tables.some((table) => table.key === linkedKey)) return;
3171
+ const first = tables[0]?.key ?? null;
3172
+ if (first !== linkedKey) updateParams({ [TABLE_PARAM]: first });
3173
+ }, [
3174
+ loading,
3175
+ diagramMode,
3176
+ linkedKey,
3177
+ tables,
3178
+ updateParams
3179
+ ]);
3180
+ const selectedTable = useMemo(() => tables.find((table) => table.key === linkedKey) ?? null, [tables, linkedKey]);
3181
+ const selectTable = useCallback((key) => {
3182
+ updateParams({
3183
+ [TABLE_PARAM]: key,
3184
+ [TABLE_FILTER_PARAM]: null
3185
+ });
3186
+ }, [updateParams]);
3187
+ const setTab = useCallback((tab) => updateParams({ [TABLE_TAB_PARAM]: tab === "data" ? null : tab }), [updateParams]);
3188
+ const needsDetails = selectedTable !== null && (DETAIL_TABS.has(activeTab) || ddlOpen);
3189
+ useEffect(() => {
3190
+ if (!needsDetails || !selectedTable) return;
3191
+ let current = true;
3192
+ setDetailsLoading(true);
3193
+ requestJson(`/admin/db/tables/${encodeURIComponent(selectedTable.name)}/details?schema=${encodeURIComponent(selectedTable.schema)}`).then((raw) => {
3194
+ const parsed = parseTableDetails(raw);
3195
+ if (current && parsed) setDetails({
3196
+ key: selectedTable.key,
3197
+ value: parsed
3198
+ });
3199
+ }).catch((err) => {
3200
+ if (current) snackbar.open({
3201
+ type: "error",
3202
+ message: err instanceof Error ? err.message : t("studio_tables_details_failed")
3203
+ });
3204
+ }).finally(() => {
3205
+ if (current) setDetailsLoading(false);
3206
+ });
3207
+ return () => {
3208
+ current = false;
3209
+ };
3210
+ }, [
3211
+ needsDetails,
3212
+ selectedTable?.key,
3213
+ detailsVersion,
3214
+ requestJson
3215
+ ]);
3216
+ const currentDetails = details && selectedTable && details.key === selectedTable.key ? details.value : null;
3217
+ /** After a change: the list and the selected table's details, read again. */
3218
+ const refresh = useCallback(() => {
3219
+ loadTables();
3220
+ setDetailsVersion((version) => version + 1);
3221
+ }, [loadTables]);
3222
+ /**
3223
+ * What a change that should leave `name` served actually left: served, or
3224
+ * not served and why — never "live" because the request succeeded.
3225
+ */
3226
+ const reportServed = useCallback((list, key, done) => {
3227
+ const table = list?.find((candidate) => candidate.key === key);
3228
+ if (!table) snackbar.open({
3229
+ type: "success",
3230
+ message: `${done}.`
3231
+ });
3232
+ else if (table.served) snackbar.open({
3233
+ type: "success",
3234
+ message: t("studio_tables_done_served", {
3235
+ done,
3236
+ path: `/api/data/${table.slug}`
3237
+ })
3238
+ });
3239
+ else snackbar.open({
3240
+ type: "warning",
3241
+ message: t("studio_tables_done_not_served", {
3242
+ done,
3243
+ reason: t(notServedReasonKey(table))
3244
+ })
3245
+ });
3246
+ }, [snackbar, t]);
3247
+ const handleReloadSchema = async () => {
3248
+ try {
3249
+ const res = await requestJson("/admin/schema/reload", { method: "POST" });
3250
+ const count = isRecord(res) ? asNumber(res.tables, 0) : 0;
3251
+ snackbar.open({
3252
+ type: "success",
3253
+ message: t("studio_tables_schema_reloaded", { count })
3254
+ });
3255
+ refresh();
3256
+ } catch (err) {
3257
+ snackbar.open({
3258
+ type: "error",
3259
+ message: err instanceof Error ? err.message : t("studio_tables_schema_reload_failed")
3260
+ });
3261
+ }
3262
+ };
3263
+ const handleEnableAndExpose = async (table) => {
3264
+ try {
3265
+ await requestJson(`/admin/db/tables/${encodeURIComponent(table.name)}`, {
3266
+ method: "PATCH",
3267
+ body: {
3268
+ schema: table.schema,
3269
+ rlsEnabled: true,
3270
+ meta: { exposed: true }
3271
+ }
3272
+ });
3273
+ if (table.policies.length === 0) await requestJson(`/admin/db/tables/${encodeURIComponent(table.name)}/policies`, {
3274
+ method: "POST",
3275
+ body: {
3276
+ schema: table.schema,
3277
+ name: "authenticated_all",
3278
+ operation: "ALL",
3279
+ using: SIGNED_IN_SQL,
3280
+ withCheck: SIGNED_IN_SQL
3281
+ }
3282
+ });
3283
+ reportServed(await loadTables(), table.key, t("studio_tables_protected_and_exposed", { name: table.name }));
3284
+ } catch (err) {
3285
+ snackbar.open({
3286
+ type: "error",
3287
+ message: err instanceof Error ? err.message : t("studio_tables_expose_failed")
3288
+ });
3289
+ }
3290
+ };
3291
+ const filteredTables = useMemo(() => {
3292
+ const query = search.trim().toLowerCase();
3293
+ if (!query) return tables;
3294
+ return tables.filter((table) => table.name.toLowerCase().includes(query) || table.slug.toLowerCase().includes(query));
3295
+ }, [tables, search]);
3296
+ const schema = tables[0]?.schema ?? "public";
3297
+ const formatter = new Intl.NumberFormat(i18n?.language);
3298
+ return /* @__PURE__ */ jsxs("div", {
3299
+ className: "flex h-full w-full overflow-hidden bg-surface-card",
3300
+ children: [
3301
+ /* @__PURE__ */ jsxs("aside", {
3302
+ className: cls("w-60 shrink-0 flex flex-col border-r bg-surface-card", defaultBorderMixin),
3303
+ children: [
3304
+ /* @__PURE__ */ jsxs("div", {
3305
+ className: cls("h-[42px] px-3 border-b bg-surface-sheet flex items-center justify-between gap-2 shrink-0", defaultBorderMixin),
3306
+ children: [/* @__PURE__ */ jsxs("div", {
3307
+ className: "flex items-center gap-2 min-w-0",
3308
+ children: [/* @__PURE__ */ jsx(DatabaseIcon, {
3309
+ size: iconSize.smallest,
3310
+ className: "text-text-secondary dark:text-text-secondary-dark shrink-0"
3311
+ }), /* @__PURE__ */ jsx(Typography, {
3312
+ variant: "caption",
3313
+ className: "font-medium text-text-secondary dark:text-text-secondary-dark truncate",
3314
+ children: t("studio_tool_tables")
3315
+ })]
3316
+ }), /* @__PURE__ */ jsxs("div", {
3317
+ className: "flex items-center gap-1",
3318
+ children: [/* @__PURE__ */ jsx(Tooltip, {
3319
+ title: t("studio_tables_reload_schema"),
3320
+ children: /* @__PURE__ */ jsx(IconButton, {
3321
+ size: "small",
3322
+ "aria-label": t("studio_tables_reload_schema"),
3323
+ onClick: () => void handleReloadSchema(),
3324
+ children: /* @__PURE__ */ jsx(RefreshCwIcon, { size: iconSize.smallest })
3325
+ })
3326
+ }), /* @__PURE__ */ jsxs(Button, {
3327
+ size: "small",
3328
+ variant: "outlined",
3329
+ onClick: () => setCreateOpen(true),
3330
+ children: [/* @__PURE__ */ jsx(PlusIcon, { size: iconSize.smallest }), t("studio_api_keys_new")]
3331
+ })]
3332
+ })]
3333
+ }),
3334
+ /* @__PURE__ */ jsx("div", {
3335
+ className: "px-2 pt-2",
3336
+ children: /* @__PURE__ */ jsx(ToggleButtonGroup, {
3337
+ fullWidth: true,
3338
+ "aria-label": t("studio_tables_view_mode"),
3339
+ value: diagramMode ? "diagram" : "list",
3340
+ onValueChange: (mode) => updateParams({ [TABLES_VIEW_PARAM]: mode === "diagram" ? "diagram" : null }),
3341
+ options: [{
3342
+ value: "list",
3343
+ label: t("studio_tables_mode_tables"),
3344
+ icon: /* @__PURE__ */ jsx(TableIcon, { size: iconSize.smallest })
3345
+ }, {
3346
+ value: "diagram",
3347
+ label: t("studio_tables_mode_diagram"),
3348
+ icon: /* @__PURE__ */ jsx(LucideIconByName, {
3349
+ name: "Network",
3350
+ size: 14
3351
+ })
3352
+ }]
3353
+ })
3354
+ }),
3355
+ /* @__PURE__ */ jsx("div", {
3356
+ className: "p-2",
3357
+ children: /* @__PURE__ */ jsx(SearchBar, {
3358
+ size: "small",
3359
+ onTextSearch: (value) => setSearch(value ?? ""),
3360
+ placeholder: t("studio_tables_filter_placeholder"),
3361
+ innerClassName: "w-full"
3362
+ })
3363
+ }),
3364
+ /* @__PURE__ */ jsx("div", {
3365
+ className: "flex-1 overflow-y-auto px-2 pb-3 flex flex-col gap-0.5",
3366
+ children: loading && tables.length === 0 ? /* @__PURE__ */ jsx("div", {
3367
+ className: "flex items-center justify-center py-8",
3368
+ children: /* @__PURE__ */ jsx(CircularProgress, { size: "small" })
3369
+ }) : filteredTables.length === 0 ? /* @__PURE__ */ jsxs("div", {
3370
+ className: "px-3 py-6 text-center flex flex-col items-center gap-2",
3371
+ children: [/* @__PURE__ */ jsx(Typography, {
3372
+ variant: "body2",
3373
+ color: "secondary",
3374
+ children: tables.length === 0 ? t("studio_tables_empty") : t("studio_tables_no_match")
3375
+ }), tables.length === 0 && /* @__PURE__ */ jsxs(Button, {
3376
+ size: "small",
3377
+ variant: "outlined",
3378
+ onClick: () => setCreateOpen(true),
3379
+ children: [/* @__PURE__ */ jsx(PlusIcon, { size: iconSize.small }), t("studio_tables_create_first")]
3380
+ })]
3381
+ }) : filteredTables.map((table) => {
3382
+ return /* @__PURE__ */ jsxs("button", {
3383
+ type: "button",
3384
+ onClick: () => selectTable(table.key),
3385
+ className: cls("w-full text-left px-2.5 h-8 rounded-lg flex items-center justify-between gap-2 transition-colors cursor-pointer", table.key === linkedKey ? "bg-surface-active text-text-primary dark:text-text-primary-dark font-medium" : "text-text-secondary dark:text-text-secondary-dark hover:bg-surface-hover hover:text-text-primary dark:hover:text-text-primary-dark"),
3386
+ children: [/* @__PURE__ */ jsxs("span", {
3387
+ className: "flex items-center gap-2 min-w-0",
3388
+ children: [table.kind === "view" ? /* @__PURE__ */ jsx(EyeIcon, {
3389
+ size: 14,
3390
+ className: "shrink-0 text-text-disabled dark:text-text-disabled-dark"
3391
+ }) : /* @__PURE__ */ jsx(TableIcon, {
3392
+ size: 14,
3393
+ className: "shrink-0 text-text-disabled dark:text-text-disabled-dark"
3394
+ }), /* @__PURE__ */ jsx("span", {
3395
+ className: "truncate text-[13px]",
3396
+ children: table.name
3397
+ })]
3398
+ }), /* @__PURE__ */ jsx(Tooltip, {
3399
+ title: table.served ? t("studio_tables_served_tooltip") : t("studio_tables_not_exposed_tooltip"),
3400
+ children: /* @__PURE__ */ jsx("span", { children: /* @__PURE__ */ jsx(StatusDot, {
3401
+ tone: table.served ? "ok" : "idle",
3402
+ "aria-label": table.served ? t("studio_tables_served_tooltip") : t("studio_tables_not_exposed_tooltip")
3403
+ }) })
3404
+ })]
3405
+ }, table.key);
3406
+ })
3407
+ })
3408
+ ]
3409
+ }),
3410
+ /* @__PURE__ */ jsxs("main", {
3411
+ className: "flex-1 flex flex-col min-w-0 overflow-hidden",
3412
+ children: [error && /* @__PURE__ */ jsx("div", {
3413
+ className: "p-4",
3414
+ children: /* @__PURE__ */ jsx(Alert, {
3415
+ color: "error",
3416
+ children: error
3417
+ })
3418
+ }), diagramMode ? /* @__PURE__ */ jsx("div", {
3419
+ className: "flex-1 min-h-0",
3420
+ children: /* @__PURE__ */ jsx(TablesDiagram, {
3421
+ catalog: tables,
3422
+ highlightTable: selectedTable?.name ?? null,
3423
+ onOpenTable: (name) => updateParams({
3424
+ [TABLE_PARAM]: `${schema}.${name}`,
3425
+ [TABLES_VIEW_PARAM]: null,
3426
+ [TABLE_FILTER_PARAM]: null
3427
+ })
3428
+ })
3429
+ }) : !selectedTable ? /* @__PURE__ */ jsxs("div", {
3430
+ className: "flex-1 flex flex-col items-center justify-center p-8 text-center gap-4",
3431
+ children: [
3432
+ /* @__PURE__ */ jsx(DatabaseIcon, { className: "w-10 h-10 text-text-disabled" }),
3433
+ /* @__PURE__ */ jsxs("div", {
3434
+ className: "max-w-md flex flex-col gap-1",
3435
+ children: [/* @__PURE__ */ jsx(Typography, {
3436
+ variant: "h6",
3437
+ children: t("studio_tables_intro_title")
3438
+ }), /* @__PURE__ */ jsx(Typography, {
3439
+ variant: "body2",
3440
+ color: "secondary",
3441
+ children: t("studio_tables_intro_body")
3442
+ })]
3443
+ }),
3444
+ /* @__PURE__ */ jsxs(Button, {
3445
+ variant: "filled",
3446
+ color: "primary",
3447
+ onClick: () => setCreateOpen(true),
3448
+ children: [/* @__PURE__ */ jsx(PlusIcon, { size: iconSize.small }), t("studio_tables_new_table")]
3449
+ })
3450
+ ]
3451
+ }) : /* @__PURE__ */ jsxs(Fragment, { children: [
3452
+ /* @__PURE__ */ jsxs("div", {
3453
+ className: "h-[42px] px-4 flex items-center justify-between gap-4 bg-surface-sheet shrink-0",
3454
+ children: [/* @__PURE__ */ jsxs("div", {
3455
+ className: "flex items-center gap-2.5 min-w-0",
3456
+ children: [
3457
+ /* @__PURE__ */ jsxs(Typography, {
3458
+ variant: "subtitle2",
3459
+ className: "font-mono font-semibold truncate",
3460
+ children: [
3461
+ selectedTable.schema,
3462
+ ".",
3463
+ selectedTable.name
3464
+ ]
3465
+ }),
3466
+ /* @__PURE__ */ jsx(Chip, {
3467
+ size: "smallest",
3468
+ colorScheme: selectedTable.served ? "greenLight" : "orangeLight",
3469
+ children: selectedTable.served ? `/api/data/${selectedTable.slug}` : t("studio_tables_not_exposed")
3470
+ }),
3471
+ selectedTable.kind === "table" && /* @__PURE__ */ jsx(Tooltip, {
3472
+ title: t("studio_tables_rls_chip_tooltip"),
3473
+ children: /* @__PURE__ */ jsx(Chip, {
3474
+ size: "smallest",
3475
+ colorScheme: selectedTable.rlsEnabled ? "blueLight" : "grayLight",
3476
+ onClick: () => setTab("policies"),
3477
+ children: selectedTable.rlsEnabled ? `RLS (${selectedTable.policies.length})` : t("studio_tables_rls_off")
3478
+ })
3479
+ }),
3480
+ selectedTable.kind === "view" && /* @__PURE__ */ jsx(Chip, {
3481
+ size: "smallest",
3482
+ children: selectedTable.materialized ? t("studio_tables_kind_matview") : t("studio_tables_kind_view")
3483
+ }),
3484
+ selectedTable.rowEstimate !== null && /* @__PURE__ */ jsx(Typography, {
3485
+ variant: "caption",
3486
+ color: "secondary",
3487
+ className: "whitespace-nowrap",
3488
+ children: t("studio_tables_row_estimate", { count: formatter.format(selectedTable.rowEstimate) })
3489
+ })
3490
+ ]
3491
+ }), /* @__PURE__ */ jsx("div", {
3492
+ className: "flex items-center gap-2 shrink-0",
3493
+ children: /* @__PURE__ */ jsxs(Button, {
3494
+ size: "small",
3495
+ variant: "text",
3496
+ onClick: () => setDdlOpen(true),
3497
+ children: [/* @__PURE__ */ jsx(CodeIcon, { size: iconSize.smallest }), t("studio_tables_view_sql")]
3498
+ })
3499
+ })]
3500
+ }),
3501
+ /* @__PURE__ */ jsxs(Tabs, {
3502
+ value: activeTab,
3503
+ onValueChange: (value) => {
3504
+ if (isInspectorTab(value)) setTab(value);
3505
+ },
3506
+ variant: "boxy",
3507
+ className: "border-b border-hairline px-4 bg-surface-sheet shrink-0",
3508
+ children: [
3509
+ /* @__PURE__ */ jsx(Tab, {
3510
+ value: "data",
3511
+ children: t("studio_tables_tab_data_plain")
3512
+ }),
3513
+ /* @__PURE__ */ jsx(Tab, {
3514
+ value: "structure",
3515
+ children: t("studio_tables_tab_structure")
3516
+ }),
3517
+ selectedTable.kind === "table" && /* @__PURE__ */ jsx(Tab, {
3518
+ value: "policies",
3519
+ children: t("studio_tables_tab_policies")
3520
+ }),
3521
+ /* @__PURE__ */ jsx(Tab, {
3522
+ value: "relations",
3523
+ children: t("studio_tables_tab_relations")
3524
+ }),
3525
+ /* @__PURE__ */ jsx(Tab, {
3526
+ value: "stats",
3527
+ children: t("studio_tables_tab_stats")
3528
+ }),
3529
+ /* @__PURE__ */ jsx(Tab, {
3530
+ value: "settings",
3531
+ children: t("settings_heading")
3532
+ })
3533
+ ]
3534
+ }),
3535
+ !selectedTable.served && selectedTable.kind === "table" && /* @__PURE__ */ jsx("div", {
3536
+ className: "px-4 pt-3 shrink-0",
3537
+ children: /* @__PURE__ */ jsx(Alert, {
3538
+ color: "warning",
3539
+ size: "small",
3540
+ children: /* @__PURE__ */ jsxs("div", {
3541
+ className: "flex items-center justify-between gap-4",
3542
+ children: [/* @__PURE__ */ jsx("span", { children: t("studio_tables_not_served", { reason: t(notServedReasonKey(selectedTable)) }) }), /* @__PURE__ */ jsxs(Button, {
3543
+ size: "small",
3544
+ variant: "outlined",
3545
+ onClick: () => void handleEnableAndExpose(selectedTable),
3546
+ children: [/* @__PURE__ */ jsx(ShieldIcon, { size: iconSize.smallest }), t("studio_tables_enable_and_expose")]
3547
+ })]
3548
+ })
3549
+ })
3550
+ }),
3551
+ activeTab === "data" ? /* @__PURE__ */ jsx(DataTab, { table: selectedTable }, selectedTable.key) : /* @__PURE__ */ jsxs("div", {
3552
+ className: "flex-1 overflow-auto p-5",
3553
+ children: [
3554
+ detailsLoading && !currentDetails && /* @__PURE__ */ jsx("div", {
3555
+ className: "flex items-center justify-center py-10",
3556
+ children: /* @__PURE__ */ jsx(CircularProgress, { size: "small" })
3557
+ }),
3558
+ activeTab === "structure" && /* @__PURE__ */ jsx(StructureTab, {
3559
+ table: selectedTable,
3560
+ tables,
3561
+ details: currentDetails,
3562
+ onChanged: refresh
3563
+ }),
3564
+ activeTab === "policies" && /* @__PURE__ */ jsx(PoliciesTab, {
3565
+ table: selectedTable,
3566
+ details: currentDetails,
3567
+ onChanged: refresh
3568
+ }),
3569
+ activeTab === "relations" && /* @__PURE__ */ jsx(RelationsTab, {
3570
+ table: selectedTable,
3571
+ tables,
3572
+ details: currentDetails
3573
+ }),
3574
+ activeTab === "stats" && /* @__PURE__ */ jsx(StatsTab, {
3575
+ table: selectedTable,
3576
+ details: currentDetails,
3577
+ onChanged: refresh
3578
+ }),
3579
+ activeTab === "settings" && /* @__PURE__ */ jsx(SettingsTab, {
3580
+ table: selectedTable,
3581
+ onChanged: refresh,
3582
+ onTableReplaced: (key) => {
3583
+ loadTables().then(() => selectTable(key));
3584
+ }
3585
+ })
3586
+ ]
3587
+ }),
3588
+ /* @__PURE__ */ jsx(TableDdlSheet, {
3589
+ open: ddlOpen,
3590
+ onOpenChange: setDdlOpen,
3591
+ title: selectedTable.key,
3592
+ ddl: currentDetails?.ddl ?? null,
3593
+ loading: detailsLoading
3594
+ })
3595
+ ] })]
3596
+ }),
3597
+ /* @__PURE__ */ jsx(CreateTableDialog, {
3598
+ open: createOpen,
3599
+ onOpenChange: setCreateOpen,
3600
+ schema,
3601
+ onCreated: (name) => {
3602
+ const key = `${schema}.${name}`;
3603
+ loadTables().then((list) => {
3604
+ reportServed(list, key, t("studio_tables_table_created", { name }));
3605
+ selectTable(key);
3606
+ });
3607
+ }
3608
+ })
3609
+ ]
3610
+ });
3611
+ }
3612
+ //#endregion
3613
+ export { TableEditorView };
3614
+
3615
+ //# sourceMappingURL=TableEditorView-BRZNvD6U.js.map