-
Notifications
You must be signed in to change notification settings - Fork 12
feat(console): add toast notification system for user feedback #66
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
base: main
Are you sure you want to change the base?
Changes from all commits
6d113a3
ef9b1e7
1c708e2
6e8cb81
835417f
1a718ed
993031e
dad3421
4ba2d88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /** | ||
| * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com). | ||
| * | ||
| * WSO2 LLC. licenses this file to you under the Apache License, | ||
| * Version 2.0 (the "License"); you may not use this file except | ||
| * in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| import { | ||
| Dialog, | ||
| DialogTitle, | ||
| DialogContent, | ||
| DialogActions, | ||
| Button, | ||
| Typography, | ||
| CircularProgress, | ||
| } from '@wso2/oxygen-ui'; | ||
|
|
||
| export interface ConfirmDialogProps { | ||
| open: boolean; | ||
| title: string; | ||
| message: string; | ||
| confirmLabel?: string; | ||
| cancelLabel?: string; | ||
| confirmColor?: 'error' | 'primary' | 'secondary'; | ||
| onConfirm: () => void; | ||
| onCancel: () => void; | ||
| isLoading?: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * Reusable confirmation dialog for destructive or important actions. | ||
| * Use for delete confirmations, irreversible operations, etc. | ||
| */ | ||
| export function ConfirmDialog({ | ||
| open, | ||
| title, | ||
| message, | ||
| confirmLabel = 'Confirm', | ||
| cancelLabel = 'Cancel', | ||
| confirmColor = 'error', | ||
| onConfirm, | ||
| onCancel, | ||
| isLoading = false, | ||
| }: ConfirmDialogProps) { | ||
| return ( | ||
| <Dialog open={open} onClose={onCancel} maxWidth="xs" fullWidth> | ||
| <DialogTitle>{title}</DialogTitle> | ||
| <DialogContent> | ||
| <Typography variant="body2" color="text.secondary"> | ||
| {message} | ||
| </Typography> | ||
| </DialogContent> | ||
| <DialogActions> | ||
| <Button | ||
| onClick={onCancel} | ||
| variant="outlined" | ||
| disabled={isLoading} | ||
| > | ||
| {cancelLabel} | ||
| </Button> | ||
| <Button | ||
| onClick={onConfirm} | ||
| variant="contained" | ||
| color={confirmColor} | ||
| disabled={isLoading} | ||
| startIcon={isLoading ? <CircularProgress size={16} color="inherit" /> : undefined} | ||
| > | ||
| {isLoading ? 'Loading...' : confirmLabel} | ||
| </Button> | ||
| </DialogActions> | ||
| </Dialog> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,3 +17,4 @@ | |
| */ | ||
|
|
||
| export * from './components'; | ||
| export * from './providers'; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /** | ||
| * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com). | ||
| * | ||
| * WSO2 LLC. licenses this file to you under the Apache License, | ||
| * Version 2.0 (the "License"); you may not use this file except | ||
| * in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| import { createContext } from 'react'; | ||
|
|
||
| // Notification severity types matching MUI Alert | ||
| export type NotificationType = 'success' | 'error' | 'warning' | 'info'; | ||
|
|
||
| // Shape of the context value | ||
| export interface NotificationContextType { | ||
| notify: (type: NotificationType, message: string) => void; | ||
| } | ||
|
|
||
| // Context with null default - useNotification hook will throw if used outside provider | ||
| export const NotificationContext = createContext<NotificationContextType | null>(null); |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,74 @@ | ||||||||||||||||||
| /** | ||||||||||||||||||
| * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com). | ||||||||||||||||||
| * | ||||||||||||||||||
| * WSO2 LLC. licenses this file to you under the Apache License, | ||||||||||||||||||
| * Version 2.0 (the "License"); you may not use this file except | ||||||||||||||||||
| * in compliance with the License. | ||||||||||||||||||
| * You may obtain a copy of the License at | ||||||||||||||||||
| * | ||||||||||||||||||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||
| * | ||||||||||||||||||
| * Unless required by applicable law or agreed to in writing, | ||||||||||||||||||
| * software distributed under the License is distributed on an | ||||||||||||||||||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||||||||||||||||||
| * KIND, either express or implied. See the License for the | ||||||||||||||||||
| * specific language governing permissions and limitations | ||||||||||||||||||
| * under the License. | ||||||||||||||||||
| */ | ||||||||||||||||||
|
|
||||||||||||||||||
| import React, { useCallback, useMemo, useState } from 'react'; | ||||||||||||||||||
| import { Alert, Snackbar } from '@wso2/oxygen-ui'; | ||||||||||||||||||
| import { NotificationContext, NotificationType } from './NotificationContext'; | ||||||||||||||||||
|
|
||||||||||||||||||
| interface Notification { | ||||||||||||||||||
| id: string; | ||||||||||||||||||
| type: NotificationType; | ||||||||||||||||||
| message: string; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| interface NotificationProviderProps { | ||||||||||||||||||
| children: React.ReactNode; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| const AUTO_HIDE_DURATION = 5000; | ||||||||||||||||||
|
|
||||||||||||||||||
| export function NotificationProvider({ children }: NotificationProviderProps) { | ||||||||||||||||||
| const [notifications, setNotifications] = useState<Notification[]>([]); | ||||||||||||||||||
|
|
||||||||||||||||||
| // Add a new notification | ||||||||||||||||||
| const notify = useCallback((type: NotificationType, message: string) => { | ||||||||||||||||||
| const id = Date.now().toString(); | ||||||||||||||||||
| setNotifications((prev) => [...prev, { id, type, message }]); | ||||||||||||||||||
| }, []); | ||||||||||||||||||
|
Comment on lines
+39
to
+42
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential ID collision with Date.now(). Using 🔎 Consider using a more robust ID generation:- const notify = useCallback((type: NotificationType, message: string) => {
- const id = Date.now().toString();
+ const notify = useCallback((type: NotificationType, message: string) => {
+ const id = `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
setNotifications((prev) => [...prev, { id, type, message }]);
}, []);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
|
|
||||||||||||||||||
| // Remove a notification by id | ||||||||||||||||||
| const removeNotification = useCallback((id: string) => { | ||||||||||||||||||
| setNotifications((prev) => prev.filter((n) => n.id !== id)); | ||||||||||||||||||
| }, []); | ||||||||||||||||||
|
|
||||||||||||||||||
| // Memoize context value to prevent unnecessary re-renders | ||||||||||||||||||
| const contextValue = useMemo(() => ({ notify }), [notify]); | ||||||||||||||||||
|
|
||||||||||||||||||
| return ( | ||||||||||||||||||
| <NotificationContext.Provider value={contextValue}> | ||||||||||||||||||
| {children} | ||||||||||||||||||
| {/* Render notifications - show only the first one, queue the rest */} | ||||||||||||||||||
| {notifications.length > 0 && ( | ||||||||||||||||||
| <Snackbar | ||||||||||||||||||
| open | ||||||||||||||||||
| autoHideDuration={AUTO_HIDE_DURATION} | ||||||||||||||||||
| onClose={() => removeNotification(notifications[0].id)} | ||||||||||||||||||
| anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }} | ||||||||||||||||||
| > | ||||||||||||||||||
| <Alert | ||||||||||||||||||
| severity={notifications[0].type} | ||||||||||||||||||
| onClose={() => removeNotification(notifications[0].id)} | ||||||||||||||||||
| sx={{ width: '100%' }} | ||||||||||||||||||
| > | ||||||||||||||||||
| {notifications[0].message} | ||||||||||||||||||
| </Alert> | ||||||||||||||||||
| </Snackbar> | ||||||||||||||||||
| )} | ||||||||||||||||||
| </NotificationContext.Provider> | ||||||||||||||||||
| ); | ||||||||||||||||||
| } | ||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: wso2/ai-agent-management-platform
Length of output: 104
🏁 Script executed:
Repository: wso2/ai-agent-management-platform
Length of output: 2041
🏁 Script executed:
Repository: wso2/ai-agent-management-platform
Length of output: 4710
🏁 Script executed:
Repository: wso2/ai-agent-management-platform
Length of output: 2315
Remove or document the
ConfirmDialogcomponent usage.The
ConfirmDialogcomponent is exported but never imported or used anywhere in the codebase. The application already usesConfirmationDialogProviderwith theuseConfirmationDialoghook (as seen inGlobalProviders.tsx,AgentsList.tsx, andProjectList.tsx), which provides a centralized, queue-based confirmation pattern.If
ConfirmDialogserves a different purpose (e.g., direct prop-controlled confirmations vs. global state-managed ones), add documentation clarifying when to use each. Otherwise, remove it to avoid confusion and reduce bundle size.