Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 6 additions & 18 deletions lib/features/erd/erd_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:flutter/material.dart' as material;
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart'
show Clipboard, ClipboardData, LogicalKeyboardKey;
import 'package:querya_desktop/core/database/table_mutation_engine.dart';
import 'package:querya_desktop/core/theme/querya_theme_scope.dart';
import 'package:querya_desktop/core/theme/querya_typography.dart';
import 'package:querya_desktop/features/erd/erd_canvas_controls.dart';
Expand All @@ -24,7 +23,6 @@ import 'package:querya_desktop/shared/widgets/querya_action_menu.dart';
import 'package:querya_desktop/shared/widgets/querya_empty_state.dart';
import 'package:querya_desktop/shared/widgets/querya_search_field.dart';
import 'package:querya_desktop/features/workspace/sql_editor_chrome.dart';
import 'package:querya_desktop/features/workspace/sql_execution_delegate.dart';
import 'package:querya_desktop/shared/widgets/querya_action_button.dart';
import 'package:querya_desktop/shared/widgets/querya_spinner.dart';
import 'package:shadcn_flutter/shadcn_flutter.dart';
Expand All @@ -51,29 +49,23 @@ enum _ExportAction { mermaid, svg, png, copyMermaid }
class ErdView extends material.StatefulWidget {
const ErdView({
super.key,
this.delegate,
this.dialect,
required this.source,
this.databaseName = '',
this.source,
this.focusTable,
this.neighbourhoodDepth,
this.onOpenTable,
this.onOpenFullDiagram,
this.onSaveFile,
}) : assert(source != null || (delegate != null && dialect != null));

/// Query runner and dialect, used when [source] is not given.
final SqlExecutionDelegate? delegate;
final SqlDialect? dialect;
});

/// Draw only [focusTable] and the tables within this many foreign keys.
final int? neighbourhoodDepth;

/// Opens the diagram's full schema, from a neighbourhood's empty state.
final material.VoidCallback? onOpenFullDiagram;

/// Where the tables come from; the delegate and dialect when omitted.
final ErdSource? source;
/// Where the tables come from.
final ErdSource source;

