Skip to content

Commit 93bee06

Browse files
authored
fix: support not setting default in variant when using PARAGON_THEME_URLS (#810)
1 parent 9f92281 commit 93bee06

File tree

2 files changed

+55
-11
lines changed

2 files changed

+55
-11
lines changed

src/react/hooks/paragon/useParagonThemeUrls.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ const useParagonThemeUrls = () => useMemo(() => {
5656
if (!paragonThemeUrls) {
5757
return undefined;
5858
}
59-
6059
const paragonCoreCssUrl = typeof paragonThemeUrls?.core?.urls === 'object' ? paragonThemeUrls.core.urls.default : paragonThemeUrls?.core?.url;
6160
const brandCoreCssUrl = typeof paragonThemeUrls?.core?.urls === 'object' ? paragonThemeUrls.core.urls.brandOverride : undefined;
6261
const defaultThemeVariants = paragonThemeUrls.defaults;
@@ -117,23 +116,24 @@ const useParagonThemeUrls = () => useMemo(() => {
117116
coreCss.default = fallbackThemeUrl(localParagonCoreUrl?.fileName);
118117
}
119118

120-
if (!coreCss.brandOverride && localBrandCoreUrl) {
119+
if (!coreCss.brandOverride && !isEmptyObject(localBrandCoreUrl)) {
121120
coreCss.brandOverride = fallbackThemeUrl(localBrandCoreUrl?.fileName);
122121
}
123122

124-
if (isEmptyObject(themeVariantsCss)) {
125-
Object.entries(localParagonThemeVariants).forEach(([themeVariant, { fileName, ...rest }]) => {
123+
Object.entries(localParagonThemeVariants).forEach(([themeVariant, { fileName, ...rest }]) => {
124+
if (!themeVariantsCss[themeVariant]?.urls?.default) {
126125
themeVariantsCss[themeVariant] = {
127-
urls: { default: fallbackThemeUrl(fileName), ...rest.urls },
126+
urls: { ...themeVariantsCss[themeVariant]?.urls, default: fallbackThemeUrl(fileName), ...rest.urls },
128127
};
129-
});
130-
131-
Object.entries(localBrandThemeVariants).forEach(([themeVariant, { fileName, ...rest }]) => {
128+
}
129+
});
130+
Object.entries(localBrandThemeVariants).forEach(([themeVariant, { fileName, ...rest }]) => {
131+
if (!themeVariantsCss[themeVariant]?.urls?.brandOverride) {
132132
themeVariantsCss[themeVariant] = {
133-
urls: { brandOverride: fallbackThemeUrl(fileName), ...rest.urls, ...themeVariantsCss[themeVariant]?.urls },
133+
urls: { ...themeVariantsCss[themeVariant]?.urls, brandOverride: fallbackThemeUrl(fileName), ...rest.urls },
134134
};
135-
});
136-
}
135+
}
136+
});
137137

138138
return {
139139
core: { urls: coreCss },

src/react/hooks/paragon/useParagonThemeUrls.test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,5 +274,49 @@ describe('useParagonThemeUrls', () => {
274274
}),
275275
);
276276
});
277+
it('returns expected object when only brand override URLs are present, fallback to PARAGON_THEME', () => {
278+
const config = {
279+
PARAGON_THEME_URLS: {
280+
core: {
281+
urls: {
282+
brandOverride: 'https://www.example.com/example-brand-core.css',
283+
},
284+
},
285+
defaults: {
286+
light: 'light',
287+
},
288+
variants: {
289+
light: {
290+
urls: {
291+
brandOverride: 'https://www.example.com/example-brand-light.css',
292+
},
293+
},
294+
},
295+
},
296+
};
297+
mergeConfig(config);
298+
const { result } = renderHook(() => useParagonThemeUrls());
299+
expect(result.current).toEqual(
300+
expect.objectContaining({
301+
core: {
302+
urls: {
303+
default: '//localhost:8080/local-core.min.css',
304+
brandOverride: 'https://www.example.com/example-brand-core.css',
305+
},
306+
},
307+
defaults: {
308+
light: 'light',
309+
},
310+
variants: {
311+
light: {
312+
urls: {
313+
default: '//localhost:8080/local-light.min.css',
314+
brandOverride: 'https://www.example.com/example-brand-light.css',
315+
},
316+
},
317+
},
318+
}),
319+
);
320+
});
277321
});
278322
});

0 commit comments

Comments
 (0)