Skip to content
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

fix(ui): update config at runtime to apply branding #1381

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions packages/app/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@
href="<%= publicPath %>/safari-pinned-tab.svg"
color="#5bbad5"
/>
<link
rel="icon"
href="<%= config.getOptionalString('app.branding.iconLogo') %>"
/>
<link rel="icon" id="dynamic-favicon" href="/favicon.ico" />
<title><%= config.getOptionalString('app.title') ?? 'Backstage' %></title>
</head>
<body>
Expand Down
2 changes: 2 additions & 0 deletions packages/app/src/components/AppBase/AppBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { entityPage } from '../catalog/EntityPage';
import { HomePage } from '../home/HomePage';
import { LearningPaths } from '../learningPaths/LearningPathsPage';
import { SearchPage } from '../search/SearchPage';
import ConfigUpdater from '../Root/ConfigUpdater';

const AppBase = () => {
const {
Expand Down Expand Up @@ -73,6 +74,7 @@ const AppBase = () => {
<AlertDisplay />
<OAuthRequestDialog />
<AppRouter>
<ConfigUpdater />
<Root>
<FlatRoutes>
{dynamicRoutes.filter(({ path }) => path === '/').length === 0 && (
Expand Down
35 changes: 35 additions & 0 deletions packages/app/src/components/Root/ConfigUpdater.tsx
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;
Loading