Skip to content

Commit

Permalink
Remove imports_exports and csv_imports_exports feature flags (#4089)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoldar committed May 9, 2024
1 parent b1c1361 commit d8435f2
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 61 deletions.
10 changes: 3 additions & 7 deletions lib/plausible/imported.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,9 @@ defmodule Plausible.Imported do
@spec tables() :: [String.t()]
def tables, do: @table_names

@spec max_complete_imports(Site.t()) :: non_neg_integer()
def max_complete_imports(site) do
if FunWithFlags.enabled?(:imports_exports, for: site) do
@max_complete_imports
else
1
end
@spec max_complete_imports() :: non_neg_integer()
def max_complete_imports() do
@max_complete_imports
end

@spec load_import_data(Site.t()) :: Site.t()
Expand Down
7 changes: 1 addition & 6 deletions lib/plausible_web/controllers/google_analytics_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,7 @@ defmodule PlausibleWeb.GoogleAnalyticsController do

redirect_route = Routes.site_path(conn, :settings_imports_exports, site.domain)

result =
if FunWithFlags.enabled?(:imports_exports, for: site) do
Google.API.list_properties_and_views(access_token)
else
Google.UA.API.list_views(access_token)
end
result = Google.API.list_properties_and_views(access_token)

error =
case params["error"] do
Expand Down
11 changes: 2 additions & 9 deletions lib/plausible_web/live/imports_exports_settings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,10 @@ defmodule PlausibleWeb.Live.ImportsExportsSettings do
|> assign_new(:current_user, fn ->
Plausible.Repo.get(Plausible.Auth.User, user_id)
end)
|> assign_new(:max_imports, fn %{site: site} ->
Imported.max_complete_imports(site)
end)

:ok = Imported.listen()

{:ok, socket}
{:ok, assign(socket, max_imports: Imported.max_complete_imports())}
end

def render(assigns) do
Expand All @@ -55,8 +52,6 @@ defmodule PlausibleWeb.Live.ImportsExportsSettings do

at_maximum? = length(assigns.site_imports) >= assigns.max_imports

csv_imports_exports_enabled? = FunWithFlags.enabled?(:csv_imports_exports, for: assigns.site)

import_warning =
cond do
import_in_progress? ->
Expand All @@ -74,8 +69,7 @@ defmodule PlausibleWeb.Live.ImportsExportsSettings do
assign(assigns,
import_in_progress?: import_in_progress?,
at_maximum?: at_maximum?,
import_warning: import_warning,
csv_imports_exports_enabled?: csv_imports_exports_enabled?
import_warning: import_warning
)

~H"""
Expand All @@ -90,7 +84,6 @@ defmodule PlausibleWeb.Live.ImportsExportsSettings do
</.button_link>
<.button_link
:if={@csv_imports_exports_enabled?}
class="w-36 h-20"
theme="bright"
disabled={@import_in_progress? or @at_maximum?}
Expand Down
42 changes: 18 additions & 24 deletions lib/plausible_web/templates/site/settings_imports_exports.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
</h2>
<p class="mt-1 text-sm leading-5 text-gray-500 dark:text-gray-200">
Import existing data from external sources.
<%= if FunWithFlags.enabled?(:csv_imports_exports, for: @site) do %>
Pick one of the options below to start a new import.
<% else %>
Click below to start a new import.
<% end %>
Pick one of the options below to start a new import.
</p>

<PlausibleWeb.Components.Generic.docs_info slug="google-analytics-import" />
Expand All @@ -20,23 +16,21 @@
) %>
</div>

<%= if FunWithFlags.enabled?(:csv_imports_exports, for: @site) or Plausible.Auth.is_super_admin?(@current_user) do %>
<div class="shadow bg-white dark:bg-gray-800 dark:text-gray-200 sm:rounded-md sm:overflow-hidden py-6 px-4 sm:p-6">
<header class="relative border-b border-gray-200 pb-4 mb-5">
<h2 class="text-lg leading-6 font-medium text-gray-900 dark:text-gray-100">
Export Data
</h2>
<p class="mt-1 text-sm leading-5 text-gray-500 dark:text-gray-200">
Export all your data into CSV format.
</p>
</header>
<div class="shadow bg-white dark:bg-gray-800 dark:text-gray-200 sm:rounded-md sm:overflow-hidden py-6 px-4 sm:p-6">
<header class="relative border-b border-gray-200 pb-4 mb-5">
<h2 class="text-lg leading-6 font-medium text-gray-900 dark:text-gray-100">
Export Data
</h2>
<p class="mt-1 text-sm leading-5 text-gray-500 dark:text-gray-200">
Export all your data into CSV format.
</p>
</header>

<%= live_render(@conn, PlausibleWeb.Live.CSVExport,
session: %{
"site_id" => @site.id,
"email_to" => @current_user.email,
"storage" => on_ee(do: "s3", else: "local")
}
) %>
</div>
<% end %>
<%= live_render(@conn, PlausibleWeb.Live.CSVExport,
session: %{
"site_id" => @site.id,
"email_to" => @current_user.email,
"storage" => on_ee(do: "s3", else: "local")
}
) %>
</div>
9 changes: 1 addition & 8 deletions lib/plausible_web/views/layout_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@ defmodule PlausibleWeb.LayoutView do
end

def settings_tabs(conn) do
imports_exports_key =
if FunWithFlags.enabled?(:csv_imports_exports, for: conn.assigns.site) do
"Imports & Exports"
else
"Imports"
end

[
%{key: "General", value: "general", icon: :rocket_launch},
%{key: "People", value: "people", icon: :users},
Expand All @@ -66,7 +59,7 @@ defmodule PlausibleWeb.LayoutView do
end,
%{key: "Custom Properties", value: "properties", icon: :document_text},
%{key: "Integrations", value: "integrations", icon: :arrow_path_rounded_square},
%{key: imports_exports_key, value: "imports-exports", icon: :arrows_up_down},
%{key: "Imports & Exports", value: "imports-exports", icon: :arrows_up_down},
%{
key: "Shields",
icon: :shield_exclamation,
Expand Down
3 changes: 0 additions & 3 deletions priv/repo/seeds.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
# We recommend using the bang functions (`insert!`, `update!`
# and so on) as they will fail if something goes wrong.

FunWithFlags.enable(:imports_exports)
FunWithFlags.enable(:csv_imports_exports)

user = Plausible.Factory.insert(:user, email: "user@plausible.test", password: "plausible")

native_stats_range =
Expand Down
4 changes: 2 additions & 2 deletions test/plausible_web/controllers/site_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -679,15 +679,15 @@ defmodule PlausibleWeb.SiteControllerTest do
end

test "disables import buttons when imports are at maximum", %{conn: conn, site: site} do
insert_list(Plausible.Imported.max_complete_imports(site), :site_import,
insert_list(Plausible.Imported.max_complete_imports(), :site_import,
site: site,
status: SiteImport.completed()
)

conn = get(conn, "/#{site.domain}/settings/imports-exports")

assert html_response(conn, 200) =~
"Maximum of #{Plausible.Imported.max_complete_imports(site)} imports is reached."
"Maximum of #{Plausible.Imported.max_complete_imports()} imports is reached."
end

test "considers older legacy imports when showing pageview count", %{conn: conn, site: site} do
Expand Down
2 changes: 0 additions & 2 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ end
{:ok, _} = Application.ensure_all_started(:ex_machina)
Mox.defmock(Plausible.HTTPClient.Mock, for: Plausible.HTTPClient.Interface)
Application.ensure_all_started(:double)
FunWithFlags.enable(:imports_exports)
FunWithFlags.enable(:csv_imports_exports)

# Temporary flag to test `experimental_reduced_joins` flag on all tests.
if System.get_env("TEST_EXPERIMENTAL_REDUCED_JOINS") == "1" do
Expand Down

0 comments on commit d8435f2

Please sign in to comment.