@rebasepro/studio 0.35.1 → 0.36.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 (91) 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-B7QHjEGY.js} +2 -2
  19. package/dist/{StorageView-D0D8z4lI.js.map → StorageView-B7QHjEGY.js.map} +1 -1
  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/TableEditor/CreateTableDialog.d.ts +8 -0
  58. package/dist/components/TableEditor/DdlConfirm.d.ts +23 -0
  59. package/dist/components/TableEditor/SqlBlock.d.ts +7 -0
  60. package/dist/components/TableEditor/TableDdlSheet.d.ts +9 -0
  61. package/dist/components/TableEditor/TableEditorView.d.ts +7 -0
  62. package/dist/components/TableEditor/tableModel.d.ts +210 -0
  63. package/dist/components/TableEditor/tabs/DataTab.d.ts +12 -0
  64. package/dist/components/TableEditor/tabs/PoliciesTab.d.ts +8 -0
  65. package/dist/components/TableEditor/tabs/RelationsTab.d.ts +8 -0
  66. package/dist/components/TableEditor/tabs/SettingsTab.d.ts +11 -0
  67. package/dist/components/TableEditor/tabs/StatsTab.d.ts +8 -0
  68. package/dist/components/TableEditor/tabs/StructureTab.d.ts +12 -0
  69. package/dist/index.es.js +29 -15
  70. package/dist/index.es.js.map +1 -1
  71. package/dist/{sql_utils-CYcgpgam.js → sql_utils-DkMYltfq.js} +27 -3
  72. package/dist/sql_utils-DkMYltfq.js.map +1 -0
  73. package/dist/useRunAsUsers-GPFCxcBC.js +69 -0
  74. package/dist/useRunAsUsers-GPFCxcBC.js.map +1 -0
  75. package/dist/utils/adminFetch.d.ts +1 -0
  76. package/dist/utils/csv_parse.d.ts +11 -0
  77. package/dist/utils/explain_plan.d.ts +70 -0
  78. package/dist/utils/sql_params.d.ts +51 -0
  79. package/dist/utils/sql_utils.d.ts +16 -0
  80. package/package.json +11 -9
  81. package/dist/RLSEditor-CTG3jLE7.js +0 -2572
  82. package/dist/RLSEditor-CTG3jLE7.js.map +0 -1
  83. package/dist/SQLEditor-DRo5kW1h.js.map +0 -1
  84. package/dist/SchemaVisualizer-Dy4kWKT5.js.map +0 -1
  85. package/dist/TableEditorView-BKhSBG-K.js +0 -1694
  86. package/dist/TableEditorView-BKhSBG-K.js.map +0 -1
  87. package/dist/components/SchemaVisualizer/SchemaVisualizer.d.ts +0 -3
  88. package/dist/policy-presets-CJKzAvQp.js +0 -167
  89. package/dist/policy-presets-CJKzAvQp.js.map +0 -1
  90. package/dist/sql_utils-CYcgpgam.js.map +0 -1
  91. package/dist/useRunAsUsers-CF7tkGzj.js.map +0 -1
