Crm consolidated views followup (#5764)

* skip experimental comment

* alias

* remove cv abbreviations

* uncapitalize word

* use enabled?/1 in tests

* ask for confirmation before delete

* remove settings link
This commit is contained in:
RobertJoonas 2025-10-01 10:23:30 +01:00 committed by GitHub
parent fc5f56e475
commit 627602d2a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 34 deletions

View File

@ -1,22 +1,16 @@
defmodule PlausibleWeb.CustomerSupport.Team.Components.ConsolidatedViews do
@moduledoc """
[Experimental - new feature]
Lists ConsolidatedViews of a team and allows creating one if none exist. Current
limitation is one consolidated view per team, which always includes all sites of
this team.
"""
use PlausibleWeb, :live_component
import PlausibleWeb.CustomerSupport.Live
alias Plausible.ConsolidatedView
def update(%{team: team}, socket) do
cvs =
case Plausible.ConsolidatedView.get(team) do
nil -> []
cv -> [cv]
end
{:ok, assign(socket, team: team, consolidated_views: cvs)}
consolidated_views = ConsolidatedView.get(team) |> List.wrap()
{:ok, assign(socket, team: team, consolidated_views: consolidated_views)}
end
def render(assigns) do
@ -35,7 +29,6 @@ defmodule PlausibleWeb.CustomerSupport.Team.Components.ConsolidatedViews do
<.th>Domain</.th>
<.th>Timezone</.th>
<.th invisible>Dashboard</.th>
<.th invisible>Settings</.th>
<.th invisible>Delete</.th>
</:thead>
@ -51,22 +44,11 @@ defmodule PlausibleWeb.CustomerSupport.Team.Components.ConsolidatedViews do
</.styled_link>
</.td>
<.td>
<.styled_link
new_tab={true}
href={
Routes.site_path(
PlausibleWeb.Endpoint,
:settings_general,
consolidated_view.domain,
[]
)
}
>
Settings
</.styled_link>
</.td>
<.td>
<.delete_button phx-click="delete-consolidated-view" phx-target={@myself} />
<.delete_button
phx-click="delete-consolidated-view"
phx-target={@myself}
data-confirm="Are you sure you want to delete this consolidated view?"
/>
</.td>
</:tbody>
</.table>
@ -76,19 +58,19 @@ defmodule PlausibleWeb.CustomerSupport.Team.Components.ConsolidatedViews do
end
def handle_event("create-consolidated-view", _, socket) do
case Plausible.ConsolidatedView.enable(socket.assigns.team) do
{:ok, cv} ->
case ConsolidatedView.enable(socket.assigns.team) do
{:ok, consolidated_view} ->
success("Consolidated view created")
{:noreply, assign(socket, consolidated_views: [cv])}
{:noreply, assign(socket, consolidated_views: [consolidated_view])}
{:error, _} ->
failure("Could not create consolidated View")
failure("Could not create consolidated view")
{:noreply, socket}
end
end
def handle_event("delete-consolidated-view", _, socket) do
Plausible.ConsolidatedView.disable(socket.assigns.team)
ConsolidatedView.disable(socket.assigns.team)
success("Deleted consolidated view")
{:noreply, assign(socket, consolidated_views: [])}
end

View File

@ -204,7 +204,7 @@ defmodule PlausibleWeb.Live.CustomerSupport.TeamsTest do
lv |> element(@create_consolidated_view_button) |> render_click()
assert not is_nil(Plausible.ConsolidatedView.get(team))
assert Plausible.ConsolidatedView.enabled?(team)
end
test "renders existing consolidated view", %{conn: conn, user: user} do
@ -218,7 +218,6 @@ defmodule PlausibleWeb.Live.CustomerSupport.TeamsTest do
assert table_text =~ team.identifier
assert table_text =~ "Dashboard"
assert table_text =~ "Settings"
assert element_exists?(html, @delete_consolidated_view_button)
end
@ -231,7 +230,7 @@ defmodule PlausibleWeb.Live.CustomerSupport.TeamsTest do
lv |> element(@delete_consolidated_view_button) |> render_click()
assert is_nil(Plausible.ConsolidatedView.get(team))
assert not Plausible.ConsolidatedView.enabled?(team)
end
end