Shared hooks and utilities for PgFlowDashboard LiveViews.
Provides common functionality for configuration access and real-time subscriptions.
Summary
Functions
Determines view mode based on count and threshold.
Formats a duration in milliseconds for display.
Formats a datetime relative to now.
Formats a timestamp for display in the configured time zone.
Assigns dashboard configuration for LiveViews.
Splits a list fetched with limit+1 into results and has_more flag.
Schedules a refresh timer for polling updates.
Returns a short form of a UUID for display.
Returns CSS classes for a status badge.
Returns the color for a status in hex format (for SVG).
Subscribes to updates for a specific run.
Subscribes to PgFlow PubSub topics for real-time updates.
Unsubscribes from a specific run's updates.
Functions
Determines view mode based on count and threshold.
Returns :card for small datasets (≤ threshold) and :list for larger ones.
Default threshold is 12 (fits nicely in a 3-column grid).
Examples
iex> determine_view_mode(5)
:card
iex> determine_view_mode(15)
:list
iex> determine_view_mode(15, 20)
:card
Formats a duration in milliseconds for display.
Formats in a compact style suitable for dashboards: "50ms", "1.5s", "2.3m", "1.2h".
Formats a datetime relative to now.
Returns strings like "in 5 minutes", "in 2 hours", "3 minutes ago".
Formats a timestamp for display in the configured time zone.
Assigns dashboard configuration for LiveViews.
This function should be called in the on_mount callback:
def on_mount(:default, _params, session, socket) do
PgFlowDashboard.Live.LiveHelpers.on_mount(session, socket)
end
Splits a list fetched with limit+1 into results and has_more flag.
When fetching paginated data, request page_size + 1 items. This function
splits the result to determine if there are more items available.
Examples
iex> paginate_results([1, 2, 3], 2)
{[1, 2], true}
iex> paginate_results([1, 2], 2)
{[1, 2], false}
Schedules a refresh timer for polling updates.
Returns a short form of a UUID for display.
Returns CSS classes for a status badge.
Returns the color for a status in hex format (for SVG).
Subscribes to updates for a specific run.
Subscribes to PgFlow PubSub topics for real-time updates.
Unsubscribes from a specific run's updates.