Lotus.Web.Dashboards.FilterOptions (Lotus Web v1.2.0)

Copy Markdown View Source

The options of the select filters of a dashboard, for the current filter values.

A select filter gets its options from Lotus.list_dashboard_filter_options/2: the static config["options"], or the rows of its source query. A filter that depends on another filter gets the value of that filter as a query variable, so resolve/3 walks the filters parent first, and a city filter sees the country value that resolve/3 already checked.

Core does not check a value against the options, so resolve/3 does. When the options of a dependent filter change, its value stays only if it is one of the new options, and otherwise becomes "". The clear goes down the chain (country → city → district).

The filters can be Lotus.Storage.DashboardFilter structs or the maps the dashboard editor keeps for filters not saved yet, whose ids are strings.

Summary

Types

The options state of one select filter

Functions

Resolves the options of every select filter.

Types

state()

@type state() ::
  {:ok, [%{value: term(), label: term()}]} | {:error, term()} | :waiting

The options state of one select filter:

  • {:ok, options} - the options, each %{value: term(), label: term()}
  • {:error, reason} - the source query failed or may not run
  • :waiting - the filter depends on a filter that has no value

Functions

resolve(filters, filter_values, opts \\ [])

@spec resolve([map()], map(), keyword()) ::
  {%{required(String.t()) => state()}, map()}

Resolves the options of every select filter.

Returns the state of each select filter by name, and the filter values with the values that are no longer an option cleared.

Options

  • :run_opts - options for the source query, such as :context and :scope
  • :authorize - a function that takes a source query id and returns :allow or {:deny, reason}. Defaults to allowing every query.