-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ui): update config at runtime to apply branding
Signed-off-by: Yi Cai <yicai@redhat.com>
- Loading branch information
Showing
3 changed files
with
38 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React, { useEffect } from 'react'; | ||
import { configApiRef, useApi } from '@backstage/core-plugin-api'; | ||
|
||
const ConfigUpdater: React.FC = () => { | ||
const configApi = useApi(configApiRef); | ||
|
||
useEffect(() => { | ||
const updateConfig = () => { | ||
const logoIconBase64URI = configApi.getOptionalString( | ||
'app.branding.iconLogo', | ||
); | ||
|
||
if (logoIconBase64URI) { | ||
const favicon = document.getElementById( | ||
'dynamic-favicon', | ||
) as HTMLLinkElement; | ||
if (favicon) { | ||
favicon.href = logoIconBase64URI; | ||
} else { | ||
const newFavicon = document.createElement('link'); | ||
newFavicon.id = 'dynamic-favicon'; | ||
newFavicon.rel = 'icon'; | ||
newFavicon.href = logoIconBase64URI; | ||
document.head.appendChild(newFavicon); | ||
} | ||
} | ||
}; | ||
|
||
updateConfig(); | ||
}, [configApi]); | ||
|
||
return null; | ||
}; | ||
|
||
export default ConfigUpdater; |