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
fix(sdk): fix failing tests for white-labeled colors (#68790)
Phoomparin Manof46fdd8d279d
diff --git a/frontend/src/embedding-sdk-bundle/hooks/private/use-embedding-theme-override.ts b/frontend/src/embedding-sdk-bundle/hooks/private/use-embedding-theme-override.tsindex f038cd5f8f8..fa5a2e45d9b 100644--- a/frontend/src/embedding-sdk-bundle/hooks/private/use-embedding-theme-override.ts+++ b/frontend/src/embedding-sdk-bundle/hooks/private/use-embedding-theme-override.ts@@ -27,14 +27,18 @@ export function useEmbeddingThemeOverride(const appColors = useSetting("application-colors");return useMemo(() => {- if (isEmbeddingThemeV1(theme)) {+ if (!theme || isEmbeddingThemeV1(theme)) {const themeWithPreset = applyThemePreset(theme);// !! Mutate the global colors object to apply the new colors.// This must be done before ThemeProvider calls getThemeOverrides.setGlobalEmbeddingColors(themeWithPreset?.colors, appColors ?? {});- return getEmbeddingThemeOverride(themeWithPreset || {}, font);+ return getEmbeddingThemeOverride(+ themeWithPreset || {},+ font,+ appColors ?? {},+ );}// We must include Modular Embedding specific overrides for portals (e.g. popover and modal) to target the correct portal iddiff --git a/frontend/src/embedding-sdk-bundle/lib/theme/get-embedding-theme.ts b/frontend/src/embedding-sdk-bundle/lib/theme/get-embedding-theme.tsindex 8f3aa6f6f40..6709339eea4 100644--- a/frontend/src/embedding-sdk-bundle/lib/theme/get-embedding-theme.ts+++ b/frontend/src/embedding-sdk-bundle/lib/theme/get-embedding-theme.ts@@ -18,9 +18,13 @@ import {SDK_TO_MAIN_APP_COLORS_MAPPING,SDK_TO_MAIN_APP_TOOLTIP_COLORS_MAPPING,} from "metabase/embedding-sdk/theme/embedding-color-palette";-import type { MetabaseAccentColorKey } from "metabase/lib/colors";+import type {+ MetabaseAccentColorKey,+ MetabaseColorKey,+} from "metabase/lib/colors";import { mapChartColorsToAccents } from "metabase/lib/colors/accents";import type { MantineThemeOverride } from "metabase/ui";+import type { ColorSettings } from "metabase-types/api";import { colorTuple } from "./color-tuple";@@ -39,6 +43,7 @@ const stripUndefinedKeys = <T>(x: T): unknown =>export function getEmbeddingThemeOverride(theme: MetabaseTheme,font: string | undefined,+ whitelabeledColors?: ColorSettings | undefined,): MantineThemeOverride {const components: MetabaseComponentTheme = merge(DEFAULT_EMBEDDED_COMPONENT_THEME,@@ -58,10 +63,24 @@ export function getEmbeddingThemeOverride(},components: getEmbeddingComponentOverrides(),+ colors: {},};+ // Apply whitelabeled colors from appearance settings+ for (const key in whitelabeledColors) {+ if (!override.colors) {+ override.colors = {};+ }++ override.colors[key as MetabaseColorKey] = colorTuple(+ whitelabeledColors[key],+ );+ }+if (theme.colors) {- override.colors = {};+ if (!override.colors) {+ override.colors = {};+ }const userColors = { ...theme.colors };