Skip to content

Commit eaf82dc

Browse files
Merge pull request #291 from QueryaHub/issue/266-f5-button-disabled
fix(ui): disable workspace Execute/Refresh when query cannot run (#266)
2 parents 39e7c91 + 6c0e665 commit eaf82dc

2 files changed

Lines changed: 55 additions & 22 deletions

File tree

lib/features/main_screen/workspace_panel.dart

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ import 'package:flutter/material.dart' as material
1313
Icons,
1414
MouseRegion,
1515
AnimatedContainer,
16-
AnimatedScale,
1716
SystemMouseCursors,
1817
SizedBox,
1918
SingleChildScrollView,
2019
Row,
2120
MainAxisSize,
2221
Widget,
23-
BoxConstraints;
22+
BoxConstraints,
23+
Tooltip;
2424
import 'package:querya_desktop/core/layout/vertical_split_pane.dart';
2525
import 'package:querya_desktop/core/motion/querya_cross_fade_stack.dart';
2626
import 'package:querya_desktop/core/motion/querya_motion.dart';
@@ -406,31 +406,22 @@ class _TabButtonState extends State<_TabButton> {
406406
}
407407
}
408408

409-
class _RunButton extends StatefulWidget {
409+
class _RunButton extends StatelessWidget {
410410
const _RunButton();
411411

412-
@override
413-
State<_RunButton> createState() => _RunButtonState();
414-
}
415-
416-
class _RunButtonState extends State<_RunButton> {
417-
bool _hovered = false;
412+
static const _noConnectionTooltip =
413+
'Select an active database connection to execute queries';
418414

419415
@override
420416
Widget build(BuildContext context) {
421-
return material.MouseRegion(
422-
onEnter: (_) => setState(() => _hovered = true),
423-
onExit: (_) => setState(() => _hovered = false),
424-
cursor: material.SystemMouseCursors.click,
425-
child: material.AnimatedScale(
426-
scale: _hovered ? 1.03 : 1.0,
427-
duration: context.motionDuration(QueryaMotion.fast),
428-
curve: context.motionCurve(QueryaMotion.enter),
429-
child: OutlineButton(
430-
onPressed: () {},
431-
leading: const material.Icon(material.Icons.play_arrow, size: 18),
432-
child: const Text('Execute/Refresh (F5)'),
433-
),
417+
return const material.Tooltip(
418+
message: _noConnectionTooltip,
419+
waitDuration: Duration(milliseconds: 450),
420+
child: OutlineButton(
421+
key: Key('workspace_run_button'),
422+
onPressed: null,
423+
leading: material.Icon(material.Icons.play_arrow, size: 18),
424+
child: Text('Execute/Refresh (F5)'),
434425
),
435426
);
436427
}

test/features/main_screen/workspace_panel_layout_test.dart

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,47 @@ void main() {
7272
await tester.pumpAndSettle();
7373
});
7474
});
75+
76+
testWidgets('Execute button hidden when no active connection', (tester) async {
77+
await pumpWidgetWithSurfaceSize(
78+
tester,
79+
const material.Size(800, 600),
80+
queryaThemeTestShell(
81+
child: const material.SizedBox.expand(
82+
child: WorkspacePanel(),
83+
),
84+
),
85+
);
86+
87+
expect(find.byKey(const Key('workspace_run_button')), findsNothing);
88+
expect(find.text('Execute/Refresh (F5)'), findsNothing);
89+
});
90+
91+
testWidgets('Execute button is disabled when execute is unavailable',
92+
(tester) async {
93+
await pumpWidgetWithSurfaceSize(
94+
tester,
95+
const material.Size(800, 600),
96+
queryaThemeTestShell(
97+
child: const material.SizedBox.expand(
98+
child: WorkspacePanel(
99+
activeConnection: stubSplitWorkspaceConnection,
100+
),
101+
),
102+
),
103+
);
104+
105+
final buttonFinder = find.byKey(const Key('workspace_run_button'));
106+
expect(buttonFinder, findsOneWidget);
107+
final button = tester.widget<OutlineButton>(buttonFinder);
108+
expect(button.onPressed, isNull);
109+
expect(
110+
find.text(
111+
'Select an active database connection to execute queries',
112+
),
113+
findsNothing,
114+
);
115+
expect(find.byType(material.Tooltip), findsWidgets);
116+
});
75117
});
76118
}

0 commit comments

Comments
 (0)