Alert Utilities
Alert query builders and time-range utilities
Utilities for building alert queries and managing time ranges.
Package
@tetherto/mdk-ui-foundation
Utilities
breakTimeIntoIntervals
Split [start, end] into consecutive windows of intervalMs. The final window is clamped to end. Returns an empty array when the range is empty or inverted. Mirrors Mining OS's breakTimeIntoIntervals.
Function
(start: number, end: number, intervalMs: number = ONE_DAY_MS) => TimeInterval[]buildCurrentAlertDevicesParams
list-things params for the current-alerts table: every device that currently carries one or more alerts, with the fields the <CurrentAlerts> table reads. Consumed by useCurrentAlertDevices.
Function
(filterTags: string[] = []) => ListThingsParamsbuildHistoricalAlertsParams
history-log params for a single alerts window. The chunked fetch (useHistoricalAlerts) calls this once per 24h sub-window.
Function
(range: HistoricalAlertsRange) => HistoryLogParamsfetchHistoricalAlertsInChunks
Fetch a historical-alerts range as successive 24h windows, merging the results by uuid. fetchWindow is called once per window (oldest → newest); individual window failures are swallowed (matches Mining OS) so one bad window doesn't dro…
Function
(range: { start: number; end: number }, fetchWindow: (window: TimeInterval) => Promise<T[]>, options: FetchHistoricalAlertsOptions = {}) => Promise<T[]>getAlertsForDevices
Flatten an array of devices into a list of incident rows, one per alert. Devices without last.alerts are skipped. The output is not yet sorted; pair with sortIncidentsBySeverity for the final list-view order.
Function
(devices: ListThingsDevice[], formatDate: (d: Date) => string = (d) => d.toISOString()) => IncidentRow[]getDefaultHistoricalAlertsRange
Default historical-alerts range: the last DEFAULT_HISTORICAL_WINDOW_MS ending now. Used by the devkit <Alerts> feature and the shell Alerts page to seed their range state.
Function
(now: number = Date.now()) => HistoricalAlertsRangemapDevicesToIncidents
One-shot helper: devices → sorted rows. Used by the useActiveIncidents hook's select projection.
Function
(devices: ListThingsDevice[], formatDate?: (d: Date) => string) => IncidentRow[]mapHistoryLogToAlerts
Normalise raw history-log alert rows into the shape the devkit <HistoricalAlerts> table consumes. The table derives its device label, short code, and filter tokens from each row's thing (treated as a device), so this guarantees `thin…
Function
(rows: HistoricalAlert[] = []) => HistoricalAlert[]mergeAlertsByUuid
Concatenate next onto prev, replacing any row that shares a uuid (later windows win) and appending the rest. Rows without a uuid are always appended. Mirrors Mining OS's updateHistoricalData.
Function
(prev: T[], next: T[]) => T[]sortIncidentsBySeverity
Sort rows by severity (critical → high → medium), then by id for deterministic ordering when severities tie. Returns a new array.
Function
(rows: IncidentRow[]) => IncidentRow[]