MDK Logo

Alerts

Alerts views and bell button — current alerts, historical log, and header alarm indicator

@tetherto/mdk-react-devkit/foundation

Alerts components cover the full alarm surface: AlarmsBellButton in the app header, the Alerts feature composite (current + historical tabs), and the standalone HistoricalAlerts table. Pair with the dashboard for live context.

Prerequisites

Components

ComponentDescription
HistoricalAlertsHistorical alerts log with date-range picker and data table
AlarmsBellButtonTop-bar bell button with three-line severity alarm badge
AlertsCurrent and historical alerts log view

Alerts

Full-page alerts surface combining current and historical alert tabs. Consumes alarm data from the MDK adapter store.

Full-page alerts surface that wraps CurrentAlerts and (when isHistoricalAlertsEnabled) HistoricalAlerts, coordinating their shared filter state, date range, and alert click handling. Must be rendered inside <MdkProvider>. It manages:

  1. Current alerts (devices, isCurrentAlertsLoading): raw devices payload and loading flag passed to CurrentAlerts.
  2. Historical alerts (historicalAlerts, isHistoricalAlertsLoading, isHistoricalAlertsEnabled): log data and visibility toggle.
  3. Filtering (selectedAlertId, initialSeverity, typeFiltersForSite): deep-link focus, severity pre-selection, and site type filters.
  4. Callbacks (onAlertClick, onDateRangeChange): row navigation and date range updates.
  5. Sound (isSoundEnabled, isDemoMode): critical-alert beep toggle and demo/preview mode.
  6. Layout (header, className): optional header slot and root class.

Import

import { Alerts } from '@tetherto/mdk-react-devkit/foundation'

Props

PropStatusTypeDefaultDescription
devicesOptionalDevice[][]noneRaw devices payload for current alerts (see useCurrentAlertDevices)
isCurrentAlertsLoadingOptionalbooleanfalseWhen true, shows the loading state in CurrentAlerts
historicalAlertsOptionalAlert[]nonePre-fetched historical alerts (see useHistoricalAlerts)
isHistoricalAlertsLoadingOptionalbooleanfalseWhen true, shows the loading state in HistoricalAlerts
isHistoricalAlertsEnabledOptionalbooleanfalseWhen true, renders the historical alerts log section
selectedAlertIdOptionalstringnoneFocuses the table on a single alert (deep-link from URL)
initialSeverityOptionalstringnonePre-selects a severity filter (typically from a ?severity= URL param)
onAlertClickOptionalfunctionnoneCalled with device id and alert uuid when the user opens an alert row
onDateRangeChangeOptionalfunctionnoneCalled when the user picks a new date range in the historical log
dateRangeOptionalHistoricalAlertsRangelast 14 daysControlled date range ({ start: number, end: number } in ms)
isSoundEnabledOptionalbooleanfalseEnables the critical-alert audible beep when a critical alert is present
isDemoModeOptionalbooleanfalseWhen true, skips sound notifications (safe for preview environments)
typeFiltersForSiteOptionalCascaderOption[]noneSite-specific overrides for the TagFilterBar type filter
headerOptionalReactNodenoneOptional header (e.g. breadcrumbs) rendered above the alerts tables
classNameOptionalstringnoneRoot class name from the host app

Hook integration

Wire Alerts with the MDK adapter hooks for live data:

import { useDevices } from '@tetherto/mdk-react-adapter'
import { useCurrentAlertDevices, useHistoricalAlerts } from '@tetherto/mdk-react-adapter'
import { Alerts } from '@tetherto/mdk-react-devkit/foundation'

function AlertsPage() {
  const { filterTags } = useDevices()
  const devices = useCurrentAlertDevices({ filterTags })
  const [range, setRange] = useState(() => getDefaultHistoricalAlertsRange())
  const historical = useHistoricalAlerts(range)

  return (
    <Alerts
      devices={devices.data}
      isCurrentAlertsLoading={devices.isLoading}
      historicalAlerts={historical.data}
      isHistoricalAlertsLoading={historical.isLoading}
      isHistoricalAlertsEnabled
      dateRange={range}
      onDateRangeChange={setRange}
      onAlertClick={(id, uuid) => router.push(`/alerts/${uuid}`)}
    />
  )
}

