Skip to content

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

Convert the "View SQL" to an icon only (#67159)

Nemanja Glumac2d523dc16b26
diff --git a/e2e/test/scenarios/collections/instance-analytics.cy.spec.js b/e2e/test/scenarios/collections/instance-analytics.cy.spec.js
index 5f995a3c460..7543d8a571f 100644
--- a/e2e/test/scenarios/collections/instance-analytics.cy.spec.js
+++ b/e2e/test/scenarios/collections/instance-analytics.cy.spec.js
@@ -26,7 +26,7 @@ describe("scenarios > Metabase Analytics Collection (AuditV2) ", () => {
cy.signInAsAdmin();
H.visitQuestion(ORDERS_QUESTION_ID);
cy.findByRole("button", { name: /Editor/ }).click();
- cy.findByRole("button", { name: /View SQL/ }).click();
+ cy.findByLabelText("View SQL").click();
cy.findByTestId("native-query-preview-sidebar").should("be.visible");
H.openNavigationSidebar();
@@ -35,7 +35,7 @@ describe("scenarios > Metabase Analytics Collection (AuditV2) ", () => {
cy.findByRole("link", { name: /Question views last week/i }).click();
cy.findByRole("button", { name: /Editor/ }).click();
- cy.findByRole("button", { name: /View SQL/ }).should("not.exist");
+ cy.findByLabelText("View SQL").should("not.exist");
cy.findByTestId("native-query-preview-sidebar").should("not.exist");
});
diff --git a/e2e/test/scenarios/custom-column/custom-column.cy.spec.js b/e2e/test/scenarios/custom-column/custom-column.cy.spec.js
index 7c51548c6cd..89fec750a12 100644
--- a/e2e/test/scenarios/custom-column/custom-column.cy.spec.js
+++ b/e2e/test/scenarios/custom-column/custom-column.cy.spec.js
@@ -1502,7 +1502,7 @@ describe("scenarios > question > custom column > exiting the editor", () => {
H.popover().findByText("Custom Expression").click();
cy.log("Close summarize modal by clicking outside");
- cy.button("View SQL").click();
+ cy.findByLabelText("View SQL").click();
H.modal().should("not.exist");
cy.get("popover").should("not.exist");
diff --git a/e2e/test/scenarios/question/notebook-native-preview-sidebar.cy.spec.ts b/e2e/test/scenarios/question/notebook-native-preview-sidebar.cy.spec.ts
index 6b1cb15de59..458e349f891 100644
--- a/e2e/test/scenarios/question/notebook-native-preview-sidebar.cy.spec.ts
+++ b/e2e/test/scenarios/question/notebook-native-preview-sidebar.cy.spec.ts
@@ -12,17 +12,12 @@ describe("scenarios > question > notebook > native query preview sidebar", () =>
beforeEach(() => {
H.restore();
cy.signInAsAdmin();
- cy.intercept(
- "PUT",
- "/api/setting/notebook-native-preview-shown",
- cy.spy().as("updatePreviewStateSpy"),
- );
});
it("should not show empty sidebar when no data source is selected", () => {
cy.intercept("POST", "/api/dataset/native").as("nativeDataset");
H.openReviewsTable({ mode: "notebook", limit: 1 });
- cy.findByLabelText("View SQL").click();
+ openSidebar();
cy.wait("@nativeDataset");
cy.findByTestId("app-bar").findByLabelText("New").click();
@@ -43,14 +38,14 @@ describe("scenarios > question > notebook > native query preview sidebar", () =>
cy.intercept("POST", "/api/dataset/native").as("nativeDataset");
H.openReviewsTable({ mode: "notebook", limit: queryLimit });
- cy.findByLabelText("View SQL").click();
+ openSidebar();
cy.findByTestId("native-query-preview-sidebar").should("be.visible");
cy.log("Refreshing the page does not persist the sidebar state");
cy.reload();
cy.findByTestId("native-query-preview-sidebar").should("not.exist");
- cy.findByLabelText("View SQL").click();
+ openSidebar();
cy.wait("@nativeDataset");
cy.findByTestId("native-query-preview-sidebar").within(() => {
cy.findByText("SQL for this question").should("exist");
@@ -71,7 +66,7 @@ describe("scenarios > question > notebook > native query preview sidebar", () =>
.and("not.contain", queryLimit);
cy.log("It should be possible to close the sidebar");
- cy.findByLabelText("Hide SQL").click();
+ closeSidebar();
cy.findByTestId("native-query-preview-sidebar").should("not.exist");
});
@@ -94,7 +89,7 @@ describe("scenarios > question > notebook > native query preview sidebar", () =>
cy.location("pathname").should("eq", "/question/notebook");
cy.log("Opening a preview sidebar should completely cover the notebook");
- cy.findByLabelText("View SQL").click();
+ openSidebar();
cy.location("pathname").should("eq", "/question/notebook");
cy.log(
@@ -138,7 +133,7 @@ describe("scenarios > question > notebook > native query preview sidebar", () =>
H.openReviewsTable({ mode: "notebook", limit: 1 });
cy.wait("@metadata");
- cy.findByLabelText("View SQL").click();
+ openSidebar();
cy.wait(["@nativeDataset", "@sessionProperties"]);
cy.log(
@@ -165,7 +160,7 @@ describe("scenarios > question > notebook > native query preview sidebar", () =>
cy.signInAsAdmin();
H.visitQuestion(ORDERS_COUNT_QUESTION_ID);
H.openNotebook();
- cy.findByLabelText("View SQL").click();
+ openSidebar();
cy.findByTestId("native-query-preview-sidebar")
.should("be.visible")
.then(($sidebar) => {
@@ -180,7 +175,7 @@ describe("scenarios > question > notebook > native query preview sidebar", () =>
H.openNotebook();
cy.findByTestId("native-query-preview-sidebar").should("not.exist");
- cy.findByLabelText("View SQL").click();
+ openSidebar();
cy.findByTestId("native-query-preview-sidebar")
.should("be.visible")
.then(($sidebar) => {
@@ -267,7 +262,7 @@ describe(
});
cy.log("Simple question");
- cy.findByLabelText("View native query").click();
+ openSidebar("native");
cy.findByTestId("native-query-preview-sidebar").within(() => {
cy.findByText("Native query for this question").should("exist");
H.NativeEditor.get()
@@ -296,7 +291,7 @@ describe(
cy.log("The generated query should be valid (metabase#38181)");
H.openNotebook();
- cy.findByLabelText("View native query").click();
+ openSidebar("native");
cy.findByTestId("native-query-preview-sidebar").within(() => {
cy.findByText("Native query for this question").should("exist");
H.NativeEditor.get()
@@ -351,7 +346,7 @@ describe(
"Small Marble Shoes",
);
H.openNotebook();
- cy.findByLabelText("View native query").click();
+ openSidebar("native");
cy.findByTestId("native-query-preview-sidebar").within(() => {
cy.findByText("Native query for this question").should("exist");
@@ -401,7 +396,7 @@ describe("scenarios > notebook > native query preview sidebar tracking events",
event: "notebook_native_preview_shown",
});
- cy.findByLabelText("Hide SQL").click();
+ closeSidebar();
cy.findByTestId("native-query-preview-sidebar").should("not.exist");
H.expectUnstructuredSnowplowEvent({
@@ -458,3 +453,13 @@ function resizeSidebar(amountX: number, cb: ResizeSidebarCallback) {
});
});
}
+
+function openSidebar(variant: "sql" | "native" = "sql") {
+ const label = variant === "sql" ? "View SQL" : "View native query";
+ cy.findByLabelText(label).should("be.visible").click();
+}
+
+function closeSidebar(variant: "sql" | "native" = "sql") {
+ const label = variant === "sql" ? "Hide SQL" : "Hide native query";
+ cy.findByLabelText(label).should("be.visible").click();
+}
diff --git a/e2e/test/scenarios/visualizations-charts/bar_chart.cy.spec.js b/e2e/test/scenarios/visualizations-charts/bar_chart.cy.spec.js
index d9215e489ac..135e8453e54 100644
--- a/e2e/test/scenarios/visualizations-charts/bar_chart.cy.spec.js
+++ b/e2e/test/scenarios/visualizations-charts/bar_chart.cy.spec.js
@@ -980,7 +980,7 @@ describe("scenarios > visualizations > bar chart", () => {
// Test "graph.other_category_aggregation_fn" for native queries
H.openNotebook();
- H.queryBuilderHeader().button("View SQL").click();
+ H.queryBuilderHeader().findByLabelText("View SQL").click();
cy.findByTestId("native-query-preview-sidebar")
.button("Convert this question to SQL")
.click();
diff --git a/frontend/src/metabase/query_builder/components/view/ViewHeader/ViewTitleHeader.module.css b/frontend/src/metabase/query_builder/components/view/ViewHeader/ViewTitleHeader.module.css
index 90f266be3ed..3964b19f165 100644
--- a/frontend/src/metabase/query_builder/components/view/ViewHeader/ViewTitleHeader.module.css
+++ b/frontend/src/metabase/query_builder/components/view/ViewHeader/ViewTitleHeader.module.css
@@ -108,26 +108,6 @@
}
}
-.ToggleNativeQueryButton {
- transition:
- background 300ms linear,
- border 300ms linear;
-
- &:hover:not([data-active="true"]) {
- color: var(--mb-color-brand);
- border-color: color-mix(
- in srgb,
- var(--mb-color-brand) 40%,
- var(--mb-color-white)
- );
- background-color: color-mix(
- in srgb,
- var(--mb-color-brand) 15%,
- var(--mb-color-white)
- );
- }
-}
-
.BackButton {
color: var(--mb-color-brand);
padding: 0.75rem;
diff --git a/frontend/src/metabase/query_builder/components/view/ViewHeader/components/ToggleNativeQueryPreview/ToggleNativeQueryPreview.tsx b/frontend/src/metabase/query_builder/components/view/ViewHeader/components/ToggleNativeQueryPreview/ToggleNativeQueryPreview.tsx
index 8a193f2ee32..1afc00e40d1 100644
--- a/frontend/src/metabase/query_builder/components/view/ViewHeader/components/ToggleNativeQueryPreview/ToggleNativeQueryPreview.tsx
+++ b/frontend/src/metabase/query_builder/components/view/ViewHeader/components/ToggleNativeQueryPreview/ToggleNativeQueryPreview.tsx
@@ -5,10 +5,9 @@ import { useDispatch, useSelector } from "metabase/lib/redux";
import { setUIControls } from "metabase/query_builder/actions";
import { trackNotebookNativePreviewShown } from "metabase/query_builder/analytics";
import { getUiControls } from "metabase/query_builder/selectors";
-import { Button, Icon } from "metabase/ui";
+import { ActionIcon, Icon, Tooltip } from "metabase/ui";
import type Question from "metabase-lib/v1/Question";
-import ViewTitleHeaderS from "../../ViewTitleHeader.module.css";
import { canShowNativePreview } from "../../utils";
const BUTTON_TEXT = {
@@ -57,14 +56,17 @@ export const ToggleNativeQueryPreview = ({
};
return (
- <Button
- className={ViewTitleHeaderS.ToggleNativeQueryButton}
- leftSection={<Icon name="sql" />}
- onClick={handleClick}
- aria-label={buttonText}
- >
- {buttonText}
- </Button>
+ <Tooltip label={buttonText} position="top">
+ <ActionIcon
+ aria-label={buttonText}
+ size={32}
+ role="switch"
+ variant="viewHeader"
+ onClick={handleClick}
+ >
+ <Icon name="sql" />
+ </ActionIcon>
+ </Tooltip>
);
};