Repository navigation
feat: show sent alerts from the alerts endpoint (TRA-1298) - #792
Conversation
useNotificationAlerts now reads GET /notification-alerts instead of mock data. Unset filters are left out, and a bare YYYY-MM-DD from the date filters becomes the start or end of that local day, since the server takes only RFC 3339 instants. The mock alerts module is removed, as nothing else used it. An alert's id is now a readable string: "alert-", the sent time in UTC to the second, the event source, and the delivery's public id, e.g. "alert-20261117T004422Z-alarm-2814749767106561". The public id keeps it unique, because one event fans out to several deliveries in the same second. Refs: TRA-1298 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QrZ7zb1j4kqUQoTC3WT6qT
|
@NicholusMuwonge, requesting your review because this is a small change under the team rule that Mike takes DB or significant changes: it switches the alerts hook your Notifications screens use from mock data to the merged endpoint (#748), and changes the alert id to a readable string. There is no migration or DB change. Generated by Claude Code |
|
🚀 Preview Deployment Update ✅ This PR has been successfully merged into the preview branch. The preview environment will update shortly at: https://app.preview.trakrf.id |
NicholusMuwonge
left a comment
There was a problem hiding this comment.
Looks good, and it supersedes #793, which I've closed. I found two things in useNotificationAlerts.ts while reviewing the same change on my side:
1. The previous org's alerts show after an org switch. placeholderData: keepPreviousData keeps the last result across any key change, including currentOrg.id. So after switching org, org A's alerts stay on screen until org B's request comes back. Keep the previous page only when the org is unchanged:
placeholderData: (prev, prevQuery) =>
prevQuery?.queryKey[1] === currentOrg?.id ? prev : undefined,A test: render with org 7 and resolve page 1, switch the store to org 8 with the request still pending, then expect alerts to be [] and isLoading to be true.
2. The end-of-day cutoff stops a millisecond early. The backend stores microseconds and treats to as inclusive, adding 1µs. 23:59:59.999 therefore misses anything sent between .999 and .999999 on the "to" day. toISOString() can't go finer than milliseconds, so the bound needs the local offset written out:
const pad = (n: number, width = 2) => String(n).padStart(width, '0');
export function localDayBound(date: string, edge: 'start' | 'end'): string {
const [y, m, d] = date.split('-').map(Number);
const dt = edge === 'start' ? new Date(y, m - 1, d, 0, 0, 0, 0) : new Date(y, m - 1, d, 23, 59, 59, 999);
const offset = -dt.getTimezoneOffset();
const sign = offset < 0 ? '-' : '+';
const abs = Math.abs(offset);
const frac = edge === 'start' ? '000' : '999999';
return (
`${pad(dt.getFullYear(), 4)}-${pad(dt.getMonth() + 1)}-${pad(dt.getDate())}` +
`T${pad(dt.getHours())}:${pad(dt.getMinutes())}:${pad(dt.getSeconds())}.${frac}` +
`${sign}${pad(Math.floor(abs / 60))}:${pad(abs % 60)}`
);
}The offset comes from that day, so DST days come out right. Pin process.env.TZ = 'America/New_York' in the test and check 2026-03-08 and 2026-11-01. Under the default UTC zone a DST test passes without proving anything.
The full versions, with tests, are on the closed #793 branch (feat/tra-1366-real-notification-alerts), in useNotificationAlerts.ts and its test.
Review fixes for the alerts hook: - The previous page is kept while the next loads only when the org is unchanged, so another org's alerts no longer show after an org switch. - A bare "to" date now ends at 23:59:59.999999 with that day's own offset. The server stores microseconds and treats "to" as inclusive, and toISOString() stopped at .999, missing the day's last 999 µs. Tests pin America/New_York to check both DST days. Also restores the repo's single-quote formatting that an unconfigured Prettier run had rewritten in the previous commit. Refs: TRA-1298 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QrZ7zb1j4kqUQoTC3WT6qT
|
@NicholusMuwonge thanks, both were real, and both are fixed in 79a3441:
I kept the existing Generated by Claude Code |
|
🚀 Preview Deployment Update ✅ This PR has been successfully merged into the preview branch. The preview environment will update shortly at: https://app.preview.trakrf.id |
|
Thanks @edmacabebe , merging now. |
Requested by edmacabebe · project thread
Switches the Notifications screens from mock alerts to
GET /api/v1/notification-alerts(#748), and makes the alert id readable.Hook switch
useNotificationAlertsnow callsnotificationsApi.listAlertsthrough TanStack Query, keyed by org and query. It keeps the previous page while the next one loads, but never across an org switch. It returns the server's page andpagination.total.YYYY-MM-DDfrom the date filters becomes the start (00:00:00.000) or end (23:59:59.999999) of that local day, written with that day's own offset, since the server can't know the viewer's zone. The end keeps microseconds because the server stores them and treatstoas inclusive.src/lib/notifications/mockAlerts.tsis removed: after the switch nothing used it.detailsno longer documentsdirection, which the endpoint never sends.Alert id
idchanges from a number to a string with meaning:The time and source alone are not unique: one event fans out to several recipients and channels in the same second. The suffix is the delivery's non-sequential public id from migration 000057, so it never exposes the shared sequence. No migration in this PR.
Tests
FormatIDunit test; the storage and handler integration tests pass and assert the new id.listAlerts, fixtures updated to string ids.pnpm typecheckandpnpm lintclean.Refs: TRA-1298
https://claude.ai/code/session_01QrZ7zb1j4kqUQoTC3WT6qT
Generated by Claude Code