aminghadersohi commented on code in PR #45336:
URL: https://github.com/apache/superset/pull/45336#discussion_r4282820517
##########
superset-frontend/src/SqlLab/components/RunQueryActionButton/index.tsx:
##########
@@ -109,6 +118,32 @@ const RunQueryActionButton = ({
const shouldShowStopBtn =
!!queryState && ['running', 'pending'].indexOf(queryState) > -1;
+ const currentAction: ButtonAction = shouldShowStopBtn ? 'stop' : 'run';
+
+ // The label can switch between Stop and Run while a pointer or key is held
+ // down, and the browser dispatches the click against whatever the button
+ // shows at release time. Remember the action the gesture started on so a
+ // press that began on Stop can never run the query.
+ const gestureActionRef = useRef<ButtonAction | null>(null);
+
+ const captureGestureAction = () => {
+ gestureActionRef.current = currentAction;
+ };
+
+ const onKeyDownCapture = (event: KeyboardEvent<HTMLSpanElement>) => {
+ if (!event.repeat && (event.key === 'Enter' || event.key === ' ')) {
+ captureGestureAction();
+ }
Review Comment:
I reproduced this with native Chromium: holding Enter generates a click for
each repeated keydown; Space only clicks on keyup. The first Enter click
consumes the pending gesture, so later repeats could execute Run after
completion.
Fixed in b45e88f86fe85b71910329bd233ad2f085bce076 by retaining the original
keyboard action across repeat clicks. The new regression tests `held Enter on
Stop does not run SQL after completion` and `held Enter on the CTAS Stop button
does not run SQL after completion` fail on the previous head with two
unexpected Run calls each and pass after this change. They synthesize native
Enter clicks after `repeat: true` keydowns and verify a fresh Enter press still
runs. The component suite passes 19/19; the SqlLab suite passes 46 suites, 469
tests (one skipped).
Regression test:
`superset-frontend/src/SqlLab/components/RunQueryActionButton/RunQueryActionButton.test.tsx::held
Enter on Stop does not run SQL after completion`
Siblings checked:
- superset-frontend/src/SqlLab/components/RunQueryActionButton/index.tsx:134
— fixed in b45e88f86fe85b71910329bd233ad2f085bce076
- superset-frontend/src/SqlLab/components/RunQueryActionButton/index.tsx:155
— fixed in b45e88f86fe85b71910329bd233ad2f085bce076
- superset-frontend/src/SqlLab/components/SqlEditor/index.tsx:363 — not
affected: Ctrl+R and Ctrl+Enter invoke Run directly, never switch from Stop;
the separate Ctrl+E/Ctrl+X Stop handler only stops running/pending queries.
- superset-frontend/src/SqlLab/components/SqlEditor/index.tsx:490 — not
affected: Ctrl+Shift+Enter runs the current statement and never becomes Stop.
- superset-frontend/src/SqlLab/components/EditorWrapper/index.tsx:63 — not
affected: the Alt+Enter editor hotkey has no Stop action or native button click.
- superset-frontend/src/SqlLab/components/SqlEditor/index.tsx:816 — not
affected: CTAS/CVAS menu items only open the modal; the caret opens the menu
instead of invoking Run.
- superset-frontend/src/SqlLab/components/SqlEditor/index.tsx:1078 — not
affected: both modal Create buttons execute only their named create action,
never switch from Stop to Run.
- superset-frontend/src/SqlLab/components/ResultSet/index.tsx:832 — not
affected: Fetch data preview is a Run-only button, without a Stop handler.
- superset-frontend/src/SqlLab/components/ResultSet/index.tsx:249 — not
affected: the session-timeout retry runs on mount, not a held button gesture.
-
superset-frontend/src/components/ErrorMessage/OAuth2RedirectMessage.tsx:109 —
not affected: the OAuth retry runs on completion notification, not a Run/Stop
gesture.
- superset-frontend/src/SqlLab/components/QueryTable/index.tsx:358 — not
affected: Run query in a new tab opens a separate editor, without a Stop-to-Run
action swap.
- superset-frontend/src/SqlLab/actions/sqlLab.ts:517 — not affected:
runQuery/runQueryFromSqlEditor/reRunQuery and preview helpers dispatch explicit
Run operations and have no native button gesture state.
- superset-frontend/src/core/sqlLab/index.ts:672 — not affected: extension
cancellation dispatches only postStopQuery, never Run.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]