From f5b577574e94cd6aa4d086e00dd7d260aca26851 Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Thu, 25 May 2023 13:50:54 +0200 Subject: [PATCH] Extend the prompt in case of funnel-goal deletion --- lib/plausible/goals.ex | 8 ++++++++ .../templates/site/settings_goals.html.eex | 12 +++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/plausible/goals.ex b/lib/plausible/goals.ex index 22e426737..69c13c776 100644 --- a/lib/plausible/goals.ex +++ b/lib/plausible/goals.ex @@ -72,6 +72,14 @@ defmodule Plausible.Goals do ) end + def belongs_to_funnels?(%Goal{id: goal_id}) do + belongs_to_funnels?(goal_id) + end + + def belongs_to_funnels?(goal_id) do + Repo.exists?(from fs in Plausible.Funnel.Step, where: fs.goal_id == ^goal_id) + end + def delete(id, site) do case Repo.delete_all( from(g in Goal, diff --git a/lib/plausible_web/templates/site/settings_goals.html.eex b/lib/plausible_web/templates/site/settings_goals.html.eex index bfacd59e0..be68f79b3 100644 --- a/lib/plausible_web/templates/site/settings_goals.html.eex +++ b/lib/plausible_web/templates/site/settings_goals.html.eex @@ -12,7 +12,17 @@ <%= for goal <- @goals do %>
<%= goal_name(goal) %> - <%= button(to: "/#{URI.encode_www_form(@site.domain)}/goals/#{goal.id}", method: :delete, class: "text-sm text-red-600", data: [confirm: "Are you sure you want to remove goal #{goal_name(goal)}? This will just affect the UI, all of your analytics data will stay intact."]) do %> + + <% prompt = if Plausible.Goals.belongs_to_funnels?(goal) do %> +The goal <%= goal_name(goal) %> is part of some funnel(s). + +If you are going to delete it, the associated funnels will be either reduced or deleted completely. + +Are you sure you want to remove goal <%= goal_name(goal) %>? + <% else %> +Are you sure you want to remove goal <%= goal_name(goal) %>? This will just affect the UI, all of your analytics data will stay intact. + <% end %> + <%= button(to: "/#{URI.encode_www_form(@site.domain)}/goals/#{goal.id}", method: :delete, class: "text-sm text-red-600", data: [confirm: prompt]) do %> <% end %>