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

Copy Markdown View Source

Canonical form for the filter values a dashboard carries.

A filter value is a string. That is what survives a round-trip through the URL query string, and it is what Lotus.Dashboards expects when it applies a filter's transform to a card's query variables.

The one filter that does not arrive as a string is the date range. Its picker is two <input type="date"> elements posted under one filter name, so Phoenix parses them into %{"start" => _, "end" => _}. normalize/1 flattens that to "start,end", which is the shape the date_range_start and date_range_end transforms already parse.

Summary

Functions

Builds the filter values for a dashboard from URL params, falling back to each filter's default.

Reduces posted filter params to their canonical string form.

Splits a canonical date-range value into its two dates, either of which may be nil when that end of the range is open.

Reduces filter values to the params worth putting in the URL, dropping the ones carrying nothing.

Functions

from_params(params, filters)

@spec from_params(map(), [struct()]) :: %{optional(String.t()) => String.t()}

Builds the filter values for a dashboard from URL params, falling back to each filter's default.

normalize(filter_values)

@spec normalize(map()) :: %{optional(String.t()) => String.t()}

Reduces posted filter params to their canonical string form.

split_date_range(value)

@spec split_date_range(term()) :: {String.t() | nil, String.t() | nil}

Splits a canonical date-range value into its two dates, either of which may be nil when that end of the range is open.

to_params(filter_values)

@spec to_params(map()) :: map()

Reduces filter values to the params worth putting in the URL, dropping the ones carrying nothing.