feat: browser notifications for scenario runs
- add RunEventsService and emit run.started / run.finished from the scheduler - stream run events over SSE at GET /api/v1/scenarios/runs/events with a heartbeat - add useRunNotifications hook and NotificationToggle (opt-in bell in the side panel footer) - refresh runs lists when a run finishes - document the events stream and notifications Closes #12
This commit is contained in:
18 files changed
+503
-6
No files matched your search
@@ -0,0 +1,41 @@
|
||||
.btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
padding: 0;
|
||||
background: none;
|
||||
border: var(--border-width) solid var(--color-border);
|
||||
border-radius: var(--radius-md);
|
||||
color: var(--color-text-muted);
|
||||
cursor: pointer;
|
||||
flex-shrink: 0;
|
||||
transition: background var(--transition), color var(--transition), border-color var(--transition);
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
background: var(--color-bg-subtle);
|
||||
color: var(--color-text);
|
||||
border-color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.btn:active {
|
||||
background: var(--color-secondary);
|
||||
color: var(--color-secondary-fg);
|
||||
}
|
||||
|
||||
.btn:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.btn:disabled:hover {
|
||||
background: none;
|
||||
color: var(--color-text-muted);
|
||||
border-color: var(--color-border);
|
||||
}
|
||||
|
||||
.btn[aria-pressed='true'] {
|
||||
color: var(--color-text);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import { Bell, BellOff } from 'lucide-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import styles from './NotificationToggle.module.css';
|
||||
|
||||
/**
|
||||
* - `on`: notifications are enabled
|
||||
* - `off`: available, but not enabled (or permission not asked yet)
|
||||
* - `blocked`: the browser denied the permission
|
||||
*/
|
||||
export type NotificationToggleState = 'on' | 'off' | 'blocked';
|
||||
|
||||
export interface NotificationToggleProps {
|
||||
state: NotificationToggleState;
|
||||
onToggle: () => void;
|
||||
}
|
||||
|
||||
export function NotificationToggle({ state, onToggle }: NotificationToggleProps) {
|
||||
const { t } = useTranslation();
|
||||
const label =
|
||||
state === 'on'
|
||||
? t('notifications.disable')
|
||||
: state === 'blocked'
|
||||
? t('notifications.blocked')
|
||||
: t('notifications.enable');
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className={styles.btn}
|
||||
onClick={onToggle}
|
||||
disabled={state === 'blocked'}
|
||||
aria-label={label}
|
||||
aria-pressed={state === 'on'}
|
||||
title={label}
|
||||
>
|
||||
{state === 'on' ? <Bell size={16} /> : <BellOff size={16} />}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -26,6 +26,8 @@ export { Breadcrumbs } from './Breadcrumbs/Breadcrumbs';
|
||||
export type { BreadcrumbsProps, BreadcrumbItem } from './Breadcrumbs/Breadcrumbs';
|
||||
|
||||
export { ThemeSwitcher } from './ThemeSwitcher/ThemeSwitcher';
|
||||
export { NotificationToggle } from './NotificationToggle/NotificationToggle';
|
||||
export type { NotificationToggleState } from './NotificationToggle/NotificationToggle';
|
||||
|
||||
export { ToastProvider } from './Toast/ToastProvider';
|
||||
export type { ToastProviderProps } from './Toast/ToastProvider';
|
||||
|
||||
Reference in new issue
Block a user