MishkaGervaz.Table.Web.DataLoader.Helpers (MishkaGervaz v0.0.1-alpha.2)

Copy Markdown View Source

Pure data helpers for MishkaGervaz.Table.Web.DataLoader.

Extracted from the __using__ macro so the same primitives are reusable in user overrides and directly testable.

Summary

Functions

The empty starting state for one of the two archive-status modes (:active or :archived). Used by apply_archive_status/3 to swap state when toggling between modes.

Drops every entry from sorts whose field is in db_fields.

Rewrites the order of every entry in sorts whose field belongs to db_fields, leaving the rest untouched.

Types

mode_state()

@type mode_state() :: %{
  filter_values: map(),
  sort_fields: [sort_entry()],
  selected_ids: MapSet.t(any()),
  excluded_ids: MapSet.t(any()),
  select_all?: boolean()
}

sort_entry()

@type sort_entry() :: {atom(), :asc | :desc}

Functions

default_mode_state()

@spec default_mode_state() :: mode_state()

The empty starting state for one of the two archive-status modes (:active or :archived). Used by apply_archive_status/3 to swap state when toggling between modes.

remove_sort_group(sorts, db_fields)

@spec remove_sort_group([sort_entry()], [atom()]) :: [sort_entry()]

Drops every entry from sorts whose field is in db_fields.

toggle_sort_group(sorts, db_fields, new_order)

@spec toggle_sort_group([sort_entry()], [atom()], :asc | :desc) :: [sort_entry()]

Rewrites the order of every entry in sorts whose field belongs to db_fields, leaving the rest untouched.