Skip to content

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

GDGT-2872 Revert #77695 to allow custom widget popovers (#78124)

Kamil Mielnik07cb2f0a6c7b
diff --git a/e2e/test/scenarios/visualizations-charts/custom-viz.cy.spec.ts b/e2e/test/scenarios/visualizations-charts/custom-viz.cy.spec.ts
index 90d448a34b5..e61bbf5512e 100644
--- a/e2e/test/scenarios/visualizations-charts/custom-viz.cy.spec.ts
+++ b/e2e/test/scenarios/visualizations-charts/custom-viz.cy.spec.ts
@@ -2442,92 +2442,6 @@ describe("sandbox", () => {
.should("not.have.attr", "data-pwned-by-plugin");
});
- it("confines custom viz and custom viz setting widget to its container (GDGT-2400)", () => {
- const timeout = 100;
- const payload = `
- setInterval(function() {
- var containers = document.querySelectorAll('[data-plugin-sandbox]');
- for (var i = 0; i < containers.length; i++) {
- containers[i].setAttribute('style',
- 'position:fixed;inset:0;z-index:99999;background:red;');
- }
- }, ${timeout});
- `;
-
- cy.intercept("GET", "/api/ee/custom-viz-plugin/*/bundle*", (req) => {
- req.continue((res) => {
- res.body = `${payload}\n${String(res.body)};\n`;
- res.send();
- });
- }).as("injectedBundle");
-
- H.addCustomVizPlugin(H.CUSTOM_VIZ_FIXTURE_TGZ_4_SECURITY_COMPONENT);
- H.createQuestion(
- {
- name: "Custom Viz Setting Widget Confinement Test",
- query: {
- "source-table": SAMPLE_DB_TABLES.STATIC_ORDERS_ID,
- aggregation: [["count"]],
- },
- display: "table",
- },
- { wrapId: true, idAlias: "componentCardId" },
- );
-
- H.visitQuestion("@componentCardId");
-
- H.openVizTypeSidebar();
- cy.findByTestId("custom-viz-plugins-toggle").click();
- cy.findByTestId(
- `${H.CUSTOM_VIZ_IDENTIFIER_4_SECURITY_COMPONENT}-button`,
- ).click();
- H.openVizTypeSidebar();
- cy.wait("@injectedBundle");
-
- H.openVizSettingsSidebar();
-
- const viewportWidth = Cypress.config("viewportWidth");
- const viewportHeight = Cypress.config("viewportHeight");
-
- H.vizSettingsSidebar()
- .find("[data-plugin-sandbox]")
- .should(($element) => {
- expect($element, "attack applied position:fixed").to.have.css(
- "position",
- "fixed",
- );
-
- const rect = $element[0].getBoundingClientRect();
- const viewportWidth = Cypress.config("viewportWidth");
-
- expect(
- rect.top,
- "setting widget top offset from viewport",
- ).to.be.greaterThan(0);
- expect(rect.width, "setting widget width vs viewport").to.be.lessThan(
- viewportWidth,
- );
- expect(rect.height, "setting widget height vs viewport").to.be.eq(0);
- });
-
- H.queryVisualizationRoot()
- .find("[data-plugin-sandbox]")
- .should(($element) => {
- const rect = $element[0].getBoundingClientRect();
-
- expect(
- rect.top,
- "container top offset from viewport",
- ).to.be.greaterThan(0);
- expect(rect.width, "container width vs viewport").to.be.lessThan(
- viewportWidth,
- );
- expect(rect.height, "container height vs viewport").to.be.lessThan(
- viewportHeight,
- );
- });
- });
-
it("MutationObserver on out-of-scope nodes observes a decoy and never fires for host mutations", () => {
const payload = `
var seenMutations = 0;
diff --git a/enterprise/frontend/src/metabase-enterprise/custom_viz/components/CustomVizSettingWidget.tsx b/enterprise/frontend/src/metabase-enterprise/custom_viz/components/CustomVizSettingWidget.tsx
index 20b4a609b13..30d80c54dcd 100644
--- a/enterprise/frontend/src/metabase-enterprise/custom_viz/components/CustomVizSettingWidget.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/custom_viz/components/CustomVizSettingWidget.tsx
@@ -3,8 +3,6 @@ import type { WidgetMount } from "custom-viz";
import { usePluginMount } from "../use-plugin-mount";
import { getWidgetMountPluginId } from "../widget-mount";
-import { SandboxedPluginContainer } from "./SandboxedPluginContainer";
-
type Props = {
mount: WidgetMount<Record<string, unknown>>;
widgetProps: Record<string, unknown>;
@@ -18,6 +16,10 @@ export function CustomVizSettingWidget({ mount, widgetProps }: Props) {
const containerRef = usePluginMount(mount, widgetProps);
return (
- <SandboxedPluginContainer containerRef={containerRef} pluginId={pluginId} />
+ <div
+ ref={containerRef}
+ data-plugin-sandbox={pluginId}
+ style={{ width: "100%" }}
+ />
);
}
diff --git a/enterprise/frontend/src/metabase-enterprise/custom_viz/components/CustomVizSettingWidget.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/custom_viz/components/CustomVizSettingWidget.unit.spec.tsx
index eaccad003da..514975bbd6a 100644
--- a/enterprise/frontend/src/metabase-enterprise/custom_viz/components/CustomVizSettingWidget.unit.spec.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/custom_viz/components/CustomVizSettingWidget.unit.spec.tsx
@@ -1,9 +1,8 @@
+import { render, screen, waitFor } from "@testing-library/react";
import type { WidgetMount } from "custom-viz";
import type { ComponentType } from "react";
import { createRoot } from "react-dom/client";
-import { render, screen, waitFor } from "__support__/ui";
-
import { wrapPluginWidget } from "../widget-mount";
import { CustomVizSettingWidget } from "./CustomVizSettingWidget";
@@ -126,16 +125,4 @@ describe("CustomVizSettingWidget", () => {
expect(getWidgetContainer()).toHaveAttribute("data-plugin-sandbox", "11");
});
});
-
- it("mounts the plugin inside a host-controlled wrapper the plugin cannot tag", async () => {
- const { getWidgetContainer } = setup({ pluginId: 11 });
-
- await waitFor(() => {
- expect(getWidgetContainer()).toHaveAttribute("data-plugin-sandbox", "11");
- });
-
- const wrapper = getWidgetContainer()?.parentElement;
- expect(wrapper).not.toBeNull();
- expect(wrapper).not.toHaveAttribute("data-plugin-sandbox");
- });
});
diff --git a/enterprise/frontend/src/metabase-enterprise/custom_viz/components/SandboxedPluginContainer.module.css b/enterprise/frontend/src/metabase-enterprise/custom_viz/components/SandboxedPluginContainer.module.css
deleted file mode 100644
index b64b96b0ec2..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/custom_viz/components/SandboxedPluginContainer.module.css
+++ /dev/null
@@ -1,3 +0,0 @@
-.container {
- contain: layout paint; /* Security boundary */
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/custom_viz/components/SandboxedPluginContainer.tsx b/enterprise/frontend/src/metabase-enterprise/custom_viz/components/SandboxedPluginContainer.tsx
deleted file mode 100644
index af8b0e166fd..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/custom_viz/components/SandboxedPluginContainer.tsx
+++ /dev/null
@@ -1,29 +0,0 @@
-import type { Ref } from "react";
-
-import { Box } from "metabase/ui";
-import type { CustomVizPluginId } from "metabase-types/api";
-
-import S from "./SandboxedPluginContainer.module.css";
-
-type Props = {
- containerRef: Ref<HTMLDivElement>;
- fill?: boolean;
- pluginId: CustomVizPluginId | undefined;
-};
-
-export function SandboxedPluginContainer({
- containerRef,
- fill = false,
- pluginId,
-}: Props) {
- return (
- <Box className={S.container} h={fill ? "100%" : undefined} w="100%">
- <Box
- data-plugin-sandbox={pluginId}
- h={fill ? "100%" : undefined}
- ref={containerRef}
- w="100%"
- />
- </Box>
- );
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/custom_viz/custom-viz-plugins.tsx b/enterprise/frontend/src/metabase-enterprise/custom_viz/custom-viz-plugins.tsx
index 5b0b794d2f4..edb8d1cc64e 100644
--- a/enterprise/frontend/src/metabase-enterprise/custom_viz/custom-viz-plugins.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/custom_viz/custom-viz-plugins.tsx
@@ -36,7 +36,6 @@ import type {
import { isObject } from "metabase-types/guards";
import { isCustomVizDisplay } from "metabase-types/guards/visualization";
-import { SandboxedPluginContainer } from "./components/SandboxedPluginContainer";
import { applyDefaultVisualizationProps } from "./custom-viz-common";
import { ensureVizApi } from "./custom-viz-globals";
import type { SandboxMode } from "./sandbox";
@@ -537,10 +536,10 @@ function createCustomVizWrapper(
);
return (
- <SandboxedPluginContainer
- containerRef={containerRef}
- fill
- pluginId={pluginId}
+ <div
+ ref={containerRef}
+ data-plugin-sandbox={pluginId}
+ style={{ width: "100%", height: "100%" }}
/>
);
};