Skip to content

Commit efd1136

Browse files
Merge pull request #1079 from QueryaHub/issue/1030-mongo-query-console
feat(mongodb): MQL Query & Shell Console (#1030)
2 parents 3c8dce2 + 104bf7d commit efd1136

8 files changed

Lines changed: 1949 additions & 2 deletions

‎lib/features/mongodb/mongo_collections_view.dart‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ class MongoCollectionsView extends material.StatefulWidget {
1717
required this.connection,
1818
required this.database,
1919
this.onCollectionTap,
20+
this.onOpenQueryConsole,
2021
this.refreshToken = 0,
2122
});
2223

2324
final MongoConnection connection;
2425
final String database;
2526
final ValueChanged<String>? onCollectionTap;
27+
final material.VoidCallback? onOpenQueryConsole;
2628

2729
/// Incremented by the parent when the user requests a refresh (toolbar).
2830
final int refreshToken;
@@ -302,6 +304,18 @@ class _MongoCollectionsViewState extends material.State<MongoCollectionsView> {
302304
],
303305
),
304306
),
307+
if (widget.onOpenQueryConsole != null) ...[
308+
OutlineButton(
309+
onPressed: widget.onOpenQueryConsole,
310+
size: ButtonSize.small,
311+
leading: const material.Icon(
312+
material.Icons.terminal_rounded,
313+
size: 14,
314+
),
315+
child: const Text('MQL Console'),
316+
),
317+
const Gap(8),
318+
],
305319
material.SizedBox(
306320
width: 180,
307321
child: TextField(

‎lib/features/mongodb/mongo_documents_view.dart‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class MongoDocumentsView extends material.StatefulWidget {
4747
this.onDocumentTap,
4848
this.onOpenAggregation,
4949
this.onOpenIndexes,
50+
this.onOpenQueryConsole,
5051
this.refreshToken = 0,
5152
this.initialViewMode,
5253
});
@@ -57,6 +58,7 @@ class MongoDocumentsView extends material.StatefulWidget {
5758
final ValueChanged<Map<String, dynamic>>? onDocumentTap;
5859
final material.VoidCallback? onOpenAggregation;
5960
final material.VoidCallback? onOpenIndexes;
61+
final material.VoidCallback? onOpenQueryConsole;
6062

6163
/// Incremented by the parent when the user requests a refresh (toolbar).
6264
final int refreshToken;
@@ -552,6 +554,18 @@ class _MongoDocumentsViewState extends material.State<MongoDocumentsView> {
552554
child: const Text('Indexes'),
553555
),
554556
],
557+
if (widget.onOpenQueryConsole != null) ...[
558+
const Gap(8),
559+
OutlineButton(
560+
onPressed: widget.onOpenQueryConsole,
561+
size: ButtonSize.small,
562+
leading: const material.Icon(
563+
material.Icons.terminal_rounded,
564+
size: 14,
565+
),
566+
child: const Text('Console'),
567+
),
568+
],
555569
const Gap(12),
556570
PrimaryButton(
557571
onPressed: _addDocument,

‎lib/features/mongodb/mongo_explorer_view.dart‎

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import 'mongo_databases_view.dart';
1515
import 'mongo_documents_view.dart';
1616
import 'mongo_document_editor.dart';
1717
import 'mongo_indexes_view.dart';
18+
import 'mongo_query_workspace.dart';
1819
import 'mongo_stats_view.dart';
1920

2021
// ─── Navigation path model ──────────────────────────────────────────────────
@@ -34,6 +35,7 @@ enum _Level {
3435
stats,
3536
aggregation,
3637
indexes,
38+
queryConsole,
3739
}
3840

3941
// ─── Main explorer widget ───────────────────────────────────────────────────
@@ -64,6 +66,7 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
6466
bool _showStats = false;
6567
bool _showAggregation = false;
6668
bool _showIndexes = false;
69+
bool _showQueryConsole = false;
6770

6871
/// Bumped when the user taps Refresh in the breadcrumb bar (reload active view).
6972
int _refreshToken = 0;
@@ -169,6 +172,7 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
169172
_selectedDocument = null;
170173
_showAggregation = false;
171174
_showIndexes = false;
175+
_showQueryConsole = false;
172176
});
173177
}
174178

