Skip to content
Merged
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
7 changes: 7 additions & 0 deletions components/layout/CustomAppBar.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { AppBar, TitlePortal } from 'react-admin';
import YearSelector from './YearSelector';

// The app's own icon (client/public/icon.svg) before the title; hidden if the app has none.
const hideOnError = (e) => { e.currentTarget.style.display = 'none'; };
const AppLogo = () => (
<img src="/icon.svg" alt="" width={28} height={28} style={{ marginInlineEnd: 8, flexShrink: 0 }} onError={hideOnError} />
);

// content: what the app bar shows next to the title. Defaults to the year picker;
// pass null for nothing, or an app's own control (e.g. a project switcher).
const CustomAppBar = ({ content = <YearSelector />, ...props }) => (
<AppBar {...props}>
<AppLogo />
<TitlePortal />
{content}
</AppBar>
Expand Down
5 changes: 5 additions & 0 deletions components/layout/__tests__/CustomAppBar.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ describe('CustomAppBar', () => {
expect(screen.queryByText('year-selector')).not.toBeInTheDocument();
});

it('shows the app icon before the title', () => {
const { container } = renderBar();
expect(container.querySelector('img[src="/icon.svg"]')).toBeInTheDocument();
});

it('shows nothing next to the title for null content', () => {
renderBar({ content: null });
expect(screen.queryByText('year-selector')).not.toBeInTheDocument();
Expand Down
Loading