The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
fix(sdk-bundle): Fix EditableDashboard sometimes doesn't show the correct tab (#65802)
Mahatthana (Kelvin) Nomsawadicdad4c95ff0f
diff --git a/e2e/test-component/scenarios/embedding-sdk/editable-dashboard.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/editable-dashboard.cy.spec.tsxindex 313c7e66608..a2ce9d9ef1e 100644--- a/e2e/test-component/scenarios/embedding-sdk/editable-dashboard.cy.spec.tsx+++ b/e2e/test-component/scenarios/embedding-sdk/editable-dashboard.cy.spec.tsx@@ -410,6 +410,9 @@ describe("scenarios > embedding-sdk > editable-dashboard", () => {H.modal().within(() => {cy.findByLabelText("Name").clear().type(ADDED_QUESTION_NAME_3);+ cy.findByLabelText("Where do you want to save this?").should(+ "not.exist",+ );// Test saving a question to a different tabcy.findByLabelText("Which tab should this go on?").should("be.visible")diff --git a/enterprise/frontend/src/embedding-sdk-bundle/lib/sdk-question/load-question.ts b/enterprise/frontend/src/embedding-sdk-bundle/lib/sdk-question/load-question.tsindex 5da41793c6c..307903aa991 100644--- a/enterprise/frontend/src/embedding-sdk-bundle/lib/sdk-question/load-question.ts+++ b/enterprise/frontend/src/embedding-sdk-bundle/lib/sdk-question/load-question.ts@@ -26,9 +26,10 @@ export const loadQuestionSdk =Required<Pick<SdkQuestionState, "question">> &Pick<SdkQuestionState, "originalQuestion" | "parameterValues">> => {- const questionId = initQuestionId === "new" ? undefined : initQuestionId;+ const isNewQuestion = initQuestionId === "new";+ const questionId = isNewQuestion ? undefined : initQuestionId;- const { card, originalCard } = await resolveCards({+ const { card: resolvedCard, originalCard } = await resolveCards({cardId: questionId ?? undefined,options,dispatch,@@ -36,6 +37,10 @@ export const loadQuestionSdk =deserializedCard,});+ const card = isNewQuestion+ ? { ...resolvedCard, creationType: "custom_question" }+ : resolvedCard;+await dispatch(loadMetadataForCard(card));const metadata = getMetadata(getState());diff --git a/frontend/src/metabase/common/components/SaveQuestionModal/SaveQuestionModal.unit.spec.tsx b/frontend/src/metabase/common/components/SaveQuestionModal/SaveQuestionModal.unit.spec.tsxindex e038aef4068..8a3f5e8a066 100644--- a/frontend/src/metabase/common/components/SaveQuestionModal/SaveQuestionModal.unit.spec.tsx+++ b/frontend/src/metabase/common/components/SaveQuestionModal/SaveQuestionModal.unit.spec.tsx@@ -595,9 +595,11 @@ describe("SaveQuestionModal", () => {expect(await screen.findByLabelText(/Which tab should this go on/),).toBeInTheDocument();- expect(- await screen.findByLabelText(/Which tab should this go on/),- ).toHaveValue("Foo Tab 1");+ await waitFor(async () => {+ expect(+ await screen.findByLabelText(/Which tab should this go on/),+ ).toHaveValue("Foo Tab 1");+ });});it("should now show tab input if selected dashboard has no tabs", async () => {diff --git a/frontend/src/metabase/dashboard/components/FormDashboardTabSelect/FormDashboardTabSelect.tsx b/frontend/src/metabase/dashboard/components/FormDashboardTabSelect/FormDashboardTabSelect.tsxindex acac6ecbb74..d4a8bcc759f 100644--- a/frontend/src/metabase/dashboard/components/FormDashboardTabSelect/FormDashboardTabSelect.tsx+++ b/frontend/src/metabase/dashboard/components/FormDashboardTabSelect/FormDashboardTabSelect.tsx@@ -25,7 +25,20 @@ export const FormDashboardTabSelect = ({const firstTabId = currentData?.tabs?.length? String(currentData.tabs[0].id): undefined;- dashboardTabHelpers.setValue(firstTabId);+ /**+ * Kelvin 2025-11-13 fixes EMB-1001+ *+ * I have no idea why this fixes the problem. `dashboardTabHelpers.setValue` should have+ * worked and `useField("dashboard_tab_id")` should have picked up the change immediately.+ *+ * But this hadn't work reliably. I've also tried logging that the `setValue` calls were also+ * successful and I couldn't find other places that override the field `dashboard_tab_id` either.+ *+ * This is still a mystery to me.+ */+ setTimeout(() => {+ dashboardTabHelpers.setValue(firstTabId);+ }, 0);},[currentData, dashboardTabHelpers],);diff --git a/frontend/src/metabase/dashboard/components/FormDashboardTabSelect/FormDashboardTabSelect.unit.spec.tsx b/frontend/src/metabase/dashboard/components/FormDashboardTabSelect/FormDashboardTabSelect.unit.spec.tsxindex cff880720c7..345aee0f53c 100644--- a/frontend/src/metabase/dashboard/components/FormDashboardTabSelect/FormDashboardTabSelect.unit.spec.tsx+++ b/frontend/src/metabase/dashboard/components/FormDashboardTabSelect/FormDashboardTabSelect.unit.spec.tsx@@ -87,6 +87,7 @@ describe("FormDashboardTabSelect", () => {initialValue: FOO_TAB_1.id,});+ await waitForTabSelector(FOO_TAB_1.name);await userEvent.click(screen.getByText("Submit"));expect(onSubmit).toHaveBeenCalledWith({ dashboard_tab_id: String(FOO_TAB_1.id) },@@ -130,6 +131,7 @@ describe("FormDashboardTabSelect", () => {).not.toBeInTheDocument();});rerender(FOO_DASH.id);+ await waitForTabSelector(FOO_TAB_1.name);await userEvent.click(screen.getByText("Submit"));expect(onSubmit).toHaveBeenCalledWith(@@ -176,3 +178,11 @@ describe("FormDashboardTabSelect", () => {);});});++async function waitForTabSelector(tabName: string) {+ await waitFor(async () => {+ expect(+ await screen.findByLabelText(/Which tab should this go on/),+ ).toHaveValue(tabName);+ });+}