@@ -179,6 +183,7 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
179183
_selectedDocument = null;
180184
_showAggregation = false;
181185
_showIndexes = false;
186+
_showQueryConsole = false;
182187
});
183188
}
184189

@@ -187,6 +192,7 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
187192
_selectedDocument = doc;
188193
_showAggregation = false;
189194
_showIndexes = false;
195+
_showQueryConsole = false;
190196
});
191197
}
192198

@@ -197,6 +203,7 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
197203
_selectedDocument = null;
198204
_showAggregation = false;
199205
_showIndexes = false;
206+
_showQueryConsole = false;
200207
});
201208
}
202209

@@ -206,6 +213,7 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
206213
_selectedDocument = null;
207214
_showAggregation = false;
208215
_showIndexes = false;
216+
_showQueryConsole = false;
209217
});
210218
}
211219

@@ -214,6 +222,7 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
214222
_selectedDocument = null;
215223
_showAggregation = false;
216224
_showIndexes = false;
225+
_showQueryConsole = false;
217226
});
218227
}
219228

@@ -233,7 +242,9 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
233242
final id = _selectedDocument!['_id']?.toString() ?? 'Document';
234243
list.add(_Crumb(id, _Level.document));
235244
}
236-
if (_showIndexes) {
245+
if (_showQueryConsole) {
246+
list.add(const _Crumb('MQL Console', _Level.queryConsole));
247+
} else if (_showIndexes) {
237248
list.add(const _Crumb('Indexes', _Level.indexes));
238249
} else if (_showAggregation) {
239250
list.add(const _Crumb('Aggregation', _Level.aggregation));
@@ -248,7 +259,8 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
248259
crumb.level != _Level.document &&
249260
crumb.level != _Level.stats &&
250261
crumb.level != _Level.aggregation &&
251-
crumb.level != _Level.indexes;
262+
crumb.level != _Level.indexes &&
263+
crumb.level != _Level.queryConsole;
252264
if (leavesDocument) {
253265
if (!await confirmDiscardUnsavedWorkIfNeeded(context)) return;
254266
if (!mounted) return;
@@ -262,6 +274,9 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
262274
if (_showIndexes && crumb.level != _Level.indexes) {
263275
setState(() => _showIndexes = false);
264276
}
277+
if (_showQueryConsole && crumb.level != _Level.queryConsole) {
278+
setState(() => _showQueryConsole = false);
279+
}
265280
switch (crumb.level) {
266281
case _Level.databases:
267282
_navigateToDatabases();
@@ -277,6 +292,8 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
277292
break;
278293
case _Level.indexes:
279294
break;
295+
case _Level.queryConsole:
296+
break;
280297
}
281298
}
282299

@@ -428,6 +445,17 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
428445
);
429446
}
430447

448+
// Query Console workspace
449+
if (_showQueryConsole && _selectedDatabase != null) {
450+
return MongoQueryWorkspace(
451+
key: ValueKey('mql_${_selectedDatabase}_$_selectedCollection'),
452+
connection: conn,
453+
database: _selectedDatabase!,
454+
initialCollection: _selectedCollection,
455+
onBack: () => setState(() => _showQueryConsole = false),
456+
);
457+
}
458+
431459
// Documents list
432460
if (_selectedCollection != null && _selectedDatabase != null) {
433461
return MongoDocumentsView(
@@ -439,6 +467,7 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
439467
onDocumentTap: _navigateToDocument,
440468
onOpenAggregation: () => setState(() => _showAggregation = true),
441469
onOpenIndexes: () => setState(() => _showIndexes = true),
470+
onOpenQueryConsole: () => setState(() => _showQueryConsole = true),
442471
);
443472
}
444473

@@ -450,6 +479,7 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
450479
database: _selectedDatabase!,
451480
refreshToken: _refreshToken,
452481
onCollectionTap: _navigateToCollection,
482+
onOpenQueryConsole: () => setState(() => _showQueryConsole = true),
453483
);
454484
}
455485

0 commit comments

Comments
 (0)