See useCurrentAlertDevices and useHistoricalAlerts for hook options.

CurrentAlerts

Sortable, searchable data table of active alerts derived from a raw devices payload. Plays an audible beep when a critical alert is present and sound notifications are enabled — after the user confirms via AlertConfirmationModal. The Alerts feature wrapper manages all state for most use cases; use CurrentAlerts directly when you need a standalone current-alerts table.

Import

import { CurrentAlerts } from '@tetherto/mdk-react-devkit/foundation'
import type { CurrentAlertsProps, AlertLocalFilters } from '@tetherto/mdk-react-devkit/foundation'

Props

PropStatusTypeDefaultDescription
localFiltersRequiredAlertLocalFiltersnoneControlled filter state shared with other alerts components (see type)
onLocalFiltersChangeRequiredfunctionnoneCalled with the updated AlertLocalFilters when filters change
filterTagsRequiredstring[]noneActive search tags; mirrors the devices-store tag slice
onFilterTagsChangeRequiredfunctionnoneCalled with updated tags when the user adds or removes a search chip
devicesOptionalDevice[][]noneRaw devices payload; drives alert row derivation
isLoadingOptionalbooleanfalseWhen true, shows the table loading state
selectedAlertIdOptionalstringnoneFocuses the table on a single alert
onAlertClickOptionalfunctionnoneCalled with device id and alert uuid when the user opens an alert row
isSoundEnabledOptionalbooleanfalseEnables the critical-alert audible beep
isDemoModeOptionalbooleanfalseWhen true, skips sound notifications
typeFiltersForSiteOptionalCascaderOption[]noneSite-specific overrides for the type filter in TagFilterBar
classNameOptionalstringnoneRoot class name from the host app

AlertLocalFilters type

type AlertLocalFilters = {
  severity?: string[] | string
  status?: string[]
  type?: string[]
  id?: string[]
  thing?: { id?: string }
  [key: string]: unknown
}

Basic usage

import { CurrentAlerts } from '@tetherto/mdk-react-devkit/foundation'
import type { AlertLocalFilters } from '@tetherto/mdk-react-devkit/foundation'

function AlertsView({ devices, isLoading }) {
  const [localFilters, setLocalFilters] = useState<AlertLocalFilters>({})
  const [filterTags, setFilterTags] = useState<string[]>([])

  return (
    <CurrentAlerts
      devices={devices}
      isLoading={isLoading}
      localFilters={localFilters}
      onLocalFiltersChange={setLocalFilters}
      filterTags={filterTags}
      onFilterTagsChange={setFilterTags}
      onAlertClick={(id, uuid) => console.log('Alert clicked', id, uuid)}
    />
  )
}

HistoricalAlerts

Renders the historical alerts log as a sortable data table, with a date-range picker in the title row for adjusting the query window. Shares filter state with the current alerts view.

Import

import { HistoricalAlerts } from '@tetherto/mdk-react-devkit/foundation'
import type { HistoricalAlertsProps, HistoricalAlertsRange } from '@tetherto/mdk-react-devkit/foundation'

Props

PropStatusTypeDefaultDescription
alertsOptionalAlert[][]Pre-fetched historical alert entries
isLoadingOptionalbooleanfalseShow table loading state
localFiltersRequiredAlertLocalFiltersnoneFilters and search state shared with CurrentAlerts
filterTagsRequiredstring[]noneActive filter tags
dateRangeRequiredHistoricalAlertsRangenoneControlled start/end timestamps (ms)
onDateRangeChangeRequiredfunctionnoneFires when the user picks a new range
onAlertClickOptionalfunctionnoneRow click handler
classNameOptionalstringnoneAdditional CSS class

HistoricalAlertsRange type

type HistoricalAlertsRange = {
  start: number
  end: number
}

