From 667bb949cc8f0ccc02041e2467a1b1444619ee84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mose=20M=C3=BCller?= Date: Mon, 27 Nov 2023 15:40:25 +0100 Subject: [PATCH] rewrites NotificationsComponent to handle various notification levels --- .../src/components/NotificationsComponent.tsx | 63 ++++++++----------- 1 file changed, 25 insertions(+), 38 deletions(-) diff --git a/frontend/src/components/NotificationsComponent.tsx b/frontend/src/components/NotificationsComponent.tsx index d46c645..9a9f96c 100644 --- a/frontend/src/components/NotificationsComponent.tsx +++ b/frontend/src/components/NotificationsComponent.tsx @@ -1,70 +1,57 @@ import React from 'react'; import { ToastContainer, Toast } from 'react-bootstrap'; +export type LevelName = 'ERROR' | 'WARNING' | 'INFO' | 'DEBUG'; // Added levelname export type Notification = { id: number; - time: string; - text: string; + timeStamp: string; + message: string; + levelname: LevelName; }; type NotificationProps = { showNotification: boolean; notifications: Notification[]; - exceptions: Notification[]; removeNotificationById: (id: number) => void; - removeExceptionById: (id: number) => void; }; export const Notifications = React.memo((props: NotificationProps) => { - const { - showNotification, - notifications, - exceptions, - removeExceptionById, - removeNotificationById - } = props; + const { showNotification, notifications, removeNotificationById } = props; return ( {showNotification && notifications.map((notification) => ( removeNotificationById(notification.id)} - onClick={() => { - removeNotificationById(notification.id); - }} + onClick={() => removeNotificationById(notification.id)} onMouseLeave={() => { removeNotificationById(notification.id); }} show={true} - autohide={true} - delay={2000}> - - Notification - {notification.time} + autohide={ + notification.levelname === 'WARNING' || + notification.levelname === 'INFO' || + notification.levelname === 'DEBUG' + } + delay={ + notification.levelname === 'WARNING' || + notification.levelname === 'INFO' || + notification.levelname === 'DEBUG' + ? 2000 + : undefined + }> + + {notification.levelname} + {notification.timeStamp} - {notification.text} + {notification.message} ))} - {exceptions.map((exception) => ( - removeExceptionById(exception.id)} - onClick={() => { - removeExceptionById(exception.id); - }} - show={true} - autohide={false}> - - Exception - {exception.time} - - {exception.text} - - ))} ); });