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

Add dismissible notification when a model deployment fails #2046

Closed
wants to merge 1 commit into from
Closed
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
43 changes: 24 additions & 19 deletions frontend/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '@patternfly/react-core';
import ErrorBoundary from '~/components/error/ErrorBoundary';
import ToastNotifications from '~/components/ToastNotifications';
import GlobalToastNotifications from '~/components/GlobalToastNotifications';
import { useWatchBuildStatus } from '~/utilities/useWatchBuildStatus';
import { useUser } from '~/redux/selectors';
import { DASHBOARD_MAIN_CONTAINER_ID } from '~/utilities/const';
Expand All @@ -23,6 +24,7 @@ import AppRoutes from './AppRoutes';
import NavSidebar from './NavSidebar';
import AppNotificationDrawer from './AppNotificationDrawer';
import { AppContext } from './AppContext';
import NotificationsContextProvider from './NotificationsContext';
import { useApplicationSettings } from './useApplicationSettings';
import TelemetrySetup from './TelemetrySetup';
import { logout } from './appUtils';
Expand Down Expand Up @@ -89,25 +91,28 @@ const App: React.FC = () => {
dashboardConfig,
}}
>
<Page
className="odh-dashboard"
isManagedSidebar
header={<Header onNotificationsClick={() => setNotificationsOpen(!notificationsOpen)} />}
sidebar={isAllowed ? <NavSidebar /> : undefined}
notificationDrawer={<AppNotificationDrawer onClose={() => setNotificationsOpen(false)} />}
isNotificationDrawerExpanded={notificationsOpen}
mainContainerId={DASHBOARD_MAIN_CONTAINER_ID}
>
<ErrorBoundary>
<ProjectsContextProvider>
<QuickStarts>
<AppRoutes />
</QuickStarts>
</ProjectsContextProvider>
<ToastNotifications />
<TelemetrySetup />
</ErrorBoundary>
</Page>
<NotificationsContextProvider>
<Page
className="odh-dashboard"
isManagedSidebar
header={<Header onNotificationsClick={() => setNotificationsOpen(!notificationsOpen)} />}
sidebar={isAllowed ? <NavSidebar /> : undefined}
notificationDrawer={<AppNotificationDrawer onClose={() => setNotificationsOpen(false)} />}
isNotificationDrawerExpanded={notificationsOpen}
mainContainerId={DASHBOARD_MAIN_CONTAINER_ID}
>
<ErrorBoundary>
<ProjectsContextProvider>
<QuickStarts>
<AppRoutes />
</QuickStarts>
</ProjectsContextProvider>
<GlobalToastNotifications />
<ToastNotifications />
<TelemetrySetup />
</ErrorBoundary>
</Page>
</NotificationsContextProvider>
</AppContext.Provider>
);
};
Expand Down
46 changes: 46 additions & 0 deletions frontend/src/app/NotificationsContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import * as React from 'react';
import { AppNotification } from '~/redux/types';

type NotificationsContext = {
notifications: AppNotification[];
addNotification: (status: AppNotification['status'], title: string, message: string) => void;
};

export const NotificationsContext = React.createContext<NotificationsContext>({
notifications: [],
addNotification: () => undefined,
});

type NotificationsProviderProps = {
children: React.ReactNode;
};

const NotificationsContextProvider: React.FC<NotificationsProviderProps> = ({ children }) => {
const [notifications, setNotifications] = React.useState<AppNotification[]>([]);

const addNotification = React.useCallback(
(status: AppNotification['status'], title: string, message: string) => {
const newNotification = {
status,
title,
message,
timestamp: new Date(),
};

setNotifications([...notifications, newNotification]);
},
[notifications],
);

return (
<NotificationsContext.Provider
value={{
notifications,
addNotification,
}}
>
{children}
</NotificationsContext.Provider>
);
};
export default NotificationsContextProvider;
22 changes: 22 additions & 0 deletions frontend/src/components/GlobalToastNotifications.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import { AlertGroup } from '@patternfly/react-core';
import { NotificationsContext } from '~/app/NotificationsContext';
import ToastNotification from './ToastNotification';

const GlobalToastNotifications: React.FC = () => {
const { notifications } = React.useContext(NotificationsContext);

if (!notifications) {
return null;
}

return (
<AlertGroup isToast isLiveRegion>
{notifications.map((notification) => (
<ToastNotification notification={notification} key={notification.id} />
))}
</AlertGroup>
);
};

export default GlobalToastNotifications;
Loading