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
14 changes: 14 additions & 0 deletions lib/features/mongodb/mongo_collections_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ class MongoCollectionsView extends material.StatefulWidget {
required this.connection,
required this.database,
this.onCollectionTap,
this.onOpenQueryConsole,
this.refreshToken = 0,
});

final MongoConnection connection;
final String database;
final ValueChanged<String>? onCollectionTap;
final material.VoidCallback? onOpenQueryConsole;

/// Incremented by the parent when the user requests a refresh (toolbar).
final int refreshToken;
Expand Down Expand Up @@ -302,6 +304,18 @@ class _MongoCollectionsViewState extends material.State<MongoCollectionsView> {
],
),
),
if (widget.onOpenQueryConsole != null) ...[
OutlineButton(
onPressed: widget.onOpenQueryConsole,
size: ButtonSize.small,
leading: const material.Icon(
material.Icons.terminal_rounded,
size: 14,
),
child: const Text('MQL Console'),
),
const Gap(8),
],
material.SizedBox(
width: 180,
child: TextField(
Expand Down
14 changes: 14 additions & 0 deletions lib/features/mongodb/mongo_documents_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class MongoDocumentsView extends material.StatefulWidget {
this.onDocumentTap,
this.onOpenAggregation,
this.onOpenIndexes,
this.onOpenQueryConsole,
this.refreshToken = 0,
this.initialViewMode,
});
Expand All @@ -57,6 +58,7 @@ class MongoDocumentsView extends material.StatefulWidget {
final ValueChanged<Map<String, dynamic>>? onDocumentTap;
final material.VoidCallback? onOpenAggregation;
final material.VoidCallback? onOpenIndexes;
final material.VoidCallback? onOpenQueryConsole;

/// Incremented by the parent when the user requests a refresh (toolbar).
final int refreshToken;
Expand Down Expand Up @@ -552,6 +554,18 @@ class _MongoDocumentsViewState extends material.State<MongoDocumentsView> {
child: const Text('Indexes'),
),
],
if (widget.onOpenQueryConsole != null) ...[
const Gap(8),
OutlineButton(
onPressed: widget.onOpenQueryConsole,
size: ButtonSize.small,
leading: const material.Icon(
material.Icons.terminal_rounded,
size: 14,
),
child: const Text('Console'),
),
],
const Gap(12),
PrimaryButton(
onPressed: _addDocument,
Expand Down
34 changes: 32 additions & 2 deletions lib/features/mongodb/mongo_explorer_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'mongo_databases_view.dart';
import 'mongo_documents_view.dart';
import 'mongo_document_editor.dart';
import 'mongo_indexes_view.dart';
import 'mongo_query_workspace.dart';
import 'mongo_stats_view.dart';

// ─── Navigation path model ──────────────────────────────────────────────────
Expand All @@ -34,6 +35,7 @@ enum _Level {
stats,
aggregation,
indexes,
queryConsole,
}

// ─── Main explorer widget ───────────────────────────────────────────────────
Expand Down Expand Up @@ -64,6 +66,7 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
bool _showStats = false;
bool _showAggregation = false;
bool _showIndexes = false;
bool _showQueryConsole = false;

/// Bumped when the user taps Refresh in the breadcrumb bar (reload active view).
int _refreshToken = 0;
Expand Down Expand Up @@ -169,6 +172,7 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
_selectedDocument = null;
_showAggregation = false;
_showIndexes = false;
_showQueryConsole = false;
});
}

Expand All @@ -179,6 +183,7 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
_selectedDocument = null;
_showAggregation = false;
_showIndexes = false;
_showQueryConsole = false;
});
}

Expand All @@ -187,6 +192,7 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
_selectedDocument = doc;
_showAggregation = false;
_showIndexes = false;
_showQueryConsole = false;
});
}

Expand All @@ -197,6 +203,7 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
_selectedDocument = null;
_showAggregation = false;
_showIndexes = false;
_showQueryConsole = false;
});
}

Expand All @@ -206,6 +213,7 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
_selectedDocument = null;
_showAggregation = false;
_showIndexes = false;
_showQueryConsole = false;
});
}

Expand All @@ -214,6 +222,7 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
_selectedDocument = null;
_showAggregation = false;
_showIndexes = false;
_showQueryConsole = false;
});
}

Expand All @@ -233,7 +242,9 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
final id = _selectedDocument!['_id']?.toString() ?? 'Document';
list.add(_Crumb(id, _Level.document));
}
if (_showIndexes) {
if (_showQueryConsole) {
list.add(const _Crumb('MQL Console', _Level.queryConsole));
} else if (_showIndexes) {
list.add(const _Crumb('Indexes', _Level.indexes));
} else if (_showAggregation) {
list.add(const _Crumb('Aggregation', _Level.aggregation));
Expand All @@ -248,7 +259,8 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
crumb.level != _Level.document &&
crumb.level != _Level.stats &&
crumb.level != _Level.aggregation &&
crumb.level != _Level.indexes;
crumb.level != _Level.indexes &&
crumb.level != _Level.queryConsole;
if (leavesDocument) {
if (!await confirmDiscardUnsavedWorkIfNeeded(context)) return;
if (!mounted) return;
Expand All @@ -262,6 +274,9 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
if (_showIndexes && crumb.level != _Level.indexes) {
setState(() => _showIndexes = false);
}
if (_showQueryConsole && crumb.level != _Level.queryConsole) {
setState(() => _showQueryConsole = false);
}
switch (crumb.level) {
case _Level.databases:
_navigateToDatabases();
Expand All @@ -277,6 +292,8 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
break;
case _Level.indexes:
break;
case _Level.queryConsole:
break;
}
}

Expand Down Expand Up @@ -428,6 +445,17 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
);
}

// Query Console workspace
if (_showQueryConsole && _selectedDatabase != null) {
return MongoQueryWorkspace(
key: ValueKey('mql_${_selectedDatabase}_$_selectedCollection'),
connection: conn,
database: _selectedDatabase!,
initialCollection: _selectedCollection,
onBack: () => setState(() => _showQueryConsole = false),
);
}

// Documents list
if (_selectedCollection != null && _selectedDatabase != null) {
return MongoDocumentsView(
Expand All @@ -439,6 +467,7 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
onDocumentTap: _navigateToDocument,
onOpenAggregation: () => setState(() => _showAggregation = true),
onOpenIndexes: () => setState(() => _showIndexes = true),
onOpenQueryConsole: () => setState(() => _showQueryConsole = true),
);
}

Expand All @@ -450,6 +479,7 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
database: _selectedDatabase!,
refreshToken: _refreshToken,
onCollectionTap: _navigateToCollection,
onOpenQueryConsole: () => setState(() => _showQueryConsole = true),
);
}

Expand Down
Loading
Loading