defmodule PlausibleWeb.Live.ImportsExportsSettings do @moduledoc """ LiveView allowing listing and deleting imports. """ use PlausibleWeb, :live_view use Phoenix.HTML import PlausibleWeb.Components.Generic import PlausibleWeb.TextHelpers alias Plausible.Imported alias Plausible.Imported.SiteImport alias Plausible.Sites require Plausible.Imported.SiteImport def mount( _params, %{"domain" => domain, "current_user_id" => user_id}, socket ) do socket = socket |> assign_new(:site, fn -> Sites.get_for_user!(user_id, domain, [:owner, :admin, :super_admin]) end) |> assign_new(:site_imports, fn %{site: site} -> site |> Imported.list_all_imports() |> Enum.map( &%{site_import: &1, live_status: &1.status, tooltip: notice_label(&1, &1.status)} ) end) |> assign_new(:pageview_counts, fn %{site: site} -> Plausible.Stats.Clickhouse.imported_pageview_counts(site) end) |> assign_new(:current_user, fn -> Plausible.Repo.get(Plausible.Auth.User, user_id) end) :ok = Imported.listen() {:ok, assign(socket, max_imports: Imported.max_complete_imports())} end def render(assigns) do import_in_progress? = Enum.any?( assigns.site_imports, &(&1.live_status in [SiteImport.pending(), SiteImport.importing()]) ) at_maximum? = length(assigns.site_imports) >= assigns.max_imports import_warning = cond do import_in_progress? -> "No new imports can be started until the import in progress is completed or cancelled." at_maximum? -> "Maximum of #{assigns.max_imports} imports is reached. " <> "Delete or cancel an existing import to start a new one." true -> nil end assigns = assign(assigns, import_in_progress?: import_in_progress?, at_maximum?: at_maximum?, import_warning: import_warning ) ~H"""
<%= @import_warning %>
A maximum of <%= @max_imports %> imports at any time is allowed.
There are no imports yet for this site.