Phoenix.LiveDashboard.PageBuilder behaviour (LiveDashboard v0.2.9) View Source

Link to this section Summary

Functions

Renders a table component.

Link to this section Types

Specs

capabilities() :: %{
  applications: [atom()],
  modules: [atom()],
  processes: [atom()],
  dashboard_running?: boolean(),
  system_info: nil | binary()
}

Specs

component()

Specs

requirements() :: [{:application | :process | :module, atom()}]

Specs

session() :: map()

Specs

unsigned_params() :: map()

Link to this section Functions

Specs

table(keyword()) :: component()

Renders a table component.

This component is used in different pages like applications or sockets. It can be used in a Phoenix.LiveView in the render/1 function:

def render_page(assigns) do
  table(
    columns: columns(),
    id: @table_id,
    row_attrs: &row_attrs/1,
    row_fetcher: &fetch_applications/2,
    title: "Applications"
  )
end

Options

These are the options supported by the component:

  • :id - Required. Because is a stateful Phoenix.LiveComponent an unique id is needed.

  • :columns - Required. A Keyword list with the following keys:

    • :field - Required. An identifier for the column.
    • :header - Label to show in the current column. Default value is calculated from :field.
    • :header_attrs - A list with HTML attributes for the column header. More info: Phoenix.HTML.Tag.tag/1. Default [].
    • :format - Function which receives the row data and returns the cell information. Default is calculated from :field: row[:field].
    • :cell_attrs - A list with HTML attributes for the table cell. It also can be a function which receives the row data and returns an attribute list. More info: Phoenix.HTML.Tag.tag/1. Default: [].
    • :sortable - Either :asc or :desc with the default sorting. When set, the column header is clickable and it fetches again rows with the new order. At least one column should be sortable. Default: nil
  • :limit_options - A list of integers to limit the number of rows to show. Default: [50, 100, 500, 1000, 5000]

  • :params - Required. All the params received by the parent Phoenix.LiveView, so the table can handle its own parameters.

  • :row_fetcher - Required. A function which receives the params and the node and returns a tuple with the rows and the total number: (params(), node()) -> {list(), integer() | binary()}

  • :rows_name - A string to name the representation of the rows. Default is calculated from the current page.

  • :title - The title of the table. Default is calculated with the current page.

Link to this section Callbacks

Link to this callback

handle_event(event, unsigned_params, socket)

View Source (optional)

Specs

handle_event(event :: binary(), unsigned_params(), socket :: Socket.t()) ::
  {:noreply, Socket.t()} | {:reply, map(), Socket.t()}
Link to this callback

handle_info(msg, socket)

View Source (optional)

Specs

handle_info(msg :: term(), socket :: Socket.t()) :: {:noreply, Socket.t()}
Link to this callback

handle_params(unsigned_params, uri, socket)

View Source (optional)

Specs

handle_params(unsigned_params(), uri :: String.t(), socket :: Socket.t()) ::
  {:noreply, Socket.t()}
Link to this callback

handle_refresh(socket)

View Source (optional)

Specs

handle_refresh(socket :: Socket.t()) :: {:noreply, Socket.t()}

Specs

init(term()) :: {:ok, session()} | {:ok, session(), requirements()}

Callback invoked when a page is declared in the router.

It receives the router options and it must return the tuple {:ok, session, requirements}.

The page session will be serialized to the client and received on mount.

The requirements is an optional keyword to detect the state of the node.

The result of this detection will be passed as second argument in the menu_link/2 callback. The possible values are:

  • :applications list of applications that are running or not.
  • :modules list of modules that are loaded or not.
  • :pids list of processes that alive or not.
Link to this callback

menu_link(session, capabilities)

View Source

Specs

menu_link(session(), capabilities()) ::
  {:ok, String.t()}
  | {:disabled, String.t()}
  | {:disabled, String.t(), String.t()}
  | :skip

Callback invoked when a page is declared in the router.

It receives the session returned by the init/1 callback and the capabilities of the current node.

The possible return values are:

  • {:ok, text} when the link should be enable and text to be shown.

  • {:disabled, text} when the link should be disable and text to be shown.

  • {:disabled, text, more_info_url} similar to the previous one but it also includes a link to provide more information to the user.

  • :skip when the link should not be shown at all.

Link to this callback

mount(unsigned_params, session, socket)

View Source (optional)

Specs

mount(unsigned_params(), session(), socket :: Socket.t()) ::
  {:ok, Socket.t()} | {:ok, Socket.t(), keyword()}

Specs

render_page(assigns :: Socket.assigns()) :: component()