From 2a3a20faba951aa13604ada70c6b33506fa1907a Mon Sep 17 00:00:00 2001
From: woylie <13847569+woylie@users.noreply.github.com>
Date: Fri, 31 Jan 2025 22:04:07 +0900
Subject: [PATCH 1/3] remove show/hide attrs from col and action slots
---
lib/flop_phoenix.ex | 19 ---------
lib/flop_phoenix/table.ex | 8 ----
test/flop_phoenix_test.exs | 82 +-------------------------------------
3 files changed, 1 insertion(+), 108 deletions(-)
diff --git a/lib/flop_phoenix.ex b/lib/flop_phoenix.ex
index af022f9..bc48d0d 100644
--- a/lib/flop_phoenix.ex
+++ b/lib/flop_phoenix.ex
@@ -1063,18 +1063,6 @@ defmodule Flop.Phoenix do
behavior for the column, i.e. `{:asc_nulls_last, :desc_nulls_first}`
"""
- attr :show, :boolean,
- doc: """
- Boolean value to conditionally show the column. Defaults to `true`
- Deprecated. Use `:if` instead.
- """
-
- attr :hide, :boolean,
- doc: """
- Boolean value to conditionally hide the column. Defaults to `false`.
- Deprecated. Use `:if` instead.
- """
-
attr :col_style, :string,
doc: """
If set, a `
<.header_column
:for={col <- @col}
- :if={show_column?(col)}
on_sort={@on_sort}
event={@event}
field={col[:field]}
@@ -88,7 +87,6 @@ defmodule Flop.Phoenix.Table do
/>
<.header_column
:for={action <- @action}
- :if={show_column?(action)}
event={@event}
field={nil}
label={action[:label]}
@@ -114,7 +112,6 @@ defmodule Flop.Phoenix.Table do
>
@@ -156,7 +153,6 @@ defmodule Flop.Phoenix.Table do
@@ -167,10 +163,6 @@ defmodule Flop.Phoenix.Table do
Enum.reject(attrs, fn {_, v} -> v in ["", nil] end)
end
- defp show_column?(%{hide: true}), do: false
- defp show_column?(%{show: false}), do: false
- defp show_column?(_), do: true
-
attr :meta, Flop.Meta, required: true
attr :field, :atom, required: true
attr :label, :any, required: true
diff --git a/test/flop_phoenix_test.exs b/test/flop_phoenix_test.exs
index b88b9fa..2ffbb45 100644
--- a/test/flop_phoenix_test.exs
+++ b/test/flop_phoenix_test.exs
@@ -24,8 +24,6 @@ defmodule Flop.PhoenixTest do
attr :meta, Flop.Meta, default: %Flop.Meta{flop: %Flop{}}
attr :opts, :list, default: []
attr :target, :string, default: nil
- attr :hide_age, :boolean, default: false
- attr :show_age, :boolean, default: true
attr :path, :any, default: {__MODULE__, :route_helper, @route_helper_opts}
attr :items, :list,
@@ -48,9 +46,7 @@ defmodule Flop.PhoenixTest do
>
<:col :let={pet} label="Name" field={:name}>{pet.name}
<:col :let={pet} label="Email" field={:email}>{pet.email}
- <:col :let={pet} label="Age" hide={@hide_age} show={@show_age}>
- {pet.age}
-
+ <:col :let={pet} label="Age">{pet.age}
<:col :let={pet} label="Species" field={:species}>{pet.species}
<:col>column without label
@@ -2101,82 +2097,6 @@ defmodule Flop.PhoenixTest do
assert Floki.children(th, include_text: false) == []
end
- test "conditionally hides a column" do
- html = render_table(%{})
- assert find_one(html, "th:fl-contains('Age')")
- assert find_one(html, "td:fl-contains('8')")
-
- html = render_table(%{hide_age: false, show_age: true})
- assert find_one(html, "th:fl-contains('Age')")
- assert find_one(html, "td:fl-contains('8')")
-
- html = render_table(%{hide_age: true, show_age: true})
- assert [] = Floki.find(html, "th:fl-contains('Age')")
- assert [] = Floki.find(html, "td:fl-contains('8')")
-
- html = render_table(%{hide_age: false, show_age: false})
- assert [] = Floki.find(html, "th:fl-contains('Age')")
- assert [] = Floki.find(html, "td:fl-contains('8')")
-
- html = render_table(%{hide_age: true, show_age: false})
- assert [] = Floki.find(html, "th:fl-contains('Age')")
- assert [] = Floki.find(html, "td:fl-contains('8')")
- end
-
- test "conditionally hides an action column" do
- assigns = %{meta: %Flop.Meta{flop: %Flop{}}}
-
- html =
- parse_heex(~H"""
-
- <:col>
- <:action label="Buttons">Show Pet
-
- """)
-
- assert find_one(html, "th:fl-contains('Buttons')")
-
- html =
- parse_heex(~H"""
-
- <:col>
- <:action label="Buttons" show={true} hide={false}>
-
- """)
-
- assert find_one(html, "th:fl-contains('Buttons')")
-
- html =
- parse_heex(~H"""
-
- <:col>
- <:action label="Buttons" show={true} hide={true}>
-
- """)
-
- assert [] = Floki.find(html, "th:fl-contains('Buttons')")
-
- html =
- parse_heex(~H"""
-
- <:col>
- <:action label="Buttons" show={false} hide={true}>
-
- """)
-
- assert [] = Floki.find(html, "th:fl-contains('Buttons')")
-
- html =
- parse_heex(~H"""
-
- <:col>
- <:action label="Buttons" show={false} hide={false}>
-
- """)
-
- assert [] = Floki.find(html, "th:fl-contains('Buttons')")
- end
-
test "displays headers with sorting function" do
html = render_table(%{})
From a230093bbaede4b2b56254a15ae0d5594eafed95 Mon Sep 17 00:00:00 2001
From: woylie <13847569+woylie@users.noreply.github.com>
Date: Fri, 31 Jan 2025 22:45:41 +0900
Subject: [PATCH 2/3] remove event attribute from table and pagination
components
---
lib/flop_phoenix.ex | 69 ++----------
lib/flop_phoenix/table.ex | 16 +--
test/flop_phoenix_test.exs | 215 +++++++++++++++++++++++--------------
3 files changed, 145 insertions(+), 155 deletions(-)
diff --git a/lib/flop_phoenix.ex b/lib/flop_phoenix.ex
index bc48d0d..d32f059 100644
--- a/lib/flop_phoenix.ex
+++ b/lib/flop_phoenix.ex
@@ -124,8 +124,7 @@ defmodule Flop.Phoenix do
You will need to handle the event in the `c:Phoenix.LiveView.handle_event/3`
or `c:Phoenix.LiveComponent.handle_event/3` callback of your
- LiveView or LiveComponent module. The event name will be the one you set with
- the `:event` option.
+ LiveView or LiveComponent module.
def handle_event("paginate-pets", %{"page" => page}, socket) do
flop = Flop.set_page(socket.assigns.meta.flop, page)
@@ -380,7 +379,7 @@ defmodule Flop.Phoenix do
<.pagination
meta={@meta}
- path={~"/pets"}
+ path={~p"/pets"}
on_paginate={JS.dispatch("my_app:scroll_to", to: "#pet-table")}
/>
@@ -403,14 +402,6 @@ defmodule Flop.Phoenix do
```
"""
- attr :event, :string,
- default: nil,
- doc: """
- If set, `Flop.Phoenix` will render links with a `phx-click` attribute.
- Alternatively, set `:path`, if you want the parameters to appear in the URL.
- Deprecated in favor of `on_paginate`.
- """
-
attr :target, :string,
default: nil,
doc: """
@@ -428,7 +419,7 @@ defmodule Flop.Phoenix do
described in the `Customization` section of the module documentation.
"""
- def pagination(%{path: nil, on_paginate: nil, event: nil}) do
+ def pagination(%{path: nil, on_paginate: nil}) do
raise Flop.Phoenix.PathOrJSError, component: :pagination
end
@@ -452,7 +443,6 @@ defmodule Flop.Phoenix do
<.pagination_link
disabled={!@meta.has_previous_page?}
disabled_class={@opts[:disabled_class]}
- event={@event}
target={@target}
page={@meta.previous_page}
path={@page_link_helper.(@meta.previous_page)}
@@ -464,7 +454,6 @@ defmodule Flop.Phoenix do
<.pagination_link
disabled={!@meta.has_next_page?}
disabled_class={@opts[:disabled_class]}
- event={@event}
target={@target}
page={@meta.next_page}
path={@page_link_helper.(@meta.next_page)}
@@ -475,7 +464,6 @@ defmodule Flop.Phoenix do
<.page_links
:if={@opts[:page_links] != :hide}
- event={@event}
meta={@meta}
on_paginate={@on_paginate}
page_link_helper={@page_link_helper}
@@ -489,7 +477,6 @@ defmodule Flop.Phoenix do
attr :meta, Flop.Meta, required: true
attr :on_paginate, JS
attr :page_link_helper, :any, required: true
- attr :event, :string, required: true
attr :target, :string, required: true
attr :opts, :list, required: true
@@ -511,7 +498,6 @@ defmodule Flop.Phoenix do
- 1} {@opts[:pagination_list_item_attrs]}>
<.pagination_link
- event={@event}
target={@target}
page={1}
path={@page_link_helper.(1)}
@@ -528,7 +514,6 @@ defmodule Flop.Phoenix do
-
<.pagination_link
- event={@event}
target={@target}
page={page}
path={@page_link_helper.(page)}
@@ -545,7 +530,6 @@ defmodule Flop.Phoenix do
-
<.pagination_link
- event={@event}
target={@target}
page={@meta.total_pages}
path={@page_link_helper.(@meta.total_pages)}
@@ -561,7 +545,6 @@ defmodule Flop.Phoenix do
attr :path, :string
attr :on_paginate, JS
- attr :event, :string, required: true
attr :target, :string, required: true
attr :page, :integer, required: true
attr :disabled, :boolean, default: false
@@ -586,14 +569,6 @@ defmodule Flop.Phoenix do
"""
end
- defp pagination_link(%{event: event} = assigns) when is_binary(event) do
- ~H"""
- <.link phx-click={@event} phx-target={@target} phx-value-page={@page} {@rest}>
- {render_slot(@inner_block)}
-
- """
- end
-
defp pagination_link(%{on_paginate: nil, path: path} = assigns)
when is_binary(path) do
~H"""
@@ -728,7 +703,7 @@ defmodule Flop.Phoenix do
<.cursor_pagination
meta={@meta}
- path={~"/pets"}
+ path={~p"/pets"}
on_paginate={JS.dispatch("my_app:scroll_to", to: "#pet-table")}
/>
@@ -751,14 +726,6 @@ defmodule Flop.Phoenix do
```
"""
- attr :event, :string,
- default: nil,
- doc: """
- If set, `Flop.Phoenix` will render links with a `phx-click` attribute.
- Alternatively, set `:path`, if you want the parameters to appear in the URL.
- Deprecated. Use `on_paginate` instead.
- """
-
attr :target, :string,
default: nil,
doc: "Sets the `phx-target` attribute for the pagination links."
@@ -784,7 +751,7 @@ defmodule Flop.Phoenix do
documentation.
"""
- def cursor_pagination(%{path: nil, on_paginate: nil, event: nil}) do
+ def cursor_pagination(%{path: nil, on_paginate: nil}) do
raise Flop.Phoenix.PathOrJSError, component: :cursor_pagination
end
@@ -805,7 +772,6 @@ defmodule Flop.Phoenix do
meta={@meta}
path={@path}
on_paginate={@on_paginate}
- event={@event}
target={@target}
disabled={CursorPagination.disable?(@meta, :previous, @reverse)}
disabled_class={@opts[:disabled_class]}
@@ -818,7 +784,6 @@ defmodule Flop.Phoenix do
meta={@meta}
path={@path}
on_paginate={@on_paginate}
- event={@event}
target={@target}
disabled={CursorPagination.disable?(@meta, :next, @reverse)}
disabled_class={@opts[:disabled_class]}
@@ -834,7 +799,6 @@ defmodule Flop.Phoenix do
attr :meta, Flop.Meta, required: true
attr :path, :any, required: true
attr :on_paginate, JS
- attr :event, :string, required: true
attr :target, :string, required: true
attr :disabled, :boolean, default: false
attr :disabled_class, :string, required: true
@@ -858,15 +822,6 @@ defmodule Flop.Phoenix do
"""
end
- defp cursor_pagination_link(%{event: event} = assigns)
- when is_binary(event) do
- ~H"""
- <.link phx-click={@event} phx-target={@target} phx-value-to={@direction} {@rest}>
- {render_slot(@inner_block)}
-
- """
- end
-
defp cursor_pagination_link(%{on_paginate: nil} = assigns) do
~H"""
<.link
@@ -973,19 +928,11 @@ defmodule Flop.Phoenix do
<.table
meta={@meta}
- path={~"/pets"}
+ path={~p"/pets"}
on_sort={JS.dispatch("my_app:scroll_to", to: "#pet-table")}
/>
"""
- attr :event, :string,
- default: nil,
- doc: """
- If set, `Flop.Phoenix` will render links with a `phx-click` attribute.
- Alternatively, set `:path`, if you want the parameters to appear in the URL.
- Deprecated in favor of `on_sort`.
- """
-
attr :target, :string,
default: nil,
doc: "Sets the `phx-target` attribute for the header links."
@@ -1158,7 +1105,7 @@ defmodule Flop.Phoenix do
"""
- def table(%{path: nil, on_sort: nil, event: nil}) do
+ def table(%{path: nil, on_sort: nil}) do
raise Flop.Phoenix.PathOrJSError, component: :table
end
@@ -1179,7 +1126,6 @@ defmodule Flop.Phoenix do
col={@col}
foot={@foot}
on_sort={@on_sort}
- event={@event}
id={@id}
items={@items}
meta={@meta}
@@ -1198,7 +1144,6 @@ defmodule Flop.Phoenix do
col={@col}
foot={@foot}
on_sort={@on_sort}
- event={@event}
id={@id}
items={@items}
meta={@meta}
diff --git a/lib/flop_phoenix/table.ex b/lib/flop_phoenix/table.ex
index c9efe74..b2e32e5 100644
--- a/lib/flop_phoenix/table.ex
+++ b/lib/flop_phoenix/table.ex
@@ -39,7 +39,6 @@ defmodule Flop.Phoenix.Table do
attr :meta, Flop.Meta, required: true
attr :path, :any, required: true
attr :on_sort, JS
- attr :event, :string, required: true
attr :target, :string, required: true
attr :caption, :string, required: true
attr :opts, :any, required: true
@@ -66,7 +65,6 @@ defmodule Flop.Phoenix.Table do
<.header_column
:for={col <- @col}
on_sort={@on_sort}
- event={@event}
field={col[:field]}
label={col[:label]}
sortable={sortable?(col[:field], @meta.schema)}
@@ -87,7 +85,6 @@ defmodule Flop.Phoenix.Table do
/>
<.header_column
:for={action <- @action}
- event={@event}
field={nil}
label={action[:label]}
sortable={false}
@@ -96,7 +93,7 @@ defmodule Flop.Phoenix.Table do
merge_attrs(@opts[:thead_th_attrs], action, :thead_th_attrs)
}
path={nil}
- target={@event}
+ target={@target}
/>
|
@@ -168,7 +165,6 @@ defmodule Flop.Phoenix.Table do
attr :label, :any, required: true
attr :path, :any, required: true
attr :on_sort, JS
- attr :event, :string, required: true
attr :target, :string, required: true
attr :sortable, :boolean, required: true
attr :thead_th_attrs, :list, required: true
@@ -204,7 +200,6 @@ defmodule Flop.Phoenix.Table do
<.sort_link
path={@sort_path}
on_sort={@on_sort}
- event={@event}
field={@field}
label={@label}
target={@target}
@@ -263,17 +258,8 @@ defmodule Flop.Phoenix.Table do
attr :label, :string, required: true
attr :path, :string
attr :on_sort, JS
- attr :event, :string
attr :target, :string
- defp sort_link(%{event: event} = assigns) when is_binary(event) do
- ~H"""
- <.link phx-click={@event} phx-target={@target} phx-value-order={@field}>
- {@label}
-
- """
- end
-
defp sort_link(%{on_sort: nil, path: path} = assigns)
when is_binary(path) do
~H"""
diff --git a/test/flop_phoenix_test.exs b/test/flop_phoenix_test.exs
index 2ffbb45..9c082ae 100644
--- a/test/flop_phoenix_test.exs
+++ b/test/flop_phoenix_test.exs
@@ -19,7 +19,6 @@ defmodule Flop.PhoenixTest do
attr :caption, :string, default: nil
attr :on_sort, JS, default: nil
- attr :event, :string, default: nil
attr :id, :string, default: "some-table"
attr :meta, Flop.Meta, default: %Flop.Meta{flop: %Flop{}}
attr :opts, :list, default: []
@@ -36,7 +35,6 @@ defmodule Flop.PhoenixTest do