@rebasepro/studio 0.30.1 → 0.31.0-canary.g902a0ce
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/{ApiKeysView-Bqf6XYR1.js → ApiKeysView-9ZvwMPyh.js} +16 -6
- package/dist/ApiKeysView-9ZvwMPyh.js.map +1 -0
- package/dist/{JSEditor-DCnPXsx6.js → JSEditor-ojAVSkaU.js} +158 -100
- package/dist/JSEditor-ojAVSkaU.js.map +1 -0
- package/dist/{RLSEditor-zAat58U0.js → RLSEditor-BAwkENpj.js} +394 -206
- package/dist/RLSEditor-BAwkENpj.js.map +1 -0
- package/dist/{SQLEditor-DV_VEEpL.js → SQLEditor-DX9LfbU7.js} +10 -8
- package/dist/SQLEditor-DX9LfbU7.js.map +1 -0
- package/dist/{SchemaVisualizer-pCYQ_Ds6.js → SchemaVisualizer-C75TENPm.js} +196 -189
- package/dist/SchemaVisualizer-C75TENPm.js.map +1 -0
- package/dist/components/JSEditor/JSEditorSidebar.d.ts +3 -6
- package/dist/components/JSEditor/JSMonacoEditor.d.ts +10 -10
- package/dist/components/JSEditor/table_access.d.ts +39 -0
- package/dist/components/RLSEditor/policy-presets.d.ts +1 -1
- package/dist/components/RLSEditor/policyListing.d.ts +32 -12
- package/dist/components/RLSEditor/policyRules.d.ts +32 -14
- package/dist/components/RLSEditor/saveRules.d.ts +48 -18
- package/dist/components/RLSEditor/saveSecurityRules.d.ts +5 -4
- package/dist/components/SchemaVisualizer/useSchemaGraph.d.ts +13 -8
- package/dist/components/schema-source.d.ts +37 -0
- package/dist/index.es.js +9 -9
- package/dist/index.es.js.map +1 -1
- package/dist/schema-source-C4ekB7WU.js +93 -0
- package/dist/schema-source-C4ekB7WU.js.map +1 -0
- package/dist/{sql_utils-DXvmxiCq.js → sql_utils-CYcgpgam.js} +14 -12
- package/dist/sql_utils-CYcgpgam.js.map +1 -0
- package/dist/utils/sql_utils.d.ts +14 -10
- package/package.json +9 -9
- package/dist/ApiKeysView-Bqf6XYR1.js.map +0 -1
- package/dist/JSEditor-DCnPXsx6.js.map +0 -1
- package/dist/RLSEditor-zAat58U0.js.map +0 -1
- package/dist/SQLEditor-DV_VEEpL.js.map +0 -1
- package/dist/SchemaVisualizer-pCYQ_Ds6.js.map +0 -1
- package/dist/sql_utils-DXvmxiCq.js.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as SchemaSourceProblemView, r as schemaSourceProblem } from "./schema-source-C4ekB7WU.js";
|
|
2
|
+
import { IconForView, useRebaseContext, useTableDescriptors, useTranslation } from "@rebasepro/app";
|
|
2
3
|
import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
4
|
import { Chip, CircularProgress, IconButton, ResizablePanels, SearchBar, ToggleButtonGroup, Tooltip, Typography, cls, defaultBorderMixin, useIsDarkMode } from "@rebasepro/ui";
|
|
4
5
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
-
import {
|
|
6
|
-
import { getTableName, resolveCollectionRelations } from "@rebasepro/common";
|
|
6
|
+
import { columnTypeLabel } from "@rebasepro/types";
|
|
7
7
|
import { Background, BackgroundVariant, BaseEdge, Controls, EdgeLabelRenderer, Handle, MarkerType, MiniMap, Position, ReactFlow, ReactFlowProvider, applyEdgeChanges, applyNodeChanges, getSmoothStepPath, useReactFlow } from "@xyflow/react";
|
|
8
8
|
import "@xyflow/react/dist/style.css";
|
|
9
9
|
import dagre from "dagre";
|
|
@@ -201,66 +201,83 @@ var getCardinalityLabel = (cardinality, direction) => {
|
|
|
201
201
|
};
|
|
202
202
|
//#endregion
|
|
203
203
|
//#region src/components/SchemaVisualizer/useSchemaGraph.ts
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
204
|
+
function enumValuesOf(column) {
|
|
205
|
+
if (column.type.kind === "enum") return [...column.type.values];
|
|
206
|
+
if (column.oneOf) return column.oneOf.map(String);
|
|
207
|
+
}
|
|
208
|
+
var columnInfo = (column) => {
|
|
209
|
+
const enumValues = enumValuesOf(column);
|
|
210
|
+
return {
|
|
211
|
+
name: column.column,
|
|
212
|
+
key: column.key,
|
|
213
|
+
type: column.type.kind,
|
|
214
|
+
typeLabel: columnTypeLabel(column.type),
|
|
215
|
+
isPrimaryKey: column.primaryKey === true,
|
|
216
|
+
isForeignKey: column.foreignKeyOf !== void 0,
|
|
217
|
+
isRequired: !column.nullable,
|
|
218
|
+
isUnique: column.unique === true,
|
|
219
|
+
isEnum: enumValues !== void 0,
|
|
220
|
+
...enumValues ? { enumValues } : {},
|
|
221
|
+
...column.foreignKeyOf !== void 0 ? { relationName: column.foreignKeyOf } : {}
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* Every column the server serves, in physical order. A `belongsTo` whose key
|
|
226
|
+
* column was withheld from this caller still names its column, so the edge
|
|
227
|
+
* has a handle to leave from.
|
|
228
|
+
*/
|
|
229
|
+
var extractColumns = (table) => {
|
|
230
|
+
const columns = table.columns.map(columnInfo);
|
|
231
|
+
for (const relation of table.relations) {
|
|
232
|
+
if (relation.kind !== "belongsTo") continue;
|
|
233
|
+
const existing = columns.find((c) => c.name === relation.localKey);
|
|
234
|
+
if (existing) {
|
|
235
|
+
existing.isForeignKey = true;
|
|
236
|
+
existing.relationName = relation.name;
|
|
237
|
+
continue;
|
|
216
238
|
}
|
|
217
239
|
columns.push({
|
|
218
|
-
name:
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
isPrimaryKey: isPk,
|
|
222
|
-
isForeignKey: false,
|
|
223
|
-
isRequired: Boolean(prop.validation?.required),
|
|
224
|
-
isEnum,
|
|
225
|
-
enumValues
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
if (isPostgresCollectionConfig(collection)) try {
|
|
229
|
-
const resolvedRelations = resolveCollectionRelations(collection);
|
|
230
|
-
for (const rel of Object.values(resolvedRelations)) if (rel.kind === "belongsTo" && rel.localKey) if (!columns.some((c) => c.name === rel.localKey)) columns.push({
|
|
231
|
-
name: rel.localKey,
|
|
232
|
-
type: "number",
|
|
240
|
+
name: relation.localKey,
|
|
241
|
+
key: relation.localField,
|
|
242
|
+
type: "foreignKey",
|
|
233
243
|
typeLabel: "FK",
|
|
234
244
|
isPrimaryKey: false,
|
|
235
245
|
isForeignKey: true,
|
|
236
246
|
isRequired: false,
|
|
247
|
+
isUnique: false,
|
|
237
248
|
isEnum: false,
|
|
238
|
-
relationName:
|
|
249
|
+
relationName: relation.name
|
|
239
250
|
});
|
|
240
|
-
|
|
241
|
-
const existing = columns.find((c) => c.name === rel.localKey);
|
|
242
|
-
if (existing) {
|
|
243
|
-
existing.isForeignKey = true;
|
|
244
|
-
existing.relationName = rel.relationName;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
} catch {}
|
|
251
|
+
}
|
|
248
252
|
return columns;
|
|
249
253
|
};
|
|
250
|
-
|
|
254
|
+
/** The integer type a column that points at a serial key holds. */
|
|
255
|
+
var SERIAL_REFERENCE = {
|
|
256
|
+
smallserial: { kind: "smallint" },
|
|
257
|
+
serial: { kind: "integer" },
|
|
258
|
+
bigserial: { kind: "bigint" }
|
|
259
|
+
};
|
|
260
|
+
/** The type label of a junction column: the type of the key it points at (a serial's integer). */
|
|
261
|
+
function keyTypeLabel(table) {
|
|
262
|
+
const key = table?.columns.find((column) => column.primaryKey === true);
|
|
263
|
+
if (!key) return "FK";
|
|
264
|
+
return columnTypeLabel(SERIAL_REFERENCE[key.type.kind] ?? key.type);
|
|
265
|
+
}
|
|
266
|
+
var buildGraph = (tables, liveRls) => {
|
|
251
267
|
/**
|
|
252
268
|
* Is RLS on for this table?
|
|
253
269
|
*
|
|
254
270
|
* The database is the authority whenever we could reach it. Declaring rules
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
271
|
+
* is not the same as having them applied — see `useLiveRlsTables`. Only
|
|
272
|
+
* when there is no SQL capability do we fall back to the declaration:
|
|
273
|
+
* every declared table's posture enables RLS.
|
|
258
274
|
*/
|
|
259
|
-
const isRlsEnabled = (schema, tableName,
|
|
275
|
+
const isRlsEnabled = (schema, tableName, declared) => liveRls ? liveRls.has(`${schema}.${tableName}`) : declared;
|
|
260
276
|
const nodes = [];
|
|
261
277
|
const edges = [];
|
|
262
278
|
const tableToNodeId = /* @__PURE__ */ new Map();
|
|
263
279
|
const nodeColumns = /* @__PURE__ */ new Map();
|
|
280
|
+
const bySlug = new Map(tables.map((table) => [table.slug, table]));
|
|
264
281
|
const getPkHandle = (nodeId) => {
|
|
265
282
|
const pk = nodeColumns.get(nodeId)?.find((c) => c.isPrimaryKey);
|
|
266
283
|
return pk ? `target-${pk.name}` : "target-default";
|
|
@@ -270,23 +287,21 @@ var buildGraph = (collections, liveRls) => {
|
|
|
270
287
|
const fk = nodeColumns.get(nodeId)?.find((c) => c.name === localKey);
|
|
271
288
|
return fk ? `source-${fk.name}` : "source-default";
|
|
272
289
|
};
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
const columns = extractColumns(collection);
|
|
290
|
+
const drawn = tables.filter((table) => table.kind === "table");
|
|
291
|
+
for (const table of drawn) {
|
|
292
|
+
const nodeId = `table-${table.table}`;
|
|
293
|
+
tableToNodeId.set(table.slug, nodeId);
|
|
294
|
+
const columns = extractColumns(table);
|
|
279
295
|
nodeColumns.set(nodeId, columns);
|
|
280
296
|
const nodeData = {
|
|
281
|
-
tableName,
|
|
282
|
-
collectionName:
|
|
283
|
-
slug:
|
|
297
|
+
tableName: table.table,
|
|
298
|
+
collectionName: table.name,
|
|
299
|
+
slug: table.slug,
|
|
284
300
|
columns,
|
|
285
301
|
isJunction: false,
|
|
286
302
|
isUnmanaged: false,
|
|
287
|
-
rlsEnabled: isRlsEnabled(
|
|
288
|
-
historyEnabled:
|
|
289
|
-
icon: typeof collection.icon === "string" ? collection.icon : void 0
|
|
303
|
+
rlsEnabled: isRlsEnabled(table.schema, table.table, true),
|
|
304
|
+
historyEnabled: table.history === true
|
|
290
305
|
};
|
|
291
306
|
nodes.push({
|
|
292
307
|
id: nodeId,
|
|
@@ -299,114 +314,28 @@ var buildGraph = (collections, liveRls) => {
|
|
|
299
314
|
});
|
|
300
315
|
}
|
|
301
316
|
const processedJunctions = /* @__PURE__ */ new Set();
|
|
302
|
-
for (const
|
|
303
|
-
|
|
304
|
-
const tableName = getTableName(collection);
|
|
305
|
-
const sourceNodeId = tableToNodeId.get(tableName);
|
|
317
|
+
for (const table of drawn) {
|
|
318
|
+
const sourceNodeId = tableToNodeId.get(table.slug);
|
|
306
319
|
if (!sourceNodeId) continue;
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
resolvedRelations = resolveCollectionRelations(collection);
|
|
310
|
-
} catch {
|
|
311
|
-
continue;
|
|
312
|
-
}
|
|
313
|
-
for (const [relationKey, rel] of Object.entries(resolvedRelations)) {
|
|
314
|
-
let targetCollection;
|
|
315
|
-
try {
|
|
316
|
-
targetCollection = rel.target();
|
|
317
|
-
} catch {
|
|
318
|
-
continue;
|
|
319
|
-
}
|
|
320
|
-
if (!isPostgresCollectionConfig(targetCollection)) continue;
|
|
321
|
-
const targetTable = getTableName(targetCollection);
|
|
322
|
-
const targetNodeId = tableToNodeId.get(targetTable);
|
|
320
|
+
for (const rel of table.relations) {
|
|
321
|
+
const targetNodeId = tableToNodeId.get(rel.target);
|
|
323
322
|
if (!targetNodeId) continue;
|
|
324
323
|
if (rel.kind !== "belongsTo" && rel.kind !== "manyToMany") continue;
|
|
325
324
|
const direction = "owning";
|
|
326
325
|
const edgeData = {
|
|
327
326
|
cardinality: rel.cardinality,
|
|
328
327
|
direction,
|
|
329
|
-
relationName: rel.
|
|
328
|
+
relationName: rel.name,
|
|
330
329
|
hasJunction: rel.kind === "manyToMany",
|
|
331
330
|
hasJoinPath: false,
|
|
332
331
|
label: getCardinalityLabel(rel.cardinality, direction)
|
|
333
332
|
};
|
|
334
|
-
if (rel.kind === "manyToMany"
|
|
333
|
+
if (rel.kind === "manyToMany") {
|
|
334
|
+
if (processedJunctions.has(rel.through.table)) continue;
|
|
335
335
|
processedJunctions.add(rel.through.table);
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
type: "number",
|
|
340
|
-
typeLabel: "FK",
|
|
341
|
-
isPrimaryKey: true,
|
|
342
|
-
isForeignKey: true,
|
|
343
|
-
isRequired: true,
|
|
344
|
-
isEnum: false
|
|
345
|
-
}, {
|
|
346
|
-
name: rel.through.targetColumn,
|
|
347
|
-
type: "number",
|
|
348
|
-
typeLabel: "FK",
|
|
349
|
-
isPrimaryKey: true,
|
|
350
|
-
isForeignKey: true,
|
|
351
|
-
isRequired: true,
|
|
352
|
-
isEnum: false
|
|
353
|
-
}];
|
|
354
|
-
nodeColumns.set(junctionNodeId, junctionColumns);
|
|
355
|
-
nodes.push({
|
|
356
|
-
id: junctionNodeId,
|
|
357
|
-
type: "tableNode",
|
|
358
|
-
position: {
|
|
359
|
-
x: 0,
|
|
360
|
-
y: 0
|
|
361
|
-
},
|
|
362
|
-
data: {
|
|
363
|
-
tableName: rel.through.table,
|
|
364
|
-
collectionName: rel.through.table,
|
|
365
|
-
slug: rel.through.table,
|
|
366
|
-
columns: junctionColumns,
|
|
367
|
-
isJunction: true,
|
|
368
|
-
isUnmanaged: false,
|
|
369
|
-
rlsEnabled: isRlsEnabled("public", rel.through.table, false),
|
|
370
|
-
historyEnabled: false
|
|
371
|
-
}
|
|
372
|
-
});
|
|
373
|
-
const sourcePk = nodeColumns.get(sourceNodeId)?.find((c) => c.isPrimaryKey);
|
|
374
|
-
edges.push({
|
|
375
|
-
id: `edge-${sourceNodeId}-${junctionNodeId}`,
|
|
376
|
-
source: sourceNodeId,
|
|
377
|
-
target: junctionNodeId,
|
|
378
|
-
sourceHandle: sourcePk ? `source-${sourcePk.name}` : "source-default",
|
|
379
|
-
targetHandle: `target-${rel.through.sourceColumn}`,
|
|
380
|
-
type: "relationEdge",
|
|
381
|
-
data: {
|
|
382
|
-
...edgeData,
|
|
383
|
-
label: "1:N"
|
|
384
|
-
},
|
|
385
|
-
markerEnd: {
|
|
386
|
-
type: MarkerType.ArrowClosed,
|
|
387
|
-
width: 16,
|
|
388
|
-
height: 16
|
|
389
|
-
}
|
|
390
|
-
});
|
|
391
|
-
edges.push({
|
|
392
|
-
id: `edge-${junctionNodeId}-${targetNodeId}`,
|
|
393
|
-
source: junctionNodeId,
|
|
394
|
-
target: targetNodeId,
|
|
395
|
-
sourceHandle: `source-${rel.through.targetColumn}`,
|
|
396
|
-
targetHandle: getPkHandle(targetNodeId),
|
|
397
|
-
type: "relationEdge",
|
|
398
|
-
data: {
|
|
399
|
-
...edgeData,
|
|
400
|
-
label: "N:1"
|
|
401
|
-
},
|
|
402
|
-
markerEnd: {
|
|
403
|
-
type: MarkerType.ArrowClosed,
|
|
404
|
-
width: 16,
|
|
405
|
-
height: 16
|
|
406
|
-
}
|
|
407
|
-
});
|
|
408
|
-
} else if (rel.kind === "belongsTo") edges.push({
|
|
409
|
-
id: `edge-${sourceNodeId}-${targetNodeId}-${relationKey}`,
|
|
336
|
+
drawJunction(table, rel, sourceNodeId, targetNodeId, edgeData);
|
|
337
|
+
} else edges.push({
|
|
338
|
+
id: `edge-${sourceNodeId}-${targetNodeId}-${rel.name}`,
|
|
410
339
|
source: sourceNodeId,
|
|
411
340
|
target: targetNodeId,
|
|
412
341
|
sourceHandle: getFkHandle(sourceNodeId, rel.localKey),
|
|
@@ -421,6 +350,88 @@ var buildGraph = (collections, liveRls) => {
|
|
|
421
350
|
});
|
|
422
351
|
}
|
|
423
352
|
}
|
|
353
|
+
function drawJunction(table, rel, sourceNodeId, targetNodeId, edgeData) {
|
|
354
|
+
const junctionNodeId = `junction-${rel.through.table}`;
|
|
355
|
+
const junctionColumns = [
|
|
356
|
+
{
|
|
357
|
+
name: rel.through.sourceKey,
|
|
358
|
+
key: rel.through.sourceKey,
|
|
359
|
+
type: "foreignKey",
|
|
360
|
+
typeLabel: keyTypeLabel(table),
|
|
361
|
+
isPrimaryKey: true,
|
|
362
|
+
isForeignKey: true,
|
|
363
|
+
isRequired: true,
|
|
364
|
+
isUnique: false,
|
|
365
|
+
isEnum: false
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
name: rel.through.targetKey,
|
|
369
|
+
key: rel.through.targetKey,
|
|
370
|
+
type: "foreignKey",
|
|
371
|
+
typeLabel: keyTypeLabel(bySlug.get(rel.target)),
|
|
372
|
+
isPrimaryKey: true,
|
|
373
|
+
isForeignKey: true,
|
|
374
|
+
isRequired: true,
|
|
375
|
+
isUnique: false,
|
|
376
|
+
isEnum: false
|
|
377
|
+
},
|
|
378
|
+
...rel.through.pivot.map(columnInfo)
|
|
379
|
+
];
|
|
380
|
+
nodeColumns.set(junctionNodeId, junctionColumns);
|
|
381
|
+
nodes.push({
|
|
382
|
+
id: junctionNodeId,
|
|
383
|
+
type: "tableNode",
|
|
384
|
+
position: {
|
|
385
|
+
x: 0,
|
|
386
|
+
y: 0
|
|
387
|
+
},
|
|
388
|
+
data: {
|
|
389
|
+
tableName: rel.through.table,
|
|
390
|
+
collectionName: rel.through.table,
|
|
391
|
+
slug: rel.through.table,
|
|
392
|
+
columns: junctionColumns,
|
|
393
|
+
isJunction: true,
|
|
394
|
+
isUnmanaged: false,
|
|
395
|
+
rlsEnabled: isRlsEnabled(table.schema, rel.through.table, true),
|
|
396
|
+
historyEnabled: false
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
const sourcePk = nodeColumns.get(sourceNodeId)?.find((c) => c.isPrimaryKey);
|
|
400
|
+
edges.push({
|
|
401
|
+
id: `edge-${sourceNodeId}-${junctionNodeId}`,
|
|
402
|
+
source: sourceNodeId,
|
|
403
|
+
target: junctionNodeId,
|
|
404
|
+
sourceHandle: sourcePk ? `source-${sourcePk.name}` : "source-default",
|
|
405
|
+
targetHandle: `target-${rel.through.sourceKey}`,
|
|
406
|
+
type: "relationEdge",
|
|
407
|
+
data: {
|
|
408
|
+
...edgeData,
|
|
409
|
+
label: "1:N"
|
|
410
|
+
},
|
|
411
|
+
markerEnd: {
|
|
412
|
+
type: MarkerType.ArrowClosed,
|
|
413
|
+
width: 16,
|
|
414
|
+
height: 16
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
edges.push({
|
|
418
|
+
id: `edge-${junctionNodeId}-${targetNodeId}`,
|
|
419
|
+
source: junctionNodeId,
|
|
420
|
+
target: targetNodeId,
|
|
421
|
+
sourceHandle: `source-${rel.through.targetKey}`,
|
|
422
|
+
targetHandle: getPkHandle(targetNodeId),
|
|
423
|
+
type: "relationEdge",
|
|
424
|
+
data: {
|
|
425
|
+
...edgeData,
|
|
426
|
+
label: "N:1"
|
|
427
|
+
},
|
|
428
|
+
markerEnd: {
|
|
429
|
+
type: MarkerType.ArrowClosed,
|
|
430
|
+
width: 16,
|
|
431
|
+
height: 16
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
}
|
|
424
435
|
return {
|
|
425
436
|
nodes,
|
|
426
437
|
edges
|
|
@@ -507,10 +518,10 @@ var EMPTY_GRAPH = {
|
|
|
507
518
|
edges: []
|
|
508
519
|
};
|
|
509
520
|
var NO_POSITIONS = {};
|
|
510
|
-
var useSchemaGraph = (
|
|
521
|
+
var useSchemaGraph = (descriptors, liveRls = null, focus = null, depth = 1) => {
|
|
511
522
|
const [version, setVersion] = useState(0);
|
|
512
523
|
const relayout = useCallback(() => setVersion((v) => v + 1), []);
|
|
513
|
-
const graph = useMemo(() =>
|
|
524
|
+
const graph = useMemo(() => descriptors && descriptors.length > 0 ? buildGraph(descriptors, liveRls) : EMPTY_GRAPH, [descriptors, liveRls]);
|
|
514
525
|
const tables = graph.nodes.filter((node) => !isJunctionNode(node)).length;
|
|
515
526
|
const focused = tables > 300 ? (focus && graph.nodes.some((node) => node.id === focus) ? focus : mostConnectedTable(graph)) ?? null : null;
|
|
516
527
|
const drawn = useMemo(() => focused ? neighbourhoodOf(graph, focused, depth) : graph, [
|
|
@@ -907,14 +918,14 @@ var RelationEdge = memo(RelationEdgeInner);
|
|
|
907
918
|
//#region src/components/SchemaVisualizer/SchemaVisualizer.tsx
|
|
908
919
|
var nodeTypes = { tableNode: TableNode };
|
|
909
920
|
var edgeTypes = { relationEdge: RelationEdge };
|
|
910
|
-
function SchemaVisualizerCanvas({
|
|
921
|
+
function SchemaVisualizerCanvas({ tables }) {
|
|
911
922
|
const { t } = useTranslation();
|
|
912
923
|
const reactFlowInstance = useReactFlow();
|
|
913
924
|
const liveRls = useLiveRlsTables();
|
|
914
925
|
const isDark = useIsDarkMode();
|
|
915
926
|
const [focus, setFocus] = useState(null);
|
|
916
927
|
const [depth, setDepth] = useState(1);
|
|
917
|
-
const { nodes: layoutedNodes, edges: layoutedEdges, allNodes, relayout, tableCount, relationCount, layingOut, neighbourhood } = useSchemaGraph(
|
|
928
|
+
const { nodes: layoutedNodes, edges: layoutedEdges, allNodes, relayout, tableCount, relationCount, layingOut, neighbourhood } = useSchemaGraph(tables, liveRls, focus, depth);
|
|
918
929
|
const [nodes, setNodes] = useState([]);
|
|
919
930
|
const [edges, setEdges] = useState([]);
|
|
920
931
|
const [selectedTable, setSelectedTable] = useState(null);
|
|
@@ -998,15 +1009,15 @@ function SchemaVisualizerCanvas({ collections }) {
|
|
|
998
1009
|
localStorage.setItem("rebase_schema_viz_sidebar_size", sidebarSize.toString());
|
|
999
1010
|
} catch {}
|
|
1000
1011
|
}, [sidebarSize]);
|
|
1001
|
-
const
|
|
1002
|
-
const
|
|
1003
|
-
if (!searchQuery.trim()) return
|
|
1012
|
+
const drawnTables = useMemo(() => tables.filter((table) => table.kind === "table"), [tables]);
|
|
1013
|
+
const filteredTables = useMemo(() => {
|
|
1014
|
+
if (!searchQuery.trim()) return drawnTables;
|
|
1004
1015
|
const q = searchQuery.toLowerCase();
|
|
1005
|
-
return
|
|
1006
|
-
}, [
|
|
1016
|
+
return drawnTables.filter((table) => table.name.toLowerCase().includes(q) || table.table.toLowerCase().includes(q) || table.slug.toLowerCase().includes(q));
|
|
1017
|
+
}, [drawnTables, searchQuery]);
|
|
1007
1018
|
const junctionNodes = useMemo(() => allNodes.filter((n) => n.data.isJunction), [allNodes]);
|
|
1008
1019
|
/**
|
|
1009
|
-
* The RLS answer for one
|
|
1020
|
+
* The RLS answer for one table, from the same place the graph used.
|
|
1010
1021
|
*
|
|
1011
1022
|
* The graph's nodes already carry it, so look it up there rather than
|
|
1012
1023
|
* re-deriving — that is what kept the sidebar dots, the node badges and the
|
|
@@ -1014,7 +1025,7 @@ function SchemaVisualizerCanvas({ collections }) {
|
|
|
1014
1025
|
* draws a neighbourhood, and the list shows every table.
|
|
1015
1026
|
*/
|
|
1016
1027
|
const rlsByNodeId = useMemo(() => new Map(allNodes.map((n) => [n.id, Boolean(n.data.rlsEnabled)])), [allNodes]);
|
|
1017
|
-
const rlsEnabledFor = useCallback((
|
|
1028
|
+
const rlsEnabledFor = useCallback((table) => rlsByNodeId.get(`table-${table.table}`) ?? false, [rlsByNodeId]);
|
|
1018
1029
|
const focusName = useMemo(() => {
|
|
1019
1030
|
const node = neighbourhood ? allNodes.find((n) => n.id === neighbourhood.focus) : void 0;
|
|
1020
1031
|
return node ? node.data.collectionName : "";
|
|
@@ -1064,8 +1075,8 @@ function SchemaVisualizerCanvas({ collections }) {
|
|
|
1064
1075
|
className: "flex-grow overflow-y-auto no-scrollbar p-1",
|
|
1065
1076
|
children: [/* @__PURE__ */ jsx("div", {
|
|
1066
1077
|
className: "space-y-0.5",
|
|
1067
|
-
children:
|
|
1068
|
-
const table =
|
|
1078
|
+
children: filteredTables.map((descriptor) => {
|
|
1079
|
+
const table = descriptor.table;
|
|
1069
1080
|
const nodeId = `table-${table}`;
|
|
1070
1081
|
return /* @__PURE__ */ jsxs("div", {
|
|
1071
1082
|
onClick: () => handleTableSelect(nodeId),
|
|
@@ -1075,9 +1086,8 @@ function SchemaVisualizerCanvas({ collections }) {
|
|
|
1075
1086
|
className: "shrink-0 mr-1.5 text-text-disabled dark:text-text-disabled-dark",
|
|
1076
1087
|
children: /* @__PURE__ */ jsx(IconForView, {
|
|
1077
1088
|
collectionOrView: {
|
|
1078
|
-
slug:
|
|
1079
|
-
name:
|
|
1080
|
-
icon: typeof collection.icon === "string" ? collection.icon : void 0
|
|
1089
|
+
slug: descriptor.slug,
|
|
1090
|
+
name: descriptor.name
|
|
1081
1091
|
},
|
|
1082
1092
|
size: "smallest"
|
|
1083
1093
|
})
|
|
@@ -1087,8 +1097,8 @@ function SchemaVisualizerCanvas({ collections }) {
|
|
|
1087
1097
|
children: [/* @__PURE__ */ jsx(Typography, {
|
|
1088
1098
|
variant: "caption",
|
|
1089
1099
|
className: "text-xs truncate font-medium",
|
|
1090
|
-
children:
|
|
1091
|
-
}), table !==
|
|
1100
|
+
children: descriptor.name
|
|
1101
|
+
}), table !== descriptor.name && /* @__PURE__ */ jsx(Typography, {
|
|
1092
1102
|
variant: "caption",
|
|
1093
1103
|
className: "text-[10px] text-text-disabled dark:text-text-disabled-dark font-mono truncate",
|
|
1094
1104
|
children: table
|
|
@@ -1096,10 +1106,10 @@ function SchemaVisualizerCanvas({ collections }) {
|
|
|
1096
1106
|
}),
|
|
1097
1107
|
/* @__PURE__ */ jsxs("div", {
|
|
1098
1108
|
className: "flex items-center gap-1 shrink-0 ml-1",
|
|
1099
|
-
children: [rlsEnabledFor(
|
|
1109
|
+
children: [rlsEnabledFor(descriptor) && /* @__PURE__ */ jsx(Tooltip, {
|
|
1100
1110
|
title: "RLS enabled",
|
|
1101
1111
|
children: /* @__PURE__ */ jsx("div", { className: "w-1.5 h-1.5 rounded-full bg-green-500" })
|
|
1102
|
-
}),
|
|
1112
|
+
}), descriptor.history && /* @__PURE__ */ jsx(Tooltip, {
|
|
1103
1113
|
title: "History enabled",
|
|
1104
1114
|
children: /* @__PURE__ */ jsx("div", { className: "w-1.5 h-1.5 rounded-full bg-blue-400" })
|
|
1105
1115
|
})]
|
|
@@ -1390,30 +1400,27 @@ function SchemaVisualizerCanvas({ collections }) {
|
|
|
1390
1400
|
}
|
|
1391
1401
|
var SchemaVisualizer = () => {
|
|
1392
1402
|
const { t } = useTranslation();
|
|
1393
|
-
const
|
|
1403
|
+
const descriptors = useTableDescriptors();
|
|
1404
|
+
const problem = schemaSourceProblem(descriptors);
|
|
1405
|
+
if (problem && descriptors.tables.length === 0) return /* @__PURE__ */ jsx(SchemaSourceProblemView, { problem });
|
|
1394
1406
|
/**
|
|
1395
|
-
*
|
|
1396
|
-
* the same spinner for both. A project that declares no
|
|
1397
|
-
* fresh scaffold, a backend
|
|
1398
|
-
*
|
|
1399
|
-
* coming.
|
|
1400
|
-
*
|
|
1401
|
-
* `undefined` is the Studio bridge before the admin's collection registry
|
|
1402
|
-
* has registered itself: genuinely still loading. `[]` is that registry
|
|
1403
|
-
* saying there is nothing to draw.
|
|
1407
|
+
* Still loading and nothing to draw are different answers, and this view
|
|
1408
|
+
* once rendered the same spinner for both. A project that declares no
|
|
1409
|
+
* tables — a fresh scaffold, a backend someone opened the console against
|
|
1410
|
+
* — sat on "Loading schema…" forever, because there was nothing coming.
|
|
1404
1411
|
*/
|
|
1405
|
-
if (
|
|
1412
|
+
if (descriptors.status === "loading") return /* @__PURE__ */ jsx("div", {
|
|
1406
1413
|
className: "flex items-center justify-center h-full w-full",
|
|
1407
1414
|
children: /* @__PURE__ */ jsxs("div", {
|
|
1408
1415
|
className: "text-center space-y-3",
|
|
1409
1416
|
children: [/* @__PURE__ */ jsx(CircularProgress, { size: "small" }), /* @__PURE__ */ jsx(Typography, {
|
|
1410
1417
|
variant: "body2",
|
|
1411
1418
|
color: "secondary",
|
|
1412
|
-
children: "
|
|
1419
|
+
children: t("studio_schema_loading")
|
|
1413
1420
|
})]
|
|
1414
1421
|
})
|
|
1415
1422
|
});
|
|
1416
|
-
if (
|
|
1423
|
+
if (!descriptors.tables.some((table) => table.kind === "table")) return /* @__PURE__ */ jsx("div", {
|
|
1417
1424
|
className: "flex items-center justify-center h-full w-full p-6",
|
|
1418
1425
|
children: /* @__PURE__ */ jsxs("div", {
|
|
1419
1426
|
className: "max-w-md text-center space-y-2",
|
|
@@ -1421,13 +1428,13 @@ var SchemaVisualizer = () => {
|
|
|
1421
1428
|
/* @__PURE__ */ jsx(Typography, {
|
|
1422
1429
|
variant: "subtitle2",
|
|
1423
1430
|
className: "block",
|
|
1424
|
-
children: t("
|
|
1431
|
+
children: t("studio_schema_no_tables_declared")
|
|
1425
1432
|
}),
|
|
1426
1433
|
/* @__PURE__ */ jsx(Typography, {
|
|
1427
1434
|
variant: "body2",
|
|
1428
1435
|
color: "secondary",
|
|
1429
1436
|
className: "block",
|
|
1430
|
-
children: t("
|
|
1437
|
+
children: t("studio_schema_no_tables_declared_body")
|
|
1431
1438
|
}),
|
|
1432
1439
|
/* @__PURE__ */ jsx(Typography, {
|
|
1433
1440
|
variant: "body2",
|
|
@@ -1440,10 +1447,10 @@ var SchemaVisualizer = () => {
|
|
|
1440
1447
|
});
|
|
1441
1448
|
return /* @__PURE__ */ jsx("div", {
|
|
1442
1449
|
className: "flex h-full w-full bg-surface-card overflow-hidden text-text-primary dark:text-text-primary-dark",
|
|
1443
|
-
children: /* @__PURE__ */ jsx(ReactFlowProvider, { children: /* @__PURE__ */ jsx(SchemaVisualizerCanvas, {
|
|
1450
|
+
children: /* @__PURE__ */ jsx(ReactFlowProvider, { children: /* @__PURE__ */ jsx(SchemaVisualizerCanvas, { tables: descriptors.tables }) })
|
|
1444
1451
|
});
|
|
1445
1452
|
};
|
|
1446
1453
|
//#endregion
|
|
1447
1454
|
export { SchemaVisualizer };
|
|
1448
1455
|
|
|
1449
|
-
//# sourceMappingURL=SchemaVisualizer-
|
|
1456
|
+
//# sourceMappingURL=SchemaVisualizer-C75TENPm.js.map
|