alert_handler module

class AlertHandler

Bases: object

Manages alerts for the application.

This class provides functionality for: - Displaying a modal with all alerts, which can be filtered and dismissed. - Showing ephemeral alerts at the top-middle of the screen for 4 seconds without removing them from the store.

callbacks()

Registers Dash callbacks for the AlertHandler functionality.

This method defines callbacks for: - Toggling the alert modal. - Setting the alert filter based on user input. - Displaying alerts in the modal, filtered by type. - Removing dismissed alerts from the store. - Displaying ephemeral alerts.

Return type:

None

Notes

  • Alerts must be added to each callback to ensure proper functionality.

layout()

Creates the layout for the AlertHandler.

The layout includes: - dcc.Store components for storing all alerts and the current filter. - A fixed container for displaying ephemeral alerts. - An interval component to drive ephemeral updates. - A modal with filter buttons and a dismissable alert container. - A button to open the modal.

Returns:

A Dash HTML Div component containing the layout for the AlertHandler.

Return type:

html.Div

create_alert(message, color='info', ephemeral=False)

Creates a standardized alert record.

Parameters:
  • message (str) – The alert message to display.

  • color (str, optional) – The color of the alert, typically ‘info’, ‘warning’, or ‘danger’. Defaults to ‘info’.

  • ephemeral (bool, optional) – If True, the alert appears at the top-center for 4 seconds but remains in the store for the modal. Defaults to False.

Returns:

A dictionary containing the alert details, including timestamp, message, color, and ephemeral status.

Return type:

dict[str, Any]