Skip to content

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

fix(sdk-bundle): restore back button after "Edit question" in embedded dashboards (#77389)

Sébastien15195d006a9c
diff --git a/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/enterprise.unit.spec.tsx b/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/enterprise.unit.spec.tsx
index 7536b11c69c..b295f959197 100644
--- a/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/enterprise.unit.spec.tsx
+++ b/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/enterprise.unit.spec.tsx
@@ -129,6 +129,28 @@ describe("EditableDashboard", () => {
expect(screen.getByText("Test dashboard")).toBeInTheDocument();
});
+ it("should allow to go back to the dashboard after editing a question from the dashcard menu (EMB-2012)", async () => {
+ await setupEnterprise({ dashboardName: "Test dashboard" });
+
+ const dashcard = screen.getAllByTestId("dashcard").at(0);
+ await userEvent.click(within(dashcard!).getByTestId("dashcard-menu"));
+
+ const menu = await screen.findByRole("menu");
+ await userEvent.click(within(menu).getByText("Edit question"));
+
+ // We should be in the question view
+ expect(
+ await screen.findByTestId("query-visualization-root"),
+ ).toBeInTheDocument();
+
+ // The back button should be there, just like when drilling into a question
+ const backButton = await screen.findByLabelText("Back to Test dashboard");
+ await userEvent.click(backButton);
+
+ // We should be back on the dashboard
+ expect(await screen.findByTestId("dashboard-grid")).toBeInTheDocument();
+ });
+
it("should allow to pass `dataPickerProps.entityTypes` to the query builder", async () => {
await setupEnterprise({
dataPickerProps: {
diff --git a/frontend/src/embedding-sdk-bundle/components/public/dashboard/SdkDashboard.tsx b/frontend/src/embedding-sdk-bundle/components/public/dashboard/SdkDashboard.tsx
index 4456cec75f1..3ccbe1d066c 100644
--- a/frontend/src/embedding-sdk-bundle/components/public/dashboard/SdkDashboard.tsx
+++ b/frontend/src/embedding-sdk-bundle/components/public/dashboard/SdkDashboard.tsx
@@ -438,6 +438,23 @@ const SdkDashboardInner = ({
],
);
+ // "Edit question" opens the card via adhocQuestionUrl without going through
+ // onNavigateToNewCardFromDashboard, so it never pushes to the navigation stack
+ // and the back button stays hidden. Push a virtual entry here so the question
+ // view renders a back button to the dashboard, matching the drill-in flow.
+ const onEditQuestionWithNav = useCallback(
+ (question: Parameters<typeof onEditQuestion>[0]) => {
+ sdkNavigation?.push({
+ type: "open-card",
+ virtual: true,
+ name: question.displayName() ?? t`Question`,
+ onPop: () => onNavigateBackToDashboard(),
+ });
+ onEditQuestion(question);
+ },
+ [onEditQuestion, sdkNavigation, onNavigateBackToDashboard],
+ );
+
if (isLocaleLoading) {
return (
<MaybeStyledWrapper
@@ -598,7 +615,7 @@ const SdkDashboardInner = ({
.with({ finalRenderMode: "dashboard" }, () => (
<SdkDashboardProvider
plugins={plugins}
- onEditQuestion={onEditQuestion}
+ onEditQuestion={onEditQuestionWithNav}
>
{children ?? (
<MaybeStyledWrapper