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
Closes EMB-906 custom branding images for SDK (#64946)
Sébastiend2b54425f261
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.schema.ts b/enterprise/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.schema.tsindex 422e748bb7d..9f9328dafc3 100644--- a/enterprise/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.schema.ts+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.schema.ts@@ -42,6 +42,8 @@ const propsSchema: Yup.SchemaOf<InteractiveDashboardProps> = Yup.object({plugins: Yup.object({mapQuestionClickActions: Yup.mixed().optional(),dashboard: Yup.mixed().optional(),+ getNoDataIllustration: Yup.mixed().optional(),+ getNoObjectIllustration: Yup.mixed().optional(),}).optional().noUnknown(),diff --git a/enterprise/frontend/src/embedding-sdk-bundle/types/plugins.ts b/enterprise/frontend/src/embedding-sdk-bundle/types/plugins.tsindex 3dcfeed5814..13f59daadc3 100644--- a/enterprise/frontend/src/embedding-sdk-bundle/types/plugins.ts+++ b/enterprise/frontend/src/embedding-sdk-bundle/types/plugins.ts@@ -38,4 +38,17 @@ export type MetabaseDashboardPluginsConfig = {export type MetabasePluginsConfig = {mapQuestionClickActions?: MetabaseClickActionPluginsConfig;dashboard?: MetabaseDashboardPluginsConfig;+ /**+ * Provides a custom illustration to display when there is no data.+ *+ * @returns A base64-encoded image string, or null to use the default illustration+ */+ getNoDataIllustration?: () => string | null | undefined;++ /**+ * Provides a custom illustration to display when there is no object (e.g., no dashboards, no collections).+ *+ * @returns A base64-encoded image string, or null to use the default illustration+ */+ getNoObjectIllustration?: () => string | null | undefined;};diff --git a/enterprise/frontend/src/metabase-enterprise/sdk-plugins.js b/enterprise/frontend/src/metabase-enterprise/sdk-plugins.jsindex 835b8920242..761dceb017b 100644--- a/enterprise/frontend/src/metabase-enterprise/sdk-plugins.js+++ b/enterprise/frontend/src/metabase-enterprise/sdk-plugins.js@@ -1,5 +1,7 @@import { PLUGIN_IS_EE_BUILD } from "metabase/plugins";+import { initializeSdkPlugins } from "./whitelabel/sdk-overrides";+// SETTINGS OVERRIDES:PLUGIN_IS_EE_BUILD.isEEBuild = () => true;@@ -10,3 +12,5 @@ import "./shared";import "./embedding";import "./embedding-sdk";import "./metabot";++initializeSdkPlugins();diff --git a/enterprise/frontend/src/metabase-enterprise/whitelabel/sdk-overrides.ts b/enterprise/frontend/src/metabase-enterprise/whitelabel/sdk-overrides.tsnew file mode 100644index 00000000000..d42332f25b6--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/whitelabel/sdk-overrides.ts@@ -0,0 +1,59 @@+import type { SdkStoreState } from "embedding-sdk-bundle/store/types";+import { PLUGIN_SELECTORS } from "metabase/plugins";+import type { State } from "metabase-types/store";++// Store the original selector functions to preserve Enterprise/OSS behavior+const originalGetNoDataIllustration = PLUGIN_SELECTORS.getNoDataIllustration;+const originalGetNoObjectIllustration =+ PLUGIN_SELECTORS.getNoObjectIllustration;++// Flag to ensure initialization happens only once+let isInitialized = false;++/**+ * Initialize SDK plugins by overriding core plugin selectors to be SDK-aware.+ * This allows the SDK to provide custom implementations while maintaining+ * backward compatibility with Enterprise and OSS versions.+ */+export const initializeSdkPlugins = () => {+ if (isInitialized) {+ return;+ }++ isInitialized = true;++ // Override the selectors to be SDK-aware+ PLUGIN_SELECTORS.getNoDataIllustration = (state: State) => {+ try {+ // Check if we're in an SDK context with plugins+ const sdkState = (state as SdkStoreState).sdk;+ const sdkResult = sdkState?.plugins?.getNoDataIllustration?.();+ if (sdkResult !== null && sdkResult !== undefined) {+ return sdkResult;+ }+ } catch (error) {+ // Log error but don't break the application+ console.error("Error in SDK getNoDataIllustration plugin:", error);+ }++ // Fall back to original Enterprise/OSS behavior+ return originalGetNoDataIllustration(state);+ };++ PLUGIN_SELECTORS.getNoObjectIllustration = (state: State) => {+ try {+ // Check if we're in an SDK context with plugins+ const sdkState = (state as SdkStoreState).sdk;+ const sdkResult = sdkState?.plugins?.getNoObjectIllustration?.();+ if (sdkResult !== null && sdkResult !== undefined) {+ return sdkResult;+ }+ } catch (error) {+ // Log error but don't break the application+ console.error("Error in SDK getNoObjectIllustration plugin:", error);+ }++ // Fall back to original Enterprise/OSS behavior+ return originalGetNoObjectIllustration(state);+ };+};diff --git a/enterprise/frontend/src/metabase-enterprise/whitelabel/sdk-overrides.unit.spec.ts b/enterprise/frontend/src/metabase-enterprise/whitelabel/sdk-overrides.unit.spec.tsnew file mode 100644index 00000000000..eeabf55ab87--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/whitelabel/sdk-overrides.unit.spec.ts@@ -0,0 +1,221 @@+import { PLUGIN_SELECTORS } from "metabase/plugins";++import { initializeSdkPlugins } from "./sdk-overrides";++describe("SDK Plugin Initialization", () => {+ let originalGetNoDataIllustration: typeof PLUGIN_SELECTORS.getNoDataIllustration;+ let originalGetNoObjectIllustration: typeof PLUGIN_SELECTORS.getNoObjectIllustration;++ beforeAll(() => {+ // Store original selectors before all tests+ originalGetNoDataIllustration = PLUGIN_SELECTORS.getNoDataIllustration;+ originalGetNoObjectIllustration = PLUGIN_SELECTORS.getNoObjectIllustration;++ // Initialize SDK plugins once for all tests+ initializeSdkPlugins();+ });++ afterAll(() => {+ // Restore original selectors after all tests+ PLUGIN_SELECTORS.getNoDataIllustration = originalGetNoDataIllustration;+ PLUGIN_SELECTORS.getNoObjectIllustration = originalGetNoObjectIllustration;+ });++ describe("initializeSdkPlugins", () => {+ it("should initialize SDK plugins and make selectors SDK-aware", () => {+ // Selectors should be different after initialization+ expect(PLUGIN_SELECTORS.getNoDataIllustration).not.toBe(+ originalGetNoDataIllustration,+ );+ expect(PLUGIN_SELECTORS.getNoObjectIllustration).not.toBe(+ originalGetNoObjectIllustration,+ );+ });++ it("should return SDK plugin result when SDK plugins are available", () => {+ const mockSdkIllustration = "custom-sdk-illustration.svg";+ const mockSdkPlugins = {+ getNoDataIllustration: jest.fn().mockReturnValue(mockSdkIllustration),+ };++ const mockState = {+ sdk: {+ plugins: mockSdkPlugins,+ },+ } as any;++ const result = PLUGIN_SELECTORS.getNoDataIllustration(mockState);++ expect(result).toBe(mockSdkIllustration);+ expect(mockSdkPlugins.getNoDataIllustration).toHaveBeenCalled();+ });++ it.each([null, undefined])(+ "should fall back to original selector when SDK plugin returns %s",+ (pluginReturnValue) => {+ const mockSdkPlugins = {+ getNoDataIllustration: jest.fn().mockReturnValue(pluginReturnValue),+ };++ const mockState = {+ sdk: {+ plugins: mockSdkPlugins,+ },+ } as any;++ // Should not throw an error when SDK plugin returns null+ expect(() => {+ PLUGIN_SELECTORS.getNoDataIllustration(mockState);+ }).not.toThrow();++ const result = PLUGIN_SELECTORS.getNoDataIllustration(mockState);+ const originalResult = originalGetNoDataIllustration(mockState);++ expect(result).toBe(originalResult);+ expect(mockSdkPlugins.getNoDataIllustration).toHaveBeenCalled();+ },+ );++ it("should handle missing SDK plugins gracefully", () => {+ const mockState = {+ sdk: {+ plugins: null,+ },+ } as any;++ // Should not throw an error when no SDK plugins are available+ expect(() => {+ PLUGIN_SELECTORS.getNoDataIllustration(mockState);+ }).not.toThrow();+ });++ it("should handle errors in SDK plugin functions gracefully", () => {+ const mockSdkPlugins = {+ getNoDataIllustration: jest.fn().mockImplementation(() => {+ throw new Error("Plugin error");+ }),+ };++ const mockState = {+ sdk: {+ plugins: mockSdkPlugins,+ },+ } as any;++ const consoleSpy = jest+ .spyOn(console, "error")+ .mockImplementation(() => {});++ // Should not throw an error even when SDK plugin throws+ expect(() => {+ PLUGIN_SELECTORS.getNoDataIllustration(mockState);+ }).not.toThrow();++ expect(consoleSpy).toHaveBeenCalledWith(+ "Error in SDK getNoDataIllustration plugin:",+ expect.any(Error),+ );++ consoleSpy.mockRestore();+ });++ it("should return SDK plugin result for getNoObjectIllustration when SDK plugins are available", () => {+ const mockSdkIllustration = "custom-sdk-no-object-illustration.svg";+ const mockSdkPlugins = {+ getNoObjectIllustration: jest.fn().mockReturnValue(mockSdkIllustration),+ };++ const mockState = {+ sdk: {+ plugins: mockSdkPlugins,+ },+ } as any;++ const result = PLUGIN_SELECTORS.getNoObjectIllustration(mockState);++ expect(result).toBe(mockSdkIllustration);+ expect(mockSdkPlugins.getNoObjectIllustration).toHaveBeenCalled();+ });++ it("should handle SDK getNoObjectIllustration plugin functions that return null", () => {+ const mockSdkPlugins = {+ getNoObjectIllustration: jest.fn().mockReturnValue(null),+ };++ const mockState = {+ sdk: {+ plugins: mockSdkPlugins,+ },+ } as any;++ // Should not throw an error when SDK plugin returns null+ expect(() => {+ PLUGIN_SELECTORS.getNoObjectIllustration(mockState);+ }).not.toThrow();++ expect(PLUGIN_SELECTORS.getNoObjectIllustration(mockState)).toBeDefined();++ expect(mockSdkPlugins.getNoObjectIllustration).toHaveBeenCalled();+ });++ it("should handle SDK getNoObjectIllustration plugin functions that return undefined", () => {+ const mockSdkPlugins = {+ getNoObjectIllustration: jest.fn().mockReturnValue(undefined),+ };++ const mockState = {+ sdk: {+ plugins: mockSdkPlugins,+ },+ } as any;++ // Should not throw an error when SDK plugin returns undefined+ expect(() => {+ PLUGIN_SELECTORS.getNoObjectIllustration(mockState);+ }).not.toThrow();+ });++ it("should handle missing SDK getNoObjectIllustration plugin gracefully", () => {+ const mockState = {+ sdk: {+ plugins: null,+ },+ } as any;++ // Should not throw an error when no SDK plugins are available+ expect(() => {+ PLUGIN_SELECTORS.getNoObjectIllustration(mockState);+ }).not.toThrow();+ });++ it("should handle errors in SDK getNoObjectIllustration plugin functions gracefully", () => {+ const mockSdkPlugins = {+ getNoObjectIllustration: jest.fn().mockImplementation(() => {+ throw new Error("Plugin error");+ }),+ };++ const mockState = {+ sdk: {+ plugins: mockSdkPlugins,+ },+ } as any;++ const consoleSpy = jest+ .spyOn(console, "error")+ .mockImplementation(() => {});++ // Should not throw an error even when SDK plugin throws+ expect(() => {+ PLUGIN_SELECTORS.getNoObjectIllustration(mockState);+ }).not.toThrow();++ expect(consoleSpy).toHaveBeenCalledWith(+ "Error in SDK getNoObjectIllustration plugin:",+ expect.any(Error),+ );++ consoleSpy.mockRestore();+ });+ });+});