Skip to content

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

feat(SDK, EmbedJS): Add touch support for Popover targets to improve mobile usability (#71484)

Timofey Kachalovefc354420f9e
diff --git a/e2e/support/helpers/e2e-mobile-device-helpers.ts b/e2e/support/helpers/e2e-mobile-device-helpers.ts
new file mode 100644
index 00000000000..16b022e0305
--- /dev/null
+++ b/e2e/support/helpers/e2e-mobile-device-helpers.ts
@@ -0,0 +1,19 @@
+export function enableTouchEmulation() {
+ cy.then(() =>
+ Cypress.automation("remote:debugger:protocol", {
+ command: "Emulation.setTouchEmulationEnabled",
+ params: { enabled: true, maxTouchPoints: 5 },
+ }),
+ );
+
+ cy.window().its("navigator.maxTouchPoints").should("be.greaterThan", 0);
+}
+
+export function disableTouchEmulation() {
+ cy.then(() =>
+ Cypress.automation("remote:debugger:protocol", {
+ command: "Emulation.setTouchEmulationEnabled",
+ params: { enabled: false },
+ }),
+ );
+}
diff --git a/e2e/test-component/scenarios/embedding-sdk/notebook-touch.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/notebook-touch.cy.spec.tsx
new file mode 100644
index 00000000000..75028a43eda
--- /dev/null
+++ b/e2e/test-component/scenarios/embedding-sdk/notebook-touch.cy.spec.tsx
@@ -0,0 +1,76 @@
+import { InteractiveQuestion } from "@metabase/embedding-sdk-react";
+
+import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
+import { createQuestion } from "e2e/support/helpers";
+import { getSdkRoot } from "e2e/support/helpers/e2e-embedding-sdk-helpers";
+import {
+ disableTouchEmulation,
+ enableTouchEmulation,
+} from "e2e/support/helpers/e2e-mobile-device-helpers";
+import { mountSdkContent } from "e2e/support/helpers/embedding-sdk-component-testing";
+import { signInAsAdminAndEnableEmbeddingSdk } from "e2e/support/helpers/embedding-sdk-testing";
+import { mockAuthProviderAndJwtSignIn } from "e2e/support/helpers/embedding-sdk-testing/embedding-sdk-helpers";
+
+const { ORDERS, ORDERS_ID } = SAMPLE_DATABASE;
+
+describe("scenarios > embedding-sdk > notebook touch support", () => {
+ beforeEach(() => {
+ signInAsAdminAndEnableEmbeddingSdk();
+
+ createQuestion({
+ name: "Notebook touch test",
+ query: {
+ "source-table": ORDERS_ID,
+ aggregation: [["count"]],
+ breakout: [["field", ORDERS.PRODUCT_ID, null]],
+ },
+ }).then(({ body: question }) => {
+ cy.wrap(question.id).as("questionId");
+ });
+
+ cy.signOut();
+ mockAuthProviderAndJwtSignIn();
+ });
+
+ describe("touch device", () => {
+ beforeEach(() => {
+ cy.viewport("iphone-x");
+ enableTouchEmulation();
+ });
+
+ afterEach(() => {
+ disableTouchEmulation();
+ });
+
+ it("remove step button should be visible without hover (EMB-1457)", () => {
+ cy.get<number>("@questionId").then((questionId) => {
+ mountSdkContent(<InteractiveQuestion questionId={questionId} />);
+ });
+
+ getSdkRoot().within(() => {
+ cy.findByTestId("notebook-button").click();
+
+ // The "Summarize" step should have a visible remove button
+ // without needing to hover first
+ cy.findByLabelText("Remove step").should("be.visible");
+ });
+ });
+
+ it("notebook step buttons should respond to first tap (EMB-1457)", () => {
+ cy.get<number>("@questionId").then((questionId) => {
+ mountSdkContent(<InteractiveQuestion questionId={questionId} />);
+ });
+
+ getSdkRoot().within(() => {
+ cy.findByTestId("notebook-button").click();
+
+ // The question has a Summarize step. Clicking the existing
+ // aggregation pill should open the popover on the first tap
+ // without requiring a second tap.
+ cy.findByTestId("step-summarize-0-0").findByText("Count").click();
+
+ cy.findByTestId("clause-popover").should("be.visible");
+ });
+ });
+ });
+});
diff --git a/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookStep.module.css b/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookStep.module.css
index 4bb443c874e..50722457418 100644
--- a/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookStep.module.css
+++ b/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookStep.module.css
@@ -21,3 +21,17 @@
padding-bottom: 1rem;
}
}
+
+.StepRoot .StepHeader {
+ visibility: hidden;
+}
+
+.StepRoot:hover .StepHeader {
+ visibility: visible;
+}
+
+@media (hover: none) {
+ .StepRoot .StepHeader {
+ visibility: visible;
+ }
+}
diff --git a/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookStep.tsx b/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookStep.tsx
index f436429c24f..95a8318f280 100644
--- a/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookStep.tsx
+++ b/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookStep.tsx
@@ -100,10 +100,7 @@ export function NotebookStep({
return (
<ExpandingContent isInitiallyOpen={!isLastOpened} isOpen>
- <Box
- className={cx(CS.hoverParent, CS.hoverVisibility, S.StepRoot)}
- data-testid={step.testID}
- >
+ <Box className={S.StepRoot} data-testid={step.testID}>
<Box w={`${(11 / 12) * 100}%`} maw="75rem">
<StepHeader
step={step}
diff --git a/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookStepHeader/NotebookStepHeader.tsx b/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookStepHeader/NotebookStepHeader.tsx
index fe43a925d6e..fb3c5fa5ec5 100644
--- a/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookStepHeader/NotebookStepHeader.tsx
+++ b/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookStepHeader/NotebookStepHeader.tsx
@@ -6,6 +6,7 @@ import CS from "metabase/css/core/index.css";
import { Flex, Icon } from "metabase/ui";
import type { NotebookStepHeaderProps } from "../../../types";
+import S from "../NotebookStep.module.css";
export function NotebookStepHeader({
title,
@@ -22,7 +23,7 @@ export function NotebookStepHeader({
CS.mlAuto,
CS.textLight,
CS.textMediumHover,
- CS.hoverChild,
+ S.StepHeader,
)}
onClick={onRevert}
>