Skip to content

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

export `InteractiveQuestion.NavigationBackButton` and deprecate the old one (#69292)

Nicolò Pretto22c79120050e
diff --git a/e2e/test-component/scenarios/embedding-sdk/interactive-question.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/interactive-question.cy.spec.tsx
index c946da44855..e63b0680a86 100644
--- a/e2e/test-component/scenarios/embedding-sdk/interactive-question.cy.spec.tsx
+++ b/e2e/test-component/scenarios/embedding-sdk/interactive-question.cy.spec.tsx
@@ -166,30 +166,65 @@ describe("scenarios > embedding-sdk > interactive-question", () => {
});
});
- describe("BackButton component", () => {
- it("should show BackButton after drilling even with title=false (metabase#68556)", () => {
+ describe("NavigationBackButton component", () => {
+ it("should show NavigationBackButton after drilling and allow navigating back", () => {
+ mountSdkContent(
+ <InteractiveQuestion questionId={ORDERS_QUESTION_ID}>
+ <InteractiveQuestion.NavigationBackButton />
+ <InteractiveQuestion.Title />
+ <InteractiveQuestion.QuestionVisualization />
+ </InteractiveQuestion>,
+ );
+
+ getSdkRoot().within(() => {
+ cy.findByText("Orders").should("be.visible");
+
+ cy.log(
+ "NavigationBackButton should not be visible initially (no navigation history)",
+ );
+ cy.findByText(/Back to/).should("not.exist");
+
+ cy.log("Perform a drill on the first row's Product ID");
+ H.tableInteractiveBody().findAllByText("14").first().click();
+ H.popover().findByText("View this Product's Orders").click();
+
+ cy.log("NavigationBackButton should now be visible");
+ cy.findByText("Back to Orders").should("be.visible");
+
+ cy.log("Click the back button to return to the original question");
+ cy.findByText("Back to Orders").click();
+
+ cy.log("Should be back at the original question");
+ cy.findByText("Orders").should("be.visible");
+
+ cy.log("NavigationBackButton should be hidden again");
+ cy.findByText(/Back to/).should("not.exist");
+ });
+ });
+
+ it("should show NavigationBackButton after drilling even with title=false (metabase#68556)", () => {
mountSdkContent(
<InteractiveQuestion questionId={ORDERS_QUESTION_ID} title={false} />,
);
getSdkRoot().within(() => {
- // Title should not be visible
+ cy.log("Title should not be visible");
cy.findByText("Orders").should("not.exist");
- // BackButton should not be visible initially
+ cy.log("NavigationBackButton should not be visible initially");
cy.findByText(/Back to/).should("not.exist");
- // Perform a drill on the first row's Product ID
+ cy.log("Perform a drill on the first row's Product ID");
H.tableInteractiveBody().findAllByText("14").first().click();
H.popover().findByText("View this Product's Orders").click();
- // BackButton should be visible after drill
+ cy.log("NavigationBackButton should be visible after drill");
cy.findByText("Back to Orders").should("be.visible");
- // Click back
+ cy.log("Click back");
cy.findByText("Back to Orders").click();
- // BackButton should be hidden again
+ cy.log("NavigationBackButton should be hidden again");
cy.findByText(/Back to/).should("not.exist");
});
});
diff --git a/enterprise/frontend/src/embedding-sdk-package/components/public/InteractiveQuestion/InteractiveQuestion.tsx b/enterprise/frontend/src/embedding-sdk-package/components/public/InteractiveQuestion/InteractiveQuestion.tsx
index 462b40a589d..612db98857e 100644
--- a/enterprise/frontend/src/embedding-sdk-package/components/public/InteractiveQuestion/InteractiveQuestion.tsx
+++ b/enterprise/frontend/src/embedding-sdk-package/components/public/InteractiveQuestion/InteractiveQuestion.tsx
@@ -12,6 +12,11 @@ const subComponents: InteractiveQuestionComponents = {
getWindow()?.METABASE_EMBEDDING_SDK_BUNDLE?.InteractiveQuestion
?.BackButton,
),
+ NavigationBackButton: createComponent(
+ () =>
+ getWindow()?.METABASE_EMBEDDING_SDK_BUNDLE?.InteractiveQuestion
+ ?.NavigationBackButton,
+ ),
Filter: createComponent(
() =>
getWindow()?.METABASE_EMBEDDING_SDK_BUNDLE?.InteractiveQuestion?.Filter,
diff --git a/frontend/src/embedding-sdk-bundle/components/public/InteractiveQuestion/InteractiveQuestion.tsx b/frontend/src/embedding-sdk-bundle/components/public/InteractiveQuestion/InteractiveQuestion.tsx
index 43da1a8c95b..c43ca9ae8c1 100644
--- a/frontend/src/embedding-sdk-bundle/components/public/InteractiveQuestion/InteractiveQuestion.tsx
+++ b/frontend/src/embedding-sdk-bundle/components/public/InteractiveQuestion/InteractiveQuestion.tsx
@@ -1,4 +1,5 @@
import { withPublicComponentWrapper } from "embedding-sdk-bundle/components/private/PublicComponentWrapper";
+import { SdkInternalNavigationBackButton } from "embedding-sdk-bundle/components/private/SdkInternalNavigation/SdkInternalNavigationBackButton";
import {
BackButton,
Breakout,
@@ -46,7 +47,10 @@ export type InteractiveQuestionProps = Omit<
* @interface
*/
export type InteractiveQuestionComponents = {
+ /** @deprecated Use `InteractiveQuestion.NavigationBackButton` instead */
BackButton: typeof BackButton;
+ /** Back button to navigate back after drills and internal navigation. It will render null if there's nothing to go back to */
+ NavigationBackButton: typeof SdkInternalNavigationBackButton;
Filter: typeof Filter;
FilterDropdown: typeof FilterDropdown;
ResetButton: typeof QuestionResetButton;
@@ -81,6 +85,7 @@ export const _InteractiveQuestion = (props: InteractiveQuestionProps) => (
const subComponents: InteractiveQuestionComponents = {
BackButton: BackButton,
+ NavigationBackButton: SdkInternalNavigationBackButton,
Filter: Filter,
FilterDropdown: FilterDropdown,
ResetButton: QuestionResetButton,