diff --git a/js/apps/admin-ui/src/realm-settings/themes/PatternflyVars.ts b/js/apps/admin-ui/src/realm-settings/themes/PatternflyVars.ts index c1bba8ce521..cb64e222fa4 100644 --- a/js/apps/admin-ui/src/realm-settings/themes/PatternflyVars.ts +++ b/js/apps/admin-ui/src/realm-settings/themes/PatternflyVars.ts @@ -159,8 +159,8 @@ const flattenVariables = (theme: ThemeType): FlattenedVariable[] => { const defaultValue = convert(v.defaultValue, theme); const variable = convert(v.variable, theme); - // Skip variables that don't have a value for this theme - if (defaultValue === undefined && variable === undefined) return; + // Skip variables that don't apply to this theme (no CSS variable name to set) + if (variable === undefined) return; const flattenedVar: FlattenedVariable = { name: v.name, diff --git a/js/apps/admin-ui/src/realm-settings/themes/QuickTheme.tsx b/js/apps/admin-ui/src/realm-settings/themes/QuickTheme.tsx index 3c301abad7c..ed09e5c5d52 100644 --- a/js/apps/admin-ui/src/realm-settings/themes/QuickTheme.tsx +++ b/js/apps/admin-ui/src/realm-settings/themes/QuickTheme.tsx @@ -31,9 +31,13 @@ export const QuickTheme = ({ realm, theme }: QuickThemeProps) => { const { favicon, logo, bgimage, fileName } = realm; const logoName = - "img/logo" + logo?.name.substring(logo.name.lastIndexOf(".")); + logo instanceof File + ? "img/logo" + logo.name.substring(logo.name.lastIndexOf(".")) + : undefined; const bgimageName = - "img/bgimage" + bgimage?.name.substring(bgimage.name.lastIndexOf(".")); + bgimage instanceof File + ? "img/bgimage" + bgimage.name.substring(bgimage.name.lastIndexOf(".")) + : undefined; const themeNameClean = (realm.themeName ?? "quick-theme") diff --git a/js/apps/admin-ui/src/realm-settings/themes/ThemeColors.tsx b/js/apps/admin-ui/src/realm-settings/themes/ThemeColors.tsx index 87ab74cf507..28fcc4af2cc 100644 --- a/js/apps/admin-ui/src/realm-settings/themes/ThemeColors.tsx +++ b/js/apps/admin-ui/src/realm-settings/themes/ThemeColors.tsx @@ -144,34 +144,42 @@ export const ThemeColors = ({ const defaultValue = (v: DefaultValueType | undefined, theme: ThemeType) => typeof v === "string" ? v : v?.[theme]; - const reset = () => { - setOverriddenColors(new Set()); - + const buildThemeDefaults = (themeType: ThemeType): Record => { + const themeMapping = themeType === "light" ? lightTheme() : darkTheme(); const parentDefaults: Record = {}; - mapping.forEach((m) => { + themeMapping.forEach((m) => { if (m.defaultValue && !m.parentName) { - parentDefaults[m.name] = defaultValue(m.defaultValue, theme)!; + parentDefaults[m.name] = defaultValue(m.defaultValue, themeType)!; } }); + return themeMapping.reduce>((acc, m) => { + if (!m.variable) return acc; + let value = defaultValue(m.defaultValue, themeType); + if (m.parentName && value?.includes("{{")) { + const parentValue = parentDefaults[m.parentName]; + if (parentValue) { + const resolved = resolveColorReferences( + value, + parentValue, + themeType, + ); + value = resolveColorToHex(resolved); + } + } + if (value !== undefined) { + acc[defaultValue(m.variable, themeType)!] = value; + } + return acc; + }, {}); + }; + const reset = () => { + setOverriddenColors(new Set()); + const currentValues = form.getValues(); form.reset({ - [theme]: mapping.reduce>((acc, m) => { - if (!m.variable) return acc; - - let value = defaultValue(m.defaultValue, theme); - if (m.parentName && value?.includes("{{")) { - const parentValue = parentDefaults[m.parentName]; - if (parentValue) { - const resolved = resolveColorReferences(value, parentValue, theme); - value = resolveColorToHex(resolved); - } - } - - if (value !== undefined) { - acc[defaultValue(m.variable, theme)!] = value; - } - return acc; - }, {}), + ...currentValues, + light: buildThemeDefaults("light"), + dark: buildThemeDefaults("dark"), }); }; @@ -222,11 +230,15 @@ export const ThemeColors = ({ useEffect(() => { setupForm(); + }, [realm]); + + useEffect(() => { + setOverriddenColors(new Set()); switchTheme(theme); return () => { switchTheme(originalTheme); }; - }, [realm, theme]); + }, [theme]); return ( <> @@ -300,14 +312,14 @@ export const ThemeColors = ({ ) : (