From 7fa7e85decb2ba4ef1c14141a8c75c188f22d85b Mon Sep 17 00:00:00 2001 From: bmanifold Date: Wed, 1 Nov 2023 14:45:49 -0400 Subject: [PATCH] Add feature flags for TODOs and Flows (#2542) Why: * Some sections of the UI were still displaying `TODO` and needed to be hidden for beta release, so a feature flag was created. Also, the 'Flows' are not ready to be utilized in the UI at this time, so a feature flag was created to hide any mention of 'Flows'. --- elixir/apps/domain/lib/domain/config.ex | 10 ++++++++++ .../domain/lib/domain/config/definitions.ex | 10 ++++++++++ elixir/apps/web/lib/web/live/clients/show.ex | 18 ++++++++++++++---- elixir/apps/web/lib/web/live/gateways/show.ex | 18 ++++++++++++++---- elixir/apps/web/lib/web/live/policies/show.ex | 14 +++++++++++--- elixir/apps/web/lib/web/live/relays/show.ex | 12 ++++++++++-- elixir/apps/web/lib/web/live/resources/show.ex | 12 ++++++++++-- 7 files changed, 79 insertions(+), 15 deletions(-) diff --git a/elixir/apps/domain/lib/domain/config.ex b/elixir/apps/domain/lib/domain/config.ex index d7cac36df..24d01f5c3 100644 --- a/elixir/apps/domain/lib/domain/config.ex +++ b/elixir/apps/domain/lib/domain/config.ex @@ -113,10 +113,20 @@ defmodule Domain.Config do end end + ## Feature flag helpers + def sign_up_enabled? do compile_config!(Definitions, :feature_sign_up_enabled) end + def flow_activities_enabled? do + compile_config!(Definitions, :feature_flow_activities_enabled) + end + + def todos_enabled? do + compile_config!(Definitions, :feature_todos_enabled) + end + ## Test helpers if Mix.env() != :test do diff --git a/elixir/apps/domain/lib/domain/config/definitions.ex b/elixir/apps/domain/lib/domain/config/definitions.ex index e69042d6d..93c7cd2c4 100644 --- a/elixir/apps/domain/lib/domain/config/definitions.ex +++ b/elixir/apps/domain/lib/domain/config/definitions.ex @@ -613,4 +613,14 @@ defmodule Domain.Config.Definitions do Boolean flag to turn Sign-ups on/off. """ defconfig(:feature_sign_up_enabled, :boolean, default: true) + + @doc """ + Boolean flag to turn UI flow activities on/off. + """ + defconfig(:feature_flow_activities_enabled, :boolean, default: false) + + @doc """ + Boolean flag to turn UI TODOs on/off. + """ + defconfig(:feature_todos_enabled, :boolean, default: false) end diff --git a/elixir/apps/web/lib/web/live/clients/show.ex b/elixir/apps/web/lib/web/live/clients/show.ex index fb2013aea..799f8b3e3 100644 --- a/elixir/apps/web/lib/web/live/clients/show.ex +++ b/elixir/apps/web/lib/web/live/clients/show.ex @@ -1,7 +1,7 @@ defmodule Web.Clients.Show do use Web, :live_view import Web.Policies.Components - alias Domain.{Clients, Flows} + alias Domain.{Clients, Flows, Config} def mount(%{"id" => id}, _session, socket) do with {:ok, client} <- Clients.fetch_client_by_id(id, socket.assigns.subject, preload: :actor), @@ -9,7 +9,17 @@ defmodule Web.Clients.Show do Flows.list_flows_for(client, socket.assigns.subject, preload: [gateway: [:group], policy: [:resource, :actor_group]] ) do - {:ok, assign(socket, client: client, flows: flows)} + socket = + assign( + socket, + client: client, + flows: flows, + todos_enabled?: Config.todos_enabled?(), + flow_activities_enabled?: Config.flow_activities_enabled?() + ) + + {:ok, socket, + temporary_assigns: [flows: [], todos_enabled?: nil, flow_activities_enabled?: nil]} else {:error, _reason} -> raise Web.LiveErrors.NotFoundError end @@ -66,7 +76,7 @@ defmodule Web.Clients.Show do <.relative_datetime datetime={@client.last_seen_at} /> - <.vertical_table_row> + <.vertical_table_row :if={@todos_enabled?}> <:label>Transfer <:value>TODO @@ -118,7 +128,7 @@ defmodule Web.Clients.Show do (<%= flow.gateway_remote_ip %>) - <:col :let={flow} label="ACTIVITY"> + <:col :let={flow} :if={@flow_activities_enabled?} label="ACTIVITY"> <.link navigate={~p"/#{@account}/flows/#{flow.id}"} class="font-medium text-blue-600 dark:text-blue-500 hover:underline" diff --git a/elixir/apps/web/lib/web/live/gateways/show.ex b/elixir/apps/web/lib/web/live/gateways/show.ex index d398477b1..1246489f7 100644 --- a/elixir/apps/web/lib/web/live/gateways/show.ex +++ b/elixir/apps/web/lib/web/live/gateways/show.ex @@ -1,7 +1,7 @@ defmodule Web.Gateways.Show do use Web, :live_view import Web.Policies.Components - alias Domain.{Gateways, Flows} + alias Domain.{Gateways, Flows, Config} def mount(%{"id" => id}, _session, socket) do with {:ok, gateway} <- @@ -11,7 +11,17 @@ defmodule Web.Gateways.Show do preload: [client: [:actor], policy: [:resource, :actor_group]] ) do :ok = Gateways.subscribe_for_gateways_presence_in_group(gateway.group) - {:ok, assign(socket, gateway: gateway, flows: flows)} + + socket = + assign( + socket, + gateway: gateway, + flows: flows, + todos_enabled?: Config.todos_enabled?(), + flow_activities_enabled?: Config.flow_activities_enabled?() + ) + + {:ok, socket} else {:error, _reason} -> raise Web.LiveErrors.NotFoundError end @@ -52,7 +62,7 @@ defmodule Web.Gateways.Show do <:label>Instance Name <:value><%= @gateway.name_suffix %> - <.vertical_table_row> + <.vertical_table_row :if={@todos_enabled?}> <:label>Connectivity <:value>TODO: Peer to Peer @@ -143,7 +153,7 @@ defmodule Web.Gateways.Show do (<%= flow.client_remote_ip %>) - <:col :let={flow} label="ACTIVITY"> + <:col :let={flow} :if={@flow_activities_enabled?} label="ACTIVITY"> <.link navigate={~p"/#{@account}/flows/#{flow.id}"} class="font-medium text-blue-600 dark:text-blue-500 hover:underline" diff --git a/elixir/apps/web/lib/web/live/policies/show.ex b/elixir/apps/web/lib/web/live/policies/show.ex index 842f1b976..ad988c150 100644 --- a/elixir/apps/web/lib/web/live/policies/show.ex +++ b/elixir/apps/web/lib/web/live/policies/show.ex @@ -1,7 +1,7 @@ defmodule Web.Policies.Show do use Web, :live_view import Web.Policies.Components - alias Domain.{Policies, Flows} + alias Domain.{Policies, Flows, Config} def mount(%{"id" => id}, _session, socket) do with {:ok, policy} <- @@ -12,7 +12,15 @@ defmodule Web.Policies.Show do Flows.list_flows_for(policy, socket.assigns.subject, preload: [client: [:actor], gateway: [:group]] ) do - {:ok, assign(socket, policy: policy, flows: flows, page_title: "Policy")} + socket = + assign(socket, + policy: policy, + flows: flows, + page_title: "Policy", + flow_activities_enabled?: Config.flow_activities_enabled?() + ) + + {:ok, socket} else _other -> raise Web.LiveErrors.NotFoundError end @@ -120,7 +128,7 @@ defmodule Web.Policies.Show do (<%= flow.gateway_remote_ip %>) - <:col :let={flow} label="ACTIVITY"> + <:col :let={flow} :if={@flow_activities_enabled?} label="ACTIVITY"> <.link navigate={~p"/#{@account}/flows/#{flow.id}"} class={link_style()}> Show diff --git a/elixir/apps/web/lib/web/live/relays/show.ex b/elixir/apps/web/lib/web/live/relays/show.ex index ee7ff07b9..4ee27925e 100644 --- a/elixir/apps/web/lib/web/live/relays/show.ex +++ b/elixir/apps/web/lib/web/live/relays/show.ex @@ -1,11 +1,19 @@ defmodule Web.Relays.Show do use Web, :live_view - alias Domain.Relays + alias Domain.{Relays, Config} def mount(%{"id" => id}, _session, socket) do with {:ok, relay} <- Relays.fetch_relay_by_id(id, socket.assigns.subject, preload: :group) do :ok = Relays.subscribe_for_relays_presence_in_group(relay.group) + + socket = + assign( + socket, + relay: relay, + todos_enabled?: Config.todos_enabled?() + ) + {:ok, assign(socket, relay: relay)} else {:error, _reason} -> raise Web.LiveErrors.NotFoundError @@ -87,7 +95,7 @@ defmodule Web.Relays.Show do <%= @relay.last_seen_user_agent %> - <.vertical_table_row> + <.vertical_table_row :if={@todos_enabled?}> <:label>Deployment Method <:value>TODO: Docker diff --git a/elixir/apps/web/lib/web/live/resources/show.ex b/elixir/apps/web/lib/web/live/resources/show.ex index a7d140cc2..4bf1b816b 100644 --- a/elixir/apps/web/lib/web/live/resources/show.ex +++ b/elixir/apps/web/lib/web/live/resources/show.ex @@ -1,7 +1,7 @@ defmodule Web.Resources.Show do use Web, :live_view import Web.Policies.Components - alias Domain.{Resources, Flows} + alias Domain.{Resources, Flows, Config} def mount(%{"id" => id}, _session, socket) do with {:ok, resource} <- @@ -12,7 +12,15 @@ defmodule Web.Resources.Show do Flows.list_flows_for(resource, socket.assigns.subject, preload: [client: [:actor], gateway: [:group], policy: [:resource, :actor_group]] ) do - {:ok, assign(socket, resource: resource, flows: flows)} + socket = + assign( + socket, + resource: resource, + flows: flows, + todos_enabled?: Config.todos_enabled?() + ) + + {:ok, socket} else {:error, _reason} -> raise Web.LiveErrors.NotFoundError end