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
4 changes: 4 additions & 0 deletions lib/features/main_screen/main_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1562,7 +1562,11 @@ class _MainContentSplitState extends State<_MainContentSplit>
lastSelectedExtensionObject:
ws.lastSelectedExtensionObject,
lastSelectedMongoDb: ws.lastSelectedMongoDb,
lastSelectedMongoCollection:
ws.lastSelectedMongoCollection,
lastSelectedRedisDb: ws.lastSelectedRedisDb,
selectedRedisKey: ws.selectedRedisKey,
lastSelectedRedisKey: ws.lastSelectedRedisKey,
onNavigateHome: () {
widget.workspace.value =
widget.workspace.value.unselectActiveObject();
Expand Down
32 changes: 30 additions & 2 deletions lib/features/main_screen/main_screen_workspace_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ class MainScreenWorkspaceState {
this.lastSelectedExtensionObject,
this.lastSelectedMongoDb,
this.lastSelectedMongoCollection,
this.selectedRedisKey,
this.lastSelectedRedisDb,
this.lastSelectedRedisKey,
this.isReadOnly = false,
});

final ConnectionRow? activeConnection;
final int? activeRedisDb;
final String? selectedRedisKey;
final String? activeMongoDB;
final String? selectedMongoCollection;
final ({
Expand Down Expand Up @@ -104,6 +107,9 @@ class MainScreenWorkspaceState {
/// Last Redis database index opened for 1-click return from server stats.
final int? lastSelectedRedisDb;

/// Last Redis key opened for 1-click return from server stats.
final String? lastSelectedRedisKey;

final bool isReadOnly;

static const empty = MainScreenWorkspaceState();
Expand All @@ -112,6 +118,7 @@ class MainScreenWorkspaceState {
return MainScreenWorkspaceState(
activeConnection: activeConnection,
activeRedisDb: activeRedisDb,
selectedRedisKey: selectedRedisKey,
activeMongoDB: activeMongoDB,
selectedMongoCollection: selectedMongoCollection,
selectedPostgresObject: selectedPostgresObject,
Expand All @@ -130,6 +137,7 @@ class MainScreenWorkspaceState {
lastSelectedMongoDb: lastSelectedMongoDb,
lastSelectedMongoCollection: lastSelectedMongoCollection,
lastSelectedRedisDb: lastSelectedRedisDb,
lastSelectedRedisKey: lastSelectedRedisKey,
isReadOnly: !isReadOnly,
);
}
Expand All @@ -139,6 +147,7 @@ class MainScreenWorkspaceState {
return MainScreenWorkspaceState(
activeConnection: connection,
activeRedisDb: null,
selectedRedisKey: null,
activeMongoDB: null,
selectedMongoCollection: null,
selectedPostgresObject: null,
Expand All @@ -165,6 +174,8 @@ class MainScreenWorkspaceState {
same ? (selectedMongoCollection ?? lastSelectedMongoCollection) : null,
lastSelectedRedisDb:
same ? (activeRedisDb ?? lastSelectedRedisDb) : null,
lastSelectedRedisKey:
same ? (selectedRedisKey ?? lastSelectedRedisKey) : null,
isReadOnly: false,
);
}
Expand All @@ -175,6 +186,7 @@ class MainScreenWorkspaceState {
return MainScreenWorkspaceState(
activeConnection: activeConnection,
activeRedisDb: null,
selectedRedisKey: null,
activeMongoDB: null,
selectedMongoCollection: null,
selectedPostgresObject: null,
Expand All @@ -198,6 +210,7 @@ class MainScreenWorkspaceState {
lastSelectedMongoCollection:
selectedMongoCollection ?? lastSelectedMongoCollection,
lastSelectedRedisDb: activeRedisDb ?? lastSelectedRedisDb,
lastSelectedRedisKey: selectedRedisKey ?? lastSelectedRedisKey,
isReadOnly: isReadOnly,
);
}
Expand Down Expand Up @@ -256,7 +269,11 @@ class MainScreenWorkspaceState {
break;
case 'redis':
if (lastSelectedRedisDb != null) {
return selectRedisDb(conn, lastSelectedRedisDb!);
return selectRedisDb(
conn,
lastSelectedRedisDb!,
key: lastSelectedRedisKey,
);
}
break;
default:
Expand Down Expand Up @@ -408,10 +425,15 @@ class MainScreenWorkspaceState {
);
}

MainScreenWorkspaceState selectRedisDb(ConnectionRow connection, int db) {
MainScreenWorkspaceState selectRedisDb(
ConnectionRow connection,
int db, {
String? key,
}) {
return MainScreenWorkspaceState(
activeConnection: connection,
activeRedisDb: db,
selectedRedisKey: key,
activeMongoDB: null,
selectedPostgresObject: null,
postgresSqlTabRequestToken: postgresSqlTabRequestToken,
Expand All @@ -428,6 +450,8 @@ class MainScreenWorkspaceState {
lastSelectedMongoDb: null,
lastSelectedMongoCollection: null,
lastSelectedRedisDb: db,
lastSelectedRedisKey:
key ?? (db == lastSelectedRedisDb ? lastSelectedRedisKey : null),
isReadOnly: isReadOnly,
);
}
Expand Down Expand Up @@ -607,6 +631,7 @@ class MainScreenWorkspaceState {
return other is MainScreenWorkspaceState &&
activeConnection?.id == other.activeConnection?.id &&
activeRedisDb == other.activeRedisDb &&
selectedRedisKey == other.selectedRedisKey &&
activeMongoDB == other.activeMongoDB &&
selectedMongoCollection == other.selectedMongoCollection &&
_pgEquals(selectedPostgresObject, other.selectedPostgresObject) &&
Expand All @@ -627,13 +652,15 @@ class MainScreenWorkspaceState {
lastSelectedMongoDb == other.lastSelectedMongoDb &&
lastSelectedMongoCollection == other.lastSelectedMongoCollection &&
lastSelectedRedisDb == other.lastSelectedRedisDb &&
lastSelectedRedisKey == other.lastSelectedRedisKey &&
isReadOnly == other.isReadOnly;
}

@override
int get hashCode => Object.hashAll([
activeConnection?.id,
activeRedisDb,
selectedRedisKey,
activeMongoDB,
selectedMongoCollection,
selectedPostgresObject == null
Expand Down Expand Up @@ -705,6 +732,7 @@ class MainScreenWorkspaceState {
lastSelectedMongoDb,
lastSelectedMongoCollection,
lastSelectedRedisDb,
lastSelectedRedisKey,
isReadOnly,
]);
}
Expand Down
15 changes: 15 additions & 0 deletions lib/features/main_screen/workspace_panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ class WorkspacePanel extends StatefulWidget {
this.lastSelectedSqliteObject,
this.lastSelectedExtensionObject,
this.lastSelectedMongoDb,
this.lastSelectedMongoCollection,
this.lastSelectedRedisDb,
this.selectedRedisKey,
this.lastSelectedRedisKey,
this.onNavigateHome,
this.onRestoreLastSelectedObject,
this.isReadOnly = false,
Expand Down Expand Up @@ -164,9 +167,18 @@ class WorkspacePanel extends StatefulWidget {
/// Last MongoDB database for 1-click return from stats.
final String? lastSelectedMongoDb;

/// Last MongoDB collection for 1-click return from stats.
final String? lastSelectedMongoCollection;

/// Last Redis database index for 1-click return from stats.
final int? lastSelectedRedisDb;

/// Currently selected Redis key, if any.
final String? selectedRedisKey;

/// Last Redis key for 1-click return from stats.
final String? lastSelectedRedisKey;

/// Collection to open in [MongoExplorerView] after Quick Switcher jump.
final String? initialMongoCollection;

Expand Down Expand Up @@ -320,6 +332,7 @@ class _WorkspacePanelState extends State<WorkspacePanel> {
key: ValueKey('mongo_stats_${activeConn.id}'),
connectionRow: activeConn,
lastSelectedMongoDb: widget.lastSelectedMongoDb,
lastSelectedMongoCollection: widget.lastSelectedMongoCollection,
onRestoreLastSelectedObject: widget.onRestoreLastSelectedObject,
),
object: mongoDb == null
Expand All @@ -341,6 +354,7 @@ class _WorkspacePanelState extends State<WorkspacePanel> {
key: ValueKey('redis_stats_${activeConn.id}'),
connectionRow: activeConn,
lastSelectedRedisDb: widget.lastSelectedRedisDb,
lastSelectedRedisKey: widget.lastSelectedRedisKey,
onRestoreLastSelectedObject: widget.onRestoreLastSelectedObject,
),
object: redisDb == null
Expand All @@ -349,6 +363,7 @@ class _WorkspacePanelState extends State<WorkspacePanel> {
key: ValueKey('redis_${activeConn.id}_db_$redisDb'),
connectionRow: activeConn,
database: redisDb,
initialKey: widget.selectedRedisKey,
isReadOnly: widget.isReadOnly,
),
);
Expand Down
21 changes: 21 additions & 0 deletions lib/features/mongodb/mongo_explorer_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
// Navigation state
String? _selectedDatabase;
String? _selectedCollection;
String? _lastSelectedCollection;
Map<String, dynamic>? _selectedDocument;

@override
Expand All @@ -75,6 +76,7 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
}
if (widget.initialCollection != null) {
_selectedCollection = widget.initialCollection;
_lastSelectedCollection = widget.initialCollection;
}
}

Expand Down Expand Up @@ -159,6 +161,7 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
void _navigateToCollection(String collName) {
setState(() {
_selectedCollection = collName;
_lastSelectedCollection = collName;
_selectedDocument = null;
});
}
Expand Down Expand Up @@ -310,6 +313,24 @@ class _MongoExplorerViewState extends material.State<MongoExplorerView> {
key: ValueKey('stats_${widget.connectionRow.id}'),
connectionRow: widget.connectionRow,
connection: conn,
lastSelectedMongoDb: _selectedDatabase,
lastSelectedMongoCollection:
_selectedCollection ?? _lastSelectedCollection,
onRestoreLastSelectedObject:
(_selectedCollection ?? _lastSelectedCollection) != null
? () {
setState(() {
_showStats = false;
if (_selectedCollection == null &&
_lastSelectedCollection != null) {
_navigateToCollection(
_lastSelectedCollection!);
}
});
}
: (_selectedDatabase != null
? () => setState(() => _showStats = false)
: null),
onBack: () => setState(() => _showStats = false),
),
],
Expand Down
73 changes: 51 additions & 22 deletions lib/features/mongodb/mongo_stats_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class MongoStatsView extends material.StatefulWidget {
this.connection,
this.onBack,
this.lastSelectedMongoDb,
this.lastSelectedMongoCollection,
this.onRestoreLastSelectedObject,
});

Expand All @@ -35,6 +36,9 @@ class MongoStatsView extends material.StatefulWidget {

/// Remembers the last visited database for 1-click return from stats.
final String? lastSelectedMongoDb;

/// Remembers the last visited collection for 1-click return from stats.
final String? lastSelectedMongoCollection;
final material.VoidCallback? onRestoreLastSelectedObject;

@override
Expand Down Expand Up @@ -208,6 +212,26 @@ class _MongoStatsViewState extends material.State<MongoStatsView> {

final cs = Theme.of(context).colorScheme;

return material.Container(
color: cs.background,
child: material.Column(
crossAxisAlignment: material.CrossAxisAlignment.stretch,
children: [
material.Padding(
padding: const material.EdgeInsets.fromLTRB(24, 20, 24, 16),
child: _header(context),
),
const Divider(height: 1),
material.Expanded(
child: _buildBody(context, cs),
),
],
),
);
}

material.Widget _buildBody(
material.BuildContext context, shadcn.ColorScheme cs) {
if (_loading) {
return const material.Center(
child: QueryaSpinner(
Expand Down Expand Up @@ -273,25 +297,21 @@ class _MongoStatsViewState extends material.State<MongoStatsView> {
);
}

return material.Container(
color: cs.background,
child: material.RefreshIndicator(
onRefresh: _refreshNow,
child: material.LayoutBuilder(
builder: (context, constraints) {
final contentWidth = math.max(0.0, constraints.maxWidth - 48);
return material.SingleChildScrollView(
physics: const material.AlwaysScrollableScrollPhysics(),
padding: const material.EdgeInsets.all(24),
child: material.SizedBox(
width: contentWidth,
child: material.Column(
mainAxisSize: material.MainAxisSize.min,
crossAxisAlignment: material.CrossAxisAlignment.stretch,
children: [
_header(context),
const Gap(24),
_summaryChips(context, status),
return material.RefreshIndicator(
onRefresh: _refreshNow,
child: material.LayoutBuilder(
builder: (context, constraints) {
final contentWidth = math.max(0.0, constraints.maxWidth - 48);
return material.SingleChildScrollView(
physics: const material.AlwaysScrollableScrollPhysics(),
padding: const material.EdgeInsets.all(24),
child: material.SizedBox(
width: contentWidth,
child: material.Column(
mainAxisSize: material.MainAxisSize.min,
crossAxisAlignment: material.CrossAxisAlignment.stretch,
children: [
_summaryChips(context, status),
const Gap(24),
_gridRow(
_memoryCard(context, status),
Expand Down Expand Up @@ -345,8 +365,7 @@ class _MongoStatsViewState extends material.State<MongoStatsView> {
);
},
),
),
);
);
}

material.Widget _header(material.BuildContext context) {
Expand Down Expand Up @@ -394,7 +413,17 @@ class _MongoStatsViewState extends material.State<MongoStatsView> {
alignment: material.WrapAlignment.end,
crossAxisAlignment: material.WrapCrossAlignment.center,
children: [
if (widget.lastSelectedMongoDb != null &&
if (widget.lastSelectedMongoCollection != null &&
widget.onRestoreLastSelectedObject != null)
OutlineButton(
onPressed: widget.onRestoreLastSelectedObject,
leading: const material.Icon(
material.Icons.table_chart_outlined,
size: 18,
),
child: Text('Return to ${widget.lastSelectedMongoCollection}'),
)
else if (widget.lastSelectedMongoDb != null &&
widget.onRestoreLastSelectedObject != null)
OutlineButton(
onPressed: widget.onRestoreLastSelectedObject,
Expand Down
Loading
Loading