improve code in table components

This commit is contained in:
2022-12-03 21:41:54 -05:00
parent 58b32817ba
commit 0894293620
9 changed files with 68 additions and 65 deletions

View File

@ -89,19 +89,20 @@ defmodule CanneryWeb.Components.AmmoGroupTableComponent do
[%{label: gettext("Ammo type"), key: :ammo_type} | columns]
end
extra_data = %{
current_user: current_user,
ammo_type: ammo_type,
columns: columns,
container: container,
actions: actions,
range: range
}
rows =
ammo_groups
|> Repo.preload([:ammo_type, :container])
|> Enum.map(fn ammo_group ->
ammo_group
|> get_row_data_for_ammo_group(%{
current_user: current_user,
ammo_type: ammo_type,
columns: columns,
container: container,
actions: actions,
range: range
})
ammo_group |> get_row_data_for_ammo_group(extra_data)
end)
socket |> assign(columns: columns, rows: rows)

View File

@ -121,11 +121,12 @@ defmodule CanneryWeb.Components.AmmoTypeTableComponent do
%{label: nil, key: "actions", type: :actions, sortable: false}
])
extra_data = %{actions: actions, current_user: current_user}
rows =
ammo_types
|> Enum.map(fn ammo_type ->
ammo_type
|> get_ammo_type_values(columns, %{actions: actions, current_user: current_user})
ammo_type |> get_ammo_type_values(columns, extra_data)
end)
socket |> assign(columns: columns, rows: rows)

View File

@ -66,15 +66,16 @@ defmodule CanneryWeb.Components.ContainerTableComponent do
end)
end)
extra_data = %{
current_user: current_user,
tag_actions: tag_actions,
actions: actions
}
rows =
containers
|> Enum.map(fn container ->
container
|> get_row_data_for_container(columns, %{
current_user: current_user,
tag_actions: tag_actions,
actions: actions
})
container |> get_row_data_for_container(columns, extra_data)
end)
socket