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
Exclude pages already added in page shields suggestions (#5637)
Adam Rutkowski1d135d4a74ea
diff --git a/lib/plausible_web/live/shields/page_rules.ex b/lib/plausible_web/live/shields/page_rules.exindex 96e304820d..b85e7a46ad 100644--- a/lib/plausible_web/live/shields/page_rules.ex+++ b/lib/plausible_web/live/shields/page_rules.ex@@ -125,7 +125,9 @@ defmodule PlausibleWeb.Live.Shields.PageRules dosubmit_value={f[:page_path].value}display_value={f[:page_path].value || ""}module={PlausibleWeb.Live.Components.ComboBox}- suggest_fun={fn input, options -> suggest_page_paths(input, options, @site) end}+ suggest_fun={+ fn input, options -> suggest_page_paths(input, options, @site, @page_rules) end+ }id={"#{f[:page_path].id}-#{modal_unique_id}"}creatable/>@@ -217,8 +219,15 @@ defmodule PlausibleWeb.Live.Shields.PageRules do|> Calendar.strftime("%Y-%m-%d %H:%M:%S")end- def suggest_page_paths(input, _options, site) do- query = Plausible.Stats.Query.from(site, %{})+ def suggest_page_paths(input, _options, site, page_rules) do+ query =+ site+ |> Plausible.Stats.Query.from(%{})+ |> Plausible.Stats.Query.add_filter([+ :is_not,+ "event:page",+ Enum.map(page_rules, & &1.page_path)+ ])site|> Plausible.Stats.filter_suggestions(query, "page", input)diff --git a/test/plausible_web/live/shields/pages_test.exs b/test/plausible_web/live/shields/pages_test.exsindex 51579531aa..d3f1dd46f9 100644--- a/test/plausible_web/live/shields/pages_test.exs+++ b/test/plausible_web/live/shields/pages_test.exs@@ -166,6 +166,57 @@ defmodule PlausibleWeb.Live.Shields.PagesTest do"This rule might be redundant because the following rules may match first:\n\n/test/*"end+ test "debug - check combo box behavior", %{conn: conn, site: site} do+ populate_stats(site, [+ build(:pageview, pathname: "/blog/post1", timestamp: Date.add(Date.utc_today(), -3)),+ build(:pageview, pathname: "/blog/post2", timestamp: Date.add(Date.utc_today(), -3))+ ])++ opt1_selector = "li#dropdown-page_rule_page_path-modalseq0-option-1"+ opt2_selector = "li#dropdown-page_rule_page_path-modalseq0-option-2"++ lv = get_liveview(conn, site)++ type_into_combo(lv, "page_rule_page_path-modalseq0", "blog")+ html = lv |> render()++ assert text_of_element(html, opt1_selector) == "/blog/post1"+ assert text_of_element(html, opt2_selector) == "/blog/post2"++ lv+ |> element("form")+ |> render_submit(%{+ "page_rule[page_path]" => "/blog/post2"+ })++ type_into_combo(lv, "page_rule_page_path-modalseq0", "blog")+ html = lv |> render()++ assert text_of_element(html, opt1_selector) == "/blog/post1"+ refute element_exists?(html, opt2_selector)++ lv+ |> element("form")+ |> render_submit(%{+ "page_rule[page_path]" => "/blog/post1"+ })++ type_into_combo(lv, "page_rule_page_path-modalseq0", "blog")+ html = lv |> render()++ refute element_exists?(html, opt1_selector)+ refute element_exists?(html, opt2_selector)+ end++ defp type_into_combo(lv, id, text) do+ lv+ |> element("input##{id}")+ |> render_change(%{+ "_target" => ["display-#{id}"],+ "display-#{id}" => "#{text}"+ })+ end+defp get_liveview(conn, site) doconn = assign(conn, :live_module, PlausibleWeb.Live.Shields){:ok, lv, _html} = live(conn, "/#{site.domain}/settings/shields/pages")