fix: sort Fee Type by name in LiveView and exports
Use Ash related-field sort (membership_fee_type.name) instead of membership_fee_type_id so column order is alphabetical. Load membership_fee_type when sorting by it even if column is hidden. In-memory re-sort (Build) uses loaded fee type name.
This commit is contained in:
parent
d41d13d122
commit
94bcb5dc8c
3 changed files with 48 additions and 19 deletions
|
|
@ -965,9 +965,10 @@ defmodule MvWeb.MemberLive.Index do
|
|||
query =
|
||||
Ash.Query.load(query, groups: [:id, :name, :slug])
|
||||
|
||||
# Load membership_fee_type when the column is visible
|
||||
# Load membership_fee_type when the column is visible or when sorting by it
|
||||
query =
|
||||
if :membership_fee_type in socket.assigns.member_fields_visible do
|
||||
if :membership_fee_type in socket.assigns.member_fields_visible or
|
||||
socket.assigns.sort_field in [:membership_fee_type, "membership_fee_type"] do
|
||||
Ash.Query.load(query, membership_fee_type: [:id, :name])
|
||||
else
|
||||
query
|
||||
|
|
@ -1133,9 +1134,9 @@ defmodule MvWeb.MemberLive.Index do
|
|||
field in [:groups, "groups"] ->
|
||||
{query, true}
|
||||
|
||||
# Membership fee type sort -> by FK at DB
|
||||
# Membership fee type sort -> by related name at DB
|
||||
field in [:membership_fee_type, "membership_fee_type"] ->
|
||||
{Ash.Query.sort(query, membership_fee_type_id: order), false}
|
||||
{Ash.Query.sort(query, [{"membership_fee_type.name", order}]), false}
|
||||
|
||||
# Custom field sort -> after load
|
||||
custom_field_sort?(field) ->
|
||||
|
|
@ -1777,6 +1778,15 @@ defmodule MvWeb.MemberLive.Index do
|
|||
end
|
||||
end)
|
||||
|
||||
# If fee type is visible but start_date was not in the list, append it
|
||||
with_extras =
|
||||
if :membership_fee_type in (member_fields_visible || []) and
|
||||
:membership_fee_type not in with_extras do
|
||||
with_extras ++ [:membership_fee_type]
|
||||
else
|
||||
with_extras
|
||||
end
|
||||
|
||||
if :groups in (member_fields_visible || []), do: with_extras ++ [:groups], else: with_extras
|
||||
end
|
||||
|
||||
|
|
@ -1815,6 +1825,14 @@ defmodule MvWeb.MemberLive.Index do
|
|||
&expand_db_string_for_export(&1, membership_fee_type_visible, computed_strings)
|
||||
)
|
||||
|
||||
# If fee type is visible but start_date was not in the list, append it before computed/groups
|
||||
db_with_extras =
|
||||
if membership_fee_type_visible and "membership_fee_type" not in db_with_extras do
|
||||
db_with_extras ++ ["membership_fee_type"]
|
||||
else
|
||||
db_with_extras
|
||||
end
|
||||
|
||||
# Any remaining computed fields not inserted above (future-proof)
|
||||
remaining_computed =
|
||||
computed_strings
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue