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 `` element is rendered and the value of the @@ -1129,13 +1117,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 `` element is rendered and the value of the diff --git a/lib/flop_phoenix/table.ex b/lib/flop_phoenix/table.ex index 1e21d86..c9efe74 100644 --- a/lib/flop_phoenix/table.ex +++ b/lib/flop_phoenix/table.ex @@ -65,7 +65,6 @@ defmodule Flop.Phoenix.Table do <.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