-
Notifications
You must be signed in to change notification settings - Fork 632
OCPBUGS-53412,CONSOLE-4404,CONSOLE-4062: Add the ability to specify second logo, favicons #14749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
c449766
6b4d1f8
e72b2cc
b664fb3
1c59d5a
2d337f4
c39264f
2a5c1d9
74f34e4
2527418
ce23313
940f17d
e7b9656
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,7 +111,11 @@ func main() { | |
|
||
fBranding := fs.String("branding", "okd", "Console branding for the masthead logo and title. One of okd, openshift, ocp, online, dedicated, azure, or rosa. Defaults to okd.") | ||
fCustomProductName := fs.String("custom-product-name", "", "Custom product name for console branding.") | ||
fCustomLogoFile := fs.String("custom-logo-file", "", "Custom product image for console branding.") | ||
|
||
customLogoFlags := serverconfig.LogosKeyValue{} | ||
fs.Var(&customLogoFlags, "custom-logo-files", "List of custom product images used for console branding. Each entry consist of theme type (Dark | Light | Default) as a key and path to image file as value.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I understand, even though I think we have decided to remove this configuration from bridge, due to its nature of being only a secondary API to console.operator, meaning this configuration is meant for developers of the bridge/console only and no real customer should be dependent on this. cc @jhadvig @TheRealJon to confirm or deny. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sense, thank you @Mylanos |
||
customFaviconFlags := serverconfig.LogosKeyValue{} | ||
fs.Var(&customFaviconFlags, "custom-favicon-files", "List of custom product images used for console branding. Each entry consist of theme type (Dark | Light | Default) as a key and path to image file as value.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we update the help message for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, will update. |
||
fStatuspageID := fs.String("statuspage-id", "", "Unique ID assigned by statuspage.io page that provides status info.") | ||
fDocumentationBaseURL := fs.String("documentation-base-url", "", "The base URL for documentation links.") | ||
|
||
|
@@ -207,12 +211,6 @@ func main() { | |
flags.FatalIfFailed(flags.NewInvalidFlagError("branding", "value must be one of okd, openshift, ocp, online, dedicated, azure, or rosa")) | ||
} | ||
|
||
if *fCustomLogoFile != "" { | ||
if _, err := os.Stat(*fCustomLogoFile); err != nil { | ||
klog.Fatalf("could not read logo file: %v", err) | ||
} | ||
} | ||
|
||
if len(consolePluginsFlags) > 0 { | ||
klog.Infoln("The following console plugins are enabled:") | ||
for pluginName := range consolePluginsFlags { | ||
|
@@ -266,7 +264,8 @@ func main() { | |
BaseURL: baseURL, | ||
Branding: branding, | ||
CustomProductName: *fCustomProductName, | ||
CustomLogoFile: *fCustomLogoFile, | ||
CustomLogoFiles: customLogoFlags, | ||
CustomFaviconFiles: customFaviconFlags, | ||
ControlPlaneTopology: *fControlPlaneTopology, | ||
StatuspageID: *fStatuspageID, | ||
DocumentationBaseURL: documentationBaseURL, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,106 @@ | ||
import * as React from 'react'; | ||
import { | ||
ThemeContext, | ||
THEME_DARK, | ||
THEME_LIGHT, | ||
applyThemeBehaviour, | ||
darkThemeMq, | ||
} from '@console/internal/components/ThemeProvider'; | ||
import okdLogoImg from '../../imgs/okd-logo.svg'; | ||
import openshiftLogoImg from '../../imgs/openshift-logo.svg'; | ||
import onlineLogoImg from '../../imgs/openshift-online-logo.svg'; | ||
import dedicatedLogoImg from '../../imgs/openshift-dedicated-logo.svg'; | ||
import rosaLogoImg from '../../imgs/openshift-service-on-aws-logo.svg'; | ||
|
||
type CUSTOM_LOGO = typeof FAVICON_TYPE | typeof MASTHEAD_TYPE; | ||
export const FAVICON_TYPE = 'Favicon'; | ||
export const MASTHEAD_TYPE = 'Masthead'; | ||
|
||
export const getBrandingDetails = () => { | ||
let logoImg, productName; | ||
let staticLogo, productName; | ||
// Webpack won't bundle these images if we don't directly reference them, hence the switch | ||
switch (window.SERVER_FLAGS.branding) { | ||
case 'openshift': | ||
logoImg = openshiftLogoImg; | ||
staticLogo = openshiftLogoImg; | ||
productName = 'Red Hat OpenShift'; | ||
break; | ||
case 'ocp': | ||
logoImg = openshiftLogoImg; | ||
staticLogo = openshiftLogoImg; | ||
productName = 'Red Hat OpenShift'; | ||
break; | ||
case 'online': | ||
logoImg = onlineLogoImg; | ||
staticLogo = onlineLogoImg; | ||
productName = 'Red Hat OpenShift Online'; | ||
break; | ||
case 'dedicated': | ||
logoImg = dedicatedLogoImg; | ||
staticLogo = dedicatedLogoImg; | ||
productName = 'Red Hat OpenShift Dedicated'; | ||
break; | ||
case 'azure': | ||
logoImg = openshiftLogoImg; | ||
staticLogo = openshiftLogoImg; | ||
productName = 'Azure Red Hat OpenShift'; | ||
break; | ||
case 'rosa': | ||
logoImg = rosaLogoImg; | ||
staticLogo = rosaLogoImg; | ||
productName = 'Red Hat OpenShift Service on AWS'; | ||
break; | ||
default: | ||
logoImg = okdLogoImg; | ||
staticLogo = okdLogoImg; | ||
productName = 'OKD'; | ||
} | ||
if (window.SERVER_FLAGS.customLogoURL) { | ||
logoImg = window.SERVER_FLAGS.customLogoURL; | ||
} | ||
if (window.SERVER_FLAGS.customProductName) { | ||
productName = window.SERVER_FLAGS.customProductName; | ||
} | ||
return { logoImg, productName }; | ||
return { staticLogo, productName }; | ||
}; | ||
|
||
// when user specifies logo with customLogoFile instead of customLogoFiles the URL | ||
// query parameters will be ignored and the single specified logo will always be provided | ||
export const useCustomLogoURL = (type: CUSTOM_LOGO): string => { | ||
const [logoUrl, setLogoUrl] = React.useState(''); | ||
const theme = React.useContext(ThemeContext); | ||
|
||
React.useEffect(() => { | ||
// return when customLogos have not been configured | ||
if (!window.SERVER_FLAGS.customLogoURL) { | ||
return; | ||
} | ||
let reqTheme; | ||
const fetchData = async () => { | ||
if (type === FAVICON_TYPE) { | ||
if (!darkThemeMq.matches) { | ||
// Fetch Light theme favicon if the Dark preference is not set via the system preference | ||
reqTheme = THEME_LIGHT; | ||
} else { | ||
reqTheme = THEME_DARK; | ||
} | ||
} else { | ||
reqTheme = applyThemeBehaviour( | ||
theme, | ||
() => { | ||
return THEME_DARK; | ||
}, | ||
() => { | ||
return THEME_LIGHT; | ||
}, | ||
); | ||
} | ||
const fetchURL = `${window.SERVER_FLAGS.basePath}custom-logo?type=${type}&theme=${reqTheme}`; | ||
const response = await fetch(fetchURL); | ||
if (response.ok) { | ||
const blob = await response.blob(); | ||
setLogoUrl(URL.createObjectURL(blob)); | ||
} else if (response.status === 404) { | ||
return; | ||
} else { | ||
throw new Error(`Failed to fetch ${fetchURL}: ${response.statusText}`); | ||
} | ||
}; | ||
fetchData().catch((err) => { | ||
// eslint-disable-next-line no-console | ||
console.warn(`Error while fetching ${type} logo: ${err}`); | ||
}); | ||
}, [theme, type]); | ||
|
||
return logoUrl; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets add better description for these two fields, since one sets custom logo for favicon and the other for masthead