@checkstack/notification-frontend 0.2.34 → 0.2.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +51 -0
- package/package.json +7 -7
- package/src/components/NotificationBell.tsx +4 -83
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,56 @@
|
|
|
1
1
|
# @checkstack/notification-frontend
|
|
2
2
|
|
|
3
|
+
## 0.2.36
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 208ad71: Centralize realtime cache invalidation: signals now carry their owning `pluginId` end-to-end, and a single `SignalAutoInvalidator` mounted near the React Query client invalidates `[[pluginId]]` for every incoming signal automatically.
|
|
8
|
+
|
|
9
|
+
**Breaking change to `createSignal`** (`@checkstack/signal-common`): the factory now takes a single object argument with `pluginMetadata`, `event`, and `payloadSchema`. The signal id is constructed as `${pluginMetadata.pluginId}.${event}` and the resulting `Signal` carries a `pluginId` field. The `SignalMessage` wire envelope and `ServerToClientMessage` `signal` variant gained a `pluginId` field so the frontend can route invalidations without parsing the id.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
// Before
|
|
13
|
+
export const ANOMALY_STATE_CHANGED = createSignal(
|
|
14
|
+
"anomaly.state_changed",
|
|
15
|
+
z.object({ ... }),
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
// After
|
|
19
|
+
export const ANOMALY_STATE_CHANGED = createSignal({
|
|
20
|
+
pluginMetadata,
|
|
21
|
+
event: "state_changed",
|
|
22
|
+
payloadSchema: z.object({ ... }),
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**New plugin field**: `FrontendPlugin.foreignSignals?: Signal<unknown>[]` lets a plugin opt its `[[pluginId]]` cache into invalidation when another plugin's signal fires (e.g. `dependency-frontend` declares `[SYSTEM_STATUS_CHANGED]` because dependency payloads embed system status). Same-plugin signals must NOT be listed — they are always auto-invalidated.
|
|
27
|
+
|
|
28
|
+
**Removed boilerplate**: per-component `useSignal(X, () => refetch())` and `useSignal(X, () => queryClient.invalidateQueries(...))` calls have been removed across `incident-frontend`, `maintenance-frontend`, `healthcheck-frontend`, `slo-frontend`, `dependency-frontend`, `satellite-frontend`, `announcement-frontend`, `notification-frontend`, and `dashboard-frontend`. The `NotificationBell` unread count is now derived directly from the `getUnreadCount` query (auto-invalidated) instead of a local state mirror.
|
|
29
|
+
|
|
30
|
+
**User-visible bug fix**: the system detail page anomaly widget (`SystemAnomalyWidget`) now updates in real-time when anomalies change, with no per-widget signal subscription required. The dashboard status page also stays fresh on `ANOMALY_STATE_CHANGED`, `ANOMALY_BASELINE_UPDATED`, and `ANOMALY_TREND_DETECTED`.
|
|
31
|
+
|
|
32
|
+
UI-state consumers that legitimately need a `useSignal` (the dashboard activity terminal, the queue lag alert, and the rolling-preset date refresh in `useHealthCheckData`) keep their handlers; the auto-invalidator runs alongside them.
|
|
33
|
+
|
|
34
|
+
- Updated dependencies [208ad71]
|
|
35
|
+
- @checkstack/signal-frontend@0.1.0
|
|
36
|
+
- @checkstack/frontend-api@0.4.0
|
|
37
|
+
- @checkstack/notification-common@0.3.0
|
|
38
|
+
- @checkstack/auth-frontend@0.5.31
|
|
39
|
+
- @checkstack/ui@1.6.1
|
|
40
|
+
|
|
41
|
+
## 0.2.35
|
|
42
|
+
|
|
43
|
+
### Patch Changes
|
|
44
|
+
|
|
45
|
+
- Updated dependencies [8d1ef12]
|
|
46
|
+
- Updated dependencies [8d1ef12]
|
|
47
|
+
- @checkstack/common@0.7.0
|
|
48
|
+
- @checkstack/ui@1.6.0
|
|
49
|
+
- @checkstack/auth-frontend@0.5.30
|
|
50
|
+
- @checkstack/frontend-api@0.3.11
|
|
51
|
+
- @checkstack/notification-common@0.2.9
|
|
52
|
+
- @checkstack/signal-frontend@0.0.16
|
|
53
|
+
|
|
3
54
|
## 0.2.34
|
|
4
55
|
|
|
5
56
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@checkstack/notification-frontend",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.36",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "src/index.tsx",
|
|
6
6
|
"checkstack": {
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
"lint:code": "eslint . --max-warnings 0"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@checkstack/notification-common": "0.2.
|
|
16
|
-
"@checkstack/frontend-api": "0.3.
|
|
17
|
-
"@checkstack/auth-frontend": "0.5.
|
|
18
|
-
"@checkstack/signal-frontend": "0.0.
|
|
19
|
-
"@checkstack/common": "0.
|
|
20
|
-
"@checkstack/ui": "1.
|
|
15
|
+
"@checkstack/notification-common": "0.2.9",
|
|
16
|
+
"@checkstack/frontend-api": "0.3.11",
|
|
17
|
+
"@checkstack/auth-frontend": "0.5.30",
|
|
18
|
+
"@checkstack/signal-frontend": "0.0.16",
|
|
19
|
+
"@checkstack/common": "0.7.0",
|
|
20
|
+
"@checkstack/ui": "1.6.0",
|
|
21
21
|
"react": "^18.2.0",
|
|
22
22
|
"react-router-dom": "^6.22.0",
|
|
23
23
|
"lucide-react": "^0.344.0"
|
|
@@ -13,14 +13,9 @@ import {
|
|
|
13
13
|
useToast,
|
|
14
14
|
} from "@checkstack/ui";
|
|
15
15
|
import { useApi, usePluginClient } from "@checkstack/frontend-api";
|
|
16
|
-
import { useSignal } from "@checkstack/signal-frontend";
|
|
17
16
|
import { resolveRoute } from "@checkstack/common";
|
|
18
|
-
import type { Notification } from "@checkstack/notification-common";
|
|
19
17
|
import {
|
|
20
18
|
NotificationApi,
|
|
21
|
-
NOTIFICATION_RECEIVED,
|
|
22
|
-
NOTIFICATION_COUNT_CHANGED,
|
|
23
|
-
NOTIFICATION_READ,
|
|
24
19
|
notificationRoutes,
|
|
25
20
|
} from "@checkstack/notification-common";
|
|
26
21
|
import { authApiRef } from "@checkstack/auth-frontend/api";
|
|
@@ -33,22 +28,14 @@ export const NotificationBell = () => {
|
|
|
33
28
|
|
|
34
29
|
const [isOpen, setIsOpen] = useState(false);
|
|
35
30
|
|
|
36
|
-
//
|
|
37
|
-
|
|
38
|
-
number | undefined
|
|
39
|
-
>();
|
|
40
|
-
const [signalNotifications, setSignalNotifications] = useState<
|
|
41
|
-
Notification[] | undefined
|
|
42
|
-
>();
|
|
43
|
-
|
|
44
|
-
// Fetch unread count via useQuery
|
|
31
|
+
// Realtime updates arrive via SignalAutoInvalidator on `[["notification"]]`,
|
|
32
|
+
// so both queries stay fresh without per-component signal handlers.
|
|
45
33
|
const { data: unreadData, isLoading: unreadLoading } =
|
|
46
34
|
notificationClient.getUnreadCount.useQuery(undefined, {
|
|
47
35
|
enabled: !!session,
|
|
48
36
|
staleTime: 30_000,
|
|
49
37
|
});
|
|
50
38
|
|
|
51
|
-
// Fetch recent notifications via useQuery
|
|
52
39
|
const { data: notificationsData, isLoading: notificationsLoading } =
|
|
53
40
|
notificationClient.getNotifications.useQuery(
|
|
54
41
|
{ limit: 5, offset: 0, unreadOnly: true },
|
|
@@ -58,80 +45,14 @@ export const NotificationBell = () => {
|
|
|
58
45
|
},
|
|
59
46
|
);
|
|
60
47
|
|
|
61
|
-
// Mark all as read mutation
|
|
62
48
|
const markAsReadMutation = notificationClient.markAsRead.useMutation();
|
|
63
49
|
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
const recentNotifications =
|
|
67
|
-
signalNotifications ?? notificationsData?.notifications ?? [];
|
|
68
|
-
|
|
69
|
-
// ==========================================================================
|
|
70
|
-
// REALTIME SIGNAL SUBSCRIPTIONS (replaces polling)
|
|
71
|
-
// ==========================================================================
|
|
72
|
-
|
|
73
|
-
// Handle new notification received
|
|
74
|
-
useSignal(
|
|
75
|
-
NOTIFICATION_RECEIVED,
|
|
76
|
-
useCallback((payload) => {
|
|
77
|
-
// Increment unread count
|
|
78
|
-
setSignalUnreadCount((prev) => (prev ?? 0) + 1);
|
|
79
|
-
|
|
80
|
-
// Add to recent notifications if dropdown is open
|
|
81
|
-
setSignalNotifications((prev) => [
|
|
82
|
-
{
|
|
83
|
-
id: payload.id,
|
|
84
|
-
title: payload.title,
|
|
85
|
-
body: payload.body,
|
|
86
|
-
importance: payload.importance,
|
|
87
|
-
userId: "", // Not needed for display
|
|
88
|
-
isRead: false,
|
|
89
|
-
createdAt: new Date(),
|
|
90
|
-
},
|
|
91
|
-
...(prev ?? []).slice(0, 4), // Keep only 5 items
|
|
92
|
-
]);
|
|
93
|
-
}, []),
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
// Handle count changes from other sources
|
|
97
|
-
useSignal(
|
|
98
|
-
NOTIFICATION_COUNT_CHANGED,
|
|
99
|
-
useCallback((payload) => {
|
|
100
|
-
setSignalUnreadCount(payload.unreadCount);
|
|
101
|
-
}, []),
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
// Handle notification marked as read
|
|
105
|
-
useSignal(
|
|
106
|
-
NOTIFICATION_READ,
|
|
107
|
-
useCallback(
|
|
108
|
-
(payload) => {
|
|
109
|
-
if (payload.notificationId) {
|
|
110
|
-
// Single notification marked as read - remove from list
|
|
111
|
-
setSignalNotifications((prev) =>
|
|
112
|
-
(prev ?? []).filter((n) => n.id !== payload.notificationId),
|
|
113
|
-
);
|
|
114
|
-
// Use unreadData?.count as fallback when signalUnreadCount hasn't been set yet
|
|
115
|
-
setSignalUnreadCount((prev) =>
|
|
116
|
-
Math.max(0, (prev ?? unreadData?.count ?? 1) - 1),
|
|
117
|
-
);
|
|
118
|
-
} else {
|
|
119
|
-
// All marked as read - clear the list
|
|
120
|
-
setSignalNotifications([]);
|
|
121
|
-
setSignalUnreadCount(0);
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
[unreadData?.count],
|
|
125
|
-
),
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
// ==========================================================================
|
|
50
|
+
const unreadCount = unreadData?.count ?? 0;
|
|
51
|
+
const recentNotifications = notificationsData?.notifications ?? [];
|
|
129
52
|
|
|
130
53
|
const handleMarkAllAsRead = async () => {
|
|
131
54
|
try {
|
|
132
55
|
await markAsReadMutation.mutateAsync({});
|
|
133
|
-
setSignalUnreadCount(0);
|
|
134
|
-
setSignalNotifications([]);
|
|
135
56
|
} catch {
|
|
136
57
|
toast.error("Failed to mark all as read");
|
|
137
58
|
}
|