Basic usage

<HistoricalAlerts
  alerts={historicalAlerts}
  localFilters={localFilters}
  filterTags={filterTags}
  dateRange={{ start: rangeStart, end: rangeEnd }}
  onDateRangeChange={({ start, end }) => setRange({ start, end })}
  onAlertClick={(id, uuid) => console.log('Alert clicked', id, uuid)}
/>

Loading state

<HistoricalAlerts
  alerts={[]}
  isLoading
  localFilters={localFilters}
  filterTags={filterTags}
  dateRange={dateRange}
  onDateRangeChange={onDateRangeChange}
/>

Behavior notes

  • The component wires a DateRangePicker into the table title via AlertsTableTitle, so date range changes come back through onDateRangeChange.
  • Rows are sorted by severity (descending) then creation date (descending) by default.
  • Timestamps are formatted through useTimezoneFormatter()'s getFormattedDate.

TagFilterBar

Strip of removable filter chips and a tag-input search field for narrowing the alerts table by severity, status, type, and device tags. Used as the subtitle slot of AlertsTableTitle inside CurrentAlerts.

Import

import { TagFilterBar } from '@tetherto/mdk-react-devkit/foundation'
import type { TagFilterBarProps } from '@tetherto/mdk-react-devkit/foundation'

Props

PropStatusTypeDefaultDescription
filterTagsRequiredstring[]noneActive search tag chips
localFiltersRequiredAlertLocalFiltersnoneControlled filter state (severity, status, type)
onSearchTagsChangeRequiredfunctionnoneCalled with updated tags when the user adds or removes a chip
onLocalFiltersChangeRequiredfunctionnoneCalled with updated AlertLocalFilters when a cascader selection changes
typeFiltersForSiteOptionalCascaderOption[]default filter listSite-specific overrides for the "Type" cascader children
placeholderOptionalstringnonePlaceholder text for the tag-input field
classNameOptionalstringnoneRoot class name from the host app

Basic usage

import { TagFilterBar } from '@tetherto/mdk-react-devkit/foundation'

<TagFilterBar
  filterTags={filterTags}
  localFilters={localFilters}
  onSearchTagsChange={setFilterTags}
  onLocalFiltersChange={setLocalFilters}
/>

AlertsTableTitle

Heading strip for an alerts table — renders the section title and an optional subtitle slot (typically used for TagFilterBar or DateRangePicker). Used internally by CurrentAlerts and HistoricalAlerts.

Import

import { AlertsTableTitle } from '@tetherto/mdk-react-devkit/foundation'

Props

PropStatusTypeDefaultDescription
titleRequiredReactNodenoneSection heading content
subtitleOptionalReactNodenoneOptional content rendered below the title (e.g. TagFilterBar or DateRangePicker)
classNameOptionalstringnoneRoot class name from the host app

Basic usage

import { AlertsTableTitle, TagFilterBar } from '@tetherto/mdk-react-devkit/foundation'

<AlertsTableTitle
  title="Current Alerts"
  subtitle={
    <TagFilterBar
      filterTags={filterTags}
      localFilters={localFilters}
      onSearchTagsChange={setFilterTags}
      onLocalFiltersChange={setLocalFilters}
    />
  }
/>

AlertConfirmationModal

One-time consent dialog that appears before critical-alert sound notifications are activated. Renders a non-dismissible Dialog with an "Understood" button. Once confirmed (tracked in sessionStorage), CurrentAlerts begins playing the beep.

Import

import { AlertConfirmationModal } from '@tetherto/mdk-react-devkit/foundation'

Props

PropStatusTypeDefaultDescription
isOpenRequiredbooleannoneControls modal visibility
onOkRequiredfunctionnoneCalled when the user clicks "Understood"

Basic usage

import { AlertConfirmationModal } from '@tetherto/mdk-react-devkit/foundation'

<AlertConfirmationModal
  isOpen={showConfirmation}
  onOk={() => setShowConfirmation(false)}
/>

Next steps

On this page