Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
Use prima modal in ip_rules settings (#5910)
Uku Taht3c9ba41cb6f1
diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.ymlindex ac20172da9..851de773d7 100644--- a/.github/workflows/elixir.yml+++ b/.github/workflows/elixir.yml@@ -11,7 +11,7 @@ concurrency:cancel-in-progress: trueenv:- CACHE_VERSION: v15+ CACHE_VERSION: v16PERSISTENT_CACHE_DIR: cachedjobs:diff --git a/lib/plausible_web/live/components/prima_modal.ex b/lib/plausible_web/live/components/prima_modal.exindex bcb883b5b9..381586d218 100644--- a/lib/plausible_web/live/components/prima_modal.ex+++ b/lib/plausible_web/live/components/prima_modal.ex@@ -4,11 +4,12 @@ defmodule PlausibleWeb.Live.Components.PrimaModal doalias Prima.Modalattr :id, :string, required: true+ attr :use_portal?, :boolean, default: Mix.env() not in [:test, :ce_test]slot :inner_block, required: truedef modal(assigns) do~H"""- <Modal.modal id={@id}>+ <Modal.modal portal={@use_portal?} id={@id}><Modal.modal_overlaytransition_enter={{"ease-out duration-300", "opacity-0", "opacity-100"}}transition_leave={{"ease-in duration-200", "opacity-100", "opacity-0"}}diff --git a/lib/plausible_web/live/shields/ip_rules.ex b/lib/plausible_web/live/shields/ip_rules.exindex 8e7208b7c6..3115000133 100644--- a/lib/plausible_web/live/shields/ip_rules.ex+++ b/lib/plausible_web/live/shields/ip_rules.ex@@ -5,7 +5,7 @@ defmodule PlausibleWeb.Live.Shields.IPRules douse PlausibleWeb, :live_component- alias PlausibleWeb.Live.Components.Modal+ alias PlausibleWeb.Live.Components.PrimaModalalias Plausible.Shieldsalias Plausible.Shield@@ -50,9 +50,7 @@ defmodule PlausibleWeb.Live.Shields.IPRules do<.button:if={@ip_rules_count < Shields.maximum_ip_rules()}id="add-ip-rule"- x-data- x-on:click={Modal.JS.open("ip-rule-form-modal")}- class="mt-4"+ phx-click={Prima.Modal.JS.open("ip-rule-form-modal")}>Add IP address</.button>@@ -61,8 +59,7 @@ defmodule PlausibleWeb.Live.Shields.IPRules do<.filter_bar :if={@ip_rules_count < Shields.maximum_ip_rules()} filtering_enabled?={false}><.buttonid="add-ip-rule"- x-data- x-on:click={Modal.JS.open("ip-rule-form-modal")}+ phx-click={Prima.Modal.JS.open("ip-rule-form-modal")}mt?={false}>Add IP address@@ -139,50 +136,63 @@ defmodule PlausibleWeb.Live.Shields.IPRules do</div><% end %>- <.live_component module={Modal} id="ip-rule-form-modal">- <.form- :let={f}- for={@form}- phx-submit="save-ip-rule"- phx-target={@myself}- class="max-w-md w-full mx-auto"- >- <.title>Add IP to block list</.title>-- <div class="mt-4">- <p- :if={not ip_rule_present?(@ip_rules, @remote_ip)}- class="text-sm text-gray-500 dark:text-gray-400 mb-4"+ <PrimaModal.modal id="ip-rule-form-modal">+ <div class="p-5 sm:p-6 max-w-md">+ <div class="hidden sm:block absolute top-0 right-0 pt-4 pr-4">+ <button+ phx-click={Prima.Modal.JS.close()}+ class="text-gray-400 dark:text-gray-500 hover:text-gray-500 dark:hover:text-gray-400">- Your current IP address is: <span class="font-mono"><%= @remote_ip %></span>.- <.styled_link phx-target={@myself} phx-click="prefill-own-ip-rule">- Click here- </.styled_link>- to block your own traffic, or enter a custom address below.- </p>-- <.input- autofocus- field={f[:inet]}- label="IP address"- placeholder="e.g. 192.168.127.12"- />+ <span class="sr-only">Close</span>+ <Heroicons.x_mark class="size-6" />+ </button></div>+ <div class="flex flex-col gap-y-4 text-center sm:text-left">+ <PrimaModal.modal_title>+ Add IP to block list+ </PrimaModal.modal_title>+ <.form+ :let={f}+ for={@form}+ phx-submit="save-ip-rule"+ phx-target={@myself}+ >+ <div>+ <p+ :if={not ip_rule_present?(@ip_rules, @remote_ip)}+ class="text-sm text-gray-500 dark:text-gray-400 mb-4"+ >+ Your current IP address is: <span class="font-mono"><%= @remote_ip %></span>.+ <.styled_link phx-target={@myself} phx-click="prefill-own-ip-rule">+ Click here+ </.styled_link>+ to block your own traffic, or enter a custom address below.+ </p>- <.input- field={f[:description]}- label="Description (optional)"- placeholder="e.g. The Office"- />+ <.input+ data-autofocus+ field={f[:inet]}+ label="IP address"+ placeholder="e.g. 192.168.127.12"+ />+ </div>- <p class="mt-4 text-sm text-gray-500 dark:text-gray-400">- Once added, we will start rejecting traffic from this IP within a few minutes.- </p>- <.button type="submit" class="w-full">- Add IP address- </.button>- </.form>- </.live_component>+ <.input+ field={f[:description]}+ label="Description (optional)"+ placeholder="e.g. The Office"+ />++ <p class="mt-4 text-sm text-gray-500 dark:text-gray-400">+ Once added, we will start rejecting traffic from this IP within a few minutes.+ </p>+ <.button type="submit" class="w-full">+ Add IP address+ </.button>+ </.form>+ </div>+ </div>+ </PrimaModal.modal></.tile></.settings_tiles></div>@@ -212,7 +222,7 @@ defmodule PlausibleWeb.Live.Shields.IPRules do{:ok, rule} ->socket =socket- |> Modal.close("ip-rule-form-modal")+ |> Prima.Modal.push_close("ip-rule-form-modal")|> assign(form: new_form(),ip_rules: [rule | socket.assigns.ip_rules],diff --git a/lib/plausible_web/live/sites.ex b/lib/plausible_web/live/sites.exindex 7aae38a0e8..8c71fd3351 100644--- a/lib/plausible_web/live/sites.ex+++ b/lib/plausible_web/live/sites.ex@@ -498,7 +498,7 @@ defmodule PlausibleWeb.Live.Sites doclass="group relative cursor-pointer"id={"site-card-#{hash_domain(@site.domain)}"}data-domain={@site.domain}- phx-click={Prima.Modal.open(@modal_id)}+ phx-click={Prima.Modal.JS.open(@modal_id)}><div class="col-span-1 flex flex-col gap-y-5 bg-white dark:bg-gray-900 rounded-md shadow-sm p-6 group-hover:shadow-lg cursor-pointer transition duration-100"><div class="w-full flex items-center justify-between gap-x-2.5">@@ -730,7 +730,7 @@ defmodule PlausibleWeb.Live.Sites do<div class="p-5 pb-3 sm:p-6 sm:pb-3"><div class="hidden sm:block absolute top-0 right-0 pt-4 pr-4"><button- phx-click={Prima.Modal.close()}+ phx-click={Prima.Modal.JS.close()}class="text-gray-400 dark:text-gray-500 hover:text-gray-500 dark:hover:text-gray-400"><span class="sr-only">Close</span>diff --git a/mix.exs b/mix.exsindex ccee086569..6b85b8ff94 100644--- a/mix.exs+++ b/mix.exs@@ -114,7 +114,7 @@ defmodule Plausible.MixProject do{:phoenix_live_view, "~> 1.1"},{:php_serializer, "~> 2.0"},{:plug, "~> 1.13", override: true},- {:prima, "~> 0.1.8"},+ {:prima, "~> 0.2.1"},{:plug_cowboy, "~> 2.3"},{:polymorphic_embed, "~> 5.0"},{:postgrex, "~> 0.19.0"},diff --git a/mix.lock b/mix.lockindex eb03596902..c583d621ce 100644--- a/mix.lock+++ b/mix.lock@@ -135,7 +135,7 @@"plug_crypto": {:hex, :plug_crypto, "1.2.5", "918772575e48e81e455818229bf719d4ab4181fcbf7f85b68a35620f78d89ced", [:mix], [], "hexpm", "26549a1d6345e2172eb1c233866756ae44a9609bd33ee6f99147ab3fd87fd842"},"polymorphic_embed": {:hex, :polymorphic_embed, "5.0.3", "37444e0af941026a2c29b0539b6471bdd6737a6492a19264bf2bb0118e3ac242", [:mix], [{:attrs, "~> 0.6", [hex: :attrs, repo: "hexpm", optional: false]}, {:ecto, "~> 3.12", [hex: :ecto, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 4.1", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_html_helpers, "~> 1.0", [hex: :phoenix_html_helpers, repo: "hexpm", optional: true]}, {:phoenix_live_view, "~> 0.20 or ~> 1.0", [hex: :phoenix_live_view, repo: "hexpm", optional: true]}], "hexpm", "2fed44f57abf0a0fc7642e0eb0807a55b65de1562712cc0620772cbbb80e49c1"},"postgrex": {:hex, :postgrex, "0.19.3", "a0bda6e3bc75ec07fca5b0a89bffd242ca209a4822a9533e7d3e84ee80707e19", [:mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "d31c28053655b78f47f948c85bb1cf86a9c1f8ead346ba1aa0d0df017fa05b61"},- "prima": {:hex, :prima, "0.1.9", "34868e3570cf2c4fac42d6254e33678e9d75a8fe3d3253a38ee437f6481a2896", [:mix], [{:esbuild, "~> 0.7", [hex: :esbuild, repo: "hexpm", optional: false]}, {:phoenix, ">= 1.7.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 4.2", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 1.1", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}], "hexpm", "7f24efb617dd94da867bf2d362eeab846897270eff989aeaa261f04590feae3f"},+ "prima": {:hex, :prima, "0.2.1", "337d9ee0cc3a09115ba9969d4bb592c0c4b56a6826a039ad890b4dc3c03ffb80", [:mix], [{:esbuild, "~> 0.7", [hex: :esbuild, repo: "hexpm", optional: false]}, {:phoenix, ">= 1.7.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 4.2", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 1.1", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}], "hexpm", "bc5e2b34986d66206720c5a14fa148f77c8c2dc1fec60260923053568e91d634"},"prom_ex": {:hex, :prom_ex, "1.11.0", "1f6d67f2dead92224cb4f59beb3e4d319257c5728d9638b4a5e8ceb51a4f9c7e", [:mix], [{:absinthe, ">= 1.7.0", [hex: :absinthe, repo: "hexpm", optional: true]}, {:broadway, ">= 1.1.0", [hex: :broadway, repo: "hexpm", optional: true]}, {:ecto, ">= 3.11.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:finch, "~> 0.18", [hex: :finch, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:oban, ">= 2.10.0", [hex: :oban, repo: "hexpm", optional: true]}, {:octo_fetch, "~> 0.4", [hex: :octo_fetch, repo: "hexpm", optional: false]}, {:peep, "~> 3.0", [hex: :peep, repo: "hexpm", optional: false]}, {:phoenix, ">= 1.7.0", [hex: :phoenix, repo: "hexpm", optional: true]}, {:phoenix_live_view, ">= 0.20.0", [hex: :phoenix_live_view, repo: "hexpm", optional: true]}, {:plug, ">= 1.16.0", [hex: :plug, repo: "hexpm", optional: true]}, {:plug_cowboy, ">= 2.6.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:telemetry, ">= 1.0.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:telemetry_metrics, "~> 1.0", [hex: :telemetry_metrics, repo: "hexpm", optional: false]}, {:telemetry_metrics_prometheus_core, "~> 1.2", [hex: :telemetry_metrics_prometheus_core, repo: "hexpm", optional: false]}, {:telemetry_poller, "~> 1.1", [hex: :telemetry_poller, repo: "hexpm", optional: false]}], "hexpm", "76b074bc3730f0802978a7eb5c7091a65473eaaf07e99ec9e933138dcc327805"},"public_suffix": {:git, "https://github.com/axelson/publicsuffix-elixir", "fa40c243d4b5d8598b90cff268bc4e33f3bb63f1", []},"ranch": {:hex, :ranch, "1.8.1", "208169e65292ac5d333d6cdbad49388c1ae198136e4697ae2f474697140f201c", [:make, :rebar3], [], "hexpm", "aed58910f4e21deea992a67bf51632b6d60114895eb03bb392bb733064594dd0"},diff --git a/test/plausible_web/live/shields/ip_addresses_test.exs b/test/plausible_web/live/shields/ip_addresses_test.exsindex 5050c1c356..0885d767cd 100644--- a/test/plausible_web/live/shields/ip_addresses_test.exs+++ b/test/plausible_web/live/shields/ip_addresses_test.exs@@ -45,11 +45,7 @@ defmodule PlausibleWeb.Live.Shields.IPAddressesTest doconn = get(conn, "/#{site.domain}/settings/shields/ip_addresses")resp = html_response(conn, 200)- assert element_exists?(resp, ~s/button#add-ip-rule[x-data]/)- attr = text_of_attr(resp, ~s/button#add-ip-rule/, "x-on:click")-- assert attr =~ "open-modal"- assert attr =~ "ip-rule-form-modal"+ assert element_exists?(resp, ~s/button#add-ip-rule/)endtest "add rule button is not rendered when maximum reached", %{conn: conn, site: site} dodiff --git a/test/plausible_web/live/sites_test.exs b/test/plausible_web/live/sites_test.exsindex a7b91fed32..e6d83d2155 100644--- a/test/plausible_web/live/sites_test.exs+++ b/test/plausible_web/live/sites_test.exs@@ -104,9 +104,7 @@ defmodule PlausibleWeb.Live.SitesTest do{:ok, _lv, html} = live(conn, "/sites")- template = find_portal_template(html, "#invitation-modal-#{transfer.transfer_id}")-- assert text(template) =~+ assert text_of_element(html, "#invitation-modal-#{transfer.transfer_id}") =~"You are unable to accept the ownership of this site because your account does not have a subscription"end@@ -203,9 +201,8 @@ defmodule PlausibleWeb.Live.SitesTest do{:ok, _lv, html} = live(conn, "/sites")- template = find_portal_template(html, "#invitation-modal-#{transfer.transfer_id}")-- assert text(template) =~ "Owning this site would exceed your site limit"+ assert text_of_element(html, "#invitation-modal-#{transfer.transfer_id}") =~+ "Owning this site would exceed your site limit"end@tag :ee_only@@ -222,9 +219,7 @@ defmodule PlausibleWeb.Live.SitesTest do{:ok, _lv, html} = live(conn, "/sites")- template = find_portal_template(html, "#invitation-modal-#{transfer.transfer_id}")-- assert text(template) =~+ assert text_of_element(html, "#invitation-modal-#{transfer.transfer_id}") =~"The site uses Custom Properties, which your current subscription does not support"enddiff --git a/test/support/html.ex b/test/support/html.exindex fdde79a227..792d173f3a 100644--- a/test/support/html.ex+++ b/test/support/html.ex@@ -81,26 +81,6 @@ defmodule Plausible.Test.Support.HTML dotext_of_attr(element, "name")end- @doc """- When using liveview <.portal> element, it renders a <template> that gets rendered into DOM- by JS. In order to make assertions about portal contents, we need to find the <template> element- and get its contents. Unfortunately <template> elements are not treated like standard elements by LazyHTML.- Functions like LazyHTML.text() or LazyHTML.query() return nothing for <template> elements. So this function tricks LazyHTML by:- 1. Finding the template element- 2. Transforming it into a <div> so it can be used like a normal LazyHTML node- )- """- def find_portal_template(html, id) do- template_id = id <> "-portal"-- [{"template", attrs, children}] =- lazy_parse(html)- |> find(template_id)- |> LazyHTML.to_tree()-- LazyHTML.from_tree([{"div", attrs, children}])- end-defp lazy_parse(%LazyHTML{} = lazy) dolazyend