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
Add support for auto refresh prop in modular embeddings (#68896)
Mahatthana (Kelvin) Nomsawadi2e9aa4019c11
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.tsindex 3d2d1030eb2..1a52cd2df9e 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@@ -8,7 +8,7 @@ import {const { H } = cy;-describe("scenarios > embedding > sdk iframe embedding", () => {+describe("scenarios > embedding > modular embedding", () => {beforeEach(() => {H.prepareSdkIframeEmbedTest({ signOut: true });});@@ -268,6 +268,76 @@ describe("scenarios > embedding > sdk iframe embedding", () => {getIframeWindow().findByText("Orders in a dashboard").should("be.visible");});+ describe("auto-refreshing dashboard", () => {+ /**+ * Unfortunately, cy.clock() doesn't seem to work with mocking the timing inside the iframe,+ * so we have to use real timeouts here.+ */+ it('does not automatically refresh the dashboard when "auto-refresh-interval" is not set', () => {+ const frame = H.loadSdkIframeEmbedTestPage({+ elements: [+ {+ component: "metabase-dashboard",+ attributes: {+ dashboardId: ORDERS_DASHBOARD_ID,+ },+ },+ ],+ });++ frame.within(() => {+ cy.findByText("Orders in a dashboard").should("be.visible");+ cy.findByText("Orders").should("be.visible");+ H.assertTableRowsCount(2000);+ });++ cy.get("@getDashCardQuery.all").then((requests) => {+ cy.wrap(requests.length).as("initialRequestCount");+ });++ cy.log("wait for the retrigger");+ cy.wait(1000);+ cy.get("@initialRequestCount").then((initialRequestCount) => {+ cy.get("@getDashCardQuery.all").should(+ "have.length",+ initialRequestCount,+ );+ });+ });++ it('automatically refresh the dashboard when "auto-refresh-interval" is set', () => {+ const frame = H.loadSdkIframeEmbedTestPage({+ elements: [+ {+ component: "metabase-dashboard",+ attributes: {+ dashboardId: ORDERS_DASHBOARD_ID,+ autoRefreshInterval: 1,+ },+ },+ ],+ });++ frame.within(() => {+ cy.findByText("Orders in a dashboard").should("be.visible");+ cy.findByText("Orders").should("be.visible");+ H.assertTableRowsCount(2000);+ });++ cy.get("@getDashCardQuery.all").then((requests) => {+ cy.wrap(requests.length).as("initialRequestCount");+ });++ cy.log("wait for the retrigger");+ cy.get("@initialRequestCount").then((initialRequestCount) => {+ cy.get("@getDashCardQuery.all").should(+ "have.length.above",+ initialRequestCount,+ );+ });+ });+ });+it("CSP nonces are set for custom expression styles (EMB-707)", () => {const frame = H.loadSdkIframeEmbedTestPage({elements: [@@ -305,138 +375,138 @@ describe("scenarios > embedding > sdk iframe embedding", () => {cy.findByRole("button", { name: "Cancel" }).click();});});-});-describe("scenarios > embedding > Modular embedding", () => {- beforeEach(() => {- H.resetSnowplow();- H.prepareSdkIframeEmbedTest({- enabledAuthMethods: ["jwt"],- signOut: false,+ describe("analytics", () => {+ beforeEach(() => {+ H.resetSnowplow();+ H.prepareSdkIframeEmbedTest({+ enabledAuthMethods: ["jwt"],+ signOut: false,+ });+ H.enableTracking();});- H.enableTracking();- });- it("should send an modular embedding usage event", () => {- cy.signOut();- cy.visit("http://localhost:4000");- const frame = H.loadSdkIframeEmbedTestPage({- origin: "http://different-than-metabase-instance.com",- elements: [- {- component: "metabase-dashboard",- attributes: {- dashboardId: ORDERS_DASHBOARD_ID,- "with-subscriptions": true,+ it("should send an modular embedding usage event", () => {+ cy.signOut();+ cy.visit("http://localhost:4000");+ const frame = H.loadSdkIframeEmbedTestPage({+ origin: "http://different-than-metabase-instance.com",+ elements: [+ {+ component: "metabase-dashboard",+ attributes: {+ dashboardId: ORDERS_DASHBOARD_ID,+ "with-subscriptions": true,+ },},- },- {- component: "metabase-question",- attributes: {- questionId: ORDERS_QUESTION_ID,+ {+ component: "metabase-question",+ attributes: {+ questionId: ORDERS_QUESTION_ID,+ },},- },- {- component: "metabase-question",- attributes: {- questionId: "new",+ {+ component: "metabase-question",+ attributes: {+ questionId: "new",+ },},- },- {- component: "metabase-browser",- attributes: {},- },- ],- selector: `[dashboard-id="${ORDERS_DASHBOARD_ID}"] > iframe`, // get only the first iframe- });+ {+ component: "metabase-browser",+ attributes: {},+ },+ ],+ selector: `[dashboard-id="${ORDERS_DASHBOARD_ID}"] > iframe`, // get only the first iframe+ });- frame.within(() => {- cy.findByText("Orders in a dashboard").should("be.visible");- cy.findByText("Orders").should("be.visible");- H.assertTableRowsCount(2000);- });+ frame.within(() => {+ cy.findByText("Orders in a dashboard").should("be.visible");+ cy.findByText("Orders").should("be.visible");+ H.assertTableRowsCount(2000);+ });- H.expectUnstructuredSnowplowEvent({- event: "setup",- global: {- auth_method: "sso",- },- dashboard: {- with_title: {- false: 0,- true: 1,- },- with_downloads: {- false: 1,- true: 0,- },- drills: {- false: 0,- true: 1,- },- with_subscriptions: {- false: 0,- true: 1,- },- },- question: {- drills: {- false: 0,- true: 1,- },- with_downloads: {- false: 1,- true: 0,- },- with_title: {- false: 0,- true: 1,+ H.expectUnstructuredSnowplowEvent({+ event: "setup",+ global: {+ auth_method: "sso",},- is_save_enabled: {- false: 1,- true: 0,+ dashboard: {+ with_title: {+ false: 0,+ true: 1,+ },+ with_downloads: {+ false: 1,+ true: 0,+ },+ drills: {+ false: 0,+ true: 1,+ },+ with_subscriptions: {+ false: 0,+ true: 1,+ },},- with_alerts: {- false: 1,- true: 0,+ question: {+ drills: {+ false: 0,+ true: 1,+ },+ with_downloads: {+ false: 1,+ true: 0,+ },+ with_title: {+ false: 0,+ true: 1,+ },+ is_save_enabled: {+ false: 1,+ true: 0,+ },+ with_alerts: {+ false: 1,+ true: 0,+ },},- },- exploration: {- is_save_enabled: {- false: 1,- true: 0,+ exploration: {+ is_save_enabled: {+ false: 1,+ true: 0,+ },},- },- browser: {- read_only: {- false: 0,- true: 1,+ browser: {+ read_only: {+ false: 0,+ true: 1,+ },},- },+ });});- });- it("should not send an modular embedding usage event in the preview", () => {- cy.visit(`/question/${ORDERS_QUESTION_ID}`);+ it("should not send an modular embedding usage event in the preview", () => {+ cy.visit(`/question/${ORDERS_QUESTION_ID}`);- H.openEmbedJsModal();- H.embedModalEnableEmbedding();+ H.openEmbedJsModal();+ H.embedModalEnableEmbedding();- H.waitForSimpleEmbedIframesToLoad();- H.getSimpleEmbedIframeContent().within(() => {- cy.findByText("Orders").should("be.visible");- });+ H.waitForSimpleEmbedIframesToLoad();+ H.getSimpleEmbedIframeContent().within(() => {+ cy.findByText("Orders").should("be.visible");+ });- H.expectUnstructuredSnowplowEvent(- {- event: "setup",- global: {- auth_method: "session",+ H.expectUnstructuredSnowplowEvent(+ {+ event: "setup",+ global: {+ auth_method: "session",+ },},- },- // Expect that the usage event shouldn't be sent- 0,- );+ // Expect that the usage event shouldn't be sent+ 0,+ );+ });});});diff --git a/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/EditableDashboard.schema.ts b/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/EditableDashboard.schema.tsindex d3e99665d87..339bc9b54b5 100644--- a/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/EditableDashboard.schema.ts+++ b/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/EditableDashboard.schema.ts@@ -48,6 +48,7 @@ const propsSchema: Yup.SchemaOf<EditableDashboardProps> = Yup.object({.noUnknown(),renderDrillThroughQuestion: Yup.mixed().optional(),style: Yup.mixed().optional(),+ autoRefreshInterval: Yup.mixed().optional(),withCardTitle: Yup.mixed().optional(),withDownloads: Yup.mixed().optional(),withSubscriptions: Yup.mixed().optional(),diff --git a/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/EditableDashboard.stories.tsx b/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/EditableDashboard.stories.tsxindex 7e0e2a24300..30132fbc526 100644--- a/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/EditableDashboard.stories.tsx+++ b/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/EditableDashboard.stories.tsx@@ -155,6 +155,9 @@ const meta = {action: "onLoadWithoutCards",},},+ args: {+ autoRefreshInterval: 0,+ },render: ({ "dataPickerProps.entityTypes": entityTypes, ...args }) => {return (<EditableDashboarddiff --git a/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/EditableDashboard.tsx b/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/EditableDashboard.tsxindex 58313a01fb6..7bc8578a899 100644--- a/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/EditableDashboard.tsx+++ b/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/EditableDashboard.tsx@@ -32,6 +32,7 @@ export const EditableDashboardInner = (props: EditableDashboardProps) => {DASHBOARD_ACTION.EDIT_DASHBOARD,DASHBOARD_ACTION.DASHBOARD_SUBSCRIPTIONS,DASHBOARD_ACTION.DOWNLOAD_PDF,+ DASHBOARD_ACTION.REFRESH_INDICATOR,];const getClickActionMode: SdkDashboardInnerProps["getClickActionMode"] = ({diff --git a/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/enterprise.unit.spec.tsx b/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/enterprise.unit.spec.tsxindex cad9c002764..b43b2a09946 100644--- a/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/enterprise.unit.spec.tsx+++ b/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/enterprise.unit.spec.tsx@@ -10,6 +10,7 @@ import { screen, waitFor, within } from "__support__/ui";import { ROOT_COLLECTION } from "metabase/entities/collections";import { createMockCollection } from "metabase-types/api/mocks";+import { addEnterpriseAutoRefreshTests } from "../shared-tests/auto-refresh.spec";import { addEnterpriseSubscriptionsTests } from "../shared-tests/subscriptions.spec";import {type SetupSdkDashboardOptions,@@ -30,6 +31,7 @@ const setupEnterprise = async (describe("EditableDashboard", () => {addEnterpriseSubscriptionsTests(setupEnterprise);+ addEnterpriseAutoRefreshTests(setupEnterprise);it("should support dashboard editing", async () => {await setupEnterprise();diff --git a/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/premium.unit.spec.tsx b/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/premium.unit.spec.tsxindex 4f04e31f103..faf5b14efa2 100644--- a/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/premium.unit.spec.tsx+++ b/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/premium.unit.spec.tsx@@ -10,6 +10,7 @@ import { screen, within } from "__support__/ui";import { ROOT_COLLECTION } from "metabase/entities/collections";import { createMockCollection } from "metabase-types/api/mocks";+import { addPremiumAutoRefreshTests } from "../shared-tests/auto-refresh.spec";import { addPremiumSubscriptionsTests } from "../shared-tests/subscriptions.spec";import {type SetupSdkDashboardOptions,@@ -33,6 +34,7 @@ const setupPremium = async (describe("EditableDashboard", () => {addPremiumSubscriptionsTests(setupPremium);+ addPremiumAutoRefreshTests(setupPremium);it("should allow to create a new question in addition to adding existing questions", async () => {await setupPremium();diff --git a/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.schema.ts b/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.schema.tsindex b2e3335cea8..6335ed69dfa 100644--- a/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.schema.ts+++ b/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.schema.ts@@ -50,6 +50,7 @@ const propsSchema: Yup.SchemaOf<InteractiveDashboardProps> = Yup.object({.noUnknown(),renderDrillThroughQuestion: Yup.mixed().optional(),style: Yup.mixed().optional(),+ autoRefreshInterval: Yup.mixed().optional(),withCardTitle: Yup.mixed().optional(),withDownloads: Yup.mixed().optional(),withSubscriptions: Yup.mixed().optional(),diff --git a/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.stories.tsx b/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.stories.tsxindex 838b04a6fe6..330239912e0 100644--- a/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.stories.tsx+++ b/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.stories.tsx@@ -144,6 +144,9 @@ export default {action: "onLoadWithoutCards",},},+ args: {+ autoRefreshInterval: 0,+ },};const Template: StoryFn<InteractiveDashboardProps> = (args) => {diff --git a/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.tsx b/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.tsxindex f537d34c053..624c665bda5 100644--- a/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.tsx+++ b/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.tsx@@ -47,6 +47,7 @@ const InteractiveDashboardInner = (props: InteractiveDashboardProps) => {dashboardActions={[DASHBOARD_ACTION.DASHBOARD_SUBSCRIPTIONS,DASHBOARD_ACTION.DOWNLOAD_PDF,+ DASHBOARD_ACTION.REFRESH_INDICATOR,]}dashcardMenu={({ dashcard, result, downloadsEnabled }) =>downloadsEnabled?.results &&diff --git a/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/tests/enterprise.unit.spec.tsx b/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/tests/enterprise.unit.spec.tsxindex 74b04e79110..cbd64abbd5e 100644--- a/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/tests/enterprise.unit.spec.tsx+++ b/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/tests/enterprise.unit.spec.tsx@@ -1,3 +1,4 @@+import { addEnterpriseAutoRefreshTests } from "../../shared-tests/auto-refresh.spec";import { addEnterpriseSubscriptionsTests } from "../../shared-tests/subscriptions.spec";import {type SetupSdkDashboardOptions,@@ -19,4 +20,5 @@ console.warn = () => {};describe("InteractiveDashboard", () => {addEnterpriseSubscriptionsTests(setupEnterprise);+ addEnterpriseAutoRefreshTests(setupEnterprise);});diff --git a/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/tests/premium.unit.spec.tsx b/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/tests/premium.unit.spec.tsxindex 5eaaff8f04c..0140531d886 100644--- a/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/tests/premium.unit.spec.tsx+++ b/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/tests/premium.unit.spec.tsx@@ -1,3 +1,4 @@+import { addPremiumAutoRefreshTests } from "../../shared-tests/auto-refresh.spec";import { addPremiumSubscriptionsTests } from "../../shared-tests/subscriptions.spec";import {type SetupSdkDashboardOptions,@@ -22,4 +23,5 @@ console.warn = () => {};describe("InteractiveDashboard", () => {addPremiumSubscriptionsTests(setupPremium);+ addPremiumAutoRefreshTests(setupPremium);});diff --git a/frontend/src/embedding-sdk-bundle/components/public/dashboard/SdkDashboard.tsx b/frontend/src/embedding-sdk-bundle/components/public/dashboard/SdkDashboard.tsxindex 93508e3a8fd..d2a9f7ffcc5 100644--- a/frontend/src/embedding-sdk-bundle/components/public/dashboard/SdkDashboard.tsx+++ b/frontend/src/embedding-sdk-bundle/components/public/dashboard/SdkDashboard.tsx@@ -7,6 +7,7 @@ import {useRef,useState,} from "react";+import { useUnmount } from "react-use";import { match } from "ts-pattern";import { t } from "ttag";@@ -51,6 +52,7 @@ import {useDashboardContext,} from "metabase/dashboard/context";import { getDashboardComplete, getIsDirty } from "metabase/dashboard/selectors";+import type { RefreshPeriod } from "metabase/dashboard/types";import { EmbeddingEntityContextProvider } from "metabase/embedding/context";import type { ParameterValues } from "metabase/embedding-sdk/types/dashboard";import { isStaticEmbeddingEntityLoadingError } from "metabase/lib/errors/is-static-embedding-entity-loading-error";@@ -114,6 +116,11 @@ export type SdkDashboardProps = PropsWithChildren<*/dashboardId: SdkDashboardId;+ /**+ * The interval between auto refreshes on the dashboard, in seconds.+ */+ autoRefreshInterval?: number;+/*** Query parameters for the dashboard. For a single option, use a `string` value, and use a list of strings for multiple options.* <br/>@@ -155,6 +162,7 @@ export type SdkDashboardInnerProps = SdkDashboardProps &const SdkDashboardInner = ({dashboardId: rawDashboardId,token: rawToken,+ autoRefreshInterval,initialParameters = {},withTitle = true,withCardTitle = true,@@ -411,6 +419,7 @@ const SdkDashboardInner = ({style={style}><Dashboard className={EmbedFrameS.EmbedFrame} />+ <AutoRefreshController refreshPeriod={autoRefreshInterval} /></SdkDashboardStyledWrapperWithRef>)}</SdkDashboardProvider>@@ -528,3 +537,22 @@ function DashboardQueryBuilder({/>);}++interface AutoRefreshControllerProps {+ refreshPeriod: RefreshPeriod | undefined;+}+function AutoRefreshController({ refreshPeriod }: AutoRefreshControllerProps) {+ const { onRefreshPeriodChange } = useDashboardContext();++ useEffect(() => {+ const normalizedRefreshPeriod =+ refreshPeriod != null && refreshPeriod >= 0 ? refreshPeriod : null;+ onRefreshPeriodChange(normalizedRefreshPeriod);+ }, [refreshPeriod, onRefreshPeriodChange]);++ useUnmount(() => {+ onRefreshPeriodChange(null);+ });++ return null;+}diff --git a/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/StaticDashboard.schema.ts b/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/StaticDashboard.schema.tsindex 1ee14baea2c..48ab49d081e 100644--- a/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/StaticDashboard.schema.ts+++ b/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/StaticDashboard.schema.ts@@ -29,6 +29,7 @@ const propsSchema: Yup.SchemaOf<StaticDashboardProps> = Yup.object({.optional().noUnknown(),style: Yup.mixed().optional(),+ autoRefreshInterval: Yup.mixed().optional(),withCardTitle: Yup.mixed().optional(),withDownloads: Yup.mixed().optional(),withSubscriptions: Yup.mixed().optional(),diff --git a/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/StaticDashboard.stories.tsx b/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/StaticDashboard.stories.tsxindex 5486092a899..b0afbbb8553 100644--- a/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/StaticDashboard.stories.tsx+++ b/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/StaticDashboard.stories.tsx@@ -142,6 +142,9 @@ export default {action: "onLoadWithoutCards",},},+ args: {+ autoRefreshInterval: 0,+ },};const Template: StoryFn<StaticDashboardProps> = (args) => {diff --git a/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/StaticDashboard.tsx b/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/StaticDashboard.tsxindex 1267956b565..1d387cfa9b3 100644--- a/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/StaticDashboard.tsx+++ b/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/StaticDashboard.tsx@@ -47,6 +47,7 @@ const StaticDashboardInner = (props: StaticDashboardProps) => {dashboardActions={[DASHBOARD_ACTION.DASHBOARD_SUBSCRIPTIONS,DASHBOARD_ACTION.DOWNLOAD_PDF,+ DASHBOARD_ACTION.REFRESH_INDICATOR,]}navigateToNewCardFromDashboard={null}dashcardMenu={({ dashcard, result }) =>diff --git a/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/tests/enterprise.unit.spec.tsx b/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/tests/enterprise.unit.spec.tsxindex 2e218644fb4..466b4953f13 100644--- a/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/tests/enterprise.unit.spec.tsx+++ b/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/tests/enterprise.unit.spec.tsx@@ -4,6 +4,7 @@ import type { ComponentType } from "react";import { screen, waitFor, within } from "__support__/ui";import type { SdkDashboardProps } from "embedding-sdk-bundle/components/public/dashboard/SdkDashboard";+import { addEnterpriseAutoRefreshTests } from "../../shared-tests/auto-refresh.spec";import { addEnterpriseSubscriptionsTests } from "../../shared-tests/subscriptions.spec";import {type SetupSdkDashboardOptions,@@ -28,6 +29,7 @@ console.warn = () => {};describe("StaticDashboard", () => {addEnterpriseSubscriptionsTests(setupEnterprise);+ addEnterpriseAutoRefreshTests(setupEnterprise);it("should not allow users to click the dashcard title", async () => {await setupEnterprise();diff --git a/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/tests/premium.unit.spec.tsx b/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/tests/premium.unit.spec.tsxindex 530d7a882d5..a581f1b798c 100644--- a/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/tests/premium.unit.spec.tsx+++ b/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/tests/premium.unit.spec.tsx@@ -2,6 +2,7 @@ import type { ComponentType } from "react";import type { SdkDashboardProps } from "embedding-sdk-bundle/components/public/dashboard/SdkDashboard";+import { addPremiumAutoRefreshTests } from "../../shared-tests/auto-refresh.spec";import { addPremiumSubscriptionsTests } from "../../shared-tests/subscriptions.spec";import {type SetupSdkDashboardOptions,@@ -29,4 +30,5 @@ console.warn = () => {};describe("StaticDashboard", () => {addPremiumSubscriptionsTests(setupPremium);+ addPremiumAutoRefreshTests(setupPremium);});diff --git a/frontend/src/embedding-sdk-bundle/components/public/dashboard/shared-tests/auto-refresh.spec.ts b/frontend/src/embedding-sdk-bundle/components/public/dashboard/shared-tests/auto-refresh.spec.tsnew file mode 100644index 00000000000..32a2757efa6--- /dev/null+++ b/frontend/src/embedding-sdk-bundle/components/public/dashboard/shared-tests/auto-refresh.spec.ts@@ -0,0 +1,116 @@+import { waitFor } from "@testing-library/react";++import { findRequests } from "__support__/server-mocks";+import { screen } from "__support__/ui";+import type { Dashboard } from "metabase-types/api";++import type { SetupSdkDashboardOptions } from "../tests/setup";++type SetupOpts = Omit<SetupSdkDashboardOptions, "component">;++export function addEnterpriseAutoRefreshTests(+ setup: (options?: SetupOpts) => Promise<{ dashboard: Dashboard }>,+) {+ describe("autoRefreshInterval property", () => {+ const DASHBOARD_CARD_QUERY_REQUEST_COUNT = 1;++ afterEach(() => {+ jest.useRealTimers();+ });++ it("should support auto-refreshing dashboards for positive integers", async () => {+ jest.useFakeTimers();++ await setup({ props: { autoRefreshInterval: 10 } });++ // Wait for initial dashboard load+ await waitFor(async () => {+ const initialRequests = await getDashboardQueryRequests();+ expect(initialRequests.length).toBe(+ 1 * DASHBOARD_CARD_QUERY_REQUEST_COUNT,+ );+ });++ // Advance time by the auto-refresh interval (10 seconds)+ jest.advanceTimersByTime(10_000);++ // Wait for the auto-refresh request to be made+ await waitFor(async () => {+ const requestsAfterRefresh = await getDashboardQueryRequests();+ expect(requestsAfterRefresh.length).toBe(+ 2 * DASHBOARD_CARD_QUERY_REQUEST_COUNT,+ );+ });++ // Advance time again to test multiple refresh cycles+ jest.advanceTimersByTime(10_000);++ await waitFor(async () => {+ const requestsAfterSecondRefresh = await getDashboardQueryRequests();+ expect(requestsAfterSecondRefresh.length).toBe(+ 3 * DASHBOARD_CARD_QUERY_REQUEST_COUNT,+ );+ });+ });++ it("should show the auto-refresh indicator in the dashboard header for positive integers", async () => {+ await setup({ props: { autoRefreshInterval: 10 } });++ expect(+ screen.getByRole("button", { name: "Auto Refresh" }),+ ).toBeVisible();+ });++ describe.each([+ { name: "null", value: null },+ { name: "undefined", value: undefined },+ { name: "0", value: 0 },+ { name: "negative", value: -10 },+ ])("when interval is $name", ({ value }) => {+ it("should not auto-refresh", async () => {+ jest.useFakeTimers();++ // Forces the type, because users can literally pass any type here+ await setup({ props: { autoRefreshInterval: value as number } });++ // Wait for initial dashboard load+ await waitFor(async () => {+ const initialRequests = await getDashboardQueryRequests();+ expect(initialRequests.length).toBe(+ DASHBOARD_CARD_QUERY_REQUEST_COUNT,+ );+ });++ // Advance time significantly+ jest.advanceTimersByTime(30_000);++ // Verify no additional requests were made+ const finalRequests = await getDashboardQueryRequests();+ expect(finalRequests.length).toBe(DASHBOARD_CARD_QUERY_REQUEST_COUNT);+ });++ it("should not show the auto-refresh indicator in the dashboard header", async () => {+ // Forces the type, because users can literally pass any type here+ await setup({ props: { autoRefreshInterval: value as number } });++ expect(+ screen.queryByRole("button", { name: "Auto Refresh" }),+ ).not.toBeInTheDocument();+ });+ });+ });+}++export const addPremiumAutoRefreshTests = addEnterpriseAutoRefreshTests;++async function getDashboardQueryRequests() {+ return findRequests("POST").then((requests) =>+ requests.filter((req) =>+ req.url.match(+ new RegExp(+ "^http://localhost/api/dashboard/\\d+/dashcard/\\d+/card/\\d+/query",+ ),+ ),+ ),+ );+}diff --git a/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderButtonRow/DashboardHeaderButtonRow.tsx b/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderButtonRow/DashboardHeaderButtonRow.tsxindex 62b174c3f58..0808b078c72 100644--- a/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderButtonRow/DashboardHeaderButtonRow.tsx+++ b/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderButtonRow/DashboardHeaderButtonRow.tsx@@ -42,6 +42,7 @@ export const DashboardHeaderButtonRow = ({downloadsEnabled,withSubscriptions,dashboardActions,+ refreshPeriod,} = useDashboardContext();const hasModelActionsEnabled = useSelector(getHasModelActionsEnabled);@@ -80,6 +81,7 @@ export const DashboardHeaderButtonRow = ({onFullscreenChange,downloadsEnabled,withSubscriptions,+ refreshPeriod,...buttonComponentProps,})) {diff --git a/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderButtonRow/DashboardHeaderButtonRow.unit.spec.tsx b/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderButtonRow/DashboardHeaderButtonRow.unit.spec.tsxindex 3145e113a3b..208e8939a81 100644--- a/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderButtonRow/DashboardHeaderButtonRow.unit.spec.tsx+++ b/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderButtonRow/DashboardHeaderButtonRow.unit.spec.tsx@@ -100,10 +100,8 @@ const DASHBOARD_EXPECTED_DATA_MAP: Record<icon: "download",tooltip: "Download as PDF",},- DASHBOARD_SUBSCRIPTIONS: {- icon: "subscription",- tooltip: "Subscriptions",- },+ DASHBOARD_SUBSCRIPTIONS: {},+ REFRESH_INDICATOR: {},};const setup = ({diff --git a/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderButtonRow/action-buttons.tsx b/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderButtonRow/action-buttons.tsxindex 894a3445f12..99d1054165e 100644--- a/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderButtonRow/action-buttons.tsx+++ b/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderButtonRow/action-buttons.tsx@@ -20,6 +20,7 @@ import {} from "../buttons";import { AddLinkOrEmbedButton } from "../buttons/AddLinkOrEmbedButton";import { DashboardSubscriptionsButton } from "../buttons/DashboardSubscriptionsButton";+import { RefreshIndicator } from "../buttons/RefreshIndicator";import { DASHBOARD_ACTION } from "./dashboard-action-keys";import type { DashboardActionButton, DashboardActionKey } from "./types";@@ -135,4 +136,8 @@ export const dashboardActionButtons: Record<enabled: ({ withSubscriptions }) => withSubscriptions,component: () => <DashboardSubscriptionsButton />,},+ [DASHBOARD_ACTION.REFRESH_INDICATOR]: {+ enabled: ({ refreshPeriod }) => refreshPeriod != null && refreshPeriod > 0,+ component: () => <RefreshIndicator />,+ },};diff --git a/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderButtonRow/dashboard-action-keys.tsx b/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderButtonRow/dashboard-action-keys.tsxindex 0898d3cba9c..c8a471e5e8f 100644--- a/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderButtonRow/dashboard-action-keys.tsx+++ b/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderButtonRow/dashboard-action-keys.tsx@@ -19,6 +19,7 @@ export const DASHBOARD_ACTION = {DOWNLOAD_PDF: "DOWNLOAD_PDF",// Modular embeddings (modular embedding, modular embedding SDK)DASHBOARD_SUBSCRIPTIONS: "DASHBOARD_SUBSCRIPTIONS",+ REFRESH_INDICATOR: "REFRESH_INDICATOR",} as const;type DashboardActionKey = keyof typeof DASHBOARD_ACTION;diff --git a/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderButtonRow/types.ts b/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderButtonRow/types.tsindex e5f2b6ee888..f609a0dd354 100644--- a/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderButtonRow/types.ts+++ b/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderButtonRow/types.ts@@ -38,6 +38,7 @@ export type DashboardActionButton = {| "isFullscreen"| "onFullscreenChange"| "withSubscriptions"+ | "refreshPeriod">,) => boolean;};diff --git a/frontend/src/metabase/dashboard/components/DashboardHeader/buttons/RefreshIndicator.tsx b/frontend/src/metabase/dashboard/components/DashboardHeader/buttons/RefreshIndicator.tsxnew file mode 100644index 00000000000..16f4f47a875--- /dev/null+++ b/frontend/src/metabase/dashboard/components/DashboardHeader/buttons/RefreshIndicator.tsx@@ -0,0 +1,26 @@+import { useEffect, useState } from "react";++import CS from "metabase/css/core/index.css";+import { useDashboardContext } from "metabase/dashboard/context";++import { RefreshWidgetTarget } from "../../RefreshWidget/RefreshWidgetTarget";++/**+ * This is only used in modular embeddings+ */+export function RefreshIndicator() {+ const { refreshPeriod, setRefreshElapsedHook } = useDashboardContext();+ const [elapsed, setElapsed] = useState<number | null>(null);++ useEffect(() => {+ setRefreshElapsedHook(setElapsed);+ }, [setRefreshElapsedHook]);++ return (+ <RefreshWidgetTarget+ elapsed={elapsed}+ period={refreshPeriod}+ className={CS.cursorDefault}+ />+ );+}diff --git a/frontend/src/metabase/dashboard/components/RefreshWidget/RefreshWidgetTarget.tsx b/frontend/src/metabase/dashboard/components/RefreshWidget/RefreshWidgetTarget.tsxindex a4c37285cb7..b3c956063da 100644--- a/frontend/src/metabase/dashboard/components/RefreshWidget/RefreshWidgetTarget.tsx+++ b/frontend/src/metabase/dashboard/components/RefreshWidget/RefreshWidgetTarget.tsx@@ -44,6 +44,7 @@ export const RefreshWidgetTarget = ({}name="clock"aria-label={t`Auto Refresh`}+ {...buttonProps}><CountdownIconwidth={16}diff --git a/frontend/src/metabase/dashboard/hooks/use-dashboard-refresh-period.ts b/frontend/src/metabase/dashboard/hooks/use-dashboard-refresh-period.tsindex 17a34ddeac1..69a2aaba10d 100644--- a/frontend/src/metabase/dashboard/hooks/use-dashboard-refresh-period.ts+++ b/frontend/src/metabase/dashboard/hooks/use-dashboard-refresh-period.ts@@ -1,10 +1,9 @@+import { useInterval } from "@mantine/hooks";import { useCallback, useRef, useState } from "react";import { useUnmount } from "react-use";import type { DashboardRefreshPeriodControls } from "../types";-import { useInterval } from "./use-interval";-const TICK_PERIOD = 1; // secondsexport const useDashboardRefreshPeriod = ({onRefresh,diff --git a/frontend/src/metabase/dashboard/hooks/use-interval.ts b/frontend/src/metabase/dashboard/hooks/use-interval.tsdeleted file mode 100644index a52e3dd7138..00000000000--- a/frontend/src/metabase/dashboard/hooks/use-interval.ts+++ /dev/null@@ -1,39 +0,0 @@-import { useCallback, useEffect, useRef, useState } from "react";--/**- * it's a copy of mantine's useInterval, but with memoization of the callbacks- */-export function useInterval(fn: () => void, interval: number) {- const [active, setActive] = useState(false);- const intervalRef = useRef<number>();- const fnRef = useRef<() => void>();-- useEffect(() => {- fnRef.current = fn;- }, [fn]);-- const start = useCallback(() => {- setActive((old) => {- if (!old && !intervalRef.current) {- intervalRef.current = window.setInterval(fnRef.current!, interval);- }- return true;- });- }, [interval, fnRef]);-- const stop = useCallback(() => {- setActive(false);- window.clearInterval(intervalRef.current);- intervalRef.current = undefined;- }, []);-- const toggle = useCallback(() => {- if (active) {- stop();- } else {- start();- }- }, [active, start, stop]);-- return { start, stop, toggle, active };-}diff --git a/frontend/src/metabase/dashboard/types/embed-display-options.ts b/frontend/src/metabase/dashboard/types/embed-display-options.tsindex 34854f7c25a..61a5e99ebd9 100644--- a/frontend/src/metabase/dashboard/types/embed-display-options.ts+++ b/frontend/src/metabase/dashboard/types/embed-display-options.ts@@ -30,6 +30,6 @@ export type EmbedDisplayParams = {getClickActionMode: ClickActionModeGetter | undefined;downloadsEnabled: EmbedResourceDownloadOptions;withFooter: boolean;- // TODO: (Kelvin 2025-11-17) move this to a new type in EMB-1025+ // TODO: (Kelvin 2026-01-29) move this to a new type in EMB-1025 (canceled at moment)withSubscriptions: boolean;};diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk/components/SdkIframeEmbedRoute.tsx b/frontend/src/metabase/embedding/embedding-iframe-sdk/components/SdkIframeEmbedRoute.tsxindex c2278e0d205..a6663275202 100644--- a/frontend/src/metabase/embedding/embedding-iframe-sdk/components/SdkIframeEmbedRoute.tsx+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk/components/SdkIframeEmbedRoute.tsx@@ -171,6 +171,7 @@ const SdkIframeEmbedView = ({key={rerenderKey}className={SdkIframeEmbedRouteS.Dashboard}{...entityProps}+ autoRefreshInterval={settings.autoRefreshInterval}withTitle={settings.withTitle}withDownloads={settings.withDownloads}initialParameters={settings.initialParameters}@@ -192,6 +193,7 @@ const SdkIframeEmbedView = ({className={SdkIframeEmbedRouteS.Dashboard}dashboardId={settings.dashboardId ?? null}token={settings.token}+ autoRefreshInterval={settings.autoRefreshInterval}withTitle={settings.withTitle}withDownloads={settings.withDownloads}withSubscriptions={settings.withSubscriptions}diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk/constants.ts b/frontend/src/metabase/embedding/embedding-iframe-sdk/constants.tsindex da28df138c6..624bf56a5b8 100644--- a/frontend/src/metabase/embedding/embedding-iframe-sdk/constants.ts+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk/constants.ts@@ -30,6 +30,7 @@ export const ALLOWED_EMBED_SETTING_KEYS_MAP = {] satisfies (keyof SdkIframeEmbedBaseSettings)[],dashboard: ["dashboardId",+ "autoRefreshInterval","withTitle","withDownloads","withSubscriptions",@@ -67,6 +68,7 @@ export const ALLOWED_EMBED_SETTING_KEYS_MAP = {] satisfies (keyof BrowserEmbedOptions)[],metabot: ["layout"] satisfies (keyof MetabotEmbedOptions)[],} as const;+export const ALLOWED_GUEST_EMBED_SETTING_KEYS_MAP = {base: ["apiKey",@@ -77,6 +79,7 @@ export const ALLOWED_GUEST_EMBED_SETTING_KEYS_MAP = {] satisfies (keyof SdkIframeEmbedBaseSettings)[],dashboard: ["token",+ "autoRefreshInterval","withTitle","withDownloads","initialParameters",diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk/embed.ts b/frontend/src/metabase/embedding/embedding-iframe-sdk/embed.tsindex 88beff4ef55..c7a2e95b510 100644--- a/frontend/src/metabase/embedding/embedding-iframe-sdk/embed.ts+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk/embed.ts@@ -497,6 +497,7 @@ function createCustomElement<Arr extends readonly string[]>(const MetabaseDashboardElement = createCustomElement("metabase-dashboard", ["dashboard-id","token",+ "auto-refresh-interval","with-title","with-downloads","with-subscriptions",diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk/types/embed.ts b/frontend/src/metabase/embedding/embedding-iframe-sdk/types/embed.tsindex 133f3e939a3..be64ea22a75 100644--- a/frontend/src/metabase/embedding/embedding-iframe-sdk/types/embed.ts+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk/types/embed.ts@@ -74,6 +74,7 @@ export type DashboardEmbedOptions = StrictUnion<componentName: "metabase-dashboard";drills?: boolean;+ autoRefreshInterval?: number;withTitle?: boolean;withDownloads?: boolean;withSubscriptions?: boolean;diff --git a/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.styled.tsx b/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.styled.tsxindex e3072ac4db4..999168f0d73 100644--- a/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.styled.tsx+++ b/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.styled.tsx@@ -40,6 +40,7 @@ export const SearchInputContainer = styled.div<{}return css`background-color: var(--mb-color-background-primary);+&:hover {background-color: var(--mb-color-background-secondary);}