Skip to content

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

Forward query edits from viz settings in SDK QuestionSettings (#77262)

Mahatthana (Kelvin) Nomsawadiff2b145e37a6
diff --git a/e2e/test/scenarios/embedding/sdk-iframe-embedding/reproductions.cy.spec.ts b/e2e/test/scenarios/embedding/sdk-iframe-embedding/reproductions.cy.spec.ts
new file mode 100644
index 00000000000..f336a8aecf9
--- /dev/null
+++ b/e2e/test/scenarios/embedding/sdk-iframe-embedding/reproductions.cy.spec.ts
@@ -0,0 +1,28 @@
+const { H } = cy;
+import { ORDERS_QUESTION_ID } from "e2e/support/cypress_sample_instance_data";
+
+describe("issue 77135", () => {
+ it("should add/remove columns via viz settings (EMB-2057)", () => {
+ H.prepareSdkIframeEmbedTest({
+ withToken: "bleeding-edge",
+ signOut: false,
+ });
+
+ H.visitCustomHtmlPage(`
+ ${H.getNewEmbedScriptTag()}
+ ${H.getNewEmbedConfigurationScript({})}
+ <metabase-question question-id="${ORDERS_QUESTION_ID}" />
+ `);
+
+ H.getSimpleEmbedIframeContent().within(() => {
+ H.tableInteractive().findByText("Tax").should("be.visible");
+
+ cy.findByTestId("viz-settings-button").click();
+ cy.findByRole("button", { name: /Add or remove columns/ }).click();
+
+ cy.findByLabelText("Tax").should("be.checked").click();
+
+ H.tableInteractive().findByText("Tax").should("not.exist");
+ });
+ });
+});
diff --git a/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/QuestionSettings/QuestionSettings.tsx b/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/QuestionSettings/QuestionSettings.tsx
index 9eee4492cf3..7199b518f3f 100644
--- a/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/QuestionSettings/QuestionSettings.tsx
+++ b/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/QuestionSettings/QuestionSettings.tsx
@@ -40,8 +40,14 @@ const QuestionSettingsContent = ({
];
}, [queryResults, question]);
- const onChange = async (settings: VisualizationSettings) => {
- await updateQuestion(question.updateSettings(settings).lockDisplay());
+ const onChange = async (
+ settings: VisualizationSettings,
+ nextQuestion?: Question,
+ ) => {
+ await updateQuestion(
+ (nextQuestion ?? question).updateSettings(settings).lockDisplay(),
+ { run: Boolean(nextQuestion) },
+ );
};
const { chartSettings, handleChangeSettings, transformedSeries } =