/// Table to pick and centre once the schema is drawn.
final String? focusTable;
Expand Down Expand Up @@ -155,8 +147,8 @@ class _ErdViewState extends material.State<ErdView> {
final depth = widget.neighbourhoodDepth;
final focus = widget.focusTable;
final schema = depth != null && focus != null
? await _source.loadNeighbourhood(focus, depth: depth)
: await _source.loadSchema();
? await widget.source.loadNeighbourhood(focus, depth: depth)
: await widget.source.loadSchema();
if (!mounted) return;
setState(() {
_schema = schema;
Expand Down Expand Up @@ -188,10 +180,6 @@ class _ErdViewState extends material.State<ErdView> {
: ErdRouter.route(_visibleOf(schema), layout);
}

ErdSource get _source =>
widget.source ??
SqlErdSource(delegate: widget.delegate!, dialect: widget.dialect!);

/// The focused table as named in [schema]: `public.orders` falls back to
/// `orders` when the current schema names it without a prefix.
String? _focusIn(ErdSchema schema) {
Expand Down
4 changes: 2 additions & 2 deletions lib/features/workspace/generic_sql_workspace.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:querya_desktop/core/storage/mutation_audit_recorder.dart';
import 'package:querya_desktop/core/actions/sql_editor_actions.dart';
import 'package:querya_desktop/core/actions/sql_editor_command_bridge.dart';
import 'package:querya_desktop/core/database/destructive_sql_detector.dart';
import 'package:querya_desktop/features/erd/erd_source.dart';
import 'package:querya_desktop/core/database/sql_table_target_extractor.dart';
import 'package:querya_desktop/core/database/table_mutation_engine.dart';
import 'package:querya_desktop/core/layout/vertical_split_pane.dart';
Expand Down Expand Up @@ -1179,8 +1180,7 @@ class GenericSqlWorkspaceState extends material.State<GenericSqlWorkspace> {
if (session.isDiagram) {
return ErdView(
key: material.ValueKey(session.id),
delegate: widget.delegate,
dialect: widget.dialect,
source: SqlErdSource(delegate: widget.delegate, dialect: widget.dialect),
databaseName: effectiveDatabase,
onOpenTable: _openTableFromDiagram,
);
Expand Down
26 changes: 12 additions & 14 deletions test/features/erd/erd_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:querya_desktop/features/erd/erd_layout.dart';
import 'package:querya_desktop/features/erd/erd_model.dart';
import 'package:querya_desktop/features/erd/erd_router.dart';
import 'package:querya_desktop/features/erd/erd_view.dart';
import 'package:querya_desktop/features/erd/erd_source.dart';
import 'package:querya_desktop/features/workspace/sql_execution_delegate.dart';

import '../../support/fake_sql_execution_delegate.dart';
Expand Down Expand Up @@ -489,8 +490,7 @@ void main() {
final saved = <String, Uint8List>{};
await t.pumpWidget(queryaThemeTestShell(
child: ErdView(
delegate: delegate(),
dialect: SqlDialect.sqlite,
source: SqlErdSource(delegate: delegate(), dialect: SqlDialect.sqlite),
onOpenTable: (n) => opened = n,
onSaveFile: (n, b) async => saved[n] = b,
),
Expand Down Expand Up @@ -528,7 +528,7 @@ void main() {
await t.binding.setSurfaceSize(const material.Size(1200, 800));
addTearDown(() => t.binding.setSurfaceSize(null));
await t.pumpWidget(queryaThemeTestShell(
child: ErdView(delegate: delegate(), dialect: SqlDialect.sqlite),
child: ErdView(source: SqlErdSource(delegate: delegate(), dialect: SqlDialect.sqlite)),
));
await t.pump();
await t.pump();
Expand Down Expand Up @@ -568,7 +568,7 @@ void main() {
]);
});
await t.pumpWidget(queryaThemeTestShell(
child: ErdView(delegate: junction, dialect: SqlDialect.sqlite),
child: ErdView(source: SqlErdSource(delegate: junction, dialect: SqlDialect.sqlite)),
));
await t.pump();
await t.pump();
Expand Down Expand Up @@ -613,7 +613,7 @@ void main() {
testWidgets('zoom buttons change the zoom label', (t) async {
await t.binding.setSurfaceSize(const material.Size(1200, 800));
await t.pumpWidget(queryaThemeTestShell(
child: ErdView(delegate: delegate(), dialect: SqlDialect.sqlite),
child: ErdView(source: SqlErdSource(delegate: delegate(), dialect: SqlDialect.sqlite)),
));
await t.pump();
await t.pump();
Expand All @@ -632,7 +632,7 @@ void main() {
(t) async {
await t.binding.setSurfaceSize(const material.Size(1200, 800));
await t.pumpWidget(queryaThemeTestShell(
child: ErdView(delegate: threeTables(), dialect: SqlDialect.sqlite),
child: ErdView(source: SqlErdSource(delegate: threeTables(), dialect: SqlDialect.sqlite)),
));
await t.pump();
await t.pump();
Expand All @@ -652,7 +652,7 @@ void main() {
(t) async {
await t.binding.setSurfaceSize(const material.Size(1200, 800));
await t.pumpWidget(queryaThemeTestShell(
child: ErdView(delegate: threeTables(), dialect: SqlDialect.sqlite),
child: ErdView(source: SqlErdSource(delegate: threeTables(), dialect: SqlDialect.sqlite)),
));
await t.pump();
await t.pump();
Expand Down Expand Up @@ -693,7 +693,7 @@ void main() {
]);
});
await t.pumpWidget(queryaThemeTestShell(
child: ErdView(delegate: wide, dialect: SqlDialect.sqlite),
child: ErdView(source: SqlErdSource(delegate: wide, dialect: SqlDialect.sqlite)),
));
await t.pump();
await t.pump();
Expand All @@ -712,9 +712,8 @@ void main() {
testWidgets('a failed load shows a titled state with Retry', (t) async {
await t.pumpWidget(queryaThemeTestShell(
child: ErdView(
delegate: FakeSqlExecutionDelegate(
onExecute: (sql) => throw StateError('no access')),
dialect: SqlDialect.sqlite,
source: SqlErdSource(delegate: FakeSqlExecutionDelegate(
onExecute: (sql) => throw StateError('no access')), dialect: SqlDialect.sqlite),
),
));
await t.pump();
Expand All @@ -726,9 +725,8 @@ void main() {
testWidgets('shows empty state', (t) async {
await t.pumpWidget(queryaThemeTestShell(
child: ErdView(
delegate: FakeSqlExecutionDelegate(
onExecute: (_) => const SqlExecutionResult()),
dialect: SqlDialect.postgres,
source: SqlErdSource(delegate: FakeSqlExecutionDelegate(
onExecute: (_) => const SqlExecutionResult()), dialect: SqlDialect.postgres),
),
));
await t.pump();
Expand Down
Loading