Skip to content

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

fixed table width in guest embed (#70418)

Sébastien92017bab3fa8
diff --git a/e2e/test/scenarios/embedding/sdk-iframe-embedding/sdk-iframe-embedding.cy.spec.ts b/e2e/test/scenarios/embedding/sdk-iframe-embedding/sdk-iframe-embedding.cy.spec.ts
index ec152e665c6..e3f4d07889f 100644
--- a/e2e/test/scenarios/embedding/sdk-iframe-embedding/sdk-iframe-embedding.cy.spec.ts
+++ b/e2e/test/scenarios/embedding/sdk-iframe-embedding/sdk-iframe-embedding.cy.spec.ts
@@ -81,6 +81,57 @@ describe("scenarios > embedding > modular embedding", () => {
});
});
+ it("table visualization should span the full width of the container (metabase#69831)", () => {
+ cy.signInAsAdmin();
+ H.createQuestion({
+ name: "Narrow table question",
+ query: {
+ "source-table": ORDERS_TABLE_ID,
+ fields: [
+ ["field", ORDERS.ID, { "base-type": "type/BigInteger" }],
+ ["field", ORDERS.QUANTITY, { "base-type": "type/Integer" }],
+ ],
+ limit: 5,
+ },
+ }).then(({ body: question }) => {
+ cy.signOut();
+
+ const frame = H.loadSdkIframeEmbedTestPage({
+ elements: [
+ {
+ component: "metabase-question",
+ attributes: {
+ questionId: question.id,
+ },
+ },
+ ],
+ });
+
+ cy.wait("@getCardQuery");
+
+ frame.within(() => {
+ // clientWidth excludes the scrollbar gutter, giving us the actual content area
+ H.tableInteractive()
+ .findByTestId("table-scroll-container")
+ .then(($scrollContainer) => {
+ const contentWidth = $scrollContainer[0].clientWidth;
+
+ const $headerCells = $scrollContainer.find(
+ '[data-testid="header-cell"]',
+ );
+ let totalHeaderWidth = 0;
+ $headerCells.each((_, el) => {
+ totalHeaderWidth += el.getBoundingClientRect().width;
+ });
+
+ expect(Math.round(totalHeaderWidth)).to.be.at.least(
+ Math.round(contentWidth),
+ );
+ });
+ });
+ });
+ });
+
it("displays a dashboard using entity id", () => {
const frame = H.loadSdkIframeEmbedTestPage({
elements: [
diff --git a/frontend/src/embedding-sdk-bundle/components/public/SdkQuestion/SdkQuestion.unit.spec.tsx b/frontend/src/embedding-sdk-bundle/components/public/SdkQuestion/SdkQuestion.unit.spec.tsx
index 03ec6d950de..5a036ac0c17 100644
--- a/frontend/src/embedding-sdk-bundle/components/public/SdkQuestion/SdkQuestion.unit.spec.tsx
+++ b/frontend/src/embedding-sdk-bundle/components/public/SdkQuestion/SdkQuestion.unit.spec.tsx
@@ -17,6 +17,7 @@ import {
act,
mockGetBoundingClientRect,
screen,
+ waitFor,
waitForLoaderToBeRemoved,
within,
} from "__support__/ui";
@@ -186,14 +187,18 @@ describe("InteractiveQuestion", () => {
it("should render loading state when rerunning the query", async () => {
await setup({ withCustomLayout: true });
- expect(
- await within(screen.getByTestId("table-root")).findByText(
- TEST_COLUMN.display_name,
- ),
- ).toBeInTheDocument();
- expect(
- await within(screen.getByRole("gridcell")).findByText("Test Row"),
- ).toBeInTheDocument();
+ await waitFor(() => {
+ expect(
+ within(screen.getByTestId("table-root")).getByText(
+ TEST_COLUMN.display_name,
+ ),
+ ).toBeInTheDocument();
+ });
+ await waitFor(() => {
+ expect(
+ within(screen.getByRole("gridcell")).getByText("Test Row"),
+ ).toBeInTheDocument();
+ });
expect(screen.queryByTestId("loading-indicator")).not.toBeInTheDocument();
@@ -202,9 +207,11 @@ describe("InteractiveQuestion", () => {
expect(screen.queryByRole("alert")).not.toBeInTheDocument();
expect(screen.getByTestId("loading-indicator")).toBeInTheDocument();
- expect(
- within(await screen.findByRole("gridcell")).getByText("Test Row"),
- ).toBeInTheDocument();
+ await waitFor(() => {
+ expect(
+ within(screen.getByRole("gridcell")).getByText("Test Row"),
+ ).toBeInTheDocument();
+ });
});
});
diff --git a/frontend/src/metabase/visualizations/components/TableInteractive/TableInteractive.tsx b/frontend/src/metabase/visualizations/components/TableInteractive/TableInteractive.tsx
index f7e32574409..ef912c52076 100644
--- a/frontend/src/metabase/visualizations/components/TableInteractive/TableInteractive.tsx
+++ b/frontend/src/metabase/visualizations/components/TableInteractive/TableInteractive.tsx
@@ -707,8 +707,8 @@ export const TableInteractiveInner = forwardRef(function TableInteractiveInner(
}, [height, settings]);
const minGridWidth = useMemo(() => {
- return isDashcardViewTable ? width : undefined;
- }, [isDashcardViewTable, width]);
+ return isDashcardViewTable || isEmbeddingSdk ? width : undefined;
+ }, [isDashcardViewTable, isEmbeddingSdk, width]);
const tableProps = useDataGridInstance({
data: rows,