fix(notifications): limit only in header [EE-4815] (#8579)

Co-authored-by: testa113 <testa113>
pull/8596/head
Ali 2 years ago committed by GitHub
parent fd916bc8a2
commit 07df4b1591
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -33,6 +33,7 @@ export function NotificationsMenu() {
notificationsStore, notificationsStore,
(state) => state.userNotifications[user.Id] (state) => state.userNotifications[user.Id]
); );
const reducedNotifications = userNotifications?.slice(0, 50);
return ( return (
<Menu> <Menu>
@ -55,7 +56,7 @@ export function NotificationsMenu() {
<Icon icon={Bell} /> <Icon icon={Bell} />
<span <span
className={ className={
userNotifications?.length > 0 ? notificationStyles.badge : '' reducedNotifications?.length > 0 ? notificationStyles.badge : ''
} }
/> />
</div> </div>
@ -77,7 +78,7 @@ export function NotificationsMenu() {
<h4>Notifications</h4> <h4>Notifications</h4>
</div> </div>
<div className={notificationStyles.itemLast}> <div className={notificationStyles.itemLast}>
{userNotifications?.length > 0 && ( {reducedNotifications?.length > 0 && (
<Button <Button
color="none" color="none"
onClick={(e) => { onClick={(e) => {
@ -93,10 +94,10 @@ export function NotificationsMenu() {
</div> </div>
</div> </div>
</div> </div>
{userNotifications?.length > 0 ? ( {reducedNotifications?.length > 0 ? (
<> <>
<div className={notificationStyles.notifications}> <div className={notificationStyles.notifications}>
{userNotifications.map((notification) => ( {reducedNotifications.map((notification) => (
<MenuLink <MenuLink
to="portainer.notifications" to="portainer.notifications"
params={{ id: notification.id }} params={{ id: notification.id }}

@ -20,22 +20,15 @@ export const notificationsStore = create<NotificationsState>()(
userNotifications: {}, userNotifications: {},
addNotification: (userId: number, notification: ToastNotification) => { addNotification: (userId: number, notification: ToastNotification) => {
set((state) => { set((state) => {
const currentUserNotifications =
state.userNotifications[userId] || [];
// keep the new notification at the start of the list, so sorting by newest time isn't required // keep the new notification at the start of the list, so sorting by newest time isn't required
const newUserNotifications = [ const newUserNotifications = [
notification, notification,
...currentUserNotifications, ...(state.userNotifications[userId] || []),
]; ];
const maxNotifications = 50;
const reducedNotifications = newUserNotifications.slice(
0,
maxNotifications
);
return { return {
userNotifications: { userNotifications: {
...state.userNotifications, ...state.userNotifications,
[userId]: reducedNotifications, [userId]: newUserNotifications,
}, },
}; };
}); });

Loading…
Cancel
Save