Skip to content

Commit

Permalink
Merge pull request #403 from woylie/remove-deprecated-attrs
Browse files Browse the repository at this point in the history
remove deprecated attrs
  • Loading branch information
woylie authored Jan 31, 2025
2 parents be7a3d7 + 7b23772 commit 4100698
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 264 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
- Removed `input_type/3` from the `Phoenix.HTML.FormData` protocol
implementation for `Flop.Meta`, as the function has been removed from the
protocol.
- Removed the previously deprecated `:event` attribute from the
`Flop.Phoenix.pagination/1`, `Flop.Phoenix.cursor_pagination`, and
`Flop.Phoenix.table/1` components. Use `:on_paginate` and `:on_sort` instead.
- Removed the previously deprecated `:hide` and `:show` attributes from the
`:col` and `:action` slots of the `Flop.Phoenix.table/1` component. Use the
`:if` attribute instead.

### Fixed

- Fixed a warning about ranges in Elixir 1.18.

## [0.23.1] - 2024-10-17

Expand Down Expand Up @@ -128,7 +138,7 @@
component to `tbody_td_attrs` in order to match the naming of the global
table options.

### Upgrade guide
### How to upgrade

Rename the `attrs` attribute to `tbody_td_attrs` in both the `col` slot and the
`action` slot:
Expand Down
88 changes: 7 additions & 81 deletions lib/flop_phoenix.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")}
/>
Expand All @@ -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: """
Expand All @@ -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

Expand All @@ -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)}
Expand All @@ -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)}
Expand All @@ -475,7 +464,6 @@ defmodule Flop.Phoenix do
</.pagination_link>
<.page_links
:if={@opts[:page_links] != :hide}
event={@event}
meta={@meta}
on_paginate={@on_paginate}
page_link_helper={@page_link_helper}
Expand All @@ -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

Expand All @@ -511,7 +498,6 @@ defmodule Flop.Phoenix do
<ul {@opts[:pagination_list_attrs]}>
<li :if={@first > 1} {@opts[:pagination_list_item_attrs]}>
<.pagination_link
event={@event}
target={@target}
page={1}
path={@page_link_helper.(1)}
Expand All @@ -528,7 +514,6 @@ defmodule Flop.Phoenix do
<li :for={page <- @range} {@opts[:pagination_list_item_attrs]}>
<.pagination_link
event={@event}
target={@target}
page={page}
path={@page_link_helper.(page)}
Expand All @@ -545,7 +530,6 @@ defmodule Flop.Phoenix do
<li :if={@last < @meta.total_pages} {@opts[:pagination_list_item_attrs]}>
<.pagination_link
event={@event}
target={@target}
page={@meta.total_pages}
path={@page_link_helper.(@meta.total_pages)}
Expand All @@ -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
Expand All @@ -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)}
</.link>
"""
end

defp pagination_link(%{on_paginate: nil, path: path} = assigns)
when is_binary(path) do
~H"""
Expand Down Expand Up @@ -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")}
/>
Expand All @@ -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."
Expand All @@ -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

Expand All @@ -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]}
Expand All @@ -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]}
Expand All @@ -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
Expand All @@ -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)}
</.link>
"""
end

defp cursor_pagination_link(%{on_paginate: nil} = assigns) do
~H"""
<.link
Expand Down Expand Up @@ -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."
Expand Down Expand Up @@ -1063,18 +1010,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 `<colgroup>` element is rendered and the value of the
Expand Down Expand Up @@ -1129,13 +1064,6 @@ defmodule Flop.Phoenix do
""" do
attr :label, :string, doc: "The content for the header column."

attr :show, :boolean,
doc: "Boolean value to conditionally show the column. Defaults to `true`."

attr :hide, :boolean,
doc:
"Boolean value to conditionally hide the column. Defaults to `false`."

attr :col_style, :string,
doc: """
If set, a `<colgroup>` element is rendered and the value of the
Expand Down Expand Up @@ -1177,7 +1105,7 @@ defmodule Flop.Phoenix do
</Flop.Phoenix.table>
"""

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

Expand All @@ -1198,7 +1126,6 @@ defmodule Flop.Phoenix do
col={@col}
foot={@foot}
on_sort={@on_sort}
event={@event}
id={@id}
items={@items}
meta={@meta}
Expand All @@ -1217,7 +1144,6 @@ defmodule Flop.Phoenix do
col={@col}
foot={@foot}
on_sort={@on_sort}
event={@event}
id={@id}
items={@items}
meta={@meta}
Expand Down
24 changes: 1 addition & 23 deletions lib/flop_phoenix/table.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -65,9 +64,7 @@ defmodule Flop.Phoenix.Table do
<tr {@opts[:thead_tr_attrs]}>
<.header_column
:for={col <- @col}
:if={show_column?(col)}
on_sort={@on_sort}
event={@event}
field={col[:field]}
label={col[:label]}
sortable={sortable?(col[:field], @meta.schema)}
Expand All @@ -88,8 +85,6 @@ defmodule Flop.Phoenix.Table do
/>
<.header_column
:for={action <- @action}
:if={show_column?(action)}
event={@event}
field={nil}
label={action[:label]}
sortable={false}
Expand All @@ -98,7 +93,7 @@ defmodule Flop.Phoenix.Table do
merge_attrs(@opts[:thead_th_attrs], action, :thead_th_attrs)
}
path={nil}
target={@event}
target={@target}
/>
</tr>
</thead>
Expand All @@ -114,7 +109,6 @@ defmodule Flop.Phoenix.Table do
>
<td
:for={col <- @col}
:if={show_column?(col)}
{merge_td_attrs(@opts[:tbody_td_attrs], col, item)}
phx-click={@row_click && @row_click.(item)}
>
Expand Down Expand Up @@ -156,7 +150,6 @@ defmodule Flop.Phoenix.Table do
<colgroup :if={Enum.any?(@col, &(&1[:col_style] || &1[:col_class]))}>
<col
:for={col <- @col}
:if={show_column?(col)}
{reject_empty_values(style: col[:col_style], class: col[:col_class])}
/>
</colgroup>
Expand All @@ -167,16 +160,11 @@ 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
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
Expand Down Expand Up @@ -212,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}
Expand Down Expand Up @@ -271,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}
</.link>
"""
end

defp sort_link(%{on_sort: nil, path: path} = assigns)
when is_binary(path) do
~H"""
Expand Down
Loading

0 comments on commit 4100698

Please sign in to comment.