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): Properly calculate the `dirty` state for the `InteractiveQuestion.SaveButton` button (#62423)

Timofey Kachalov1dcee6ed8575
diff --git a/e2e/test-component/scenarios/embedding-sdk/sdk-question.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/sdk-question.cy.spec.tsx
index 843c668c610..27aa5d4ee13 100644
--- a/e2e/test-component/scenarios/embedding-sdk/sdk-question.cy.spec.tsx
+++ b/e2e/test-component/scenarios/embedding-sdk/sdk-question.cy.spec.tsx
@@ -9,6 +9,7 @@ import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
import {
FIRST_COLLECTION_ENTITY_ID,
FIRST_COLLECTION_ID,
+ ORDERS_QUESTION_ID,
SECOND_COLLECTION_ENTITY_ID,
THIRD_COLLECTION_ID,
} from "e2e/support/cypress_sample_instance_data";
@@ -572,4 +573,40 @@ describe("scenarios > embedding-sdk > interactive-question", () => {
cy.findByText("Back to previous results").should("not.exist");
});
});
+
+ it("should show the `Save` button when a visualization type was changed (metabase#62396)", () => {
+ mountSdkContent(<InteractiveQuestion questionId={ORDERS_QUESTION_ID} />);
+
+ getSdkRoot().within(() => {
+ cy.findByTestId("chart-type-selector-button").click();
+
+ cy.findByTestId("sdk-question-save-button").should("not.exist");
+
+ cy.findByRole("menu").within(() => {
+ cy.findByText("Trend").click();
+ });
+
+ cy.findByTestId("interactive-question-top-toolbar").within(() => {
+ cy.findByText("Save").should("exist");
+ });
+ });
+ });
+
+ it("should show the `Save` button when a visualization setting was changed (metabase#62396)", () => {
+ mountSdkContent(<InteractiveQuestion questionId={ORDERS_QUESTION_ID} />);
+
+ getSdkRoot().within(() => {
+ H.openVizSettingsSidebar();
+
+ cy.findByTestId("sdk-question-save-button").should("not.exist");
+
+ cy.findByTestId("chartsettings-sidebar").within(() => {
+ cy.findByTestId("User ID-hide-button").click();
+ });
+
+ cy.findByTestId("interactive-question-top-toolbar").within(() => {
+ cy.findByText("Save").should("exist");
+ });
+ });
+ });
});
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/SaveButton.tsx b/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/SaveButton.tsx
index cae44b2f014..4ed243dd1c8 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/SaveButton.tsx
+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/SaveButton.tsx
@@ -2,6 +2,7 @@ import type { MouseEventHandler } from "react";
import { t } from "ttag";
import type { ButtonProps } from "embedding-sdk-bundle/types/ui";
+import { isQuestionDirty } from "metabase/query_builder/utils/question";
import * as Lib from "metabase-lib";
import type Question from "metabase-lib/v1/Question";
@@ -29,7 +30,7 @@ export const shouldShowSaveButton = ({
}) => {
const canSave = question && Lib.canSave(question.query(), question.type());
const isQuestionChanged = originalQuestion
- ? question && question.isQueryDirtyComparedTo(originalQuestion)
+ ? isQuestionDirty(question, originalQuestion)
: true;
return Boolean(isQuestionChanged && canSave);
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkQuestionDefaultView/SdkQuestionDefaultView.tsx b/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkQuestionDefaultView/SdkQuestionDefaultView.tsx
index 1af8ae3f8f4..e54b765cfb7 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkQuestionDefaultView/SdkQuestionDefaultView.tsx
+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkQuestionDefaultView/SdkQuestionDefaultView.tsx
@@ -164,7 +164,11 @@ export const SdkQuestionDefaultView = ({
style={style}
>
<Stack className={InteractiveQuestionS.TopBar} gap="sm" p="md">
- <Group justify="space-between" align="flex-end">
+ <Group
+ justify="space-between"
+ align="flex-end"
+ data-testid="interactive-question-top-toolbar"
+ >
<Group gap="xs">
<Box mr="sm">
<BackButton />