Skip to content

Commit

Permalink
Merge pull request #687 from thomasfortes/liveview-1-0
Browse files Browse the repository at this point in the history
Update dependency phoenix_live_view to v1.0
  • Loading branch information
Flo0807 authored Jan 10, 2025
2 parents 5730a67 + 8b65adc commit 60a0986
Show file tree
Hide file tree
Showing 42 changed files with 259 additions and 248 deletions.
6 changes: 0 additions & 6 deletions demo/assets/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
@import "tailwindcss/utilities";

@layer utilities {
/* LiveView specific classes */
.phx-no-feedback.invalid-feedback,
.phx-no-feedback .invalid-feedback {
display: none;
}

.phx-click-loading {
opacity: 0.5;
transition: opacity 1s ease-out;
Expand Down
1 change: 0 additions & 1 deletion demo/assets/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ module.exports = {
plugins: [
require('@tailwindcss/typography'),
require('daisyui'),
plugin(({ addVariant }) => addVariant('phx-no-feedback', ['.phx-no-feedback&', '.phx-no-feedback &'])),
plugin(({ addVariant }) => addVariant('phx-click-loading', ['.phx-click-loading&', '.phx-click-loading &'])),
plugin(({ addVariant }) => addVariant('phx-submit-loading', ['.phx-submit-loading&', '.phx-submit-loading &'])),
plugin(({ addVariant }) => addVariant('phx-change-loading', ['.phx-change-loading&', '.phx-change-loading &'])),
Expand Down
2 changes: 1 addition & 1 deletion demo/lib/demo_web/components/layouts/admin.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,5 @@
</Backpex.HTML.Layout.sidebar_section>
</:sidebar>
<Backpex.HTML.Layout.flash_messages flash={@flash} />
<%= @inner_content %>
{@inner_content}
</Backpex.HTML.Layout.app_shell>
2 changes: 1 addition & 1 deletion demo/lib/demo_web/components/layouts/app.html.heex
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%= @inner_content %>
{@inner_content}
4 changes: 2 additions & 2 deletions demo/lib/demo_web/components/layouts/root.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<meta name="csrf-token" content={get_csrf_token()} />
<.sentry_meta_tag />
<.live_title suffix=" · Backpex">
<%= assigns[:page_title] || "Phoenix Admin Panel build with PETAL" %>
{assigns[:page_title] || "Phoenix Admin Panel build with PETAL"}
</.live_title>
<link phx-track-static rel="stylesheet" href={~p"/assets/app.css"} />
<script defer phx-track-static type="text/javascript" src={~p"/assets/app.js"}>
</script>
</head>
<body class="h-full">
<%= @inner_content %>
{@inner_content}
<.analytics />
</body>
</html>
2 changes: 1 addition & 1 deletion demo/lib/demo_web/live/post_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ defmodule DemoWeb.PostLive do
searchable: true,
render: fn assigns ->
~H"""
<p><%= Number.Delimit.number_to_delimited(@value, precision: 0, delimiter: ".") %></p>
<p>{Number.Delimit.number_to_delimited(@value, precision: 0, delimiter: ".")}</p>
"""
end
},
Expand Down
4 changes: 2 additions & 2 deletions demo/lib/demo_web/live/product_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ defmodule DemoWeb.ProductLive do
"""

assigns ->
~H"<p><%= Backpex.HTML.pretty_value(@value) %></p>"
~H"<p>{Backpex.HTML.pretty_value(@value)}</p>"
end,
except: [:index, :resource_action],
align: :center
Expand Down Expand Up @@ -80,7 +80,7 @@ defmodule DemoWeb.ProductLive do
end,
render: fn assigns ->
~H"""
<p><%= Number.Delimit.number_to_delimited(@value, precision: 0, delimiter: ".") %></p>
<p>{Number.Delimit.number_to_delimited(@value, precision: 0, delimiter: ".")}</p>
"""
end
},
Expand Down
2 changes: 1 addition & 1 deletion demo/lib/demo_web/live/user_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ defmodule DemoWeb.UserLive do
list_existing_files: &list_existing_files/1,
render: fn
%{value: value} = assigns when value == "" or is_nil(value) ->
~H"<p><%= Backpex.HTML.pretty_value(@value) %></p>"
~H"<p>{Backpex.HTML.pretty_value(@value)}</p>"

assigns ->
~H'<img class="h-10 w-auto" src={file_url(@value)} />'
Expand Down
4 changes: 2 additions & 2 deletions demo/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ defmodule Demo.MixProject do
{:telemetry_poller, "~> 1.0"},
{:telemetry_metrics, "~> 1.0"},
{:gettext, "~> 0.26"},
{:sentry, "~> 10.1"},
{:sentry, "~> 10.8"},
{:hackney, "~> 1.17", override: true},
{:circular_buffer, "~> 0.4.0"},

# phoenix
{:bandit, "~> 1.0"},
{:phoenix, "~> 1.7.6"},
{:phoenix_pubsub, "~> 2.0"},
{:phoenix_live_view, "~> 0.20.0"},
{:phoenix_live_view, "~> 1.0"},
{:phoenix_live_dashboard, "~> 0.8"},
{:phoenix_live_reload, "~> 1.2", only: :dev},

Expand Down
2 changes: 1 addition & 1 deletion demo/mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"phoenix_html_helpers": {:hex, :phoenix_html_helpers, "1.0.1", "7eed85c52eff80a179391036931791ee5d2f713d76a81d0d2c6ebafe1e11e5ec", [:mix], [{:phoenix_html, "~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "cffd2385d1fa4f78b04432df69ab8da63dc5cf63e07b713a4dcf36a3740e3090"},
"phoenix_live_dashboard": {:hex, :phoenix_live_dashboard, "0.8.6", "7b1f0327f54c9eb69845fd09a77accf922f488c549a7e7b8618775eb603a62c7", [:mix], [{:ecto, "~> 3.6.2 or ~> 3.7", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_mysql_extras, "~> 0.5", [hex: :ecto_mysql_extras, repo: "hexpm", optional: true]}, {:ecto_psql_extras, "~> 0.7", [hex: :ecto_psql_extras, repo: "hexpm", optional: true]}, {:ecto_sqlite3_extras, "~> 1.1.7 or ~> 1.2.0", [hex: :ecto_sqlite3_extras, repo: "hexpm", optional: true]}, {:mime, "~> 1.6 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 0.19 or ~> 1.0", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:telemetry_metrics, "~> 0.6 or ~> 1.0", [hex: :telemetry_metrics, repo: "hexpm", optional: false]}], "hexpm", "1681ab813ec26ca6915beb3414aa138f298e17721dc6a2bde9e6eb8a62360ff6"},
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.5.3", "f2161c207fda0e4fb55165f650f7f8db23f02b29e3bff00ff7ef161d6ac1f09d", [:mix], [{:file_system, "~> 0.3 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "b4ec9cd73cb01ff1bd1cac92e045d13e7030330b74164297d1aee3907b54803c"},
"phoenix_live_view": {:hex, :phoenix_live_view, "0.20.17", "f396bbdaf4ba227b82251eb75ac0afa6b3da5e509bc0d030206374237dfc9450", [:mix], [{:floki, "~> 0.36", [hex: :floki, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.6.15 or ~> 1.7.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.3 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.15", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "a61d741ffb78c85fdbca0de084da6a48f8ceb5261a79165b5a0b59e5f65ce98b"},
"phoenix_live_view": {:hex, :phoenix_live_view, "1.0.1", "5389a30658176c0de816636ce276567478bffd063c082515a6e8368b8fc9a0db", [:mix], [{:floki, "~> 0.36", [hex: :floki, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.6.15 or ~> 1.7.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.3 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.15", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c0f517e6f290f10dbb94343ac22e0109437fb1fa6f0696e7c73967b789c1c285"},
"phoenix_pubsub": {:hex, :phoenix_pubsub, "2.1.3", "3168d78ba41835aecad272d5e8cd51aa87a7ac9eb836eabc42f6e57538e3731d", [:mix], [], "hexpm", "bba06bc1dcfd8cb086759f0edc94a8ba2bc8896d5331a1e2c2902bf8e36ee502"},
"phoenix_template": {:hex, :phoenix_template, "1.0.4", "e2092c132f3b5e5b2d49c96695342eb36d0ed514c5b252a77048d5969330d639", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "2c0c81f0e5c6753faf5cca2f229c9709919aba34fab866d3bc05060c9c444206"},
"plug": {:hex, :plug, "1.16.1", "40c74619c12f82736d2214557dedec2e9762029b2438d6d175c5074c933edc9d", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "a13ff6b9006b03d7e33874945b2755253841b238c34071ed85b0e86057f8cddc"},
Expand Down
6 changes: 3 additions & 3 deletions lib/backpex/fields/belongs_to.ex
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ defmodule Backpex.Fields.BelongsTo do
def render_value(%{value: value} = assigns) when is_nil(value) do
~H"""
<p class={@live_action in [:index, :resource_action] && "truncate"}>
<%= HTML.pretty_value(nil) %>
{HTML.pretty_value(nil)}
</p>
"""
end
Expand All @@ -105,11 +105,11 @@ defmodule Backpex.Fields.BelongsTo do
<div class={[@live_action in [:index, :resource_action] && "truncate"]}>
<%= if @link do %>
<.link navigate={@link} class={[@live_action in [:index, :resource_action] && "truncate", "hover:underline"]}>
<%= @display_text %>
{@display_text}
</.link>
<% else %>
<p class={@live_action in [:index, :resource_action] && "truncate"}>
<%= HTML.pretty_value(@display_text) %>
{HTML.pretty_value(@display_text)}
</p>
<% end %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion lib/backpex/fields/currency.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ defmodule Backpex.Fields.Currency do

~H"""
<p class={@live_action in [:index, :resource_action] && "truncate"}>
<%= @casted_value %>
{@casted_value}
</p>
"""
end
Expand Down
2 changes: 1 addition & 1 deletion lib/backpex/fields/date.ex
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ defmodule Backpex.Fields.Date do

~H"""
<p class={@live_action in [:index, :resource_action] && "truncate"}>
<%= @value %>
{@value}
</p>
"""
end
Expand Down
2 changes: 1 addition & 1 deletion lib/backpex/fields/date_time.ex
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ defmodule Backpex.Fields.DateTime do

~H"""
<p class={@live_action in [:index, :resource_action] && "truncate"}>
<%= @value %>
{@value}
</p>
"""
end
Expand Down
35 changes: 19 additions & 16 deletions lib/backpex/fields/has_many.ex
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ defmodule Backpex.Fields.HasMany do
def render_value(assigns) do
~H"""
<div class={[@live_action in [:index, :resource_action] && "truncate"]}>
<%= if @value == [], do: raw("&mdash;") %>
{if @value == [], do: raw("&mdash;")}
<div class={["flex", @live_action == :show && "flex-wrap"]}>
<.intersperse :let={item} enum={@value |> Enum.sort_by(&Map.get(&1, display_field(@field)), :asc)}>
Expand Down Expand Up @@ -146,23 +146,23 @@ defmodule Backpex.Fields.HasMany do
<:label align={Backpex.Field.align_label(@field_options, assigns)}>
<Layout.input_label text={@field_options[:label]} />
</:label>
<div class="dropdown w-full" phx-feedback-for={@form[@name].name}>
<div class="dropdown w-full">
<label
tabindex="0"
class={[
"input block h-fit w-full p-2 phx-no-feedback:input-bordered phx-no-feedback:bg-transparent",
"input block h-fit w-full p-2",
@errors == [] && "input-bordered bg-transparent",
@errors != [] && "input-error bg-error/10"
]}
>
<div class="flex h-full w-full flex-wrap items-center gap-1 px-2">
<p :if={@selected == []} class="p-0.5 text-sm">
<%= @prompt %>
{@prompt}
</p>
<div :for={{label, value} <- @selected} class="badge badge-primary p-[11px]">
<p class="mr-1">
<%= label %>
{label}
</p>
<label
Expand All @@ -175,7 +175,7 @@ defmodule Backpex.Fields.HasMany do
</div>
</div>
</label>
<.error :for={msg <- @errors}><%= msg %></.error>
<.error :for={msg <- @errors}>{msg}</.error>
<div tabindex="0" class="dropdown-content z-[1] menu bg-base-100 rounded-box w-full overflow-y-auto shadow">
<div class="max-h-72 p-2">
<input
Expand All @@ -188,7 +188,7 @@ defmodule Backpex.Fields.HasMany do
value={@search_input}
/>
<p :if={@options == []} class="w-full">
<%= @not_found_text %>
{@not_found_text}
</p>
<label :if={Enum.any?(@options)}>
Expand All @@ -200,14 +200,14 @@ defmodule Backpex.Fields.HasMany do
/>
<span role="button" class="text-primary my-2 cursor-pointer text-sm underline">
<%= if @all_selected do %>
<%= Backpex.translate("Deselect all") %>
{Backpex.translate("Deselect all")}
<% else %>
<%= Backpex.translate("Select all") %>
{Backpex.translate("Select all")}
<% end %>
</span>
</label>
<input type="hidden" id={"has-many-#{@name}-hidden-input"} name={@form[@name].name} value="" />
<input type="hidden" id={"has-many-#{@name}-hidden-input"} name={"#{@form[@name].name}[]"} value="" />
<input
:for={value <- @selected_ids}
Expand All @@ -231,7 +231,7 @@ defmodule Backpex.Fields.HasMany do
class="checkbox checkbox-sm checkbox-primary"
/>
<span class="label-text">
<%= label %>
{label}
</span>
</label>
</div>
Expand All @@ -243,7 +243,7 @@ defmodule Backpex.Fields.HasMany do
phx-click="show-more"
phx-target={@myself}
>
<%= Backpex.translate("Show more") %>
{Backpex.translate("Show more")}
</button>
</div>
</div>
Expand Down Expand Up @@ -336,8 +336,10 @@ defmodule Backpex.Fields.HasMany do
defp get_assocs_by_ids(assoc_ids, schema, repo, field_options, assigns) do
case assoc_ids do
ids when is_list(ids) and ids != [] ->
filtered_ids = Enum.reject(ids, &(&1 == ""))

schema
|> where([x], x.id in ^ids)
|> where([x], x.id in ^filtered_ids)
|> maybe_options_query(field_options, assigns)
|> repo.all()

Expand All @@ -360,11 +362,11 @@ defmodule Backpex.Fields.HasMany do
~H"""
<%= if is_nil(@link) do %>
<span>
<%= HTML.pretty_value(@display_text) %>
{HTML.pretty_value(@display_text)}
</span>
<% else %>
<.link navigate={@link} class="hover:underline">
<%= @display_text %>
{@display_text}
</.link>
<% end %>
"""
Expand Down Expand Up @@ -538,9 +540,10 @@ defmodule Backpex.Fields.HasMany do
defp assign_form_errors(socket) do
%{assigns: %{form: form, name: name, field_options: field_options}} = socket

errors = if Phoenix.Component.used_input?(form[name]), do: form[name].errors, else: []
translate_error_fun = Map.get(field_options, :translate_error, &Function.identity/1)

assign(socket, :errors, translate_form_errors(form[name], translate_error_fun))
assign(socket, :errors, translate_form_errors(errors, translate_error_fun))
end

defp display_field_form({_name, field_options} = field),
Expand Down
16 changes: 8 additions & 8 deletions lib/backpex/fields/has_many_through.ex
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ defmodule Backpex.Fields.HasManyThrough do
:for={{_name, %{label: label}} <- action_fields(@field_options.child_fields, assigns, :index)}
class="font-medium"
>
<%= label %>
{label}
</th>
<th
:for={{_name, %{label: label}} <- action_fields(@field_options.pivot_fields, assigns, :index)}
class="font-medium"
>
<%= label %>
{label}
</th>
<th></th>
</tr>
Expand Down Expand Up @@ -252,13 +252,13 @@ defmodule Backpex.Fields.HasManyThrough do
:for={{_name, %{label: label}} <- action_fields(@field_options.child_fields, assigns, :index)}
class="font-medium"
>
<%= label %>
{label}
</th>
<th
:for={{_name, %{label: label}} <- action_fields(@field_options.pivot_fields, assigns, :index)}
class="font-medium"
>
<%= label %>
{label}
</th>
<th></th>
</tr>
Expand Down Expand Up @@ -330,7 +330,7 @@ defmodule Backpex.Fields.HasManyThrough do
>
<div class="py-3">
<div :for={e <- @editables} class={[unless(e.index == @edit_relational, do: "hidden")]}>
<%= hidden_inputs_for(e) %>
{hidden_inputs_for(e)}
<.select_relational_field
form={e}
label={@field_options.live_resource.singular_name()}
Expand All @@ -343,17 +343,17 @@ defmodule Backpex.Fields.HasManyThrough do
</div>
<div class="bg-base-200 flex justify-end space-x-4 px-6 py-3">
<button type="button" class="btn" phx-click="cancel-relational" phx-target={@myself}>
<%= Backpex.translate("Cancel") %>
{Backpex.translate("Cancel")}
</button>
<button type="button" class="btn btn-primary" phx-click="complete-relational" phx-target={@myself}>
<%= Backpex.translate("Apply") %>
{Backpex.translate("Apply")}
</button>
</div>
</.modal>
<button type="button" class="btn btn-sm btn-outline btn-primary" phx-click="new-relational" phx-target={@myself}>
<%= @relational_title %>
{@relational_title}
</button>
</Layout.field_container>
</div>
Expand Down
6 changes: 3 additions & 3 deletions lib/backpex/fields/inline_crud.ex
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ defmodule Backpex.Fields.InlineCRUD do
<thead class="bg-base-200/50 text-base-content uppercase">
<tr>
<th :for={{_name, %{label: label}} <- @field_options.child_fields} class="font-medium">
<%= label %>
{label}
</th>
</tr>
</thead>
<tbody class="text-base-content/75">
<tr :for={row <- @value} class="border-base-content/10 border-b last:border-b-0">
<td :for={{name, _field_options} <- @field_options.child_fields}>
<%= HTML.pretty_value(Map.get(row, name)) %>
{HTML.pretty_value(Map.get(row, name))}
</td>
</tr>
</tbody>
Expand Down Expand Up @@ -143,7 +143,7 @@ defmodule Backpex.Fields.InlineCRUD do
class={child_field_class(child_field_options, assigns)}
>
<p :if={f_nested.index == 0} class="mb-1 text-xs">
<%= child_field_options.label %>
{child_field_options.label}
</p>
<BackpexForm.input
type={input_type(child_field_options) |> Atom.to_string()}
Expand Down
4 changes: 2 additions & 2 deletions lib/backpex/fields/multi_select.ex
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ defmodule Backpex.Fields.MultiSelect do

~H"""
<div class={[@live_action in [:index, :resource_action] && "truncate"]}>
<%= if @selected_labels == [], do: raw("&mdash;") %>
{if @selected_labels == [], do: raw("&mdash;")}
<div class={["flex", @live_action == :show && "flex-wrap"]}>
<.intersperse :let={item} enum={@selected_labels}>
<:separator>
,&nbsp;
</:separator>
<p>
<%= HTML.pretty_value(item) %>
{HTML.pretty_value(item)}
</p>
</.intersperse>
</div>
Expand Down
Loading

0 comments on commit 60a0986

Please sign in to comment.