MDK Logo

Alerts

Full alerts page — combines the searchable current-alerts table, an optional historical-alerts log section, severity filters, and the sound confirmation moda…

Full alerts page — combines the searchable current-alerts table, an optional historical-alerts log section, severity filters, and the sound confirmation modal. Wraps CurrentAlerts and HistoricalAlerts and coordinates their shared filter / date-range / selected-id state.

Must be rendered inside <MdkProvider> — the embedded tables read tag filters from the devices store and use the timezone formatter hook.

import { Alerts } from "@tetherto/mdk-react-devkit";
PropStatusTypeDefaultDescription
devicesOptionalDevice[][] | undefinedDevices payload powering the "Current Alerts" table. Mirrors the API response shape of `useGetListThingsQuery({ ... alerts query })`.
isCurrentAlertsLoadingOptionalboolean | undefinedLoading flag for the "Current Alerts" table.
historicalAlertsOptionalAlert[] | undefinedPre-fetched historical alerts log entries.
isHistoricalAlertsLoadingOptionalboolean | undefined
isHistoricalAlertsEnabledOptionalboolean | undefinedfalseWhen true, shows the "Historical Alerts Log" section. Mirrors the `alertsHistoricalLogEnabled` feature flag in the source app.
selectedAlertIdOptionalstring | undefinedOptional alert id used to focus on a single alert (deep-link from URL).
initialSeverityOptionalstring | undefinedInitial severity selection (typically derived from `?severity=` URL param).
onAlertClickOptional((id?: string | undefined, uuid?: string | undefined) => void) | undefinedCallback invoked when the operator clicks an alert row. Receives the device id and alert uuid.
dateRangeOptionalHistoricalAlertsRange | undefinedControlled date range for the historical alerts. Defaults to last 14 days.
onDateRangeChangeOptional((range: HistoricalAlertsRange) => void) | undefined
isSoundEnabledOptionalboolean | undefinedfalseWhether sound notifications are enabled in user preferences.
isDemoModeOptionalboolean | undefinedfalseWhen true, sound notifications are skipped (e.g. demo / preview).
typeFiltersForSiteOptionalCascaderOption[] | undefinedOptional site-specific overrides for the type filter.
headerOptionalReact.ReactNodeOptional header (e.g. breadcrumbs) rendered above the alerts.
classNameOptionalstring | undefined

Usage

Page-level alerts feature: composes the searchable Current Alerts table with an optional Historical Alerts Log section. Handles severity-filter state, the sound-confirmation modal, historical date-range state, and the shared filterTags slice on the devices store.

Use this when you want a drop-in /alerts route. For just the current-alerts table or just the historical log, drop down to CurrentAlerts / HistoricalAlerts directly.

Requirements

  • Render inside <MdkProvider>. The component reads filterTags from the devices store and the historical log uses useTimezoneFormatter.

Data contracts

  • Devicefoundation/types/device. Same shape consumed by CurrentAlerts.
  • Alertfoundation/types/alerts. Same shape consumed by HistoricalAlerts.
  • HistoricalAlertsRange{ start: number; end: number } (ms epoch).

Notes

  • Filter tags are written to the shared devices store via useDevices().setFilterTags — clicking a row appends the device id, mirroring the source app behaviour.
  • When isHistoricalAlertsEnabled is false, only the current-alerts table renders.
  • For URL-driven deep links, pass initialSeverity (one render only) for the severity dropdown and selectedAlertId to highlight a row.

Example

/** * Runnable example for the Alerts feature page. * * Wrap the app in `<MdkProvider>` — the embedded tables read filter tags from * the devices store and the historical log uses the timezone formatter hook. */import type { Alert } from '@tetherto/mdk-react-devkit'import { Alerts } from '@tetherto/mdk-react-devkit'const NOW = Date.now()const MIN = 60 * 1000const DAY = 24 * 60 * MIN// The current-alerts table derives rows from `device.last.alerts`. We cast to// `never` to avoid duplicating the full `Device` type in the example.const mockDevices = [  [    {      id: 'miner-A1',      last: {        alerts: [          {            id: '1',            uuid: 'alrt-1',            severity: 'critical',            name: 'miner_offline',            description: 'Miner 0xA1 has stopped reporting.',            code: '001',            createdAt: NOW - 2 * MIN,          },        ],      },    },  ],]const mockHistorical: Alert[] = [  {    id: '2',    uuid: 'alrt-2',    severity: 'warning',    name: 'temp_high',    description: 'Container 03 exceeded 78°C.',    code: '002',    createdAt: NOW - 3 * DAY,    thing: { id: 'container-03' },  },]export const AlertsExample = () => {  return (    <Alerts      devices={mockDevices as never}      historicalAlerts={mockHistorical}      isHistoricalAlertsEnabled      isDemoMode      onAlertClick={(id, uuid) => {        // eslint-disable-next-line no-console        console.log('open alert', { id, uuid })      }}      onDateRangeChange={(range) => {        // eslint-disable-next-line no-console        console.log('historical range changed', range)      }}    />  )}