Merge pull request #24350 from drodil/notifications_sidebar_item

feat: allow defining custom class name + other props for notifications sidebar item
This commit is contained in:
Marek Libra
2024-04-23 12:31:14 +02:00
committed by GitHub
3 changed files with 27 additions and 5 deletions
+6
View File
@@ -9,6 +9,7 @@ import { ApiRef } from '@backstage/core-plugin-api';
import { BackstagePlugin } from '@backstage/core-plugin-api';
import { DiscoveryApi } from '@backstage/core-plugin-api';
import { FetchApi } from '@backstage/core-plugin-api';
import { IconComponent } from '@backstage/core-plugin-api';
import { JSX as JSX_2 } from 'react';
import { Notification as Notification_2 } from '@backstage/plugin-notifications-common';
import { NotificationSeverity } from '@backstage/plugin-notifications-common';
@@ -87,6 +88,11 @@ export const notificationsPlugin: BackstagePlugin<
export const NotificationsSidebarItem: (props?: {
webNotificationsEnabled?: boolean;
titleCounterEnabled?: boolean;
className?: string;
icon?: IconComponent;
text?: string;
disableHighlight?: boolean;
noTrack?: boolean;
}) => React_2.JSX.Element;
// @public (undocumented)
@@ -17,7 +17,7 @@ import React, { useEffect } from 'react';
import { useNotificationsApi } from '../../hooks';
import { SidebarItem } from '@backstage/core-components';
import NotificationsIcon from '@material-ui/icons/Notifications';
import { useApi, useRouteRef } from '@backstage/core-plugin-api';
import { IconComponent, useApi, useRouteRef } from '@backstage/core-plugin-api';
import { rootRouteRef } from '../../routes';
import { useSignal } from '@backstage/plugin-signals-react';
import { NotificationSignal } from '@backstage/plugin-notifications-common';
@@ -29,9 +29,19 @@ import { notificationsApiRef } from '../../api';
export const NotificationsSidebarItem = (props?: {
webNotificationsEnabled?: boolean;
titleCounterEnabled?: boolean;
className?: string;
icon?: IconComponent;
text?: string;
disableHighlight?: boolean;
noTrack?: boolean;
}) => {
const { webNotificationsEnabled = false, titleCounterEnabled = true } =
props ?? { webNotificationsEnabled: false, titleCounterEnabled: true };
const {
webNotificationsEnabled = false,
titleCounterEnabled = true,
icon = NotificationsIcon,
text = 'Notifications',
...restProps
} = props ?? { webNotificationsEnabled: false, titleCounterEnabled: true };
const { loading, error, value, retry } = useNotificationsApi(api =>
api.getStatus(),
@@ -95,10 +105,11 @@ export const NotificationsSidebarItem = (props?: {
// TODO: Figure out if the count can be added to hasNotifications
return (
<SidebarItem
icon={NotificationsIcon}
to={notificationsRoute()}
text="Notifications"
hasNotifications={!error && !!unreadCount}
text={text}
icon={icon}
{...restProps}
/>
);
};