@@ -1,1694 +0,0 @@
1
- import { a as asStringArray, i as asString, n as asNullableString, o as isRecord, r as asNumber, s as useAdminFetch, t as asBoolean } from "./adminFetch-BfOnfRgU.js";
2
- import { r as SIGNED_IN_SQL } from "./policy-presets-CJKzAvQp.js";
3
- import { t as FixedEditorOverlay } from "./FixedEditorOverlay-DtgPBSjq.js";
4
- import { useSnackbarController, useTranslation } from "@rebasepro/app";
5
- import { useCallback, useEffect, useMemo, useState } from "react";
6
- import { Alert, AlertCircleIcon, BooleanSwitchWithLabel, Button, Card, CheckCircleIcon, Chip, CircularProgress, DatabaseIcon, Dialog, DialogActions, DialogContent, DialogTitle, IconButton, PencilIcon, PlusIcon, RefreshCwIcon, SearchBar, Select, SelectItem, ShieldIcon, Tab, Table, TableBody, TableCell, TableHeader, TableRow, Tabs, TextField, Tooltip, Trash2Icon, Typography, VirtualTable, cls, defaultBorderMixin, iconSize } from "@rebasepro/ui";
7
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
8
- import { policy } from "@rebasepro/types";
9
- import { compilePolicyExpression } from "@rebasepro/common";
10
- //#region src/components/TableEditor/TableEditorView.tsx
11
- /**
12
- * The "Owner only" preset's condition: the row's `user_id` is the signed-in
13
- * user. Compiled, as `SIGNED_IN_SQL` is, rather than written out: the
14
- * hand-written `user_id = rebase.uid()` compared a uuid column with text and
15
- * Postgres refused the table, and the old "signed in" clause — a bare
16
- * `rebase.uid() IS NOT NULL` — let anonymous visitors through.
17
- */
18
- var OWNS_ROW_BY_USER_ID_SQL = compilePolicyExpression(policy.compare(policy.field("user_id"), "eq", policy.authUid()));
19
- var SQL_TYPES = [
20
- "text",
21
- "varchar(255)",
22
- "integer",
23
- "bigint",
24
- "numeric",
25
- "double precision",
26
- "boolean",
27
- "uuid",
28
- "timestamptz",
29
- "date",
30
- "jsonb",
31
- "text[]"
32
- ];
33
- var RLS_PRESETS = [
34
- {
35
- value: "authenticated",
36
- labelKey: "studio_tables_preset_authenticated"
37
- },
38
- {
39
- value: "public-read",
40
- labelKey: "studio_tables_preset_public_read"
41
- },
42
- {
43
- value: "owner",
44
- labelKey: "studio_tables_preset_owner"
45
- },
46
- {
47
- value: "admin-only",
48
- labelKey: "studio_tables_preset_admin_only"
49
- }
50
- ];
51
- function parseColumn(raw) {
52
- if (!isRecord(raw) || typeof raw.name !== "string") return null;
53
- return {
54
- name: raw.name,
55
- key: asString(raw.key, raw.name),
56
- dataType: asString(raw.dataType, "text"),
57
- udtName: asString(raw.udtName, "text"),
58
- nullable: asBoolean(raw.nullable, true),
59
- defaultExpr: asNullableString(raw.default ?? raw.defaultExpr),
60
- primaryKey: asBoolean(raw.primaryKey, false),
61
- unique: asBoolean(raw.unique, false)
62
- };
63
- }
64
- function parsePolicy(raw) {
65
- if (!isRecord(raw) || typeof raw.name !== "string") return null;
66
- return {
67
- name: raw.name,
68
- operation: asString(raw.operation ?? raw.command, "ALL"),
69
- roles: asStringArray(raw.roles),
70
- using: asNullableString(raw.using),
71
- withCheck: asNullableString(raw.withCheck)
72
- };
73
- }
74
- function parseIndex(raw) {
75
- if (!isRecord(raw) || typeof raw.name !== "string") return null;
76
- return {
77
- name: raw.name,
78
- definition: asString(raw.definition, ""),
79
- unique: asBoolean(raw.unique, false),
80
- primary: asBoolean(raw.primary, false)
81
- };
82
- }
83
- function parseMeta(raw) {
84
- if (!isRecord(raw)) return null;
85
- const softDeleteColumn = asNullableString(raw.softDeleteColumn ?? raw.soft_delete_column);
86
- const readonlyColumns = asStringArray(raw.readonlyColumns ?? raw.readonly_columns);
87
- return {
88
- slug: asNullableString(raw.slug),
89
- exposed: asBoolean(raw.exposed, true),
90
- description: asNullableString(raw.description),
91
- softDelete: Boolean(softDeleteColumn) || asBoolean(raw.softDelete, false),
92
- softDeleteColumn,
93
- history: asBoolean(raw.historyEnabled ?? raw.history_enabled ?? raw.history, false),
94
- readOnly: readonlyColumns.length > 0 || asBoolean(raw.readOnly, false),
95
- isPrivate: asBoolean(raw.isPrivate, false)
96
- };
97
- }
98
- function parseTable(raw) {
99
- if (!isRecord(raw) || typeof raw.name !== "string") return null;
100
- const columns = Array.isArray(raw.columns) ? raw.columns.map(parseColumn).filter((c) => c !== null) : [];
101
- const policies = Array.isArray(raw.policies) ? raw.policies.map(parsePolicy).filter((p) => p !== null) : [];
102
- const indexes = Array.isArray(raw.indexes) ? raw.indexes.map(parseIndex).filter((i) => i !== null) : [];
103
- return {
104
- schema: asString(raw.schema, "public"),
105
- name: raw.name,
106
- slug: asString(raw.slug, raw.name),
107
- rlsEnabled: asBoolean(raw.rlsEnabled, false),
108
- rlsForced: asBoolean(raw.rlsForced, false),
109
- exposed: asBoolean(raw.exposed, true),
110
- served: asBoolean(raw.served, false),
111
- columns,
112
- policies,
113
- indexes,
114
- meta: parseMeta(raw.meta)
115
- };
116
- }
117
- function parseTablesResponse(raw) {
118
- if (!isRecord(raw) || !Array.isArray(raw.tables)) return [];
119
- return raw.tables.map(parseTable).filter((t) => t !== null);
120
- }
121
- /** The rows grid's first column: a row's edit and delete buttons. */
122
- var ROW_ACTIONS_COLUMN = "__row_actions__";
123
- /** The muted icon the SQL and JS editors' result grids use for a row's action. */
124
- var ROW_ACTION_ICON = "text-surface-400 dark:text-surface-500 hover:text-surface-600 dark:hover:text-surface-300 transition-colors";
125
- /** One empty list, so a table with no rows loaded hands the grid the same array each render. */
126
- var NO_ROWS = [];
127
- /** A starting width wide enough for the column's usual values; the grid lets it be resized. */
128
- function rowColumnWidth(col) {
129
- const t = col.udtName.toLowerCase();
130
- if (t === "uuid") return 300;
131
- if (t === "timestamptz" || t === "timestamp") return 240;
132
- if (t === "date" || t === "bool" || t === "boolean") return 120;
133
- if (t === "int2" || t === "int4" || t === "int8" || t === "float4" || t === "float8" || t === "numeric") return 120;
134
- return 200;
135
- }
136
- /**
137
- * Why a table is not on `/api/data`, from what the server reported about it —
138
- * the one reason that holds, not a list of possible ones. The translation key
139
- * of the sentence, for the caller to hand to `t()`.
140
- */
141
- function notServedReasonKey(table) {
142
- if (!table.rlsEnabled) return "studio_tables_not_served_rls_off";
143
- if (!(table.meta?.exposed ?? table.exposed)) return "studio_tables_not_served_not_exposed";
144
- return "studio_tables_not_served_not_picked_up";
145
- }
146
- /** The text a cell's edit box opens with: empty for NULL, JSON for an object or array. */
147
- function cellEditText(value) {
148
- if (value === null || value === void 0) return "";
149
- return typeof value === "object" ? JSON.stringify(value) : String(value);
150
- }
151
- function formatCellValue(value) {
152
- if (value === null || value === void 0) return "NULL";
153
- if (typeof value === "object") try {
154
- return JSON.stringify(value);
155
- } catch {
156
- return String(value);
157
- }
158
- return String(value);
159
- }
160
- function parseCellInput(raw, col) {
161
- const trimmed = raw.trim();
162
- if (trimmed === "" && col.nullable) return null;
163
- const t = col.udtName.toLowerCase();
164
- if (t === "bool" || t === "boolean") {
165
- if (trimmed.toLowerCase() === "true") return true;
166
- if (trimmed.toLowerCase() === "false") return false;
167
- }
168
- if (t === "int2" || t === "int4" || t === "int8" || t === "float4" || t === "float8" || t === "numeric") {
169
- const n = Number(trimmed);
170
- if (Number.isFinite(n)) return n;
171
- }
172
- if (t === "json" || t === "jsonb" || t.startsWith("_")) try {
173
- return JSON.parse(trimmed);
174
- } catch {
175
- return raw;
176
- }
177
- return raw;
178
- }
179
- function TableEditorView() {
180
- const { requestJson } = useAdminFetch();
181
- const snackbar = useSnackbarController();
182
- const { t } = useTranslation();
183
- const [tables, setTables] = useState([]);
184
- const [loading, setLoading] = useState(true);
185
- const [error, setError] = useState(null);
186
- const [search, setSearch] = useState("");
187
- const [selectedName, setSelectedName] = useState(null);
188
- const [activeTab, setActiveTab] = useState("data");
189
- const [loadedRows, setLoadedRows] = useState(null);
190
- const [rowsLoading, setRowsLoading] = useState(false);
191
- const [rowsError, setRowsError] = useState(null);
192
- const [rowDialogOpen, setRowDialogOpen] = useState(false);
193
- const [editingRowId, setEditingRowId] = useState(null);
194
- const [rowForm, setRowForm] = useState({});
195
- const [rowSaving, setRowSaving] = useState(false);
196
- const [createOpen, setCreateOpen] = useState(false);
197
- const [newTableName, setNewTableName] = useState("");
198
- const [newTableRls, setNewTableRls] = useState("authenticated");
199
- const [draftColumns, setDraftColumns] = useState([
200
- {
201
- name: "id",
202
- type: "uuid",
203
- primaryKey: true,
204
- nullable: false,
205
- unique: false,
206
- defaultExpr: "gen_random_uuid()"
207
- },
208
- {
209
- name: "title",
210
- type: "text",
211
- primaryKey: false,
212
- nullable: false,
213
- unique: false,
214
- defaultExpr: ""
215
- },
216
- {
217
- name: "created_at",
218
- type: "timestamptz",
219
- primaryKey: false,
220
- nullable: false,
221
- unique: false,
222
- defaultExpr: "now()"
223
- }
224
- ]);
225
- const [previewSql, setPreviewSql] = useState(null);
226
- const [creating, setCreating] = useState(false);
227
- const [addColOpen, setAddColOpen] = useState(false);
228
- const [newCol, setNewCol] = useState({
229
- name: "",
230
- type: "text",
231
- primaryKey: false,
232
- nullable: true,
233
- unique: false,
234
- defaultExpr: ""
235
- });
236
- const [addingCol, setAddingCol] = useState(false);
237
- const [addIdxOpen, setAddIdxOpen] = useState(false);
238
- const [newIdxColumns, setNewIdxColumns] = useState("");
239
- const [newIdxUnique, setNewIdxUnique] = useState(false);
240
- const [addingIdx, setAddingIdx] = useState(false);
241
- const [dropOpen, setDropOpen] = useState(false);
242
- const [dropConfirm, setDropConfirm] = useState("");
243
- const [dropping, setDropping] = useState(false);
244
- const [metaSlug, setMetaSlug] = useState("");
245
- const [metaDescription, setMetaDescription] = useState("");
246
- const [metaExposed, setMetaExposed] = useState(true);
247
- const [metaSoftDelete, setMetaSoftDelete] = useState(false);
248
- const [metaHistory, setMetaHistory] = useState(false);
249
- const [metaReadOnly, setMetaReadOnly] = useState(false);
250
- const [savingMeta, setSavingMeta] = useState(false);
251
- /** Reads the tables again; resolves to the list read, or `null` when the read failed. */
252
- const loadTables = useCallback(async () => {
253
- setLoading(true);
254
- setError(null);
255
- try {
256
- const list = parseTablesResponse(await requestJson("/admin/db/tables"));
257
- setTables(list);
258
- setSelectedName((prev) => {
259
- if (prev && list.some((t) => t.name === prev)) return prev;
260
- return list[0]?.name ?? null;
261
- });
262
- return list;
263
- } catch (err) {
264
- setError(err instanceof Error ? err.message : t("studio_tables_load_failed"));
265
- return null;
266
- } finally {
267
- setLoading(false);
268
- }
269
- }, [requestJson, t]);
270
- /**
271
- * What a change that should leave `name` served actually left: served, or
272
- * created but not served and why — never "live" because the request
273
- * succeeded.
274
- */
275
- const reportServed = useCallback((list, name, done) => {
276
- const table = list?.find((candidate) => candidate.name === name);
277
- if (!table) snackbar.open({
278
- type: "success",
279
- message: `${done}.`
280
- });
281
- else if (table.served) snackbar.open({
282
- type: "success",
283
- message: t("studio_tables_done_served", {
284
- done,
285
- path: `/api/data/${table.slug}`
286
- })
287
- });
288
- else snackbar.open({
289
- type: "warning",
290
- message: t("studio_tables_done_not_served", {
291
- done,
292
- reason: t(notServedReasonKey(table))
293
- })
294
- });
295
- }, [snackbar, t]);
296
- useEffect(() => {
297
- loadTables();
298
- }, [loadTables]);
299
- const selectedTable = useMemo(() => tables.find((t) => t.name === selectedName) ?? null, [tables, selectedName]);
300
- const filteredTables = useMemo(() => {
301
- const q = search.trim().toLowerCase();
302
- if (!q) return tables;
303
- return tables.filter((t) => t.name.toLowerCase().includes(q) || t.slug.toLowerCase().includes(q));
304
- }, [tables, search]);
305
- useEffect(() => {
306
- if (!selectedTable) return;
307
- setMetaSlug(selectedTable.meta?.slug ?? selectedTable.slug);
308
- setMetaDescription(selectedTable.meta?.description ?? "");
309
- setMetaExposed(selectedTable.meta?.exposed ?? selectedTable.exposed);
310
- setMetaSoftDelete(selectedTable.meta?.softDelete ?? false);
311
- setMetaHistory(selectedTable.meta?.history ?? false);
312
- setMetaReadOnly(selectedTable.meta?.readOnly ?? false);
313
- }, [selectedTable]);
314
- const loadRows = useCallback(async (table) => {
315
- if (!table.served) {
316
- setLoadedRows({
317
- table: table.name,
318
- rows: []
319
- });
320
- setRowsError(null);
321
- return;
322
- }
323
- setRowsLoading(true);
324
- setRowsError(null);
325
- try {
326
- const raw = await requestJson(`/data/${encodeURIComponent(table.slug)}?limit=100`);
327
- setLoadedRows({
328
- table: table.name,
329
- rows: isRecord(raw) && Array.isArray(raw.data) ? raw.data.filter(isRecord) : []
330
- });
331
- } catch (err) {
332
- setLoadedRows({
333
- table: table.name,
334
- rows: []
335
- });
336
- setRowsError(err instanceof Error ? err : new Error(t("studio_tables_rows_load_failed")));
337
- } finally {
338
- setRowsLoading(false);
339
- }
340
- }, [requestJson, t]);
341
- const rows = loadedRows !== null && loadedRows.table === selectedName ? loadedRows.rows : NO_ROWS;
342
- useEffect(() => {
343
- if (selectedTable && activeTab === "data") loadRows(selectedTable);
344
- }, [
345
- selectedTable,
346
- activeTab,
347
- loadRows
348
- ]);
349
- const pkColumn = useMemo(() => selectedTable?.columns.find((c) => c.primaryKey)?.key ?? selectedTable?.columns.find((c) => c.primaryKey)?.name ?? "id", [selectedTable]);
350
- const handleReloadSchema = async () => {
351
- try {
352
- const res = await requestJson("/admin/schema/reload", { method: "POST" });
353
- const count = isRecord(res) ? asNumber(res.tables, 0) : 0;
354
- snackbar.open({
355
- type: "success",
356
- message: t("studio_tables_schema_reloaded", { count })
357
- });
358
- await loadTables();
359
- } catch (err) {
360
- snackbar.open({
361
- type: "error",
362
- message: err instanceof Error ? err.message : t("studio_tables_schema_reload_failed")
363
- });
364
- }
365
- };
366
- const buildCreatePayload = (dryRun) => {
367
- const columns = draftColumns.filter((c) => c.name.trim() !== "").map((c) => ({
368
- name: c.name.trim(),
369
- type: c.type,
370
- primaryKey: c.primaryKey,
371
- nullable: c.nullable,
372
- unique: c.unique,
373
- ...c.defaultExpr.trim() ? { default: c.defaultExpr.trim() } : {}
374
- }));
375
- const policies = [];
376
- if (newTableRls === "authenticated") policies.push({
377
- name: "authenticated_all",
378
- operation: "ALL",
379
- using: SIGNED_IN_SQL,
380
- withCheck: SIGNED_IN_SQL
381
- });
382
- else if (newTableRls === "public-read") {
383
- policies.push({
384
- name: "public_read",
385
- operation: "SELECT",
386
- using: "true"
387
- });
388
- policies.push({
389
- name: "authenticated_write",
390
- operation: "ALL",
391
- using: SIGNED_IN_SQL,
392
- withCheck: SIGNED_IN_SQL
393
- });
394
- } else if (newTableRls === "owner") policies.push({
395
- name: "owner_all",
396
- operation: "ALL",
397
- using: OWNS_ROW_BY_USER_ID_SQL,
398
- withCheck: OWNS_ROW_BY_USER_ID_SQL
399
- });
400
- return {
401
- name: newTableName.trim(),
402
- columns,
403
- enableRls: true,
404
- policies,
405
- dryRun
406
- };
407
- };
408
- const handlePreviewCreate = async () => {
409
- try {
410
- const raw = await requestJson("/admin/db/tables", {
411
- method: "POST",
412
- body: buildCreatePayload(true)
413
- });
414
- const sql = isRecord(raw) ? asStringArray(raw.statements ?? raw.sql) : [];
415
- setPreviewSql(sql);
416
- } catch (err) {
417
- snackbar.open({
418
- type: "error",
419
- message: err instanceof Error ? err.message : t("studio_tables_sql_preview_failed")
420
- });
421
- }
422
- };
423
- const handleCreateTable = async () => {
424
- setCreating(true);
425
- try {
426
- const createdName = newTableName.trim();
427
- await requestJson("/admin/db/tables", {
428
- method: "POST",
429
- body: buildCreatePayload(false)
430
- });
431
- setCreateOpen(false);
432
- setNewTableName("");
433
- setPreviewSql(null);
434
- reportServed(await loadTables(), createdName, t("studio_tables_table_created", { name: createdName }));
435
- setSelectedName(createdName);
436
- } catch (err) {
437
- snackbar.open({
438
- type: "error",
439
- message: err instanceof Error ? err.message : t("studio_tables_create_failed")
440
- });
441
- } finally {
442
- setCreating(false);
443
- }
444
- };
445
- const handleAddColumn = async () => {
446
- if (!selectedTable || !newCol.name.trim()) return;
447
- setAddingCol(true);
448
- try {
449
- await requestJson(`/admin/db/tables/${encodeURIComponent(selectedTable.name)}/columns`, {
450
- method: "POST",
451
- body: {
452
- name: newCol.name.trim(),
453
- type: newCol.type,
454
- nullable: newCol.nullable,
455
- unique: newCol.unique,
456
- ...newCol.defaultExpr.trim() ? { default: newCol.defaultExpr.trim() } : {}
457
- }
458
- });
459
- snackbar.open({
460
- type: "success",
461
- message: t("studio_tables_column_added", { name: newCol.name.trim() })
462
- });
463
- setAddColOpen(false);
464
- setNewCol({
465
- name: "",
466
- type: "text",
467
- primaryKey: false,
468
- nullable: true,
469
- unique: false,
470
- defaultExpr: ""
471
- });
472
- await loadTables();
473
- } catch (err) {
474
- snackbar.open({
475
- type: "error",
476
- message: err instanceof Error ? err.message : t("studio_tables_column_add_failed")
477
- });
478
- } finally {
479
- setAddingCol(false);
480
- }
481
- };
482
- const handleDropColumn = async (colName) => {
483
- if (!selectedTable) return;
484
- try {
485
- await requestJson(`/admin/db/tables/${encodeURIComponent(selectedTable.name)}/columns/${encodeURIComponent(colName)}`, {
486
- method: "DELETE",
487
- body: { confirm: colName }
488
- });
489
- snackbar.open({
490
- type: "success",
491
- message: t("studio_tables_column_dropped", { name: colName })
492
- });
493
- await loadTables();
494
- } catch (err) {
495
- snackbar.open({
496
- type: "error",
497
- message: err instanceof Error ? err.message : t("studio_tables_column_drop_failed")
498
- });
499
- }
500
- };
501
- const handleAddIndex = async () => {
502
- if (!selectedTable) return;
503
- const cols = newIdxColumns.split(",").map((s) => s.trim()).filter(Boolean);
504
- if (cols.length === 0) return;
505
- setAddingIdx(true);
506
- try {
507
- await requestJson(`/admin/db/tables/${encodeURIComponent(selectedTable.name)}/indexes`, {
508
- method: "POST",
509
- body: {
510
- columns: cols,
511
- unique: newIdxUnique
512
- }
513
- });
514
- snackbar.open({
515
- type: "success",
516
- message: t("studio_tables_index_created")
517
- });
518
- setAddIdxOpen(false);
519
- setNewIdxColumns("");
520
- setNewIdxUnique(false);
521
- await loadTables();
522
- } catch (err) {
523
- snackbar.open({
524
- type: "error",
525
- message: err instanceof Error ? err.message : t("studio_tables_index_create_failed")
526
- });
527
- } finally {
528
- setAddingIdx(false);
529
- }
530
- };
531
- const handleDropIndex = async (indexName) => {
532
- if (!selectedTable) return;
533
- try {
534
- await requestJson(`/admin/db/tables/${encodeURIComponent(selectedTable.name)}/indexes/${encodeURIComponent(indexName)}`, { method: "DELETE" });
535
- snackbar.open({
536
- type: "success",
537
- message: t("studio_tables_index_dropped", { name: indexName })
538
- });
539
- await loadTables();
540
- } catch (err) {
541
- snackbar.open({
542
- type: "error",
543
- message: err instanceof Error ? err.message : t("studio_tables_index_drop_failed")
544
- });
545
- }
546
- };
547
- const handleToggleRls = async (enabled) => {
548
- if (!selectedTable) return;
549
- try {
550
- await requestJson(`/admin/db/tables/${encodeURIComponent(selectedTable.name)}`, {
551
- method: "PATCH",
552
- body: { rlsEnabled: enabled }
553
- });
554
- snackbar.open({
555
- type: "success",
556
- message: t(enabled ? "studio_tables_rls_enabled_on" : "studio_tables_rls_disabled_on", { name: selectedTable.name })
557
- });
558
- await loadTables();
559
- } catch (err) {
560
- snackbar.open({
561
- type: "error",
562
- message: err instanceof Error ? err.message : t("studio_tables_rls_update_failed")
563
- });
564
- }
565
- };
566
- const handleEnableAndExpose = async () => {
567
- if (!selectedTable) return;
568
- try {
569
- await requestJson(`/admin/db/tables/${encodeURIComponent(selectedTable.name)}`, {
570
- method: "PATCH",
571
- body: {
572
- rlsEnabled: true,
573
- meta: { exposed: true }
574
- }
575
- });
576
- if (selectedTable.policies.length === 0) await requestJson(`/admin/db/tables/${encodeURIComponent(selectedTable.name)}/policies`, {
577
- method: "POST",
578
- body: {
579
- name: "authenticated_all",
580
- operation: "ALL",
581
- using: SIGNED_IN_SQL,
582
- withCheck: SIGNED_IN_SQL
583
- }
584
- });
585
- reportServed(await loadTables(), selectedTable.name, t("studio_tables_protected_and_exposed", { name: selectedTable.name }));
586
- } catch (err) {
587
- snackbar.open({
588
- type: "error",
589
- message: err instanceof Error ? err.message : t("studio_tables_expose_failed")
590
- });
591
- }
592
- };
593
- const handleSaveMeta = async () => {
594
- if (!selectedTable) return;
595
- setSavingMeta(true);
596
- try {
597
- const nonPkCols = selectedTable.columns.filter((c) => !c.primaryKey).map((c) => c.name);
598
- await requestJson(`/admin/db/tables/${encodeURIComponent(selectedTable.name)}`, {
599
- method: "PATCH",
600
- body: { meta: {
601
- slug: metaSlug.trim() || null,
602
- description: metaDescription.trim() || null,
603
- exposed: metaExposed,
604
- softDeleteColumn: metaSoftDelete ? selectedTable.meta?.softDeleteColumn ?? "deleted_at" : null,
605
- historyEnabled: metaHistory,
606
- readonlyColumns: metaReadOnly ? nonPkCols : []
607
- } }
608
- });
609
- snackbar.open({
610
- type: "success",
611
- message: t("studio_tables_meta_saved")
612
- });
613
- await loadTables();
614
- } catch (err) {
615
- snackbar.open({
616
- type: "error",
617
- message: err instanceof Error ? err.message : t("studio_tables_meta_save_failed")
618
- });
619
- } finally {
620
- setSavingMeta(false);
621
- }
622
- };
623
- const handleDropTable = async () => {
624
- if (!selectedTable || dropConfirm !== selectedTable.name) return;
625
- setDropping(true);
626
- try {
627
- await requestJson(`/admin/db/tables/${encodeURIComponent(selectedTable.name)}`, {
628
- method: "DELETE",
629
- body: { confirm: dropConfirm }
630
- });
631
- snackbar.open({
632
- type: "success",
633
- message: t("studio_tables_table_dropped", { name: selectedTable.name })
634
- });
635
- setDropOpen(false);
636
- setDropConfirm("");
637
- await loadTables();
638
- } catch (err) {
639
- snackbar.open({
640
- type: "error",
641
- message: err instanceof Error ? err.message : t("studio_tables_drop_failed")
642
- });
643
- } finally {
644
- setDropping(false);
645
- }
646
- };
647
- const openAddRow = () => {
648
- if (!selectedTable) return;
649
- const initial = {};
650
- for (const col of selectedTable.columns) {
651
- if (col.defaultExpr) continue;
652
- initial[col.name] = "";
653
- }
654
- setEditingRowId(null);
655
- setRowForm(initial);
656
- setRowDialogOpen(true);
657
- };
658
- const openEditRow = useCallback((row) => {
659
- if (!selectedTable) return;
660
- const idVal = row[pkColumn];
661
- if (idVal === void 0 || idVal === null) return;
662
- const initial = {};
663
- for (const col of selectedTable.columns) {
664
- const v = row[col.key] !== void 0 ? row[col.key] : row[col.name];
665
- initial[col.name] = v === null || v === void 0 ? "" : typeof v === "object" ? JSON.stringify(v) : String(v);
666
- }
667
- setEditingRowId(String(idVal));
668
- setRowForm(initial);
669
- setRowDialogOpen(true);
670
- }, [selectedTable, pkColumn]);
671
- const handleSaveRow = async () => {
672
- if (!selectedTable) return;
673
- setRowSaving(true);
674
- try {
675
- const payload = {};
676
- for (const col of selectedTable.columns) {
677
- const rawVal = rowForm[col.name];
678
- if (rawVal === void 0) continue;
679
- if (!editingRowId && col.defaultExpr && rawVal.trim() === "") continue;
680
- if (editingRowId && col.primaryKey) continue;
681
- payload[col.key] = parseCellInput(rawVal, col);
682
- }
683
- if (editingRowId) {
684
- await requestJson(`/data/${encodeURIComponent(selectedTable.slug)}/${encodeURIComponent(editingRowId)}`, {
685
- method: "PATCH",
686
- body: payload
687
- });
688
- snackbar.open({
689
- type: "success",
690
- message: t("studio_tables_row_updated")
691
- });
692
- } else {
693
- await requestJson(`/data/${encodeURIComponent(selectedTable.slug)}`, {
694
- method: "POST",
695
- body: payload
696
- });
697
- snackbar.open({
698
- type: "success",
699
- message: t("studio_tables_row_inserted")
700
- });
701
- }
702
- setRowDialogOpen(false);
703
- await loadRows(selectedTable);
704
- } catch (err) {
705
- snackbar.open({
706
- type: "error",
707
- message: err instanceof Error ? err.message : t("studio_tables_row_save_failed")
708
- });
709
- } finally {
710
- setRowSaving(false);
711
- }
712
- };
713
- const handleDeleteRow = useCallback(async (row) => {
714
- if (!selectedTable) return;
715
- const idVal = row[pkColumn];
716
- if (idVal === void 0 || idVal === null) return;
717
- try {
718
- await requestJson(`/data/${encodeURIComponent(selectedTable.slug)}/${encodeURIComponent(String(idVal))}`, { method: "DELETE" });
719
- snackbar.open({
720
- type: "success",
721
- message: t("studio_tables_row_deleted")
722
- });
723
- await loadRows(selectedTable);
724
- } catch (err) {
725
- snackbar.open({
726
- type: "error",
727
- message: err instanceof Error ? err.message : t("studio_tables_row_delete_failed")
728
- });
729
- }
730
- }, [
731
- selectedTable,
732
- pkColumn,
733
- requestJson,
734
- snackbar,
735
- loadRows,
736
- t
737
- ]);
738
- /**
739
- * The cell being edited in place, as in the SQL editor's result grid: the
740
- * table and row it is in, and the text its box opened with — what closing
741
- * the box unchanged is compared against.
742
- */
743
- const [editingCell, setEditingCell] = useState(null);
744
- const handleCellDoubleClick = useCallback((rowIndex, columnKey, rowData) => {
745
- if (!selectedTable) return;
746
- const col = selectedTable.columns.find((c) => c.key === columnKey);
747
- if (!col) return;
748
- if (col.primaryKey) {
749
- snackbar.open({
750
- type: "error",
751
- message: t("studio_tables_pk_not_editable", { name: col.name })
752
- });
753
- return;
754
- }
755
- const idVal = rowData[pkColumn];
756
- if (idVal === void 0 || idVal === null) {
757
- snackbar.open({
758
- type: "error",
759
- message: t("studio_tables_row_no_pk", { name: pkColumn })
760
- });
761
- return;
762
- }
763
- setEditingCell({
764
- table: selectedTable.name,
765
- rowIndex,
766
- columnKey,
767
- initialValue: cellEditText(rowData[columnKey])
768
- });
769
- }, [
770
- selectedTable,
771
- pkColumn,
772
- snackbar,
773
- t
774
- ]);
775
- const handleCellSave = useCallback(async (text, rowData, columnKey, rowIndex) => {
776
- const editing = editingCell;
777
- setEditingCell(null);
778
- if (!selectedTable || !editing || text === editing.initialValue) return;
779
- const col = selectedTable.columns.find((c) => c.key === columnKey);
780
- const idVal = rowData[pkColumn];
781
- if (!col || idVal === void 0 || idVal === null) return;
782
- const value = parseCellInput(text, col);
783
- const table = selectedTable;
784
- try {
785
- const saved = await requestJson(`/data/${encodeURIComponent(table.slug)}/${encodeURIComponent(String(idVal))}`, {
786
- method: "PATCH",
787
- body: { [columnKey]: value }
788
- });
789
- const row = isRecord(saved) && saved[pkColumn] === idVal ? saved : {
790
- ...rowData,
791
- [columnKey]: value
792
- };
793
- setLoadedRows((prev) => {
794
- if (!prev || prev.table !== table.name || prev.rows[rowIndex]?.[pkColumn] !== idVal) return prev;
795
- const next = [...prev.rows];
796
- next[rowIndex] = row;
797
- return {
798
- ...prev,
799
- rows: next
800
- };
801
- });
802
- snackbar.open({
803
- type: "success",
804
- message: t("studio_tables_row_updated")
805
- });
806
- } catch (err) {
807
- snackbar.open({
808
- type: "error",
809
- message: err instanceof Error ? err.message : t("studio_tables_row_save_failed")
810
- });
811
- }
812
- }, [
813
- editingCell,
814
- selectedTable,
815
- pkColumn,
816
- requestJson,
817
- snackbar,
818
- t
819
- ]);
820
- const rowColumns = useMemo(() => selectedTable ? [{
821
- key: ROW_ACTIONS_COLUMN,
822
- title: "",
823
- width: 76,
824
- sortable: false,
825
- resizable: false
826
- }, ...selectedTable.columns.map((col) => ({
827
- key: col.key,
828
- title: col.name,
829
- width: rowColumnWidth(col),
830
- sortable: false,
831
- resizable: true
832
- }))] : [], [selectedTable]);
833
- const monoColumnKeys = useMemo(() => {
834
- const keys = /* @__PURE__ */ new Set();
835
- for (const col of selectedTable?.columns ?? []) {
836
- const udt = col.udtName.toLowerCase();
837
- if (col.primaryKey || udt.includes("uuid") || udt.includes("json") || udt.includes("time") || udt.includes("date") || udt.includes("int") || udt.includes("float") || udt === "numeric") keys.add(col.key);
838
- }
839
- return keys;
840
- }, [selectedTable]);
841
- const renderRowCell = useCallback(({ rowData, column, rowIndex }) => {
842
- if (!rowData) return null;
843
- if (column.key === ROW_ACTIONS_COLUMN) return /* @__PURE__ */ jsxs("div", {
844
- className: "h-full flex items-center justify-center gap-0.5",
845
- children: [/* @__PURE__ */ jsx(Tooltip, {
846
- title: t("studio_tables_edit_row"),
847
- children: /* @__PURE__ */ jsx(IconButton, {
848
- size: "small",
849
- "aria-label": t("studio_tables_edit_row"),
850
- className: ROW_ACTION_ICON,
851
- onClick: () => openEditRow(rowData),
852
- children: /* @__PURE__ */ jsx(PencilIcon, { size: iconSize.smallest })
853
- })
854
- }), /* @__PURE__ */ jsx(Tooltip, {
855
- title: t("delete_row"),
856
- children: /* @__PURE__ */ jsx(IconButton, {
857
- size: "small",
858
- "aria-label": t("delete_row"),
859
- className: ROW_ACTION_ICON,
860
- onClick: () => void handleDeleteRow(rowData),
861
- children: /* @__PURE__ */ jsx(Trash2Icon, { size: iconSize.smallest })
862
- })
863
- })]
864
- });
865
- const value = rowData[column.key];
866
- if (editingCell !== null && editingCell.table === selectedName && editingCell.rowIndex === rowIndex && editingCell.columnKey === column.key) return /* @__PURE__ */ jsx(FixedEditorOverlay, {
867
- displayValue: editingCell.initialValue,
868
- onSave: (val) => void handleCellSave(val, rowData, column.key, rowIndex),
869
- onCancel: () => setEditingCell(null)
870
- });
871
- const display = formatCellValue(value);
872
- const isMono = monoColumnKeys.has(String(column.key));
873
- return /* @__PURE__ */ jsx("div", {
874
- className: "px-3 h-full flex items-center whitespace-nowrap min-w-0 cursor-text",
875
- title: display,
876
- onDoubleClick: () => handleCellDoubleClick(rowIndex, column.key, rowData),
877
- children: value === null || value === void 0 ? /* @__PURE__ */ jsx(Typography, {
878
- variant: "caption",
879
- color: "disabled",
880
- className: "italic",
881
- children: "NULL"
882
- }) : isMono ? /* @__PURE__ */ jsx(Typography, {
883
- variant: "mono",
884
- className: "truncate text-xs text-text-secondary dark:text-text-secondary-dark",
885
- children: display
886
- }) : /* @__PURE__ */ jsx(Typography, {
887
- variant: "body2",
888
- className: "truncate text-[13px]",
889
- children: display
890
- })
891
- });
892
- }, [
893
- openEditRow,
894
- handleDeleteRow,
895
- monoColumnKeys,
896
- t,
897
- editingCell,
898
- selectedName,
899
- handleCellSave,
900
- handleCellDoubleClick
901
- ]);
902
- return /* @__PURE__ */ jsxs("div", {
903
- className: "flex h-full w-full overflow-hidden bg-surface-card",
904
- children: [
905
- /* @__PURE__ */ jsxs("aside", {
906
- className: cls("w-60 shrink-0 flex flex-col border-r bg-surface-card", defaultBorderMixin),
907
- children: [
908
- /* @__PURE__ */ jsxs("div", {
909
- className: cls("h-[42px] px-3 border-b bg-surface-sheet flex items-center justify-between gap-2 shrink-0", defaultBorderMixin),
910
- children: [/* @__PURE__ */ jsxs("div", {
911
- className: "flex items-center gap-2 min-w-0",
912
- children: [/* @__PURE__ */ jsx(DatabaseIcon, {
913
- size: iconSize.smallest,
914
- className: "text-text-secondary dark:text-text-secondary-dark shrink-0"
915
- }), /* @__PURE__ */ jsx(Typography, {
916
- variant: "caption",
917
- className: "font-semibold uppercase tracking-wider text-text-disabled dark:text-text-disabled-dark truncate",
918
- children: t("studio_tool_tables")
919
- })]
920
- }), /* @__PURE__ */ jsxs("div", {
921
- className: "flex items-center gap-1",
922
- children: [/* @__PURE__ */ jsx(Tooltip, {
923
- title: t("studio_tables_reload_schema"),
924
- children: /* @__PURE__ */ jsx(IconButton, {
925
- size: "small",
926
- "aria-label": t("studio_tables_reload_schema"),
927
- onClick: handleReloadSchema,
928
- children: /* @__PURE__ */ jsx(RefreshCwIcon, { size: iconSize.smallest })
929
- })
930
- }), /* @__PURE__ */ jsxs(Button, {
931
- size: "small",
932
- color: "primary",
933
- variant: "filled",
934
- onClick: () => setCreateOpen(true),
935
- children: [/* @__PURE__ */ jsx(PlusIcon, { size: iconSize.smallest }), t("studio_api_keys_new")]
936
- })]
937
- })]
938
- }),
939
- /* @__PURE__ */ jsx("div", {
940
- className: "p-2",
941
- children: /* @__PURE__ */ jsx(SearchBar, {
942
- size: "small",
943
- onTextSearch: (v) => setSearch(v ?? ""),
944
- placeholder: t("studio_tables_filter_placeholder"),
945
- innerClassName: "w-full"
946
- })
947
- }),
948
- /* @__PURE__ */ jsx("div", {
949
- className: "flex-1 overflow-y-auto px-2 pb-3 flex flex-col gap-0.5",
950
- children: loading ? /* @__PURE__ */ jsx("div", {
951
- className: "flex items-center justify-center py-8",
952
- children: /* @__PURE__ */ jsx(CircularProgress, { size: "small" })
953
- }) : filteredTables.length === 0 ? /* @__PURE__ */ jsxs("div", {
954
- className: "px-3 py-6 text-center flex flex-col items-center gap-2",
955
- children: [/* @__PURE__ */ jsx(Typography, {
956
- variant: "body2",
957
- color: "secondary",
958
- children: tables.length === 0 ? t("studio_tables_empty") : t("studio_tables_no_match")
959
- }), tables.length === 0 && /* @__PURE__ */ jsxs(Button, {
960
- size: "small",
961
- variant: "outlined",
962
- onClick: () => setCreateOpen(true),
963
- children: [/* @__PURE__ */ jsx(PlusIcon, { size: iconSize.small }), t("studio_tables_create_first")]
964
- })]
965
- }) : filteredTables.map((table) => {
966
- return /* @__PURE__ */ jsxs("button", {
967
- type: "button",
968
- onClick: () => setSelectedName(table.name),
969
- 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.name === selectedName ? "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"),
970
- children: [/* @__PURE__ */ jsx("span", {
971
- className: "truncate text-[13px]",
972
- children: table.name
973
- }), /* @__PURE__ */ jsx("div", {
974
- className: "flex items-center gap-1 shrink-0",
975
- children: table.served ? /* @__PURE__ */ jsx(Tooltip, {
976
- title: t("studio_tables_served_tooltip"),
977
- children: /* @__PURE__ */ jsx(CheckCircleIcon, { className: "w-3.5 h-3.5 text-emerald-500/80" })
978
- }) : /* @__PURE__ */ jsx(Tooltip, {
979
- title: t("studio_tables_not_exposed_tooltip"),
980
- children: /* @__PURE__ */ jsx(AlertCircleIcon, { className: "w-3.5 h-3.5 text-amber-500/80" })
981
- })
982
- })]
983
- }, `${table.schema}.${table.name}`);
984
- })
985
- })
986
- ]
987
- }),
988
- /* @__PURE__ */ jsxs("main", {
989
- className: "flex-1 flex flex-col min-w-0 overflow-hidden",
990
- children: [error && /* @__PURE__ */ jsx("div", {
991
- className: "p-4",
992
- children: /* @__PURE__ */ jsx(Alert, {
993
- color: "error",
994
- children: error
995
- })
996
- }), !selectedTable ? /* @__PURE__ */ jsxs("div", {
997
- className: "flex-1 flex flex-col items-center justify-center p-8 text-center gap-4",
998
- children: [
999
- /* @__PURE__ */ jsx(DatabaseIcon, { className: "w-10 h-10 text-text-disabled" }),
1000
- /* @__PURE__ */ jsxs("div", {
1001
- className: "max-w-md flex flex-col gap-1",
1002
- children: [/* @__PURE__ */ jsx(Typography, {
1003
- variant: "h6",
1004
- children: t("studio_tables_intro_title")
1005
- }), /* @__PURE__ */ jsx(Typography, {
1006
- variant: "body2",
1007
- color: "secondary",
1008
- children: t("studio_tables_intro_body")
1009
- })]
1010
- }),
1011
- /* @__PURE__ */ jsxs(Button, {
1012
- variant: "filled",
1013
- onClick: () => setCreateOpen(true),
1014
- children: [/* @__PURE__ */ jsx(PlusIcon, { size: iconSize.small }), t("studio_tables_new_table")]
1015
- })
1016
- ]
1017
- }) : /* @__PURE__ */ jsxs(Fragment, { children: [
1018
- /* @__PURE__ */ jsxs("div", {
1019
- className: cls("h-[42px] px-4 border-b flex items-center justify-between gap-4 bg-surface-sheet shrink-0", defaultBorderMixin),
1020
- children: [/* @__PURE__ */ jsxs("div", {
1021
- className: "flex items-center gap-2.5 min-w-0",
1022
- children: [
1023
- /* @__PURE__ */ jsxs(Typography, {
1024
- variant: "subtitle2",
1025
- className: "font-mono font-semibold truncate",
1026
- children: [
1027
- selectedTable.schema,
1028
- ".",
1029
- selectedTable.name
1030
- ]
1031
- }),
1032
- /* @__PURE__ */ jsx(Chip, {
1033
- size: "smallest",
1034
- colorScheme: selectedTable.served ? "greenLight" : "orangeLight",
1035
- children: selectedTable.served ? `/api/data/${selectedTable.slug}` : t("studio_tables_not_exposed")
1036
- }),
1037
- /* @__PURE__ */ jsx(Chip, {
1038
- size: "smallest",
1039
- colorScheme: selectedTable.rlsEnabled ? "blueLight" : "grayLight",
1040
- children: selectedTable.rlsEnabled ? `RLS (${selectedTable.policies.length})` : t("studio_tables_rls_off")
1041
- })
1042
- ]
1043
- }), /* @__PURE__ */ jsxs("div", {
1044
- className: "flex items-center gap-2 shrink-0",
1045
- children: [
1046
- !selectedTable.served && /* @__PURE__ */ jsxs(Button, {
1047
- size: "small",
1048
- color: "primary",
1049
- variant: "filled",
1050
- onClick: handleEnableAndExpose,
1051
- children: [/* @__PURE__ */ jsx(ShieldIcon, { size: iconSize.smallest }), t("studio_tables_enable_and_expose")]
1052
- }),
1053
- activeTab === "data" && selectedTable.served && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(IconButton, {
1054
- size: "small",
1055
- "aria-label": t("studio_tables_refresh_rows"),
1056
- onClick: () => void loadRows(selectedTable),
1057
- children: /* @__PURE__ */ jsx(RefreshCwIcon, { size: iconSize.smallest })
1058
- }), /* @__PURE__ */ jsxs(Button, {
1059
- size: "small",
1060
- color: "primary",
1061
- variant: "filled",
1062
- onClick: openAddRow,
1063
- children: [/* @__PURE__ */ jsx(PlusIcon, { size: iconSize.smallest }), t("studio_tables_add_row")]
1064
- })] }),
1065
- activeTab === "columns" && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(Button, {
1066
- size: "small",
1067
- variant: "outlined",
1068
- onClick: () => setAddIdxOpen(true),
1069
- children: [/* @__PURE__ */ jsx(PlusIcon, { size: iconSize.smallest }), t("studio_tables_add_index")]
1070
- }), /* @__PURE__ */ jsxs(Button, {
1071
- size: "small",
1072
- color: "primary",
1073
- variant: "filled",
1074
- onClick: () => setAddColOpen(true),
1075
- children: [/* @__PURE__ */ jsx(PlusIcon, { size: iconSize.smallest }), t("studio_tables_add_column")]
1076
- })] })
1077
- ]
1078
- })]
1079
- }),
1080
- /* @__PURE__ */ jsxs(Tabs, {
1081
- value: activeTab,
1082
- onValueChange: (v) => {
1083
- if (v === "data" || v === "columns" || v === "settings") setActiveTab(v);
1084
- },
1085
- variant: "boxy",
1086
- className: "border-b border-hairline px-4 bg-surface-sheet shrink-0",
1087
- children: [
1088
- /* @__PURE__ */ jsx(Tab, {
1089
- value: "data",
1090
- children: t("studio_tables_tab_data", { count: rows.length })
1091
- }),
1092
- /* @__PURE__ */ jsx(Tab, {
1093
- value: "columns",
1094
- children: t("studio_tables_tab_columns", { count: selectedTable.columns.length })
1095
- }),
1096
- /* @__PURE__ */ jsx(Tab, {
1097
- value: "settings",
1098
- children: t("settings_heading")
1099
- })
1100
- ]
1101
- }),
1102
- activeTab === "data" && (selectedTable.served ? /* @__PURE__ */ jsx("div", {
1103
- className: "flex-1 relative min-h-0 min-w-0",
1104
- children: /* @__PURE__ */ jsx(VirtualTable, {
1105
- data: rows,
1106
- columns: rowColumns,
1107
- rowHeight: 32,
1108
- headerHeight: 32,
1109
- loading: rowsLoading,
1110
- error: rowsError ?? void 0,
1111
- extraData: editingCell,
1112
- cellRenderer: renderRowCell,
1113
- emptyComponent: /* @__PURE__ */ jsxs("div", {
1114
- className: "flex flex-col items-center gap-3 text-center",
1115
- children: [/* @__PURE__ */ jsx(Typography, {
1116
- variant: "body2",
1117
- color: "secondary",
1118
- children: t("studio_tables_no_rows", { name: selectedTable.name })
1119
- }), /* @__PURE__ */ jsxs(Button, {
1120
- size: "small",
1121
- variant: "filled",
1122
- onClick: openAddRow,
1123
- children: [/* @__PURE__ */ jsx(PlusIcon, { size: iconSize.small }), t("studio_tables_insert_first_row")]
1124
- })]
1125
- })
1126
- })
1127
- }) : /* @__PURE__ */ jsx("div", {
1128
- className: "flex-1 overflow-auto p-5",
1129
- children: /* @__PURE__ */ jsx(Alert, {
1130
- color: "warning",
1131
- children: /* @__PURE__ */ jsxs("div", {
1132
- className: "flex items-center justify-between gap-4",
1133
- children: [/* @__PURE__ */ jsx("span", { children: t("studio_tables_not_served", { reason: t(notServedReasonKey(selectedTable)) }) }), /* @__PURE__ */ jsx(Button, {
1134
- size: "small",
1135
- variant: "filled",
1136
- onClick: handleEnableAndExpose,
1137
- children: t("studio_tables_enable_and_expose")
1138
- })]
1139
- })
1140
- })
1141
- })),
1142
- activeTab !== "data" && /* @__PURE__ */ jsxs("div", {
1143
- className: "flex-1 overflow-auto p-5",
1144
- children: [activeTab === "columns" && /* @__PURE__ */ jsxs("div", {
1145
- className: "flex flex-col gap-6",
1146
- children: [/* @__PURE__ */ jsxs("div", {
1147
- className: "flex flex-col gap-2",
1148
- children: [/* @__PURE__ */ jsx(Typography, {
1149
- variant: "subtitle2",
1150
- children: t("studio_columns")
1151
- }), /* @__PURE__ */ jsx("div", {
1152
- className: cls("overflow-x-auto rounded-lg border", defaultBorderMixin),
1153
- children: /* @__PURE__ */ jsxs(Table, {
1154
- className: "w-full",
1155
- children: [/* @__PURE__ */ jsxs(TableHeader, { children: [
1156
- /* @__PURE__ */ jsx(TableCell, {
1157
- header: true,
1158
- children: t("studio_branch_diff_object_column")
1159
- }),
1160
- /* @__PURE__ */ jsx(TableCell, {
1161
- header: true,
1162
- children: t("type")
1163
- }),
1164
- /* @__PURE__ */ jsx(TableCell, {
1165
- header: true,
1166
- children: t("studio_tables_constraints")
1167
- }),
1168
- /* @__PURE__ */ jsx(TableCell, {
1169
- header: true,
1170
- children: t("studio_tables_default")
1171
- }),
1172
- /* @__PURE__ */ jsx(TableCell, {
1173
- header: true,
1174
- className: "text-right",
1175
- children: t("actions")
1176
- })
1177
- ] }), /* @__PURE__ */ jsx(TableBody, { children: selectedTable.columns.map((col) => /* @__PURE__ */ jsxs(TableRow, { children: [
1178
- /* @__PURE__ */ jsx(TableCell, {
1179
- className: "font-mono text-sm font-medium",
1180
- children: col.name
1181
- }),
1182
- /* @__PURE__ */ jsx(TableCell, {
1183
- className: "font-mono text-xs text-text-secondary",
1184
- children: col.dataType
1185
- }),
1186
- /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsxs("div", {
1187
- className: "flex items-center gap-1.5 flex-wrap",
1188
- children: [
1189
- col.primaryKey && /* @__PURE__ */ jsx(Chip, {
1190
- size: "small",
1191
- colorScheme: "blueLight",
1192
- children: "PK"
1193
- }),
1194
- !col.nullable && /* @__PURE__ */ jsx(Chip, {
1195
- size: "small",
1196
- colorScheme: "grayLight",
1197
- children: "NOT NULL"
1198
- }),
1199
- col.unique && !col.primaryKey && /* @__PURE__ */ jsx(Chip, {
1200
- size: "small",
1201
- colorScheme: "purpleLight",
1202
- children: "UNIQUE"
1203
- })
1204
- ]
1205
- }) }),
1206
- /* @__PURE__ */ jsx(TableCell, {
1207
- className: "font-mono text-xs text-text-secondary",
1208
- children: col.defaultExpr ?? "—"
1209
- }),
1210
- /* @__PURE__ */ jsx(TableCell, {
1211
- className: "text-right",
1212
- children: !col.primaryKey && /* @__PURE__ */ jsx(Tooltip, {
1213
- title: t("studio_tables_drop_column", { name: col.name }),
1214
- children: /* @__PURE__ */ jsx(IconButton, {
1215
- size: "small",
1216
- "aria-label": t("studio_tables_drop_column", { name: col.name }),
1217
- onClick: () => void handleDropColumn(col.name),
1218
- children: /* @__PURE__ */ jsx(Trash2Icon, {
1219
- size: iconSize.small,
1220
- className: "text-red-500"
1221
- })
1222
- })
1223
- })
1224
- })
1225
- ] }, col.name)) })]
1226
- })
1227
- })]
1228
- }), /* @__PURE__ */ jsxs("div", {
1229
- className: "flex flex-col gap-2",
1230
- children: [/* @__PURE__ */ jsx(Typography, {
1231
- variant: "subtitle2",
1232
- children: t("studio_tables_indexes_heading", { count: selectedTable.indexes.length })
1233
- }), /* @__PURE__ */ jsx("div", {
1234
- className: cls("overflow-x-auto rounded-lg border", defaultBorderMixin),
1235
- children: /* @__PURE__ */ jsxs(Table, {
1236
- className: "w-full",
1237
- children: [/* @__PURE__ */ jsxs(TableHeader, { children: [
1238
- /* @__PURE__ */ jsx(TableCell, {
1239
- header: true,
1240
- children: t("name")
1241
- }),
1242
- /* @__PURE__ */ jsx(TableCell, {
1243
- header: true,
1244
- children: t("studio_tables_definition")
1245
- }),
1246
- /* @__PURE__ */ jsx(TableCell, {
1247
- header: true,
1248
- className: "text-right",
1249
- children: t("actions")
1250
- })
1251
- ] }), /* @__PURE__ */ jsx(TableBody, { children: selectedTable.indexes.map((idx) => /* @__PURE__ */ jsxs(TableRow, { children: [
1252
- /* @__PURE__ */ jsx(TableCell, {
1253
- className: "font-mono text-xs whitespace-nowrap",
1254
- children: /* @__PURE__ */ jsxs("div", {
1255
- className: "flex items-center gap-1.5",
1256
- children: [
1257
- /* @__PURE__ */ jsx("span", { children: idx.name }),
1258
- idx.primary && /* @__PURE__ */ jsx(Chip, {
1259
- size: "small",
1260
- colorScheme: "blueLight",
1261
- children: "PK"
1262
- }),
1263
- idx.unique && !idx.primary && /* @__PURE__ */ jsx(Chip, {
1264
- size: "small",
1265
- colorScheme: "purpleLight",
1266
- children: "UNIQUE"
1267
- })
1268
- ]
1269
- })
1270
- }),
1271
- /* @__PURE__ */ jsx(TableCell, {
1272
- className: "font-mono text-xs text-text-secondary",
1273
- children: idx.definition
1274
- }),
1275
- /* @__PURE__ */ jsx(TableCell, {
1276
- className: "text-right",
1277
- children: !idx.primary && /* @__PURE__ */ jsx(IconButton, {
1278
- size: "small",
1279
- "aria-label": t("studio_tables_drop_index", { name: idx.name }),
1280
- onClick: () => void handleDropIndex(idx.name),
1281
- children: /* @__PURE__ */ jsx(Trash2Icon, {
1282
- size: iconSize.small,
1283
- className: "text-red-500"
1284
- })
1285
- })
1286
- })
1287
- ] }, idx.name)) })]
1288
- })
1289
- })]
1290
- })]
1291
- }), activeTab === "settings" && /* @__PURE__ */ jsxs("div", {
1292
- className: "max-w-2xl flex flex-col gap-5",
1293
- children: [/* @__PURE__ */ jsxs(Card, {
1294
- className: "p-4 flex flex-col gap-4",
1295
- children: [
1296
- /* @__PURE__ */ jsx(Typography, {
1297
- variant: "subtitle1",
1298
- children: t("studio_tables_meta_heading")
1299
- }),
1300
- /* @__PURE__ */ jsx(TextField, {
1301
- label: t("studio_tables_slug_label"),
1302
- value: metaSlug,
1303
- onChange: (e) => setMetaSlug(e.target.value),
1304
- placeholder: selectedTable.name
1305
- }),
1306
- /* @__PURE__ */ jsx(TextField, {
1307
- label: t("description"),
1308
- value: metaDescription,
1309
- onChange: (e) => setMetaDescription(e.target.value),
1310
- placeholder: t("studio_tables_description_placeholder")
1311
- }),
1312
- /* @__PURE__ */ jsx(BooleanSwitchWithLabel, {
1313
- label: t("studio_tables_expose_label"),
1314
- value: metaExposed,
1315
- onValueChange: setMetaExposed
1316
- }),
1317
- /* @__PURE__ */ jsx(BooleanSwitchWithLabel, {
1318
- label: t("studio_tables_enable_rls_label"),
1319
- value: selectedTable.rlsEnabled,
1320
- onValueChange: (v) => void handleToggleRls(v)
1321
- }),
1322
- /* @__PURE__ */ jsx(BooleanSwitchWithLabel, {
1323
- label: t("studio_tables_read_only_label"),
1324
- value: metaReadOnly,
1325
- onValueChange: setMetaReadOnly
1326
- }),
1327
- /* @__PURE__ */ jsx(BooleanSwitchWithLabel, {
1328
- label: t("studio_tables_soft_delete_label"),
1329
- value: metaSoftDelete,
1330
- onValueChange: setMetaSoftDelete
1331
- }),
1332
- /* @__PURE__ */ jsx(BooleanSwitchWithLabel, {
1333
- label: t("studio_tables_history_label"),
1334
- value: metaHistory,
1335
- onValueChange: setMetaHistory
1336
- }),
1337
- /* @__PURE__ */ jsx("div", {
1338
- className: "flex justify-end",
1339
- children: /* @__PURE__ */ jsx(Button, {
1340
- variant: "filled",
1341
- disabled: savingMeta,
1342
- onClick: () => void handleSaveMeta(),
1343
- children: savingMeta ? t("saving") : t("studio_tables_save_settings")
1344
- })
1345
- })
1346
- ]
1347
- }), /* @__PURE__ */ jsxs(Card, {
1348
- className: "p-4 border border-red-500/30 flex items-center justify-between gap-4",
1349
- children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx(Typography, {
1350
- variant: "subtitle2",
1351
- className: "text-red-500",
1352
- children: t("studio_tables_danger_zone")
1353
- }), /* @__PURE__ */ jsx(Typography, {
1354
- variant: "body2",
1355
- color: "secondary",
1356
- children: t("studio_tables_drop_description", { name: selectedTable.name })
1357
- })] }), /* @__PURE__ */ jsx(Button, {
1358
- variant: "outlined",
1359
- color: "error",
1360
- onClick: () => setDropOpen(true),
1361
- children: t("studio_tables_drop_table")
1362
- })]
1363
- })]
1364
- })]
1365
- })
1366
- ] })]
1367
- }),
1368
- /* @__PURE__ */ jsxs(Dialog, {
1369
- open: createOpen,
1370
- onOpenChange: setCreateOpen,
1371
- maxWidth: "2xl",
1372
- fullWidth: true,
1373
- children: [
1374
- /* @__PURE__ */ jsx(DialogTitle, { children: t("studio_tables_create_table") }),
1375
- /* @__PURE__ */ jsxs(DialogContent, {
1376
- className: "flex flex-col gap-4",
1377
- children: [
1378
- /* @__PURE__ */ jsxs("div", {
1379
- className: "grid grid-cols-1 md:grid-cols-2 gap-3",
1380
- children: [/* @__PURE__ */ jsx(TextField, {
1381
- label: t("studio_tables_name_label"),
1382
- value: newTableName,
1383
- onChange: (e) => setNewTableName(e.target.value),
1384
- placeholder: "projects"
1385
- }), /* @__PURE__ */ jsx(Select, {
1386
- label: t("studio_tables_initial_rls"),
1387
- value: newTableRls,
1388
- onValueChange: (v) => setNewTableRls(String(v)),
1389
- children: RLS_PRESETS.map((p) => /* @__PURE__ */ jsx(SelectItem, {
1390
- value: p.value,
1391
- children: t(p.labelKey)
1392
- }, p.value))
1393
- })]
1394
- }),
1395
- /* @__PURE__ */ jsxs("div", {
1396
- className: "flex flex-col gap-2",
1397
- children: [/* @__PURE__ */ jsxs("div", {
1398
- className: "flex items-center justify-between",
1399
- children: [/* @__PURE__ */ jsx(Typography, {
1400
- variant: "subtitle2",
1401
- children: t("studio_columns")
1402
- }), /* @__PURE__ */ jsxs(Button, {
1403
- size: "small",
1404
- variant: "outlined",
1405
- onClick: () => setDraftColumns((cols) => [...cols, {
1406
- name: "",
1407
- type: "text",
1408
- primaryKey: false,
1409
- nullable: true,
1410
- unique: false,
1411
- defaultExpr: ""
1412
- }]),
1413
- children: [/* @__PURE__ */ jsx(PlusIcon, { size: iconSize.small }), t("studio_tables_add_column")]
1414
- })]
1415
- }), /* @__PURE__ */ jsx("div", {
1416
- className: "flex flex-col gap-2 max-h-64 overflow-y-auto pr-1",
1417
- children: draftColumns.map((col, idx) => /* @__PURE__ */ jsxs("div", {
1418
- className: cls("grid grid-cols-12 gap-2 items-center p-2 rounded-md border", defaultBorderMixin),
1419
- children: [
1420
- /* @__PURE__ */ jsx("div", {
1421
- className: "col-span-3",
1422
- children: /* @__PURE__ */ jsx(TextField, {
1423
- size: "small",
1424
- placeholder: "column_name",
1425
- value: col.name,
1426
- onChange: (e) => setDraftColumns((prev) => prev.map((c, i) => i === idx ? {
1427
- ...c,
1428
- name: e.target.value
1429
- } : c))
1430
- })
1431
- }),
1432
- /* @__PURE__ */ jsx("div", {
1433
- className: "col-span-3",
1434
- children: /* @__PURE__ */ jsx(Select, {
1435
- size: "small",
1436
- value: col.type,
1437
- onValueChange: (v) => setDraftColumns((prev) => prev.map((c, i) => i === idx ? {
1438
- ...c,
1439
- type: String(v)
1440
- } : c)),
1441
- children: SQL_TYPES.map((t) => /* @__PURE__ */ jsx(SelectItem, {
1442
- value: t,
1443
- children: t
1444
- }, t))
1445
- })
1446
- }),
1447
- /* @__PURE__ */ jsx("div", {
1448
- className: "col-span-3",
1449
- children: /* @__PURE__ */ jsx(TextField, {
1450
- size: "small",
1451
- placeholder: t("studio_tables_default_optional_placeholder"),
1452
- value: col.defaultExpr,
1453
- onChange: (e) => setDraftColumns((prev) => prev.map((c, i) => i === idx ? {
1454
- ...c,
1455
- defaultExpr: e.target.value
1456
- } : c))
1457
- })
1458
- }),
1459
- /* @__PURE__ */ jsxs("div", {
1460
- className: "col-span-2 flex items-center gap-1",
1461
- children: [/* @__PURE__ */ jsx(Chip, {
1462
- size: "small",
1463
- colorScheme: col.primaryKey ? "blueLight" : "grayLight",
1464
- onClick: () => setDraftColumns((prev) => prev.map((c, i) => i === idx ? {
1465
- ...c,
1466
- primaryKey: !c.primaryKey,
1467
- nullable: !c.primaryKey ? false : c.nullable
1468
- } : c)),
1469
- children: "PK"
1470
- }), /* @__PURE__ */ jsx(Chip, {
1471
- size: "small",
1472
- colorScheme: !col.nullable ? "orangeLight" : "grayLight",
1473
- onClick: () => setDraftColumns((prev) => prev.map((c, i) => i === idx ? {
1474
- ...c,
1475
- nullable: !c.nullable
1476
- } : c)),
1477
- children: "NN"
1478
- })]
1479
- }),
1480
- /* @__PURE__ */ jsx("div", {
1481
- className: "col-span-1 flex justify-end",
1482
- children: /* @__PURE__ */ jsx(IconButton, {
1483
- size: "small",
1484
- "aria-label": t("studio_tables_remove_draft_column"),
1485
- onClick: () => setDraftColumns((prev) => prev.filter((_, i) => i !== idx)),
1486
- children: /* @__PURE__ */ jsx(Trash2Icon, { size: iconSize.small })
1487
- })
1488
- })
1489
- ]
1490
- }, idx))
1491
- })]
1492
- }),
1493
- previewSql && previewSql.length > 0 && /* @__PURE__ */ jsx("div", {
1494
- className: cls("rounded-md border p-3 bg-surface-frame font-mono text-xs overflow-x-auto whitespace-pre-wrap", defaultBorderMixin),
1495
- children: previewSql.join("\n")
1496
- })
1497
- ]
1498
- }),
1499
- /* @__PURE__ */ jsxs(DialogActions, { children: [
1500
- /* @__PURE__ */ jsx(Button, {
1501
- variant: "text",
1502
- onClick: () => setCreateOpen(false),
1503
- children: t("cancel")
1504
- }),
1505
- /* @__PURE__ */ jsx(Button, {
1506
- variant: "outlined",
1507
- disabled: !newTableName.trim(),
1508
- onClick: () => void handlePreviewCreate(),
1509
- children: t("studio_tables_preview_sql")
1510
- }),
1511
- /* @__PURE__ */ jsx(Button, {
1512
- variant: "filled",
1513
- disabled: creating || !newTableName.trim(),
1514
- onClick: () => void handleCreateTable(),
1515
- children: creating ? t("studio_tables_creating") : t("studio_tables_create_table")
1516
- })
1517
- ] })
1518
- ]
1519
- }),
1520
- /* @__PURE__ */ jsxs(Dialog, {
1521
- open: addColOpen,
1522
- onOpenChange: setAddColOpen,
1523
- maxWidth: "md",
1524
- fullWidth: true,
1525
- children: [
1526
- /* @__PURE__ */ jsx(DialogTitle, { children: t("studio_tables_add_column_to", { name: selectedTable?.name ?? "" }) }),
1527
- /* @__PURE__ */ jsxs(DialogContent, {
1528
- className: "flex flex-col gap-3",
1529
- children: [
1530
- /* @__PURE__ */ jsx(TextField, {
1531
- label: t("studio_tables_column_name"),
1532
- value: newCol.name,
1533
- onChange: (e) => setNewCol((c) => ({
1534
- ...c,
1535
- name: e.target.value
1536
- })),
1537
- placeholder: "status"
1538
- }),
1539
- /* @__PURE__ */ jsx(Select, {
1540
- label: t("studio_tables_sql_type"),
1541
- value: newCol.type,
1542
- onValueChange: (v) => setNewCol((c) => ({
1543
- ...c,
1544
- type: String(v)
1545
- })),
1546
- children: SQL_TYPES.map((t) => /* @__PURE__ */ jsx(SelectItem, {
1547
- value: t,
1548
- children: t
1549
- }, t))
1550
- }),
1551
- /* @__PURE__ */ jsx(TextField, {
1552
- label: t("studio_tables_default_expr"),
1553
- value: newCol.defaultExpr,
1554
- onChange: (e) => setNewCol((c) => ({
1555
- ...c,
1556
- defaultExpr: e.target.value
1557
- })),
1558
- placeholder: "'draft'"
1559
- }),
1560
- /* @__PURE__ */ jsx(BooleanSwitchWithLabel, {
1561
- label: t("studio_tables_nullable"),
1562
- value: newCol.nullable,
1563
- onValueChange: (v) => setNewCol((c) => ({
1564
- ...c,
1565
- nullable: v
1566
- }))
1567
- }),
1568
- /* @__PURE__ */ jsx(BooleanSwitchWithLabel, {
1569
- label: t("unique"),
1570
- value: newCol.unique,
1571
- onValueChange: (v) => setNewCol((c) => ({
1572
- ...c,
1573
- unique: v
1574
- }))
1575
- })
1576
- ]
1577
- }),
1578
- /* @__PURE__ */ jsxs(DialogActions, { children: [/* @__PURE__ */ jsx(Button, {
1579
- variant: "text",
1580
- onClick: () => setAddColOpen(false),
1581
- children: t("cancel")
1582
- }), /* @__PURE__ */ jsx(Button, {
1583
- variant: "filled",
1584
- disabled: addingCol || !newCol.name.trim(),
1585
- onClick: () => void handleAddColumn(),
1586
- children: addingCol ? t("studio_tables_adding") : t("studio_tables_add_column")
1587
- })] })
1588
- ]
1589
- }),
1590
- /* @__PURE__ */ jsxs(Dialog, {
1591
- open: addIdxOpen,
1592
- onOpenChange: setAddIdxOpen,
1593
- maxWidth: "md",
1594
- fullWidth: true,
1595
- children: [
1596
- /* @__PURE__ */ jsx(DialogTitle, { children: t("studio_tables_create_index_on", { name: selectedTable?.name ?? "" }) }),
1597
- /* @__PURE__ */ jsxs(DialogContent, {
1598
- className: "flex flex-col gap-3",
1599
- children: [/* @__PURE__ */ jsx(TextField, {
1600
- label: t("studio_tables_index_columns"),
1601
- value: newIdxColumns,
1602
- onChange: (e) => setNewIdxColumns(e.target.value),
1603
- placeholder: "user_id, created_at"
1604
- }), /* @__PURE__ */ jsx(BooleanSwitchWithLabel, {
1605
- label: t("studio_tables_unique_index"),
1606
- value: newIdxUnique,
1607
- onValueChange: setNewIdxUnique
1608
- })]
1609
- }),
1610
- /* @__PURE__ */ jsxs(DialogActions, { children: [/* @__PURE__ */ jsx(Button, {
1611
- variant: "text",
1612
- onClick: () => setAddIdxOpen(false),
1613
- children: t("cancel")
1614
- }), /* @__PURE__ */ jsx(Button, {
1615
- variant: "filled",
1616
- disabled: addingIdx || !newIdxColumns.trim(),
1617
- onClick: () => void handleAddIndex(),
1618
- children: addingIdx ? t("studio_tables_creating") : t("create_index")
1619
- })] })
1620
- ]
1621
- }),
1622
- /* @__PURE__ */ jsxs(Dialog, {
1623
- open: rowDialogOpen,
1624
- onOpenChange: setRowDialogOpen,
1625
- maxWidth: "lg",
1626
- fullWidth: true,
1627
- children: [
1628
- /* @__PURE__ */ jsx(DialogTitle, { children: editingRowId ? t("studio_tables_edit_row_title", { id: editingRowId }) : t("studio_tables_insert_row_into", { name: selectedTable?.name ?? "" }) }),
1629
- /* @__PURE__ */ jsx(DialogContent, {
1630
- className: "flex flex-col gap-3 max-h-[60vh] overflow-y-auto",
1631
- children: selectedTable?.columns.map((col) => /* @__PURE__ */ jsx(TextField, {
1632
- label: col.nullable ? `${col.name} (${col.dataType})` : t("studio_tables_field_required", {
1633
- name: col.name,
1634
- type: col.dataType
1635
- }),
1636
- value: rowForm[col.name] ?? "",
1637
- disabled: Boolean(editingRowId && col.primaryKey),
1638
- placeholder: col.defaultExpr ? t("studio_tables_default_placeholder", { value: col.defaultExpr }) : "",
1639
- onChange: (e) => setRowForm((prev) => ({
1640
- ...prev,
1641
- [col.name]: e.target.value
1642
- }))
1643
- }, col.name))
1644
- }),
1645
- /* @__PURE__ */ jsxs(DialogActions, { children: [/* @__PURE__ */ jsx(Button, {
1646
- variant: "text",
1647
- onClick: () => setRowDialogOpen(false),
1648
- children: t("cancel")
1649
- }), /* @__PURE__ */ jsx(Button, {
1650
- variant: "filled",
1651
- disabled: rowSaving,
1652
- onClick: () => void handleSaveRow(),
1653
- children: rowSaving ? t("saving") : editingRowId ? t("studio_save_changes") : t("studio_tables_insert_row")
1654
- })] })
1655
- ]
1656
- }),
1657
- /* @__PURE__ */ jsxs(Dialog, {
1658
- open: dropOpen,
1659
- onOpenChange: setDropOpen,
1660
- maxWidth: "sm",
1661
- fullWidth: true,
1662
- children: [
1663
- /* @__PURE__ */ jsx(DialogTitle, { children: t("studio_tables_drop_table") }),
1664
- /* @__PURE__ */ jsxs(DialogContent, {
1665
- className: "flex flex-col gap-3",
1666
- children: [/* @__PURE__ */ jsx(Alert, {
1667
- color: "error",
1668
- children: t("studio_tables_drop_warning", { name: selectedTable?.name ?? "" })
1669
- }), /* @__PURE__ */ jsx(TextField, {
1670
- label: t("studio_tables_drop_confirm_label", { name: selectedTable?.name ?? "" }),
1671
- value: dropConfirm,
1672
- onChange: (e) => setDropConfirm(e.target.value)
1673
- })]
1674
- }),
1675
- /* @__PURE__ */ jsxs(DialogActions, { children: [/* @__PURE__ */ jsx(Button, {
1676
- variant: "text",
1677
- onClick: () => setDropOpen(false),
1678
- children: t("cancel")
1679
- }), /* @__PURE__ */ jsx(Button, {
1680
- variant: "filled",
1681
- color: "error",
1682
- disabled: dropping || dropConfirm !== selectedTable?.name,
1683
- onClick: () => void handleDropTable(),
1684
- children: dropping ? t("studio_tables_dropping") : t("studio_tables_drop_table")
1685
- })] })
1686
- ]
1687
- })
1688
- ]
1689
- });
1690
- }
1691
- //#endregion
1692
- export { TableEditorView };
1693
-
1694
- //# sourceMappingURL=TableEditorView-BKhSBG-K.js.map