Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Fix canceling queries on Cmd+Enter (#62600)

Alexander Polyankinc7b3f9e02dfd
diff --git a/e2e/test/scenarios/native/native-reproductions.cy.spec.ts b/e2e/test/scenarios/native/native-reproductions.cy.spec.ts
index 73f2821da1d..35595b5cbc7 100644
--- a/e2e/test/scenarios/native/native-reproductions.cy.spec.ts
+++ b/e2e/test/scenarios/native/native-reproductions.cy.spec.ts
@@ -1,4 +1,6 @@
const { H } = cy;
+
+import { WRITABLE_DB_ID } from "e2e/support/cypress_data";
import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
import type {
NativeQuestionDetails,
@@ -8,6 +10,7 @@ import type { IconName } from "metabase/ui";
import type { Database, ListDatabasesResponse } from "metabase-types/api";
import { getRunQueryButton } from "../native-filters/helpers/e2e-sql-filter-helpers";
+
const { ORDERS_ID, REVIEWS } = SAMPLE_DATABASE;
describe("issue 11727", { tags: "@external" }, () => {
@@ -755,3 +758,62 @@ describe("issue 60719", () => {
});
});
});
+
+describe("issue 59356", () => {
+ function typeRunShortcut() {
+ cy.get("body").type("{ctrl+enter}{cmd+enter}");
+ }
+
+ function getLoader() {
+ return H.queryBuilderMain().findByTestId("loading-indicator");
+ }
+
+ function getEmptyStateMessage() {
+ return H.queryBuilderMain().findByText(
+ "Here's where your results will appear",
+ );
+ }
+
+ beforeEach(() => {
+ H.restore("postgres-writable");
+ cy.signInAsAdmin();
+ cy.intercept("POST", "/api/dataset").as("dataset");
+ });
+
+ it("should properly cancel the query via the keyboard shortcut (metabase#59356)", () => {
+ cy.log("open the native query");
+ H.startNewNativeQuestion({
+ database: WRITABLE_DB_ID,
+ query: "select pg_sleep(5000)",
+ });
+
+ cy.log("verify that the query is not running");
+ getLoader().should("not.exist");
+ getEmptyStateMessage().should("be.visible");
+ cy.get("@dataset.all").should("have.length", 0);
+
+ cy.log("run the query and verify that it is running");
+ typeRunShortcut();
+ getLoader().should("be.visible");
+ getEmptyStateMessage().should("not.exist");
+ cy.get("@dataset.all").should("have.length", 1);
+
+ cy.log("cancel the query and verify that no new query is running");
+ typeRunShortcut();
+ getLoader().should("not.exist");
+ getEmptyStateMessage().should("be.visible");
+ cy.get("@dataset.all").should("have.length", 1);
+
+ cy.log("run the query again and verify that it is running");
+ typeRunShortcut();
+ getLoader().should("be.visible");
+ getEmptyStateMessage().should("not.exist");
+ cy.get("@dataset.all").should("have.length", 2);
+
+ cy.log("cancel the query and verify that no new query is running");
+ typeRunShortcut();
+ getLoader().should("not.exist");
+ getEmptyStateMessage().should("be.visible");
+ cy.get("@dataset.all").should("have.length", 2);
+ });
+});
diff --git a/frontend/src/metabase/query_builder/actions/querying.ts b/frontend/src/metabase/query_builder/actions/querying.ts
index 4fdfc2fb94f..5f992da5536 100644
--- a/frontend/src/metabase/query_builder/actions/querying.ts
+++ b/frontend/src/metabase/query_builder/actions/querying.ts
@@ -269,7 +269,7 @@ export const cancelQuery = () => (dispatch: Dispatch, getState: GetState) => {
}
};
-export const runQuestionOrSelectedQuery =
+export const runOrCancelQuestionOrSelectedQuery =
() => (dispatch: Dispatch, getState: GetState) => {
const question = getQuestion(getState());
if (!question) {
@@ -279,6 +279,7 @@ export const runQuestionOrSelectedQuery =
const isRunning = getIsRunning(getState());
if (isRunning) {
dispatch(cancelQuery());
+ return;
}
const query = question.query();
diff --git a/frontend/src/metabase/query_builder/components/NativeQueryEditor/NativeQueryEditor.tsx b/frontend/src/metabase/query_builder/components/NativeQueryEditor/NativeQueryEditor.tsx
index f2f76be75e3..a5c23df0011 100644
--- a/frontend/src/metabase/query_builder/components/NativeQueryEditor/NativeQueryEditor.tsx
+++ b/frontend/src/metabase/query_builder/components/NativeQueryEditor/NativeQueryEditor.tsx
@@ -16,7 +16,7 @@ import SnippetCollections from "metabase/entities/snippet-collections";
import Snippets from "metabase/entities/snippets";
import { useDispatch } from "metabase/lib/redux";
import {
- runQuestionOrSelectedQuery,
+ runOrCancelQuestionOrSelectedQuery,
setIsNativeEditorOpen,
setUIControls,
} from "metabase/query_builder/actions";
@@ -404,7 +404,7 @@ const NativeQueryEditorWrapper = forwardRef<
const { isNativeEditorOpen } = props;
const runQuery = useCallback(() => {
- dispatch(runQuestionOrSelectedQuery());
+ dispatch(runOrCancelQuestionOrSelectedQuery());
}, [dispatch]);
/**
diff --git a/frontend/src/metabase/query_builder/containers/QueryBuilder.tsx b/frontend/src/metabase/query_builder/containers/QueryBuilder.tsx
index 8aa9049b954..9c320e0c668 100644
--- a/frontend/src/metabase/query_builder/containers/QueryBuilder.tsx
+++ b/frontend/src/metabase/query_builder/containers/QueryBuilder.tsx
@@ -229,7 +229,7 @@ function QueryBuilderInner(props: QueryBuilderInnerProps) {
initializeQB,
locationChanged,
setUIControls,
- runQuestionOrSelectedQuery,
+ runOrCancelQuestionOrSelectedQuery,
cancelQuery,
isBookmarked,
createBookmark,
@@ -439,7 +439,7 @@ function QueryBuilderInner(props: QueryBuilderInnerProps) {
const handleCmdEnter = () => {
if (queryBuilderMode !== "notebook") {
- runQuestionOrSelectedQuery();
+ runOrCancelQuestionOrSelectedQuery();
}
};