CSV export: robust apply_export_filters, single custom_field_ids_union, string boolean_filters, more tests
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
ad641ed49e
commit
930c039c5d
3 changed files with 172 additions and 18 deletions
|
|
@ -388,20 +388,25 @@ defmodule Mv.Membership.MemberExport do
|
|||
- `opts` - Map with `:selected_ids`, `:cycle_status_filter`, `:show_current_cycle`, `:boolean_filters`.
|
||||
- `custom_fields_by_id` - Map of custom field id => custom field struct (for boolean filter resolution).
|
||||
|
||||
When `opts.selected_ids` is not empty, returns `members` unchanged. Otherwise applies
|
||||
cycle status filter and boolean custom field filters.
|
||||
When `opts.selected_ids` is not empty, returns `members` unchanged (selected_ids
|
||||
override filters). Otherwise applies cycle status filter and boolean custom field filters.
|
||||
|
||||
Uses `Map.get(opts, :selected_ids, [])` so that `nil` or a missing key is treated as
|
||||
"export all" and filters are applied.
|
||||
"""
|
||||
@spec apply_export_filters([struct()], map(), map()) :: [struct()]
|
||||
def apply_export_filters(members, opts, custom_fields_by_id) do
|
||||
if opts[:selected_ids] != [] do
|
||||
members
|
||||
else
|
||||
selected_ids = Map.get(opts, :selected_ids, [])
|
||||
|
||||
if Enum.empty?(selected_ids) do
|
||||
members
|
||||
|> apply_cycle_status_filter(opts[:cycle_status_filter], opts[:show_current_cycle])
|
||||
|> Index.apply_boolean_custom_field_filters(
|
||||
Map.get(opts, :boolean_filters, %{}),
|
||||
Map.values(custom_fields_by_id)
|
||||
)
|
||||
else
|
||||
members
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue