mirror of
https://github.com/ash-project/ash_phoenix.git
synced 2024-09-19 06:42:47 +12:00
Fix remove_component (#86)
This commit is contained in:
parent
1a1ff1a568
commit
d22a48a514
2 changed files with 29 additions and 4 deletions
|
@ -903,11 +903,11 @@ defmodule AshPhoenix.FilterForm do
|
|||
|> set_validity()
|
||||
end
|
||||
|
||||
@doc "Removes the group *or* component with the given id"
|
||||
def remove_component(form, group_or_component_id) do
|
||||
@doc "Removes the group *or* predicate with the given id"
|
||||
def remove_component(form, group_or_predicate_id) do
|
||||
form
|
||||
|> remove_group(group_or_component_id)
|
||||
|> remove_component(group_or_component_id)
|
||||
|> remove_group(group_or_predicate_id)
|
||||
|> remove_predicate(group_or_predicate_id)
|
||||
end
|
||||
|
||||
defp remove_if_empty(form, false), do: [form]
|
||||
|
|
|
@ -61,6 +61,31 @@ defmodule AshPhoenix.FilterFormTest do
|
|||
} = form
|
||||
end
|
||||
|
||||
test "groups and predicates can be removed with remove_component" do
|
||||
form = FilterForm.new(Post)
|
||||
|
||||
{form, group_id} = FilterForm.add_group(form, operator: :or, return_id?: true)
|
||||
|
||||
{form, predicate_id} =
|
||||
FilterForm.add_predicate(form, :title, :eq, "new post", to: group_id, return_id?: true)
|
||||
|
||||
form = FilterForm.remove_component(form, predicate_id)
|
||||
|
||||
assert %FilterForm{
|
||||
components: [
|
||||
%FilterForm{
|
||||
components: []
|
||||
}
|
||||
]
|
||||
} = form
|
||||
|
||||
form = FilterForm.remove_component(form, group_id)
|
||||
|
||||
assert %FilterForm{
|
||||
components: []
|
||||
} = form
|
||||
end
|
||||
|
||||
test "with `remove_empty_groups?: true` empty groups are removed on component removal" do
|
||||
form = FilterForm.new(Post, remove_empty_groups?: true)
|
||||
|
||||
|
|
Loading…
Reference in a new issue