@rebasepro/studio 0.23.0 → 0.24.1-canary.g56af4a4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{ApiExplorer-pYMZflL3.js → ApiExplorer-Bzt7Ye49.js} +18 -29
- package/dist/ApiExplorer-Bzt7Ye49.js.map +1 -0
- package/dist/ApiKeysView-Bqf6XYR1.js +1739 -0
- package/dist/ApiKeysView-Bqf6XYR1.js.map +1 -0
- package/dist/BackupsView-BhOHB6iP.js +354 -0
- package/dist/BackupsView-BhOHB6iP.js.map +1 -0
- package/dist/{BranchesView-D6Sz1a5f.js → BranchesView-BHfwGTYc.js} +16 -10
- package/dist/BranchesView-BHfwGTYc.js.map +1 -0
- package/dist/{CronJobsView-7hjgSYId.js → CronJobsView-CMNK7eWO.js} +175 -116
- package/dist/CronJobsView-CMNK7eWO.js.map +1 -0
- package/dist/{JSEditor-qiuwmcvk.js → JSEditor-DIO2Mw8q.js} +230 -165
- package/dist/JSEditor-DIO2Mw8q.js.map +1 -0
- package/dist/{LogsExplorer-Xq8K4oo6.js → LogsExplorer-C-bwDFIl.js} +66 -44
- package/dist/LogsExplorer-C-bwDFIl.js.map +1 -0
- package/dist/{RLSEditor-Djh43lBE.js → RLSEditor-jFD_d06f.js} +246 -84
- package/dist/RLSEditor-jFD_d06f.js.map +1 -0
- package/dist/{SQLEditor-TBw_K6CW.js → SQLEditor-D5Ci4pyW.js} +502 -600
- package/dist/SQLEditor-D5Ci4pyW.js.map +1 -0
- package/dist/{SchemaVisualizer-DtDzIUNy.js → SchemaVisualizer-D-rAqwul.js} +496 -227
- package/dist/SchemaVisualizer-D-rAqwul.js.map +1 -0
- package/dist/{StorageView-CMG1DOVX.js → StorageView-CPkDKbsX.js} +838 -451
- package/dist/StorageView-CPkDKbsX.js.map +1 -0
- package/dist/assets/dagre-layout.worker-BFnhAzuR.js.map +1 -0
- package/dist/components/ApiExplorer/TryItPanel.d.ts +6 -1
- package/dist/components/ApiKeys/CreateApiKeyDialog.d.ts +21 -2
- package/dist/components/ApiKeys/scope-words.d.ts +37 -0
- package/dist/components/ApiKeys/scopes.d.ts +113 -0
- package/dist/components/AuthSimulationSelector.d.ts +5 -1
- package/dist/components/LogsExplorer/useLogTail.d.ts +9 -0
- package/dist/components/RLSEditor/policyListing.d.ts +44 -0
- package/dist/components/SQLEditor/SQLEditor.d.ts +11 -0
- package/dist/components/SchemaVisualizer/dagre-layout.d.ts +32 -0
- package/dist/components/SchemaVisualizer/dagre-layout.worker.d.ts +13 -0
- package/dist/components/SchemaVisualizer/layout-runner.d.ts +23 -0
- package/dist/components/SchemaVisualizer/schema-visualizer.utils.d.ts +21 -11
- package/dist/components/SchemaVisualizer/useSchemaGraph.d.ts +44 -1
- package/dist/components/StorageView/useVisibleFileMetadata.d.ts +46 -0
- package/dist/components/load-failure.d.ts +1 -1
- package/dist/components/useRunAsUsers.d.ts +25 -0
- package/dist/dagre-layout.worker-j9NbH9Gb.js +27 -0
- package/dist/dagre-layout.worker-j9NbH9Gb.js.map +1 -0
- package/dist/index.es.js +16 -14
- package/dist/index.es.js.map +1 -1
- package/dist/{load-failure-C6OMJSGC.js → load-failure-Bd8lFIO7.js} +2 -2
- package/dist/load-failure-Bd8lFIO7.js.map +1 -0
- package/dist/sql_utils-BZD31xE3.js +478 -0
- package/dist/sql_utils-BZD31xE3.js.map +1 -0
- package/dist/useRunAsUsers-CLaAtXt6.js +122 -0
- package/dist/useRunAsUsers-CLaAtXt6.js.map +1 -0
- package/dist/utils/sql_utils.d.ts +150 -49
- package/package.json +9 -9
- package/dist/ApiExplorer-pYMZflL3.js.map +0 -1
- package/dist/ApiKeysView-qLSs47tw.js +0 -1239
- package/dist/ApiKeysView-qLSs47tw.js.map +0 -1
- package/dist/AuthSimulationSelector-BewmhMBw.js +0 -56
- package/dist/AuthSimulationSelector-BewmhMBw.js.map +0 -1
- package/dist/BackupsView-DYTAD6aW.js +0 -253
- package/dist/BackupsView-DYTAD6aW.js.map +0 -1
- package/dist/BranchesView-D6Sz1a5f.js.map +0 -1
- package/dist/CronJobsView-7hjgSYId.js.map +0 -1
- package/dist/JSEditor-qiuwmcvk.js.map +0 -1
- package/dist/LogsExplorer-Xq8K4oo6.js.map +0 -1
- package/dist/RLSEditor-Djh43lBE.js.map +0 -1
- package/dist/SQLEditor-TBw_K6CW.js.map +0 -1
- package/dist/SchemaVisualizer-DtDzIUNy.js.map +0 -1
- package/dist/StorageView-CMG1DOVX.js.map +0 -1
- package/dist/components/ApiKeys/permissions.d.ts +0 -66
- package/dist/load-failure-C6OMJSGC.js.map +0 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { a as needsDestructiveConfirmation, c as rememberColumnWidth, d as resultsToCsv, i as keepLatestColumnWidths, l as resolveCellEdit, m as withAutoLimit, n as formatSql, o as quoteIdentifier, p as typedJsonRows, r as groupSchemaRows, s as quoteTableName, t as buildExplainSql, u as resolveQueryCollections } from "./sql_utils-BZD31xE3.js";
|
|
1
2
|
import { t as MonacoEditor } from "./MonacoEditor-CUxy5_k5.js";
|
|
2
|
-
import { ConfirmationDialog, ErrorView, IconForView, useRebaseContext, useSnackbarController, useStudioCollectionRegistry, useStudioSidePanelController, useTranslation } from "@rebasepro/app";
|
|
3
|
+
import { ConfirmationDialog, ErrorView, IconForView, useApiBase, useApiConfig, useRebaseContext, useSnackbarController, useStudioCollectionRegistry, useStudioSidePanelController, useTranslation } from "@rebasepro/app";
|
|
3
4
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
4
|
-
import { Button, Checkbox, CircularProgress, Collapse, CopyIcon, DatabaseIcon, Dialog, DialogActions, DialogContent, DialogTitle, IconButton, Menu, MenuIcon, MenuItem, MoreVerticalIcon, PencilIcon, PlayIcon, PlusIcon, RefreshCwIcon, ResizablePanels, Tab, Tabs, TerminalIcon, TextField, TextareaAutosize, Tooltip, Trash2Icon, Typography, VirtualTable, XIcon, cls, defaultBorderMixin, iconSize } from "@rebasepro/ui";
|
|
5
|
+
import { Alert, Button, Checkbox, Chip, CircularProgress, Collapse, CopyIcon, DatabaseIcon, Dialog, DialogActions, DialogContent, DialogTitle, HeartIcon, IconButton, Menu, MenuIcon, MenuItem, MoreVerticalIcon, PencilIcon, PlayIcon, PlusIcon, RefreshCwIcon, ResizablePanels, SquareIcon, Tab, Tabs, TerminalIcon, TextField, TextareaAutosize, Tooltip, Trash2Icon, Typography, VirtualTable, XIcon, cls, defaultBorderMixin, iconSize, isKeyHandled } from "@rebasepro/ui";
|
|
5
6
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
import { isArrayValue, isRecordValue, readStoredJson, readStoredString,
|
|
7
|
+
import { isArrayValue, isRecordValue, readStoredJson, readStoredString, writeStoredJson, writeStoredString } from "@rebasepro/utils";
|
|
7
8
|
import { createPortal } from "react-dom";
|
|
8
|
-
import { parse, parseFirst } from "pgsql-ast-parser";
|
|
9
9
|
//#region src/components/SQLEditor/SchemaBrowser.tsx
|
|
10
10
|
var SchemaBrowser = ({ onTableClick, schemas, isSchemaLoading, schemaError, onRetrySchema }) => {
|
|
11
11
|
const [expandedSchemas, setExpandedSchemas] = useState({ public: true });
|
|
@@ -31,9 +31,10 @@ var SchemaBrowser = ({ onTableClick, schemas, isSchemaLoading, schemaError, onRe
|
|
|
31
31
|
className: "font-semibold uppercase tracking-wider text-text-disabled dark:text-text-disabled-dark",
|
|
32
32
|
children: t("studio_schema_tables")
|
|
33
33
|
}), /* @__PURE__ */ jsx(IconButton, {
|
|
34
|
+
"aria-label": t("refresh"),
|
|
34
35
|
size: "small",
|
|
35
36
|
onClick: onRetrySchema,
|
|
36
|
-
title: "
|
|
37
|
+
title: t("refresh"),
|
|
37
38
|
children: /* @__PURE__ */ jsx(RefreshCwIcon, { size: iconSize.smallest })
|
|
38
39
|
})]
|
|
39
40
|
}), /* @__PURE__ */ jsx("div", {
|
|
@@ -99,19 +100,21 @@ var SchemaBrowser = ({ onTableClick, schemas, isSchemaLoading, schemaError, onRe
|
|
|
99
100
|
className: "flex opacity-0 group-hover:opacity-100 focus-within:opacity-100 absolute right-1 items-center bg-surface-raised px-1 gap-1 rounded transition-opacity",
|
|
100
101
|
children: [
|
|
101
102
|
/* @__PURE__ */ jsx(IconButton, {
|
|
103
|
+
"aria-label": t("copy_table_name"),
|
|
102
104
|
size: "small",
|
|
103
105
|
onClick: (e) => {
|
|
104
106
|
e.stopPropagation();
|
|
105
107
|
navigator.clipboard.writeText(table.tableName);
|
|
106
108
|
},
|
|
107
|
-
title: "
|
|
109
|
+
title: t("copy_table_name"),
|
|
108
110
|
children: /* @__PURE__ */ jsx(CopyIcon, { size: iconSize.small })
|
|
109
111
|
}),
|
|
110
112
|
/* @__PURE__ */ jsxs(Menu, {
|
|
111
113
|
trigger: /* @__PURE__ */ jsx(IconButton, {
|
|
114
|
+
"aria-label": t("generate_sql_templates"),
|
|
112
115
|
size: "small",
|
|
113
116
|
onClick: (e) => e.stopPropagation(),
|
|
114
|
-
title: "
|
|
117
|
+
title: t("generate_sql_templates"),
|
|
115
118
|
children: /* @__PURE__ */ jsx(MoreVerticalIcon, { size: iconSize.small })
|
|
116
119
|
}),
|
|
117
120
|
children: [
|
|
@@ -195,13 +198,14 @@ var SchemaBrowser = ({ onTableClick, schemas, isSchemaLoading, schemaError, onRe
|
|
|
195
198
|
children: col.dataType
|
|
196
199
|
}),
|
|
197
200
|
/* @__PURE__ */ jsx(IconButton, {
|
|
201
|
+
"aria-label": t("copy_column_name"),
|
|
198
202
|
size: "smallest",
|
|
199
203
|
className: "opacity-0 group-hover:opacity-100 absolute right-1 bg-surface-sheet transition-colors pointer-events-auto",
|
|
200
204
|
onClick: (e) => {
|
|
201
205
|
e.stopPropagation();
|
|
202
206
|
navigator.clipboard.writeText(col.name);
|
|
203
207
|
},
|
|
204
|
-
title: "
|
|
208
|
+
title: t("copy_column_name"),
|
|
205
209
|
children: /* @__PURE__ */ jsx(CopyIcon, { size: iconSize.smallest })
|
|
206
210
|
})
|
|
207
211
|
]
|
|
@@ -301,6 +305,7 @@ var SQLEditorSidebar = ({ onSelectSnippet, onTableClick, snippets, history, onDe
|
|
|
301
305
|
children: snippet.sql
|
|
302
306
|
}),
|
|
303
307
|
/* @__PURE__ */ jsx(IconButton, {
|
|
308
|
+
"aria-label": t("studio_sql_sidebar_delete_snippet"),
|
|
304
309
|
size: "smallest",
|
|
305
310
|
className: "absolute right-1 top-1 opacity-0 group-hover:opacity-100 text-text-disabled hover:text-red-500 transition-opacity",
|
|
306
311
|
onClick: (e) => {
|
|
@@ -333,6 +338,7 @@ var SQLEditorSidebar = ({ onSelectSnippet, onTableClick, snippets, history, onDe
|
|
|
333
338
|
children: snippet.sql
|
|
334
339
|
}),
|
|
335
340
|
/* @__PURE__ */ jsx(IconButton, {
|
|
341
|
+
"aria-label": t("studio_sql_sidebar_delete_snippet"),
|
|
336
342
|
size: "smallest",
|
|
337
343
|
className: "absolute right-1 top-1 opacity-0 group-hover:opacity-100 text-text-disabled hover:text-red-500 transition-opacity",
|
|
338
344
|
onClick: (e) => {
|
|
@@ -392,322 +398,6 @@ var SQLEditorSidebar = ({ onSelectSnippet, onTableClick, snippets, history, onDe
|
|
|
392
398
|
});
|
|
393
399
|
};
|
|
394
400
|
//#endregion
|
|
395
|
-
//#region src/utils/sql_utils.ts
|
|
396
|
-
/** The statements in `sqlText`, or `null` when the parser cannot read it. */
|
|
397
|
-
function parseStatements(sqlText) {
|
|
398
|
-
try {
|
|
399
|
-
return parse(sqlText);
|
|
400
|
-
} catch {
|
|
401
|
-
return null;
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
/**
|
|
405
|
-
* The `EXPLAIN` for one statement, or `null` when `sqlText` is not exactly one.
|
|
406
|
-
*
|
|
407
|
-
* Never `ANALYZE`: that executes the statement to time it, so explaining a
|
|
408
|
-
* `DELETE` deleted the rows — without the confirmation "Run" asks for.
|
|
409
|
-
*
|
|
410
|
-
* And never more than one statement. Sent as one simple query, `EXPLAIN (…)
|
|
411
|
-
* SELECT 1; DELETE …` explains the SELECT and *runs* the DELETE. Text the
|
|
412
|
-
* parser cannot read is still explained, as long as no `;` could be hiding a
|
|
413
|
-
* second statement in it.
|
|
414
|
-
*/
|
|
415
|
-
function buildExplainSql(sqlText) {
|
|
416
|
-
const statement = sqlText.trim().replace(/;+$/, "").trim();
|
|
417
|
-
if (!statement) return null;
|
|
418
|
-
const statements = parseStatements(statement);
|
|
419
|
-
return (statements ? statements.length === 1 : !statement.includes(";")) ? `EXPLAIN (FORMAT JSON) ${statement}` : null;
|
|
420
|
-
}
|
|
421
|
-
/**
|
|
422
|
-
* Whether the console's automatic `LIMIT` may be appended to `sqlText`: one
|
|
423
|
-
* top-level SELECT that has no limit of its own.
|
|
424
|
-
*
|
|
425
|
-
* Decided on the parsed statement, not the text. A search for the word SELECT
|
|
426
|
-
* also found it inside `INSERT INTO … SELECT` and `CREATE TABLE … AS SELECT`,
|
|
427
|
-
* which then copied a thousand rows and reported success, and at the start of
|
|
428
|
-
* a script whose last statement the appended `LIMIT` turned into a syntax
|
|
429
|
-
* error. Text the parser cannot read is left as written.
|
|
430
|
-
*/
|
|
431
|
-
function acceptsAutoLimit(sqlText) {
|
|
432
|
-
const statements = parseStatements(sqlText);
|
|
433
|
-
if (!statements || statements.length !== 1) return false;
|
|
434
|
-
const [statement] = statements;
|
|
435
|
-
return statement.type === "select" && !statement.limit;
|
|
436
|
-
}
|
|
437
|
-
/** A destructive command named anywhere in a text, comments included. */
|
|
438
|
-
var DESTRUCTIVE_COMMAND = /\b(DELETE|UPDATE|DROP|TRUNCATE)\b/i;
|
|
439
|
-
function isDestructiveStatement(statement) {
|
|
440
|
-
switch (statement.type) {
|
|
441
|
-
case "delete":
|
|
442
|
-
case "update": return !statement.where;
|
|
443
|
-
case "truncate table":
|
|
444
|
-
case "drop table":
|
|
445
|
-
case "drop sequence":
|
|
446
|
-
case "drop index":
|
|
447
|
-
case "drop type":
|
|
448
|
-
case "drop trigger":
|
|
449
|
-
case "drop function": return true;
|
|
450
|
-
case "alter table": return statement.changes.some((change) => change.type === "drop column" || change.type === "drop constraint");
|
|
451
|
-
case "with": return statement.bind.some((binding) => isDestructiveStatement(binding.statement)) || isDestructiveStatement(statement.in);
|
|
452
|
-
case "with recursive": return isDestructiveStatement(statement.in);
|
|
453
|
-
case "do": return DESTRUCTIVE_COMMAND.test(statement.code);
|
|
454
|
-
default: return false;
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
/**
|
|
458
|
-
* Whether "Run" asks before running `sqlText`: a statement in it deletes or
|
|
459
|
-
* updates without a WHERE of its own, drops or truncates.
|
|
460
|
-
*
|
|
461
|
-
* Decided per parsed statement, not on the text. A search of the text for the
|
|
462
|
-
* word WHERE found it in another statement or in a comment, so `DELETE FROM
|
|
463
|
-
* posts; SELECT * FROM posts WHERE id = 1` deleted every post without asking.
|
|
464
|
-
* Text the parser cannot read is confirmed whenever it names a destructive
|
|
465
|
-
* command.
|
|
466
|
-
*/
|
|
467
|
-
function needsDestructiveConfirmation(sqlText) {
|
|
468
|
-
const statements = parseStatements(sqlText);
|
|
469
|
-
if (!statements) return DESTRUCTIVE_COMMAND.test(sqlText);
|
|
470
|
-
return statements.some(isDestructiveStatement);
|
|
471
|
-
}
|
|
472
|
-
/**
|
|
473
|
-
* A table as SQL: `"schema"."table"` when the query named its schema, and a
|
|
474
|
-
* bare `"table"` when it left it to the search path — which then resolves it
|
|
475
|
-
* the same way it resolved the query.
|
|
476
|
-
*/
|
|
477
|
-
function quoteTableName(tableName, schemaName) {
|
|
478
|
-
const quote = (identifier) => `"${identifier.replace(/"/g, "\"\"")}"`;
|
|
479
|
-
return schemaName ? `${quote(schemaName)}.${quote(tableName)}` : quote(tableName);
|
|
480
|
-
}
|
|
481
|
-
/**
|
|
482
|
-
* The introspected columns of a table the query named — in the schema it
|
|
483
|
-
* named, when it named one. Unqualified, the first schema that has a table of
|
|
484
|
-
* that name answers.
|
|
485
|
-
*/
|
|
486
|
-
function findTableInfo(schemas, table) {
|
|
487
|
-
if (table.schema) return schemas[table.schema]?.find((t) => t.tableName === table.name);
|
|
488
|
-
for (const schema of Object.values(schemas)) {
|
|
489
|
-
const tableInfo = schema.find((t) => t.tableName === table.name);
|
|
490
|
-
if (tableInfo) return tableInfo;
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
/**
|
|
494
|
-
* The name Postgres gives the result column of an unaliased select item, as
|
|
495
|
-
* far as it can be told from the expression: a column keeps its name, a cast
|
|
496
|
-
* the name of what it casts, a function call the function's, and anything
|
|
497
|
-
* else a name no table column has.
|
|
498
|
-
*/
|
|
499
|
-
function expressionColumnName(expr) {
|
|
500
|
-
switch (expr.type) {
|
|
501
|
-
case "ref": return expr.name;
|
|
502
|
-
case "cast": {
|
|
503
|
-
const operandName = expressionColumnName(expr.operand);
|
|
504
|
-
if (operandName !== "?column?") return operandName;
|
|
505
|
-
return expr.to.kind === "array" ? operandName : expr.to.name;
|
|
506
|
-
}
|
|
507
|
-
case "call": return expr.function.name;
|
|
508
|
-
case "keyword": return expr.keyword;
|
|
509
|
-
case "case": return "case";
|
|
510
|
-
case "array select": return "array";
|
|
511
|
-
case "select": {
|
|
512
|
-
const [first] = expr.columns ?? [];
|
|
513
|
-
return first ? selectedColumnName(first) : "?column?";
|
|
514
|
-
}
|
|
515
|
-
default: return "?column?";
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
function selectedColumnName(column) {
|
|
519
|
-
return column.alias?.name ?? expressionColumnName(column.expr);
|
|
520
|
-
}
|
|
521
|
-
/**
|
|
522
|
-
* How many columns of the query's result may carry `name` — an upper bound:
|
|
523
|
-
* a `*` over a source whose columns are not known counts once for every name.
|
|
524
|
-
*
|
|
525
|
-
* A result row is an object keyed by column name, so where two columns share
|
|
526
|
-
* a name the row holds only the last of them. A key or a value read from such
|
|
527
|
-
* a row cannot be told apart from its namesake: for `SELECT * FROM posts p
|
|
528
|
-
* JOIN authors a …` the row's `id` is the author's.
|
|
529
|
-
*/
|
|
530
|
-
function resultColumnCounter(ast, schemas) {
|
|
531
|
-
const sources = (ast.from ?? []).map((item) => {
|
|
532
|
-
if (item.type === "table") {
|
|
533
|
-
const renamed = item.name.columnNames ?? [];
|
|
534
|
-
const columns = findTableInfo(schemas, {
|
|
535
|
-
name: item.name.name,
|
|
536
|
-
schema: item.name.schema
|
|
537
|
-
})?.columns.map((c, i) => renamed[i]?.name ?? c.name);
|
|
538
|
-
return {
|
|
539
|
-
refName: item.name.alias ?? item.name.name,
|
|
540
|
-
columns
|
|
541
|
-
};
|
|
542
|
-
}
|
|
543
|
-
if (item.type === "statement") {
|
|
544
|
-
const { statement } = item;
|
|
545
|
-
const named = statement.type === "select" && (statement.columns ?? []).every((c) => !(c.expr.type === "ref" && c.expr.name === "*"));
|
|
546
|
-
const renamed = item.columnNames ?? [];
|
|
547
|
-
const columns = named && statement.type === "select" ? (statement.columns ?? []).map((c, i) => renamed[i]?.name ?? selectedColumnName(c)) : void 0;
|
|
548
|
-
return {
|
|
549
|
-
refName: item.alias,
|
|
550
|
-
columns
|
|
551
|
-
};
|
|
552
|
-
}
|
|
553
|
-
return {
|
|
554
|
-
refName: item.alias?.name,
|
|
555
|
-
columns: void 0
|
|
556
|
-
};
|
|
557
|
-
});
|
|
558
|
-
return (name) => {
|
|
559
|
-
let count = 0;
|
|
560
|
-
for (const column of ast.columns ?? []) {
|
|
561
|
-
const expr = column.expr;
|
|
562
|
-
if (expr.type === "ref" && expr.name === "*") {
|
|
563
|
-
const covered = expr.table ? sources.filter((source) => source.refName === expr.table?.name) : sources;
|
|
564
|
-
if (covered.length === 0) count += 1;
|
|
565
|
-
for (const source of covered) count += source.columns ? source.columns.filter((c) => c === name).length : 1;
|
|
566
|
-
} else if (selectedColumnName(column) === name) count += 1;
|
|
567
|
-
}
|
|
568
|
-
return count;
|
|
569
|
-
};
|
|
570
|
-
}
|
|
571
|
-
/**
|
|
572
|
-
* Extract all tables referenced in a SQL query's FROM and JOIN clauses.
|
|
573
|
-
* Returns an empty array for non-SELECT queries or parse failures.
|
|
574
|
-
*/
|
|
575
|
-
function extractTablesFromQuery(sqlString) {
|
|
576
|
-
try {
|
|
577
|
-
const ast = parseFirst(sqlString);
|
|
578
|
-
if (ast.type !== "select") return [];
|
|
579
|
-
const tables = [];
|
|
580
|
-
const processFrom = (fromItems) => {
|
|
581
|
-
for (const item of fromItems) {
|
|
582
|
-
if (item.type === "table" && item.name) tables.push({
|
|
583
|
-
name: item.name.name,
|
|
584
|
-
schema: item.name.schema,
|
|
585
|
-
alias: item.name.alias
|
|
586
|
-
});
|
|
587
|
-
if (item.type === "join") {
|
|
588
|
-
if (item.left) processFrom([item.left]);
|
|
589
|
-
if (item.right) processFrom([item.right]);
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
};
|
|
593
|
-
if (ast.from) processFrom(ast.from);
|
|
594
|
-
return tables;
|
|
595
|
-
} catch {
|
|
596
|
-
return [];
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
/**
|
|
600
|
-
* Resolve which collections are referenced by a SQL query.
|
|
601
|
-
*
|
|
602
|
-
* Parses the SQL, extracts table names, and matches each against
|
|
603
|
-
* registered collections via `collection.table` (falling back to
|
|
604
|
-
* snake_case of `collection.slug`).
|
|
605
|
-
*
|
|
606
|
-
* For each matched collection, determines which result columns
|
|
607
|
-
* belong to that table using the database schema information.
|
|
608
|
-
*/
|
|
609
|
-
function resolveQueryCollections(sqlString, schemas, collections, resultColumns) {
|
|
610
|
-
const tables = extractTablesFromQuery(sqlString);
|
|
611
|
-
if (tables.length === 0) return [];
|
|
612
|
-
const selectColumns = [];
|
|
613
|
-
let countResultColumns;
|
|
614
|
-
try {
|
|
615
|
-
const ast = parseFirst(sqlString);
|
|
616
|
-
if (ast.type === "select") {
|
|
617
|
-
countResultColumns = resultColumnCounter(ast, schemas);
|
|
618
|
-
for (const col of ast.columns ?? []) if (col.expr?.type === "ref") selectColumns.push({
|
|
619
|
-
table: col.expr.table?.name,
|
|
620
|
-
column: col.expr.name,
|
|
621
|
-
alias: col.alias?.name
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
} catch {}
|
|
625
|
-
const results = [];
|
|
626
|
-
for (const table of tables) {
|
|
627
|
-
const matched = collections.find((c) => {
|
|
628
|
-
const tableName = ("table" in c ? c.table : void 0) || toSnakeCase(c.slug);
|
|
629
|
-
const schemaName = ("schema" in c ? c.schema : void 0) || "public";
|
|
630
|
-
return tableName === table.name && (!table.schema || table.schema === schemaName);
|
|
631
|
-
});
|
|
632
|
-
if (!matched) continue;
|
|
633
|
-
const tableColumns = findTableInfo(schemas, table)?.columns.map((c) => c.name) ?? [];
|
|
634
|
-
let pkColumn;
|
|
635
|
-
const tableRef = table.alias || table.name;
|
|
636
|
-
const idSelectCol = selectColumns.find((sc) => sc.column === "id" && (!sc.table || sc.table === tableRef || sc.table === table.name));
|
|
637
|
-
if (idSelectCol) pkColumn = idSelectCol.alias || idSelectCol.column;
|
|
638
|
-
if (!pkColumn && resultColumns) {
|
|
639
|
-
if (resultColumns.includes("id")) pkColumn = "id";
|
|
640
|
-
}
|
|
641
|
-
if (!pkColumn && tableColumns.includes("id")) pkColumn = "id";
|
|
642
|
-
if (pkColumn && (!countResultColumns || countResultColumns(pkColumn) > 1)) pkColumn = void 0;
|
|
643
|
-
results.push({
|
|
644
|
-
tableName: table.name,
|
|
645
|
-
tableAlias: table.alias,
|
|
646
|
-
collection: matched,
|
|
647
|
-
columns: tableColumns,
|
|
648
|
-
pkColumn
|
|
649
|
-
});
|
|
650
|
-
}
|
|
651
|
-
return results;
|
|
652
|
-
}
|
|
653
|
-
function determineTableAndPK(sqlString, columnKey, schemas) {
|
|
654
|
-
try {
|
|
655
|
-
const tables = extractTablesFromQuery(sqlString);
|
|
656
|
-
const ast = parseFirst(sqlString);
|
|
657
|
-
if (ast.type !== "select") return { error: "Inline editing is only supported for SELECT queries." };
|
|
658
|
-
if (tables.length === 0) return { error: "Could not find any tables in the query." };
|
|
659
|
-
const selectColumns = [];
|
|
660
|
-
if (ast.columns) {
|
|
661
|
-
for (const col of ast.columns) if (col.expr?.type === "ref") selectColumns.push({
|
|
662
|
-
table: col.expr.table?.name,
|
|
663
|
-
column: col.expr.name,
|
|
664
|
-
alias: col.alias?.name
|
|
665
|
-
});
|
|
666
|
-
}
|
|
667
|
-
const resolvedColumn = selectColumns.find((sc) => sc.alias === columnKey || !sc.alias && sc.column === columnKey);
|
|
668
|
-
const actualDbColumnName = resolvedColumn?.column ?? columnKey;
|
|
669
|
-
const columnTableRef = resolvedColumn?.table;
|
|
670
|
-
let resolvedTable = null;
|
|
671
|
-
if (tables.length === 1) resolvedTable = tables[0];
|
|
672
|
-
else {
|
|
673
|
-
if (columnTableRef) {
|
|
674
|
-
const matchedTable = tables.find((t) => t.alias === columnTableRef || t.name === columnTableRef);
|
|
675
|
-
if (matchedTable) resolvedTable = matchedTable;
|
|
676
|
-
}
|
|
677
|
-
if (!resolvedTable) {
|
|
678
|
-
const matchedTables = tables.filter((t) => findTableInfo(schemas, t)?.columns.some((c) => c.name === actualDbColumnName) ?? false);
|
|
679
|
-
if (matchedTables.length === 1) resolvedTable = matchedTables[0];
|
|
680
|
-
else if (matchedTables.length > 1) return { error: `Ambiguous column "${columnKey}": Found in multiple queried tables.` };
|
|
681
|
-
else return { error: `Could not find column "${columnKey}" in the queried tables.` };
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
if (!resolvedTable) return { error: "Could not resolve the target table." };
|
|
685
|
-
const resolvedTableName = resolvedTable.name;
|
|
686
|
-
const pkDbColumns = (findTableInfo(schemas, resolvedTable)?.columns ?? []).filter((c) => c.isPrimaryKey).map((c) => c.name);
|
|
687
|
-
if (pkDbColumns.length === 0) return { error: `Table "${resolvedTableName}" has no primary key defined.` };
|
|
688
|
-
const tableAlias = resolvedTable.alias;
|
|
689
|
-
const primaryKeys = pkDbColumns.map((dbCol) => {
|
|
690
|
-
const selectCol = selectColumns.find((sc) => sc.column === dbCol && (!sc.table || sc.table === (tableAlias || resolvedTableName)));
|
|
691
|
-
return {
|
|
692
|
-
dbColumn: dbCol,
|
|
693
|
-
resultColumn: selectCol?.alias || selectCol?.column || dbCol
|
|
694
|
-
};
|
|
695
|
-
});
|
|
696
|
-
const countResultColumns = resultColumnCounter(ast, schemas);
|
|
697
|
-
if (countResultColumns(columnKey) > 1) return { error: `Ambiguous column "${columnKey}": the result has more than one column of that name. Give each one its own alias to edit it.` };
|
|
698
|
-
const sharedKey = primaryKeys.find((pk) => countResultColumns(pk.resultColumn) > 1);
|
|
699
|
-
if (sharedKey) return { error: `Cannot tell which "${sharedKey.resultColumn}" column is the key of "${resolvedTableName}": the result has more than one column of that name. Give it its own alias (${tableAlias || resolvedTableName}.${sharedKey.dbColumn} AS ${resolvedTableName}_${sharedKey.dbColumn}) to edit this table.` };
|
|
700
|
-
return {
|
|
701
|
-
tableName: resolvedTableName,
|
|
702
|
-
schemaName: resolvedTable.schema,
|
|
703
|
-
primaryKeys
|
|
704
|
-
};
|
|
705
|
-
} catch (e) {
|
|
706
|
-
console.warn("Failed to parse SQL AST:", e);
|
|
707
|
-
return { error: `Could not safely parse query for inline editing: ${e instanceof Error ? e.message : String(e)}` };
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
//#endregion
|
|
711
401
|
//#region src/components/SQLEditor/ExplainVisualizer.tsx
|
|
712
402
|
var ExplainVisualizer = ({ plan, isRoot = true }) => {
|
|
713
403
|
const [expanded, setExpanded] = useState(true);
|
|
@@ -851,6 +541,11 @@ var ExplainVisualizer = ({ plan, isRoot = true }) => {
|
|
|
851
541
|
};
|
|
852
542
|
//#endregion
|
|
853
543
|
//#region src/components/SQLEditor/SQLEditor.tsx
|
|
544
|
+
/**
|
|
545
|
+
* The box a result cell is edited in. It closes once: Enter saves, Escape
|
|
546
|
+
* cancels, a click away saves — and the blur a closing box can still receive
|
|
547
|
+
* is not a second answer, which made Enter save twice and Escape save at all.
|
|
548
|
+
*/
|
|
854
549
|
var FixedEditorOverlay = ({ displayValue, onSave, onCancel }) => {
|
|
855
550
|
const [rect, setRect] = useState(null);
|
|
856
551
|
const [windowSize, setWindowSize] = useState({
|
|
@@ -858,6 +553,14 @@ var FixedEditorOverlay = ({ displayValue, onSave, onCancel }) => {
|
|
|
858
553
|
height: 1e3
|
|
859
554
|
});
|
|
860
555
|
const anchorRef = useRef(null);
|
|
556
|
+
const closedRef = useRef(false);
|
|
557
|
+
/** Close the box, saving `typed` when it is given. Only the first call counts. */
|
|
558
|
+
const close = (typed) => {
|
|
559
|
+
if (closedRef.current) return;
|
|
560
|
+
closedRef.current = true;
|
|
561
|
+
if (typed !== void 0) onSave(typed);
|
|
562
|
+
onCancel();
|
|
563
|
+
};
|
|
861
564
|
useEffect(() => {
|
|
862
565
|
if (anchorRef.current && anchorRef.current.parentElement) setRect(anchorRef.current.parentElement.getBoundingClientRect());
|
|
863
566
|
if (typeof window !== "undefined") {
|
|
@@ -910,17 +613,13 @@ var FixedEditorOverlay = ({ displayValue, onSave, onCancel }) => {
|
|
|
910
613
|
e.target.value = "";
|
|
911
614
|
e.target.value = val;
|
|
912
615
|
},
|
|
913
|
-
onBlur: (e) =>
|
|
914
|
-
onSave(e.target.value || null);
|
|
915
|
-
onCancel();
|
|
916
|
-
},
|
|
616
|
+
onBlur: (e) => close(e.target.value),
|
|
917
617
|
onKeyDown: (e) => {
|
|
918
618
|
if (e.key === "Enter" && !e.shiftKey) {
|
|
919
619
|
e.preventDefault();
|
|
920
|
-
|
|
921
|
-
onCancel();
|
|
620
|
+
close(e.currentTarget.value);
|
|
922
621
|
}
|
|
923
|
-
if (e.key === "Escape")
|
|
622
|
+
if (e.key === "Escape") close();
|
|
924
623
|
}
|
|
925
624
|
})
|
|
926
625
|
}), document.body)
|
|
@@ -958,7 +657,18 @@ var SQLEditor = () => {
|
|
|
958
657
|
return readStoredString(`rebase_sql_selected_role_${client?.baseUrl ? client.baseUrl.replace(/^https?:\/\//, "").replace(/[^a-zA-Z0-9]/g, "_") : "default"}`) || void 0;
|
|
959
658
|
});
|
|
960
659
|
const [availableDatabases, setAvailableDatabases] = useState([]);
|
|
660
|
+
/**
|
|
661
|
+
* The database the app reads and writes — the one the CMS opens a record
|
|
662
|
+
* on. Rows read anywhere else are not that record.
|
|
663
|
+
*/
|
|
664
|
+
const [appDatabase, setAppDatabase] = useState(void 0);
|
|
961
665
|
const [availableRoles, setAvailableRoles] = useState([]);
|
|
666
|
+
/**
|
|
667
|
+
* Who every statement runs as, once a run has shown that the server does
|
|
668
|
+
* not switch roles (`DISABLE_DB_ROLE_SWITCHING`): the role picker then
|
|
669
|
+
* changes nothing, and says so.
|
|
670
|
+
*/
|
|
671
|
+
const [connectionOwner, setConnectionOwner] = useState(null);
|
|
962
672
|
const [isLoadingConfig, setIsLoadingConfig] = useState(true);
|
|
963
673
|
const [connectionConfigError, setConnectionConfigError] = useState(null);
|
|
964
674
|
const [tabs, setTabs] = useState(() => {
|
|
@@ -973,7 +683,11 @@ var SQLEditor = () => {
|
|
|
973
683
|
error: null,
|
|
974
684
|
execTime: null,
|
|
975
685
|
lastExecutedSql: null,
|
|
976
|
-
lastExecutedConnection: null
|
|
686
|
+
lastExecutedConnection: null,
|
|
687
|
+
ranAs: null,
|
|
688
|
+
lastProvenance: null,
|
|
689
|
+
notices: [],
|
|
690
|
+
truncatedFrom: null
|
|
977
691
|
}));
|
|
978
692
|
if (restored.length > 0) return restored;
|
|
979
693
|
return [{
|
|
@@ -987,7 +701,11 @@ var SQLEditor = () => {
|
|
|
987
701
|
error: null,
|
|
988
702
|
execTime: null,
|
|
989
703
|
lastExecutedSql: null,
|
|
990
|
-
lastExecutedConnection: null
|
|
704
|
+
lastExecutedConnection: null,
|
|
705
|
+
ranAs: null,
|
|
706
|
+
lastProvenance: null,
|
|
707
|
+
notices: [],
|
|
708
|
+
truncatedFrom: null
|
|
991
709
|
}];
|
|
992
710
|
});
|
|
993
711
|
const [activeTabId, setActiveTabId] = useState(() => {
|
|
@@ -1005,6 +723,12 @@ var SQLEditor = () => {
|
|
|
1005
723
|
const loading = activeTab.loading;
|
|
1006
724
|
const error = activeTab.error;
|
|
1007
725
|
const execTime = activeTab.execTime;
|
|
726
|
+
/**
|
|
727
|
+
* The SQL whose rows are on screen, which their column widths are kept
|
|
728
|
+
* under. Not the text being typed: keyed by that, every keystroke handed
|
|
729
|
+
* the grid other widths, and every visible cell was drawn again.
|
|
730
|
+
*/
|
|
731
|
+
const resultSql = activeTab.lastExecutedSql ?? "";
|
|
1008
732
|
const setSql = (newSql) => updateActiveTab({ sql: newSql });
|
|
1009
733
|
useEffect(() => {
|
|
1010
734
|
let mounted = true;
|
|
@@ -1024,6 +748,7 @@ var SQLEditor = () => {
|
|
|
1024
748
|
if (mounted) {
|
|
1025
749
|
setAvailableDatabases(dbs);
|
|
1026
750
|
setAvailableRoles(roles);
|
|
751
|
+
setAppDatabase(currentDbFromApi);
|
|
1027
752
|
const loadedDb = readStoredString(`rebase_sql_selected_db_${projectPrefix}`) || void 0;
|
|
1028
753
|
const loadedRole = readStoredString(`rebase_sql_selected_role_${projectPrefix}`) || void 0;
|
|
1029
754
|
const initialActiveTabId = readStoredString(`rebase_sql_active_tab_${projectPrefix}`) || "1";
|
|
@@ -1147,30 +872,7 @@ var SQLEditor = () => {
|
|
|
1147
872
|
c.table_schema, c.table_name, c.ordinal_position;
|
|
1148
873
|
`, { database: selectedDatabase });
|
|
1149
874
|
const processGrouped = (data) => {
|
|
1150
|
-
|
|
1151
|
-
const schema = curr.schema || curr.SCHEMA || curr.table_schema || "public";
|
|
1152
|
-
const table = curr.table || curr.TABLE || curr.table_name;
|
|
1153
|
-
const column = curr.column || curr.COLUMN || curr.column_name;
|
|
1154
|
-
const dataType = curr.data_type || curr.DATA_TYPE || "";
|
|
1155
|
-
const isPrimaryKey = curr.is_pk === true || curr.is_pk === "true";
|
|
1156
|
-
if (!acc[schema]) acc[schema] = [];
|
|
1157
|
-
let tableInfo = acc[schema].find((t) => t.tableName === table);
|
|
1158
|
-
if (!tableInfo) {
|
|
1159
|
-
tableInfo = {
|
|
1160
|
-
schemaName: schema,
|
|
1161
|
-
tableName: table,
|
|
1162
|
-
columns: []
|
|
1163
|
-
};
|
|
1164
|
-
acc[schema].push(tableInfo);
|
|
1165
|
-
}
|
|
1166
|
-
tableInfo.columns.push({
|
|
1167
|
-
name: column,
|
|
1168
|
-
dataType,
|
|
1169
|
-
isPrimaryKey
|
|
1170
|
-
});
|
|
1171
|
-
return acc;
|
|
1172
|
-
}, {});
|
|
1173
|
-
setSchemas(grouped);
|
|
875
|
+
setSchemas(groupSchemaRows(data));
|
|
1174
876
|
};
|
|
1175
877
|
if (!result || !Array.isArray(result)) if (result && typeof result === "object" && "rows" in result && Array.isArray(result.rows)) processGrouped(result.rows);
|
|
1176
878
|
else {
|
|
@@ -1200,8 +902,23 @@ var SQLEditor = () => {
|
|
|
1200
902
|
const [autoLimit, setAutoLimit] = useState(true);
|
|
1201
903
|
const [isConfirmDialogOpen, setIsConfirmDialogOpen] = useState(false);
|
|
1202
904
|
const [pendingAction, setPendingAction] = useState(null);
|
|
905
|
+
/**
|
|
906
|
+
* The cell being edited, and the text its editor opened with — what
|
|
907
|
+
* closing the editor unchanged is compared against.
|
|
908
|
+
*/
|
|
1203
909
|
const [editingCell, setEditingCell] = useState(null);
|
|
1204
910
|
const isCurrentConnection = useCallback((connection) => connection !== null && connection.database === selectedDatabase && connection.role === selectedRole, [selectedDatabase, selectedRole]);
|
|
911
|
+
/**
|
|
912
|
+
* Which stored cell a result cell is — by what the database said about the
|
|
913
|
+
* last run's columns, and nothing else.
|
|
914
|
+
*/
|
|
915
|
+
const resolveEdit = useCallback((columnKey) => {
|
|
916
|
+
if (!activeTab.lastExecutedSql || !activeTab.lastProvenance) return { refusal: {
|
|
917
|
+
key: "studio_sql_edit_computed_column",
|
|
918
|
+
params: { column: columnKey }
|
|
919
|
+
} };
|
|
920
|
+
return resolveCellEdit(activeTab.lastExecutedSql, activeTab.lastProvenance, columnKey);
|
|
921
|
+
}, [activeTab.lastExecutedSql, activeTab.lastProvenance]);
|
|
1205
922
|
const handleDoubleClick = useCallback((rowIndex, columnKey, initialValue, rowData) => {
|
|
1206
923
|
if (!activeTab.lastExecutedSql) {
|
|
1207
924
|
snackbarController.open({
|
|
@@ -1217,15 +934,15 @@ var SQLEditor = () => {
|
|
|
1217
934
|
});
|
|
1218
935
|
return;
|
|
1219
936
|
}
|
|
1220
|
-
const resolution =
|
|
1221
|
-
if (
|
|
937
|
+
const resolution = resolveEdit(columnKey);
|
|
938
|
+
if (!resolution.target) {
|
|
1222
939
|
snackbarController.open({
|
|
1223
940
|
type: "error",
|
|
1224
|
-
message: resolution.
|
|
941
|
+
message: t(resolution.refusal.key, resolution.refusal.params)
|
|
1225
942
|
});
|
|
1226
943
|
return;
|
|
1227
944
|
}
|
|
1228
|
-
const missingPKs = resolution.
|
|
945
|
+
const missingPKs = resolution.target.key.filter((pk) => rowData[pk.resultColumn] === void 0 || rowData[pk.resultColumn] === null);
|
|
1229
946
|
if (missingPKs.length > 0) {
|
|
1230
947
|
snackbarController.open({
|
|
1231
948
|
type: "error",
|
|
@@ -1242,14 +959,15 @@ var SQLEditor = () => {
|
|
|
1242
959
|
activeTab.lastExecutedSql,
|
|
1243
960
|
activeTab.lastExecutedConnection,
|
|
1244
961
|
isCurrentConnection,
|
|
1245
|
-
|
|
962
|
+
resolveEdit,
|
|
1246
963
|
snackbarController,
|
|
1247
964
|
t
|
|
1248
965
|
]);
|
|
1249
|
-
const handleCellSave = useCallback(async (
|
|
966
|
+
const handleCellSave = useCallback(async (text, rowData, columnKey, rowIndex) => {
|
|
1250
967
|
if (!editingCell || !activeTab.lastExecutedSql) return;
|
|
1251
968
|
setEditingCell(null);
|
|
1252
|
-
if (
|
|
969
|
+
if (text === editingCell.initialValue) return;
|
|
970
|
+
const newValue = text === "" ? null : text;
|
|
1253
971
|
const connection = activeTab.lastExecutedConnection;
|
|
1254
972
|
if (!isCurrentConnection(connection)) {
|
|
1255
973
|
snackbarController.open({
|
|
@@ -1258,54 +976,44 @@ var SQLEditor = () => {
|
|
|
1258
976
|
});
|
|
1259
977
|
return;
|
|
1260
978
|
}
|
|
1261
|
-
const resolution =
|
|
1262
|
-
if (
|
|
979
|
+
const resolution = resolveEdit(columnKey);
|
|
980
|
+
if (!resolution.target) {
|
|
1263
981
|
snackbarController.open({
|
|
1264
982
|
type: "error",
|
|
1265
|
-
message: resolution.
|
|
983
|
+
message: t(resolution.refusal.key, resolution.refusal.params)
|
|
1266
984
|
});
|
|
1267
985
|
return;
|
|
1268
986
|
}
|
|
1269
|
-
const
|
|
987
|
+
const target = resolution.target;
|
|
1270
988
|
const formatValue = (val) => {
|
|
1271
989
|
if (val === null || val === void 0) return "NULL";
|
|
1272
990
|
if (typeof val === "number") return val;
|
|
1273
991
|
if (typeof val === "boolean") return val ? "TRUE" : "FALSE";
|
|
1274
992
|
return `'${String(val).replace(/'/g, "''")}'`;
|
|
1275
993
|
};
|
|
1276
|
-
const
|
|
1277
|
-
|
|
1278
|
-
const ast = parseFirst(activeTab.lastExecutedSql);
|
|
1279
|
-
if (ast.type === "select" && ast.columns) {
|
|
1280
|
-
for (const col of ast.columns) if (col.expr?.type === "ref") {
|
|
1281
|
-
const alias = col.alias?.name;
|
|
1282
|
-
const colName = col.expr.name;
|
|
1283
|
-
if (alias === resultColKey || !alias && colName === resultColKey) return colName;
|
|
1284
|
-
}
|
|
1285
|
-
}
|
|
1286
|
-
} catch {}
|
|
1287
|
-
return resultColKey;
|
|
1288
|
-
};
|
|
1289
|
-
const dbColumnName = resolveDbColumnName(columnKey);
|
|
1290
|
-
const whereConditions = resolution.primaryKeys.map((pk) => `"${pk.dbColumn}" = ${formatValue(rowData[pk.resultColumn])}`).join(" AND ");
|
|
1291
|
-
const updateSql = `UPDATE ${tableName} SET "${dbColumnName}" = ${formatValue(newValue)} WHERE ${whereConditions};`;
|
|
994
|
+
const whereConditions = target.key.map((pk) => `${quoteIdentifier(pk.column)} = ${formatValue(rowData[pk.resultColumn])}`).join(" AND ");
|
|
995
|
+
const updateSql = `UPDATE ${quoteTableName(target.table, target.schema)} SET ${quoteIdentifier(target.column)} = ${formatValue(newValue)} WHERE ${whereConditions};`;
|
|
1292
996
|
try {
|
|
1293
|
-
if (databaseAdmin?.
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
});
|
|
1298
|
-
const newResults = [...activeTab.results || []];
|
|
1299
|
-
if (newResults[rowIndex]) newResults[rowIndex] = {
|
|
1300
|
-
...newResults[rowIndex],
|
|
1301
|
-
[columnKey]: newValue
|
|
1302
|
-
};
|
|
1303
|
-
updateActiveTab({ results: newResults });
|
|
997
|
+
if (!(await databaseAdmin?.runSqlScript?.(updateSql, {
|
|
998
|
+
database: connection.database,
|
|
999
|
+
role: connection.role
|
|
1000
|
+
}))?.rowCount) {
|
|
1304
1001
|
snackbarController.open({
|
|
1305
|
-
type: "
|
|
1306
|
-
message: t("
|
|
1002
|
+
type: "error",
|
|
1003
|
+
message: t("studio_sql_update_no_row")
|
|
1307
1004
|
});
|
|
1005
|
+
return;
|
|
1308
1006
|
}
|
|
1007
|
+
const newResults = [...activeTab.results || []];
|
|
1008
|
+
if (newResults[rowIndex]) newResults[rowIndex] = {
|
|
1009
|
+
...newResults[rowIndex],
|
|
1010
|
+
[columnKey]: newValue
|
|
1011
|
+
};
|
|
1012
|
+
updateActiveTab({ results: newResults });
|
|
1013
|
+
snackbarController.open({
|
|
1014
|
+
type: "success",
|
|
1015
|
+
message: t("studio_sql_row_updated")
|
|
1016
|
+
});
|
|
1309
1017
|
} catch (e) {
|
|
1310
1018
|
snackbarController.open({
|
|
1311
1019
|
type: "error",
|
|
@@ -1314,7 +1022,7 @@ var SQLEditor = () => {
|
|
|
1314
1022
|
}
|
|
1315
1023
|
}, [
|
|
1316
1024
|
editingCell,
|
|
1317
|
-
|
|
1025
|
+
resolveEdit,
|
|
1318
1026
|
activeTab.lastExecutedSql,
|
|
1319
1027
|
activeTab.lastExecutedConnection,
|
|
1320
1028
|
activeTab.results,
|
|
@@ -1325,10 +1033,10 @@ var SQLEditor = () => {
|
|
|
1325
1033
|
t
|
|
1326
1034
|
]);
|
|
1327
1035
|
const [columnWidths, setColumnWidths] = useState(() => {
|
|
1328
|
-
return readStoredJson(`rebase_sql_column_widths_${client?.baseUrl ? client.baseUrl.replace(/^https?:\/\//, "").replace(/[^a-zA-Z0-9]/g, "_") : "default"}`, {
|
|
1036
|
+
return keepLatestColumnWidths(readStoredJson(`rebase_sql_column_widths_${client?.baseUrl ? client.baseUrl.replace(/^https?:\/\//, "").replace(/[^a-zA-Z0-9]/g, "_") : "default"}`, {
|
|
1329
1037
|
fallback: {},
|
|
1330
1038
|
accept: isRecordValue
|
|
1331
|
-
});
|
|
1039
|
+
}));
|
|
1332
1040
|
});
|
|
1333
1041
|
const [snippets, setSnippets] = useState([]);
|
|
1334
1042
|
const [history, setHistory] = useState([]);
|
|
@@ -1390,7 +1098,11 @@ var SQLEditor = () => {
|
|
|
1390
1098
|
error: null,
|
|
1391
1099
|
execTime: null,
|
|
1392
1100
|
lastExecutedSql: null,
|
|
1393
|
-
lastExecutedConnection: null
|
|
1101
|
+
lastExecutedConnection: null,
|
|
1102
|
+
ranAs: null,
|
|
1103
|
+
lastProvenance: null,
|
|
1104
|
+
notices: [],
|
|
1105
|
+
truncatedFrom: null
|
|
1394
1106
|
}]);
|
|
1395
1107
|
setActiveTabId(newId);
|
|
1396
1108
|
};
|
|
@@ -1407,23 +1119,46 @@ var SQLEditor = () => {
|
|
|
1407
1119
|
};
|
|
1408
1120
|
const handleColumnResize = useCallback(({ key, width }) => {
|
|
1409
1121
|
setColumnWidths((prev) => {
|
|
1410
|
-
const newWidths =
|
|
1411
|
-
...prev,
|
|
1412
|
-
[activeTab.sql]: {
|
|
1413
|
-
...prev[activeTab.sql] || {},
|
|
1414
|
-
[key]: width
|
|
1415
|
-
}
|
|
1416
|
-
};
|
|
1122
|
+
const newWidths = rememberColumnWidth(prev, resultSql, key, width);
|
|
1417
1123
|
writeStoredJson(`rebase_sql_column_widths_${projectPrefix}`, newWidths);
|
|
1418
1124
|
return newWidths;
|
|
1419
1125
|
});
|
|
1420
|
-
}, [
|
|
1126
|
+
}, [resultSql, projectPrefix]);
|
|
1421
1127
|
const handlePrettify = () => {
|
|
1422
|
-
|
|
1423
|
-
setSql(formatted);
|
|
1128
|
+
setSql(formatSql(activeTab.sql));
|
|
1424
1129
|
};
|
|
1425
1130
|
/** The editor, for the selection the toolbar's buttons act on. */
|
|
1426
1131
|
const editorHandle = useRef(null);
|
|
1132
|
+
/**
|
|
1133
|
+
* The tabs with a run or an explain in flight. A ref, not the tab's
|
|
1134
|
+
* `loading`: two Cmd+Enter in a row both read the render before the first
|
|
1135
|
+
* set it, and only the button was disabled — so an INSERT ran twice, and
|
|
1136
|
+
* the slower answer drew over the newer one.
|
|
1137
|
+
*/
|
|
1138
|
+
const tabsRunningRef = useRef(/* @__PURE__ */ new Set());
|
|
1139
|
+
/**
|
|
1140
|
+
* Each tab's run in flight, by tab, for "Cancel run": aborting it rejects
|
|
1141
|
+
* the run at once, and a server that can cancels the statement too.
|
|
1142
|
+
*/
|
|
1143
|
+
const runAbortRef = useRef(/* @__PURE__ */ new Map());
|
|
1144
|
+
const [cancellableTabs, setCancellableTabs] = useState(/* @__PURE__ */ new Set());
|
|
1145
|
+
const setCancellable = (tabId, cancellable) => setCancellableTabs((previous) => {
|
|
1146
|
+
const next = new Set(previous);
|
|
1147
|
+
if (cancellable) next.add(tabId);
|
|
1148
|
+
else next.delete(tabId);
|
|
1149
|
+
return next;
|
|
1150
|
+
});
|
|
1151
|
+
const handleCancelRun = () => runAbortRef.current.get(activeTab.id)?.abort();
|
|
1152
|
+
/** `work` on the active tab, unless that tab is already running something. */
|
|
1153
|
+
const runOnce = async (tabId, work) => {
|
|
1154
|
+
if (tabsRunningRef.current.has(tabId)) return;
|
|
1155
|
+
tabsRunningRef.current.add(tabId);
|
|
1156
|
+
try {
|
|
1157
|
+
await work();
|
|
1158
|
+
} finally {
|
|
1159
|
+
tabsRunningRef.current.delete(tabId);
|
|
1160
|
+
}
|
|
1161
|
+
};
|
|
1427
1162
|
const handleExplain = async () => {
|
|
1428
1163
|
const explainSql = buildExplainSql(editorHandle.current?.getSelectedText() ?? activeTab.sql);
|
|
1429
1164
|
if (!explainSql) {
|
|
@@ -1433,12 +1168,19 @@ var SQLEditor = () => {
|
|
|
1433
1168
|
});
|
|
1434
1169
|
return;
|
|
1435
1170
|
}
|
|
1171
|
+
await runOnce(activeTab.id, () => explain(explainSql));
|
|
1172
|
+
};
|
|
1173
|
+
const explain = async (explainSql) => {
|
|
1436
1174
|
updateActiveTab({
|
|
1437
1175
|
loading: true,
|
|
1438
1176
|
error: null,
|
|
1439
1177
|
results: null,
|
|
1440
1178
|
lastExecutedSql: null,
|
|
1441
|
-
lastExecutedConnection: null
|
|
1179
|
+
lastExecutedConnection: null,
|
|
1180
|
+
ranAs: null,
|
|
1181
|
+
lastProvenance: null,
|
|
1182
|
+
notices: [],
|
|
1183
|
+
truncatedFrom: null
|
|
1442
1184
|
});
|
|
1443
1185
|
const start = performance.now();
|
|
1444
1186
|
try {
|
|
@@ -1459,43 +1201,65 @@ var SQLEditor = () => {
|
|
|
1459
1201
|
updateActiveTab({ loading: false });
|
|
1460
1202
|
}
|
|
1461
1203
|
};
|
|
1462
|
-
const executeRun = useCallback(async (
|
|
1463
|
-
|
|
1464
|
-
const
|
|
1465
|
-
if (autoLimit && acceptsAutoLimit(sqlToRun) && !isAggregate) {
|
|
1466
|
-
sqlToRun = sqlToRun.trim().replace(/;$/, "");
|
|
1467
|
-
sqlToRun = `${sqlToRun} LIMIT 1000;`;
|
|
1468
|
-
}
|
|
1204
|
+
const executeRun = useCallback((sqlOverride) => runOnce(activeTab.id, async () => {
|
|
1205
|
+
const written = sqlOverride || activeTab.sql;
|
|
1206
|
+
const sqlToRun = (autoLimit ? withAutoLimit(written, 1e3) : null) ?? written;
|
|
1469
1207
|
updateActiveTab({
|
|
1470
1208
|
loading: true,
|
|
1471
1209
|
error: null,
|
|
1472
|
-
results: null
|
|
1210
|
+
results: null,
|
|
1211
|
+
notices: [],
|
|
1212
|
+
truncatedFrom: null
|
|
1473
1213
|
});
|
|
1474
1214
|
const start = performance.now();
|
|
1215
|
+
const tabId = activeTab.id;
|
|
1216
|
+
const abort = databaseAdmin?.runSqlScript ? new AbortController() : void 0;
|
|
1217
|
+
if (abort) {
|
|
1218
|
+
runAbortRef.current.set(tabId, abort);
|
|
1219
|
+
setCancellable(tabId, true);
|
|
1220
|
+
}
|
|
1475
1221
|
try {
|
|
1476
|
-
if (databaseAdmin?.executeSql) {
|
|
1477
|
-
const
|
|
1222
|
+
if (databaseAdmin?.runSqlScript || databaseAdmin?.executeSql) {
|
|
1223
|
+
const connection = {
|
|
1478
1224
|
database: selectedDatabase,
|
|
1479
1225
|
role: selectedRole
|
|
1480
|
-
}
|
|
1226
|
+
};
|
|
1227
|
+
const run = databaseAdmin.runSqlScript ? await databaseAdmin.runSqlScript(sqlToRun, {
|
|
1228
|
+
...connection,
|
|
1229
|
+
signal: abort?.signal
|
|
1230
|
+
}) : void 0;
|
|
1231
|
+
const rows = run ? run.rows : await databaseAdmin.executeSql(sqlToRun, connection);
|
|
1481
1232
|
updateActiveTab({
|
|
1482
|
-
results:
|
|
1233
|
+
results: rows,
|
|
1483
1234
|
execTime: Math.round(performance.now() - start),
|
|
1484
1235
|
lastExecutedSql: sqlToRun,
|
|
1485
|
-
lastExecutedConnection:
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1236
|
+
lastExecutedConnection: connection,
|
|
1237
|
+
ranAs: run?.effectiveRole ?? null,
|
|
1238
|
+
lastProvenance: run ? {
|
|
1239
|
+
columns: run.columns,
|
|
1240
|
+
tables: run.tables
|
|
1241
|
+
} : {
|
|
1242
|
+
columns: Object.keys(rows[0] ?? {}).map((name) => ({ name })),
|
|
1243
|
+
tables: []
|
|
1244
|
+
},
|
|
1245
|
+
notices: run?.notices ?? [],
|
|
1246
|
+
truncatedFrom: run?.truncated ? run.rowCount ?? null : null
|
|
1489
1247
|
});
|
|
1248
|
+
if (run?.effectiveRole && connection.role) setConnectionOwner(run.effectiveRole !== connection.role ? run.effectiveRole : null);
|
|
1490
1249
|
if (history[history.length - 1] !== activeTab.sql) saveHistory([...history, activeTab.sql]);
|
|
1491
1250
|
} else updateActiveTab({ error: t("studio_sql_execution_not_supported") });
|
|
1492
1251
|
} catch (e) {
|
|
1493
1252
|
const message = e instanceof Error ? e.message : String(e);
|
|
1494
|
-
updateActiveTab({ error: message || t("studio_sql_error_executing") });
|
|
1253
|
+
updateActiveTab({ error: abort?.signal.aborted ? t("studio_sql_run_cancelled") : message || t("studio_sql_error_executing") });
|
|
1495
1254
|
} finally {
|
|
1255
|
+
if (abort && runAbortRef.current.get(tabId) === abort) {
|
|
1256
|
+
runAbortRef.current.delete(tabId);
|
|
1257
|
+
setCancellable(tabId, false);
|
|
1258
|
+
}
|
|
1496
1259
|
updateActiveTab({ loading: false });
|
|
1497
1260
|
}
|
|
1498
|
-
}, [
|
|
1261
|
+
}), [
|
|
1262
|
+
activeTab.id,
|
|
1499
1263
|
activeTab.sql,
|
|
1500
1264
|
autoLimit,
|
|
1501
1265
|
databaseAdmin,
|
|
@@ -1516,6 +1280,7 @@ var SQLEditor = () => {
|
|
|
1516
1280
|
}, [activeTab.sql, executeRun]);
|
|
1517
1281
|
useEffect(() => {
|
|
1518
1282
|
const handleKeyDown = (e) => {
|
|
1283
|
+
if (isKeyHandled(e)) return;
|
|
1519
1284
|
if ((e.metaKey || e.ctrlKey) && e.key === "Enter") {
|
|
1520
1285
|
const activeElement = document.activeElement;
|
|
1521
1286
|
const isInput = activeElement?.tagName === "INPUT" || activeElement?.tagName === "TEXTAREA";
|
|
@@ -1546,11 +1311,7 @@ var SQLEditor = () => {
|
|
|
1546
1311
|
};
|
|
1547
1312
|
const handleExportCSV = () => {
|
|
1548
1313
|
if (!results || results.length === 0) return;
|
|
1549
|
-
const
|
|
1550
|
-
const str = String(val);
|
|
1551
|
-
return str.includes(",") ? `"${str}"` : str;
|
|
1552
|
-
}).join(","))].join("\n");
|
|
1553
|
-
const blob = new Blob([csv], { type: "text/csv" });
|
|
1314
|
+
const blob = new Blob([resultsToCsv(results)], { type: "text/csv" });
|
|
1554
1315
|
const url = window.URL.createObjectURL(blob);
|
|
1555
1316
|
const a = document.createElement("a");
|
|
1556
1317
|
a.href = url;
|
|
@@ -1558,9 +1319,71 @@ var SQLEditor = () => {
|
|
|
1558
1319
|
a.click();
|
|
1559
1320
|
window.URL.revokeObjectURL(url);
|
|
1560
1321
|
};
|
|
1322
|
+
const apiConfig = useApiConfig();
|
|
1323
|
+
const apiBase = useApiBase();
|
|
1324
|
+
const [downloadingFullResult, setDownloadingFullResult] = useState(false);
|
|
1325
|
+
/**
|
|
1326
|
+
* The whole result of the last run, past the rows the console keeps:
|
|
1327
|
+
* streamed by the server through a read-only cursor (`POST
|
|
1328
|
+
* /admin/sql/csv`), on the database and as the role the rows on screen
|
|
1329
|
+
* were read with.
|
|
1330
|
+
*/
|
|
1331
|
+
const handleDownloadFullCsv = async () => {
|
|
1332
|
+
const query = activeTab.lastExecutedSql;
|
|
1333
|
+
const connection = activeTab.lastExecutedConnection;
|
|
1334
|
+
if (!query || !apiBase) return;
|
|
1335
|
+
setDownloadingFullResult(true);
|
|
1336
|
+
try {
|
|
1337
|
+
const token = apiConfig?.getAuthToken ? await apiConfig.getAuthToken() : null;
|
|
1338
|
+
const response = await fetch(`${apiBase}/admin/sql/csv`, {
|
|
1339
|
+
method: "POST",
|
|
1340
|
+
headers: {
|
|
1341
|
+
"Content-Type": "application/json",
|
|
1342
|
+
...token ? { Authorization: `Bearer ${token}` } : {}
|
|
1343
|
+
},
|
|
1344
|
+
body: JSON.stringify({
|
|
1345
|
+
sql: query,
|
|
1346
|
+
database: connection?.database,
|
|
1347
|
+
role: connection?.role
|
|
1348
|
+
})
|
|
1349
|
+
});
|
|
1350
|
+
if (!response.ok) {
|
|
1351
|
+
const failure = await response.json().catch(() => null);
|
|
1352
|
+
const reason = typeof failure === "object" && failure !== null && "error" in failure && typeof failure.error === "object" && failure.error !== null && "message" in failure.error && typeof failure.error.message === "string" ? failure.error.message : `HTTP ${response.status}`;
|
|
1353
|
+
throw new Error(reason);
|
|
1354
|
+
}
|
|
1355
|
+
const blob = await response.blob();
|
|
1356
|
+
const url = window.URL.createObjectURL(blob);
|
|
1357
|
+
const a = document.createElement("a");
|
|
1358
|
+
a.href = url;
|
|
1359
|
+
a.download = `query_results_${(/* @__PURE__ */ new Date()).toISOString().slice(0, 19)}.csv`;
|
|
1360
|
+
a.click();
|
|
1361
|
+
window.URL.revokeObjectURL(url);
|
|
1362
|
+
} catch (e) {
|
|
1363
|
+
snackbarController.open({
|
|
1364
|
+
type: "error",
|
|
1365
|
+
message: t("studio_sql_download_full_failed", { message: e instanceof Error ? e.message : String(e) })
|
|
1366
|
+
});
|
|
1367
|
+
} finally {
|
|
1368
|
+
setDownloadingFullResult(false);
|
|
1369
|
+
}
|
|
1370
|
+
};
|
|
1561
1371
|
const handleExportJSON = () => {
|
|
1562
1372
|
if (!results || results.length === 0) return;
|
|
1563
|
-
|
|
1373
|
+
downloadJson(results);
|
|
1374
|
+
};
|
|
1375
|
+
/**
|
|
1376
|
+
* The result's columns say their types when the script door ran it: each
|
|
1377
|
+
* value read by its type (numbers, booleans, json), where Export JSON
|
|
1378
|
+
* writes the database's text as the grid holds it.
|
|
1379
|
+
*/
|
|
1380
|
+
const typedColumns = activeTab.lastProvenance?.columns.some((column) => column.type !== void 0) ? activeTab.lastProvenance.columns : null;
|
|
1381
|
+
const handleExportTypedJSON = () => {
|
|
1382
|
+
if (!results || results.length === 0 || !typedColumns) return;
|
|
1383
|
+
downloadJson(typedJsonRows(results, typedColumns));
|
|
1384
|
+
};
|
|
1385
|
+
const downloadJson = (rows) => {
|
|
1386
|
+
const json = JSON.stringify(rows, null, 2);
|
|
1564
1387
|
const blob = new Blob([json], { type: "application/json" });
|
|
1565
1388
|
const url = window.URL.createObjectURL(blob);
|
|
1566
1389
|
const a = document.createElement("a");
|
|
@@ -1594,6 +1417,135 @@ var SQLEditor = () => {
|
|
|
1594
1417
|
});
|
|
1595
1418
|
});
|
|
1596
1419
|
};
|
|
1420
|
+
const savedWidths = columnWidths[resultSql];
|
|
1421
|
+
const resultColumnKeys = useMemo(() => results && results.length > 0 ? Object.keys(results[0]) : [], [results]);
|
|
1422
|
+
const readFromAppDatabase = activeTab.lastExecutedConnection !== null && (activeTab.lastExecutedConnection.database === void 0 || activeTab.lastExecutedConnection.database === appDatabase);
|
|
1423
|
+
const lastProvenance = activeTab.lastProvenance;
|
|
1424
|
+
const registryCollections = collectionRegistry.collections;
|
|
1425
|
+
const actionableCollections = useMemo(() => lastProvenance && registryCollections && readFromAppDatabase ? resolveQueryCollections(lastProvenance, registryCollections).filter((mc) => resultColumnKeys.includes(mc.pkColumn)) : [], [
|
|
1426
|
+
lastProvenance,
|
|
1427
|
+
registryCollections,
|
|
1428
|
+
readFromAppDatabase,
|
|
1429
|
+
resultColumnKeys
|
|
1430
|
+
]);
|
|
1431
|
+
const getRowEntityActions = useCallback((rowData) => {
|
|
1432
|
+
if (!rowData) return [];
|
|
1433
|
+
return actionableCollections.filter((mc) => rowData[mc.pkColumn] != null).map((mc) => ({
|
|
1434
|
+
collection: mc,
|
|
1435
|
+
entityId: rowData[mc.pkColumn]
|
|
1436
|
+
}));
|
|
1437
|
+
}, [actionableCollections]);
|
|
1438
|
+
const hasRowActions = actionableCollections.length > 0;
|
|
1439
|
+
const resultColumns = useMemo(() => {
|
|
1440
|
+
const dataColumns = resultColumnKeys.map((key) => ({
|
|
1441
|
+
key,
|
|
1442
|
+
title: key,
|
|
1443
|
+
width: savedWidths?.[key] ?? 150,
|
|
1444
|
+
sortable: false,
|
|
1445
|
+
resizable: true
|
|
1446
|
+
}));
|
|
1447
|
+
return hasRowActions ? [{
|
|
1448
|
+
key: "__cms_action__",
|
|
1449
|
+
title: "",
|
|
1450
|
+
width: 36,
|
|
1451
|
+
sortable: false,
|
|
1452
|
+
resizable: false
|
|
1453
|
+
}, ...dataColumns] : dataColumns;
|
|
1454
|
+
}, [
|
|
1455
|
+
resultColumnKeys,
|
|
1456
|
+
savedWidths,
|
|
1457
|
+
hasRowActions
|
|
1458
|
+
]);
|
|
1459
|
+
const renderResultCell = useCallback(({ rowData, column, rowIndex }) => {
|
|
1460
|
+
if (column.key === "__cms_action__") {
|
|
1461
|
+
const rowActions = getRowEntityActions(rowData ?? {});
|
|
1462
|
+
if (rowActions.length === 0) return /* @__PURE__ */ jsx("div", { className: "h-full w-full" });
|
|
1463
|
+
if (rowActions.length === 1) {
|
|
1464
|
+
const ra = rowActions[0];
|
|
1465
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1466
|
+
className: "h-full flex items-center justify-center",
|
|
1467
|
+
children: /* @__PURE__ */ jsx(Tooltip, {
|
|
1468
|
+
title: t("studio_sql_edit_entity", {
|
|
1469
|
+
name: ra.collection.collection.name,
|
|
1470
|
+
id: String(ra.entityId)
|
|
1471
|
+
}),
|
|
1472
|
+
children: /* @__PURE__ */ jsx(IconButton, {
|
|
1473
|
+
size: "small",
|
|
1474
|
+
"aria-label": t("studio_sql_edit_entity", {
|
|
1475
|
+
name: ra.collection.collection.name,
|
|
1476
|
+
id: String(ra.entityId)
|
|
1477
|
+
}),
|
|
1478
|
+
className: "text-surface-400 dark:text-surface-500 hover:text-surface-600 dark:hover:text-surface-300 transition-colors",
|
|
1479
|
+
onClick: (e) => {
|
|
1480
|
+
e.stopPropagation();
|
|
1481
|
+
sidePanelController?.open({
|
|
1482
|
+
path: ra.collection.collection.slug,
|
|
1483
|
+
entityId: ra.entityId,
|
|
1484
|
+
collection: ra.collection.collection,
|
|
1485
|
+
updateUrl: false
|
|
1486
|
+
});
|
|
1487
|
+
},
|
|
1488
|
+
children: /* @__PURE__ */ jsx(PencilIcon, { size: iconSize.smallest })
|
|
1489
|
+
})
|
|
1490
|
+
})
|
|
1491
|
+
});
|
|
1492
|
+
}
|
|
1493
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1494
|
+
className: "h-full flex items-center justify-center",
|
|
1495
|
+
children: /* @__PURE__ */ jsx(Menu, {
|
|
1496
|
+
trigger: /* @__PURE__ */ jsx(IconButton, {
|
|
1497
|
+
"aria-label": t("more_actions"),
|
|
1498
|
+
size: "small",
|
|
1499
|
+
className: "text-surface-400 dark:text-surface-500 hover:text-surface-600 dark:hover:text-surface-300 transition-colors",
|
|
1500
|
+
onClick: (e) => e.stopPropagation(),
|
|
1501
|
+
children: /* @__PURE__ */ jsx(MoreVerticalIcon, { size: iconSize.smallest })
|
|
1502
|
+
}),
|
|
1503
|
+
children: rowActions.map((ra) => /* @__PURE__ */ jsx(MenuItem, {
|
|
1504
|
+
dense: true,
|
|
1505
|
+
onClick: () => {
|
|
1506
|
+
sidePanelController?.open({
|
|
1507
|
+
path: ra.collection.collection.slug,
|
|
1508
|
+
entityId: ra.entityId,
|
|
1509
|
+
collection: ra.collection.collection,
|
|
1510
|
+
updateUrl: false
|
|
1511
|
+
});
|
|
1512
|
+
},
|
|
1513
|
+
children: t("studio_sql_edit_entity", {
|
|
1514
|
+
name: ra.collection.collection.name,
|
|
1515
|
+
id: String(ra.entityId)
|
|
1516
|
+
})
|
|
1517
|
+
}, ra.collection.tableName))
|
|
1518
|
+
})
|
|
1519
|
+
});
|
|
1520
|
+
}
|
|
1521
|
+
const isEditing = editingCell?.rowIndex === rowIndex && editingCell?.columnKey === column.key;
|
|
1522
|
+
const value = rowData ? rowData[column.key] : null;
|
|
1523
|
+
const displayValue = typeof value === "object" && value !== null ? JSON.stringify(value) : String(value ?? "");
|
|
1524
|
+
if (isEditing) return /* @__PURE__ */ jsx(FixedEditorOverlay, {
|
|
1525
|
+
displayValue,
|
|
1526
|
+
onSave: (val) => handleCellSave(val, rowData ?? {}, column.key, rowIndex),
|
|
1527
|
+
onCancel: () => setEditingCell(null)
|
|
1528
|
+
});
|
|
1529
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1530
|
+
className: "px-4 py-1.5 h-full flex items-center whitespace-nowrap text-[13px] text-text-primary dark:text-text-primary-dark font-mono cursor-text group/cell",
|
|
1531
|
+
onDoubleClick: () => handleDoubleClick(rowIndex, column.key, displayValue, rowData ?? {}),
|
|
1532
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
1533
|
+
className: "truncate flex-grow",
|
|
1534
|
+
title: displayValue,
|
|
1535
|
+
children: value === null || value === void 0 ? /* @__PURE__ */ jsx("span", {
|
|
1536
|
+
className: "text-text-disabled dark:text-text-disabled-dark italic text-[11px]",
|
|
1537
|
+
children: "NULL"
|
|
1538
|
+
}) : displayValue
|
|
1539
|
+
})
|
|
1540
|
+
});
|
|
1541
|
+
}, [
|
|
1542
|
+
getRowEntityActions,
|
|
1543
|
+
editingCell,
|
|
1544
|
+
handleCellSave,
|
|
1545
|
+
handleDoubleClick,
|
|
1546
|
+
sidePanelController,
|
|
1547
|
+
t
|
|
1548
|
+
]);
|
|
1597
1549
|
const renderResults = () => {
|
|
1598
1550
|
if (loading) return /* @__PURE__ */ jsx("div", {
|
|
1599
1551
|
className: "flex-grow flex items-center justify-center",
|
|
@@ -1617,17 +1569,10 @@ var SQLEditor = () => {
|
|
|
1617
1569
|
className: "flex-grow flex items-center justify-center text-text-disabled dark:text-text-disabled-dark",
|
|
1618
1570
|
children: /* @__PURE__ */ jsxs("div", {
|
|
1619
1571
|
className: "text-center",
|
|
1620
|
-
children: [/* @__PURE__ */ jsx(
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
viewBox: "0 0 24 24",
|
|
1625
|
-
children: /* @__PURE__ */ jsx("path", {
|
|
1626
|
-
strokeLinecap: "round",
|
|
1627
|
-
strokeLinejoin: "round",
|
|
1628
|
-
strokeWidth: 1,
|
|
1629
|
-
d: "M4 7v10c0 2.21 3.582 4 8 4s8-1.79 8-4V7M4 7c0 2.21 3.582 4 8 4s8-1.79 8-4M4 7c0-2.21 3.582-4 8-4s8 1.79 8 4m0 5c0 2.21-3.582 4-8 4s-8-1.79-8-4"
|
|
1630
|
-
})
|
|
1572
|
+
children: [/* @__PURE__ */ jsx(DatabaseIcon, {
|
|
1573
|
+
size: 48,
|
|
1574
|
+
strokeWidth: 1,
|
|
1575
|
+
className: "mx-auto mb-4 opacity-50"
|
|
1631
1576
|
}), /* @__PURE__ */ jsx(Typography, {
|
|
1632
1577
|
variant: "body2",
|
|
1633
1578
|
children: t("studio_sql_run_query_placeholder")
|
|
@@ -1639,8 +1584,9 @@ var SQLEditor = () => {
|
|
|
1639
1584
|
if (plan) return /* @__PURE__ */ jsxs("div", {
|
|
1640
1585
|
className: "flex-grow overflow-auto p-4 bg-surface-sheet flex flex-col items-start",
|
|
1641
1586
|
children: [/* @__PURE__ */ jsx(Typography, {
|
|
1642
|
-
variant: "
|
|
1643
|
-
|
|
1587
|
+
variant: "label",
|
|
1588
|
+
color: "secondary",
|
|
1589
|
+
className: "mb-4",
|
|
1644
1590
|
children: t("studio_sql_visual_execution_plan")
|
|
1645
1591
|
}), /* @__PURE__ */ jsx("div", {
|
|
1646
1592
|
className: "pb-12",
|
|
@@ -1662,37 +1608,6 @@ var SQLEditor = () => {
|
|
|
1662
1608
|
children: t("studio_sql_no_results")
|
|
1663
1609
|
})]
|
|
1664
1610
|
});
|
|
1665
|
-
const savedWidths = columnWidths[activeTab.sql] || {};
|
|
1666
|
-
const resultColumnKeys = Object.keys(results[0]);
|
|
1667
|
-
const actionableCollections = (() => {
|
|
1668
|
-
if (!activeTab.lastExecutedSql || !collectionRegistry.collections) return [];
|
|
1669
|
-
try {
|
|
1670
|
-
return resolveQueryCollections(activeTab.lastExecutedSql, schemas, collectionRegistry.collections, resultColumnKeys);
|
|
1671
|
-
} catch {
|
|
1672
|
-
return [];
|
|
1673
|
-
}
|
|
1674
|
-
})().filter((mc) => mc.pkColumn && resultColumnKeys.includes(mc.pkColumn));
|
|
1675
|
-
const getRowEntityActions = (rowData) => {
|
|
1676
|
-
if (!rowData) return [];
|
|
1677
|
-
return actionableCollections.filter((mc) => rowData[mc.pkColumn] != null).map((mc) => ({
|
|
1678
|
-
collection: mc,
|
|
1679
|
-
entityId: rowData[mc.pkColumn]
|
|
1680
|
-
}));
|
|
1681
|
-
};
|
|
1682
|
-
const dataColumns = resultColumnKeys.map((key) => ({
|
|
1683
|
-
key,
|
|
1684
|
-
title: key,
|
|
1685
|
-
width: savedWidths[key] ?? 150,
|
|
1686
|
-
sortable: false,
|
|
1687
|
-
resizable: true
|
|
1688
|
-
}));
|
|
1689
|
-
const columns = actionableCollections.length > 0 ? [{
|
|
1690
|
-
key: "__cms_action__",
|
|
1691
|
-
title: "",
|
|
1692
|
-
width: 36,
|
|
1693
|
-
sortable: false,
|
|
1694
|
-
resizable: false
|
|
1695
|
-
}, ...dataColumns] : dataColumns;
|
|
1696
1611
|
return /* @__PURE__ */ jsxs("div", {
|
|
1697
1612
|
className: "flex-grow flex flex-col overflow-hidden min-h-0",
|
|
1698
1613
|
children: [
|
|
@@ -1702,19 +1617,22 @@ var SQLEditor = () => {
|
|
|
1702
1617
|
title: t("studio_sql_admin_collections_tooltip"),
|
|
1703
1618
|
children: /* @__PURE__ */ jsx(Typography, {
|
|
1704
1619
|
variant: "caption",
|
|
1705
|
-
|
|
1620
|
+
color: "secondary",
|
|
1621
|
+
className: "mr-1 shrink-0 cursor-help",
|
|
1706
1622
|
children: t("studio_sql_collections_label")
|
|
1707
1623
|
})
|
|
1708
1624
|
}), /* @__PURE__ */ jsx("div", {
|
|
1709
1625
|
className: "flex items-center gap-1.5 overflow-x-auto no-scrollbar",
|
|
1710
1626
|
children: actionableCollections.map((mc) => /* @__PURE__ */ jsx(Tooltip, {
|
|
1711
1627
|
title: `Table "${mc.tableName}" → ${mc.collection.name} (PK: ${mc.pkColumn})`,
|
|
1712
|
-
children: /* @__PURE__ */
|
|
1713
|
-
|
|
1714
|
-
|
|
1628
|
+
children: /* @__PURE__ */ jsx(Chip, {
|
|
1629
|
+
size: "smallest",
|
|
1630
|
+
className: "whitespace-nowrap",
|
|
1631
|
+
icon: typeof mc.collection.icon === "string" ? /* @__PURE__ */ jsx(IconForView, {
|
|
1715
1632
|
collectionOrView: mc.collection,
|
|
1716
|
-
|
|
1717
|
-
}),
|
|
1633
|
+
size: "smallest"
|
|
1634
|
+
}) : void 0,
|
|
1635
|
+
children: mc.collection.name
|
|
1718
1636
|
})
|
|
1719
1637
|
}, mc.tableName))
|
|
1720
1638
|
})]
|
|
@@ -1723,89 +1641,12 @@ var SQLEditor = () => {
|
|
|
1723
1641
|
className: "flex-grow relative h-full min-h-0 min-w-0",
|
|
1724
1642
|
children: /* @__PURE__ */ jsx(VirtualTable, {
|
|
1725
1643
|
data: results,
|
|
1726
|
-
columns,
|
|
1644
|
+
columns: resultColumns,
|
|
1727
1645
|
rowHeight: 32,
|
|
1728
1646
|
headerHeight: 32,
|
|
1729
1647
|
extraData: editingCell,
|
|
1730
1648
|
onColumnResizeEnd: handleColumnResize,
|
|
1731
|
-
cellRenderer:
|
|
1732
|
-
if (column.key === "__cms_action__") {
|
|
1733
|
-
const rowActions = getRowEntityActions(rowData ?? {});
|
|
1734
|
-
if (rowActions.length === 0) return /* @__PURE__ */ jsx("div", { className: "h-full w-full" });
|
|
1735
|
-
if (rowActions.length === 1) {
|
|
1736
|
-
const ra = rowActions[0];
|
|
1737
|
-
return /* @__PURE__ */ jsx("div", {
|
|
1738
|
-
className: "h-full flex items-center justify-center",
|
|
1739
|
-
children: /* @__PURE__ */ jsx(Tooltip, {
|
|
1740
|
-
title: t("studio_sql_edit_entity", {
|
|
1741
|
-
name: ra.collection.collection.name,
|
|
1742
|
-
id: String(ra.entityId)
|
|
1743
|
-
}),
|
|
1744
|
-
children: /* @__PURE__ */ jsx(IconButton, {
|
|
1745
|
-
size: "small",
|
|
1746
|
-
className: "text-surface-400 dark:text-surface-500 hover:text-surface-600 dark:hover:text-surface-300 transition-colors",
|
|
1747
|
-
onClick: (e) => {
|
|
1748
|
-
e.stopPropagation();
|
|
1749
|
-
sidePanelController?.open({
|
|
1750
|
-
path: ra.collection.collection.slug,
|
|
1751
|
-
entityId: ra.entityId,
|
|
1752
|
-
collection: ra.collection.collection,
|
|
1753
|
-
updateUrl: false
|
|
1754
|
-
});
|
|
1755
|
-
},
|
|
1756
|
-
children: /* @__PURE__ */ jsx(PencilIcon, { size: iconSize.smallest })
|
|
1757
|
-
})
|
|
1758
|
-
})
|
|
1759
|
-
});
|
|
1760
|
-
}
|
|
1761
|
-
return /* @__PURE__ */ jsx("div", {
|
|
1762
|
-
className: "h-full flex items-center justify-center",
|
|
1763
|
-
children: /* @__PURE__ */ jsx(Menu, {
|
|
1764
|
-
trigger: /* @__PURE__ */ jsx(IconButton, {
|
|
1765
|
-
size: "small",
|
|
1766
|
-
className: "text-surface-400 dark:text-surface-500 hover:text-surface-600 dark:hover:text-surface-300 transition-colors",
|
|
1767
|
-
onClick: (e) => e.stopPropagation(),
|
|
1768
|
-
children: /* @__PURE__ */ jsx(MoreVerticalIcon, { size: iconSize.smallest })
|
|
1769
|
-
}),
|
|
1770
|
-
children: rowActions.map((ra) => /* @__PURE__ */ jsx(MenuItem, {
|
|
1771
|
-
dense: true,
|
|
1772
|
-
onClick: () => {
|
|
1773
|
-
sidePanelController?.open({
|
|
1774
|
-
path: ra.collection.collection.slug,
|
|
1775
|
-
entityId: ra.entityId,
|
|
1776
|
-
collection: ra.collection.collection,
|
|
1777
|
-
updateUrl: false
|
|
1778
|
-
});
|
|
1779
|
-
},
|
|
1780
|
-
children: t("studio_sql_edit_entity", {
|
|
1781
|
-
name: ra.collection.collection.name,
|
|
1782
|
-
id: String(ra.entityId)
|
|
1783
|
-
})
|
|
1784
|
-
}, ra.collection.tableName))
|
|
1785
|
-
})
|
|
1786
|
-
});
|
|
1787
|
-
}
|
|
1788
|
-
const isEditing = editingCell?.rowIndex === rowIndex && editingCell?.columnKey === column.key;
|
|
1789
|
-
const value = rowData ? rowData[column.key] : null;
|
|
1790
|
-
const displayValue = typeof value === "object" && value !== null ? JSON.stringify(value) : String(value ?? "");
|
|
1791
|
-
if (isEditing) return /* @__PURE__ */ jsx(FixedEditorOverlay, {
|
|
1792
|
-
displayValue,
|
|
1793
|
-
onSave: (val) => handleCellSave(val, rowData ?? {}, column.key, rowIndex),
|
|
1794
|
-
onCancel: () => setEditingCell(null)
|
|
1795
|
-
});
|
|
1796
|
-
return /* @__PURE__ */ jsx("div", {
|
|
1797
|
-
className: "px-4 py-1.5 h-full flex items-center whitespace-nowrap text-[13px] text-text-primary dark:text-text-primary-dark font-mono cursor-text group/cell",
|
|
1798
|
-
onDoubleClick: () => handleDoubleClick(rowIndex, column.key, displayValue, rowData ?? {}),
|
|
1799
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
1800
|
-
className: "truncate flex-grow",
|
|
1801
|
-
title: displayValue,
|
|
1802
|
-
children: displayValue === "" ? /* @__PURE__ */ jsx("span", {
|
|
1803
|
-
className: "text-text-disabled dark:text-text-disabled-dark italic text-[11px]",
|
|
1804
|
-
children: "NULL"
|
|
1805
|
-
}) : displayValue
|
|
1806
|
-
})
|
|
1807
|
-
});
|
|
1808
|
-
}
|
|
1649
|
+
cellRenderer: renderResultCell
|
|
1809
1650
|
})
|
|
1810
1651
|
}),
|
|
1811
1652
|
/* @__PURE__ */ jsxs("div", {
|
|
@@ -1813,21 +1654,25 @@ var SQLEditor = () => {
|
|
|
1813
1654
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
1814
1655
|
className: "flex space-x-4",
|
|
1815
1656
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
1816
|
-
className: "flex items-center
|
|
1817
|
-
children: [/* @__PURE__ */ jsx(
|
|
1818
|
-
|
|
1657
|
+
className: "flex items-center gap-2",
|
|
1658
|
+
children: [/* @__PURE__ */ jsx(Typography, {
|
|
1659
|
+
variant: "caption",
|
|
1660
|
+
color: "secondary",
|
|
1819
1661
|
children: t("studio_sql_rows")
|
|
1820
|
-
}), /* @__PURE__ */ jsx(
|
|
1821
|
-
|
|
1662
|
+
}), /* @__PURE__ */ jsx(Typography, {
|
|
1663
|
+
variant: "mono",
|
|
1664
|
+
className: "text-[11px]",
|
|
1822
1665
|
children: results.length
|
|
1823
1666
|
})]
|
|
1824
1667
|
}), /* @__PURE__ */ jsxs("div", {
|
|
1825
|
-
className: "flex items-center
|
|
1826
|
-
children: [/* @__PURE__ */ jsx(
|
|
1827
|
-
|
|
1668
|
+
className: "flex items-center gap-2",
|
|
1669
|
+
children: [/* @__PURE__ */ jsx(Typography, {
|
|
1670
|
+
variant: "caption",
|
|
1671
|
+
color: "secondary",
|
|
1828
1672
|
children: t("studio_sql_time")
|
|
1829
|
-
}), /* @__PURE__ */ jsxs(
|
|
1830
|
-
|
|
1673
|
+
}), /* @__PURE__ */ jsxs(Typography, {
|
|
1674
|
+
variant: "mono",
|
|
1675
|
+
className: "text-[11px]",
|
|
1831
1676
|
children: [execTime, "ms"]
|
|
1832
1677
|
})]
|
|
1833
1678
|
})]
|
|
@@ -1837,21 +1682,28 @@ var SQLEditor = () => {
|
|
|
1837
1682
|
/* @__PURE__ */ jsx(Button, {
|
|
1838
1683
|
size: "small",
|
|
1839
1684
|
variant: "text",
|
|
1840
|
-
className: "
|
|
1685
|
+
className: "whitespace-nowrap",
|
|
1841
1686
|
onClick: handleExportMarkdown,
|
|
1842
1687
|
children: t("studio_sql_copy_markdown")
|
|
1843
1688
|
}),
|
|
1844
1689
|
/* @__PURE__ */ jsx(Button, {
|
|
1845
1690
|
size: "small",
|
|
1846
1691
|
variant: "text",
|
|
1847
|
-
className: "
|
|
1692
|
+
className: "whitespace-nowrap",
|
|
1848
1693
|
onClick: handleExportJSON,
|
|
1849
1694
|
children: t("studio_sql_export_json")
|
|
1850
1695
|
}),
|
|
1696
|
+
typedColumns && /* @__PURE__ */ jsx(Button, {
|
|
1697
|
+
size: "small",
|
|
1698
|
+
variant: "text",
|
|
1699
|
+
className: "whitespace-nowrap",
|
|
1700
|
+
onClick: handleExportTypedJSON,
|
|
1701
|
+
children: t("studio_sql_export_json_typed")
|
|
1702
|
+
}),
|
|
1851
1703
|
/* @__PURE__ */ jsx(Button, {
|
|
1852
1704
|
size: "small",
|
|
1853
1705
|
variant: "text",
|
|
1854
|
-
className: "
|
|
1706
|
+
className: "whitespace-nowrap",
|
|
1855
1707
|
onClick: handleExportCSV,
|
|
1856
1708
|
children: t("studio_sql_export_csv")
|
|
1857
1709
|
})
|
|
@@ -1880,6 +1732,7 @@ var SQLEditor = () => {
|
|
|
1880
1732
|
className: "flex h-full w-full bg-surface-card overflow-hidden text-text-primary dark:text-text-primary-dark",
|
|
1881
1733
|
children: [
|
|
1882
1734
|
/* @__PURE__ */ jsx(ResizablePanels, {
|
|
1735
|
+
dividerAriaLabel: t("resize_sidebar"),
|
|
1883
1736
|
orientation: "horizontal",
|
|
1884
1737
|
panelSizePercent: sidebarSize,
|
|
1885
1738
|
onPanelSizeChange: setSidebarSize,
|
|
@@ -1949,6 +1802,7 @@ var SQLEditor = () => {
|
|
|
1949
1802
|
children: /* @__PURE__ */ jsx(IconButton, {
|
|
1950
1803
|
size: "small",
|
|
1951
1804
|
onClick: handlePrettify,
|
|
1805
|
+
"aria-label": t("studio_sql_format_sql"),
|
|
1952
1806
|
children: /* @__PURE__ */ jsx(MenuIcon, { size: iconSize.smallest })
|
|
1953
1807
|
})
|
|
1954
1808
|
}),
|
|
@@ -1998,17 +1852,10 @@ var SQLEditor = () => {
|
|
|
1998
1852
|
isFavorite: !s.isFavorite
|
|
1999
1853
|
} : s));
|
|
2000
1854
|
},
|
|
2001
|
-
children: /* @__PURE__ */ jsx(
|
|
2002
|
-
|
|
1855
|
+
children: /* @__PURE__ */ jsx(HeartIcon, {
|
|
1856
|
+
size: iconSize.smallest,
|
|
2003
1857
|
fill: isFavorite ? "currentColor" : "none",
|
|
2004
|
-
|
|
2005
|
-
strokeWidth: 2,
|
|
2006
|
-
viewBox: "0 0 24 24",
|
|
2007
|
-
children: /* @__PURE__ */ jsx("path", {
|
|
2008
|
-
strokeLinecap: "round",
|
|
2009
|
-
strokeLinejoin: "round",
|
|
2010
|
-
d: "M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z"
|
|
2011
|
-
})
|
|
1858
|
+
className: cls(isFavorite ? "text-red-500" : "text-text-disabled dark:text-text-disabled-dark hover:text-text-primary")
|
|
2012
1859
|
})
|
|
2013
1860
|
})
|
|
2014
1861
|
}),
|
|
@@ -2029,7 +1876,7 @@ var SQLEditor = () => {
|
|
|
2029
1876
|
className: "mr-1.5 text-text-disabled dark:text-text-disabled-dark"
|
|
2030
1877
|
}), /* @__PURE__ */ jsx("span", {
|
|
2031
1878
|
className: "max-w-[160px] truncate",
|
|
2032
|
-
children: isLoadingConfig ? "..." : `${selectedDatabase || t("studio_sql_select_db")}${selectedRole ? ` (${selectedRole})` : ""}`
|
|
1879
|
+
children: isLoadingConfig ? "..." : `${selectedDatabase || t("studio_sql_select_db")}${connectionOwner ?? selectedRole ? ` (${connectionOwner ?? selectedRole})` : ""}`
|
|
2033
1880
|
})]
|
|
2034
1881
|
}),
|
|
2035
1882
|
children: /* @__PURE__ */ jsxs("div", {
|
|
@@ -2062,8 +1909,13 @@ var SQLEditor = () => {
|
|
|
2062
1909
|
children: t("studio_sql_role")
|
|
2063
1910
|
})
|
|
2064
1911
|
}),
|
|
1912
|
+
connectionOwner && /* @__PURE__ */ jsx("div", {
|
|
1913
|
+
className: "px-3 py-1.5 text-xs text-text-secondary dark:text-text-secondary-dark max-w-[240px] break-words",
|
|
1914
|
+
children: t("studio_sql_role_switching_disabled", { role: connectionOwner })
|
|
1915
|
+
}),
|
|
2065
1916
|
availableRoles.map((role) => /* @__PURE__ */ jsxs(MenuItem, {
|
|
2066
1917
|
dense: true,
|
|
1918
|
+
disabled: connectionOwner !== null,
|
|
2067
1919
|
onClick: () => handleRoleChange(role),
|
|
2068
1920
|
className: cls("text-xs", selectedRole === role && "text-primary dark:text-primary-dark"),
|
|
2069
1921
|
children: [role, role === "postgres" ? " " + t("studio_sql_collections_label") : ""]
|
|
@@ -2083,10 +1935,20 @@ var SQLEditor = () => {
|
|
|
2083
1935
|
size: iconSize.smallest,
|
|
2084
1936
|
className: "mr-2"
|
|
2085
1937
|
}), t("studio_sql_run")]
|
|
1938
|
+
}),
|
|
1939
|
+
loading && cancellableTabs.has(activeTab.id) && /* @__PURE__ */ jsxs(Button, {
|
|
1940
|
+
onClick: handleCancelRun,
|
|
1941
|
+
size: "small",
|
|
1942
|
+
variant: "text",
|
|
1943
|
+
children: [/* @__PURE__ */ jsx(SquareIcon, {
|
|
1944
|
+
size: iconSize.smallest,
|
|
1945
|
+
className: "mr-2"
|
|
1946
|
+
}), t("studio_sql_cancel_run")]
|
|
2086
1947
|
})
|
|
2087
1948
|
]
|
|
2088
1949
|
})]
|
|
2089
1950
|
}), /* @__PURE__ */ jsx(ResizablePanels, {
|
|
1951
|
+
dividerAriaLabel: t("resize_editor"),
|
|
2090
1952
|
orientation: "vertical",
|
|
2091
1953
|
panelSizePercent: editorHeight,
|
|
2092
1954
|
onPanelSizeChange: setEditorHeight,
|
|
@@ -2103,17 +1965,57 @@ var SQLEditor = () => {
|
|
|
2103
1965
|
}),
|
|
2104
1966
|
secondPanel: /* @__PURE__ */ jsxs("div", {
|
|
2105
1967
|
className: "h-full w-full flex flex-col bg-surface-well overflow-hidden min-h-0",
|
|
2106
|
-
children: [
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
1968
|
+
children: [
|
|
1969
|
+
/* @__PURE__ */ jsx("div", {
|
|
1970
|
+
className: cls("p-2 px-4 bg-surface-raised border-b shrink-0 flex items-center", defaultBorderMixin),
|
|
1971
|
+
children: /* @__PURE__ */ jsx(Typography, {
|
|
1972
|
+
variant: "caption",
|
|
1973
|
+
className: "font-semibold text-text-disabled dark:text-text-disabled-dark uppercase tracking-widest text-[10px]",
|
|
1974
|
+
children: t("studio_sql_query_results")
|
|
1975
|
+
})
|
|
1976
|
+
}),
|
|
1977
|
+
!loading && results && activeTab.ranAs && activeTab.lastExecutedConnection?.role && activeTab.ranAs !== activeTab.lastExecutedConnection.role && /* @__PURE__ */ jsx("div", {
|
|
1978
|
+
className: "px-4 pt-2 shrink-0",
|
|
1979
|
+
children: /* @__PURE__ */ jsx(Alert, {
|
|
1980
|
+
color: "warning",
|
|
1981
|
+
size: "small",
|
|
1982
|
+
children: t("studio_sql_ran_as_other_role", {
|
|
1983
|
+
ranAs: activeTab.ranAs,
|
|
1984
|
+
role: activeTab.lastExecutedConnection.role
|
|
1985
|
+
})
|
|
1986
|
+
})
|
|
1987
|
+
}),
|
|
1988
|
+
!loading && results && activeTab.truncatedFrom !== null && /* @__PURE__ */ jsx("div", {
|
|
1989
|
+
className: "px-4 pt-2 shrink-0",
|
|
1990
|
+
children: /* @__PURE__ */ jsx(Alert, {
|
|
1991
|
+
color: "info",
|
|
1992
|
+
size: "small",
|
|
1993
|
+
action: activeTab.lastExecutedSql && apiBase ? /* @__PURE__ */ jsx(Button, {
|
|
1994
|
+
size: "small",
|
|
1995
|
+
variant: "text",
|
|
1996
|
+
disabled: downloadingFullResult,
|
|
1997
|
+
onClick: handleDownloadFullCsv,
|
|
1998
|
+
children: downloadingFullResult ? t("studio_sql_downloading_full_csv") : t("studio_sql_download_full_csv")
|
|
1999
|
+
}) : void 0,
|
|
2000
|
+
children: t("studio_sql_result_truncated", {
|
|
2001
|
+
shown: results.length.toLocaleString(),
|
|
2002
|
+
total: activeTab.truncatedFrom.toLocaleString()
|
|
2003
|
+
})
|
|
2004
|
+
})
|
|
2005
|
+
}),
|
|
2006
|
+
!loading && activeTab.notices.length > 0 && /* @__PURE__ */ jsx("div", {
|
|
2007
|
+
className: "px-4 pt-2 flex flex-col gap-1 shrink-0",
|
|
2008
|
+
children: activeTab.notices.map((notice, index) => /* @__PURE__ */ jsx(Alert, {
|
|
2009
|
+
color: "warning",
|
|
2010
|
+
size: "small",
|
|
2011
|
+
children: `${notice.severity}: ${notice.message}`
|
|
2012
|
+
}, index))
|
|
2013
|
+
}),
|
|
2014
|
+
/* @__PURE__ */ jsx("div", {
|
|
2015
|
+
className: "flex-grow flex flex-col min-h-0 overflow-hidden",
|
|
2016
|
+
children: renderResults()
|
|
2112
2017
|
})
|
|
2113
|
-
|
|
2114
|
-
className: "flex-grow flex flex-col min-h-0 overflow-hidden",
|
|
2115
|
-
children: renderResults()
|
|
2116
|
-
})]
|
|
2018
|
+
]
|
|
2117
2019
|
})
|
|
2118
2020
|
})]
|
|
2119
2021
|
})
|
|
@@ -2171,4 +2073,4 @@ var SQLEditor = () => {
|
|
|
2171
2073
|
//#endregion
|
|
2172
2074
|
export { SQLEditor };
|
|
2173
2075
|
|
|
2174
|
-
//# sourceMappingURL=SQLEditor-
|
|
2076
|
+
//# sourceMappingURL=SQLEditor-D5Ci4pyW.js.map
|