diff --git a/lib/livebook_web/live/hub/edit_live.ex b/lib/livebook_web/live/hub/edit_live.ex index c4b22ef27..1e2e8ac6b 100644 --- a/lib/livebook_web/live/hub/edit_live.ex +++ b/lib/livebook_web/live/hub/edit_live.ex @@ -13,13 +13,27 @@ defmodule LivebookWeb.Hub.EditLive do Hubs.Broadcasts.subscribe([:connection]) end - {:ok, assign(socket, hub: nil, type: nil, page_title: "Hub - Livebook", params: %{})} + {:ok, + assign(socket, + hub: nil, + counter: 0, + type: nil, + page_title: "Hub - Livebook", + params: %{} + )} end @impl true def handle_params(params, _url, socket) do {id, params} = Map.pop(params, "id") - {:noreply, socket |> load_hub(id) |> assign(:params, params)} + + {:noreply, + socket + |> load_hub(id) + # Hub-specific components load data, such as secrets and we use + # a counter to force re-render on every patch. + |> update(:counter, &(&1 + 1)) + |> assign(:params, params)} end @impl true @@ -30,7 +44,13 @@ defmodule LivebookWeb.Hub.EditLive do current_user={@current_user} saved_hubs={@saved_hubs} > - <.hub_component type={@type} hub={@hub} live_action={@live_action} params={@params} /> + <.hub_component + type={@type} + hub={@hub} + counter={@counter} + live_action={@live_action} + params={@params} + /> """ end @@ -41,6 +61,7 @@ defmodule LivebookWeb.Hub.EditLive do module={LivebookWeb.Hub.Edit.PersonalComponent} hub={@hub} params={@params} + counter={@counter} live_action={@live_action} id="personal-form" /> @@ -54,6 +75,7 @@ defmodule LivebookWeb.Hub.EditLive do hub={@hub} live_action={@live_action} params={@params} + counter={@counter} id="team-form" /> """ @@ -94,6 +116,7 @@ defmodule LivebookWeb.Hub.EditLive do defp load_hub(socket, id) do hub = Hubs.fetch_hub!(id) type = Provider.type(hub) + assign(socket, hub: hub, type: type) end end diff --git a/lib/livebook_web/live/hub/file_system_form_component.ex b/lib/livebook_web/live/hub/file_system_form_component.ex index d3790e5ff..ff155297a 100644 --- a/lib/livebook_web/live/hub/file_system_form_component.ex +++ b/lib/livebook_web/live/hub/file_system_form_component.ex @@ -125,7 +125,7 @@ defmodule LivebookWeb.Hub.FileSystemFormComponent do {:noreply, socket |> put_flash(:success, message) - |> push_redirect(to: socket.assigns.return_to)} + |> push_patch(to: socket.assigns.return_to)} else {:error, %Ecto.Changeset{} = changeset} -> {:noreply, assign(socket, changeset: changeset)} {:transport_error, message} -> {:noreply, assign(socket, error_message: message)} diff --git a/lib/livebook_web/live/hub/file_system_list_component.ex b/lib/livebook_web/live/hub/file_system_list_component.ex index 1208a1843..ab6b0418a 100644 --- a/lib/livebook_web/live/hub/file_system_list_component.ex +++ b/lib/livebook_web/live/hub/file_system_list_component.ex @@ -83,7 +83,7 @@ defmodule LivebookWeb.Hub.FileSystemListComponent do :ok -> socket |> put_flash(:success, "File storage deleted successfully") - |> push_navigate(to: ~p"/hub/#{hub.id}") + |> push_patch(to: ~p"/hub/#{hub.id}") {:transport_error, reason} -> put_flash(socket, :error, reason) diff --git a/lib/livebook_web/live/hub/secret_form_component.ex b/lib/livebook_web/live/hub/secret_form_component.ex index 164126ee2..9a2c6fb5b 100644 --- a/lib/livebook_web/live/hub/secret_form_component.ex +++ b/lib/livebook_web/live/hub/secret_form_component.ex @@ -96,7 +96,7 @@ defmodule LivebookWeb.Hub.SecretFormComponent do {:noreply, socket |> put_flash(:success, message) - |> push_redirect(to: socket.assigns.return_to)} + |> push_patch(to: socket.assigns.return_to)} else {:error, changeset} -> {:noreply, assign(socket, changeset: Map.replace!(changeset, :action, :validate))} diff --git a/lib/livebook_web/live/hub/secret_list_component.ex b/lib/livebook_web/live/hub/secret_list_component.ex index f9a6766df..8f6c792a3 100644 --- a/lib/livebook_web/live/hub/secret_list_component.ex +++ b/lib/livebook_web/live/hub/secret_list_component.ex @@ -97,7 +97,7 @@ defmodule LivebookWeb.Hub.SecretListComponent do :ok -> socket |> put_flash(:success, "Secret #{secret.name} deleted successfully") - |> push_navigate(to: attrs["return_to"]) + |> push_patch(to: attrs["return_to"]) {:transport_error, reason} -> put_flash(socket, :error, reason) diff --git a/lib/livebook_web/live/hub/teams/deployment_group_form_component.ex b/lib/livebook_web/live/hub/teams/deployment_group_form_component.ex index c1e887824..4334cf405 100644 --- a/lib/livebook_web/live/hub/teams/deployment_group_form_component.ex +++ b/lib/livebook_web/live/hub/teams/deployment_group_form_component.ex @@ -103,7 +103,7 @@ defmodule LivebookWeb.Hub.Teams.DeploymentGroupFormComponent do {:noreply, socket |> put_flash(:success, message) - |> push_redirect(to: ~p"/hub/#{socket.assigns.hub.id}/deployment-groups/edit/#{id}")} + |> push_patch(to: ~p"/hub/#{socket.assigns.hub.id}/deployment-groups/edit/#{id}")} else {:error, %Ecto.Changeset{} = changeset} -> {:noreply, assign(socket, changeset: changeset)} diff --git a/lib/livebook_web/live/hub/teams/deployment_group_list_component.ex b/lib/livebook_web/live/hub/teams/deployment_group_list_component.ex index bd94e1473..9a523fb19 100644 --- a/lib/livebook_web/live/hub/teams/deployment_group_list_component.ex +++ b/lib/livebook_web/live/hub/teams/deployment_group_list_component.ex @@ -82,7 +82,7 @@ defmodule LivebookWeb.Hub.Teams.DeploymentGroupListComponent do :ok -> socket |> put_flash(:success, "Deployment group #{deployment_group.name} deleted successfully") - |> push_navigate(to: ~p"/hub/#{hub.id}") + |> push_patch(to: ~p"/hub/#{hub.id}") {:transport_error, reason} -> put_flash(socket, :error, reason) diff --git a/test/livebook_teams/web/hub/edit_live_test.exs b/test/livebook_teams/web/hub/edit_live_test.exs index 08e034d4b..549f10ffc 100644 --- a/test/livebook_teams/web/hub/edit_live_test.exs +++ b/test/livebook_teams/web/hub/edit_live_test.exs @@ -100,12 +100,8 @@ defmodule LivebookWeb.Integration.Hub.EditLiveTest do |> render_submit(attrs) assert_receive {:secret_created, ^secret} - - %{"success" => "Secret TEAM_ADD_SECRET added successfully"} = - assert_redirect(view, "/hub/#{hub.id}") - - {:ok, view, _html} = live(conn, ~p"/hub/#{hub.id}") - + assert_patch(view, "/hub/#{hub.id}") + assert render(view) =~ "Secret TEAM_ADD_SECRET added successfully" assert render(element(view, "#hub-secrets-list")) =~ secret.name assert secret in Livebook.Hubs.get_secrets(hub) end @@ -148,11 +144,8 @@ defmodule LivebookWeb.Integration.Hub.EditLiveTest do updated_secret = %{secret | value: new_value} assert_receive {:secret_updated, ^updated_secret} - - %{"success" => "Secret TEAM_EDIT_SECRET updated successfully"} = - assert_redirect(view, "/hub/#{hub.id}") - - {:ok, view, _html} = live(conn, ~p"/hub/#{hub.id}") + assert_patch(view, "/hub/#{hub.id}") + assert render(view) =~ "Secret TEAM_EDIT_SECRET updated successfully" assert render(element(view, "#hub-secrets-list")) =~ secret.name assert updated_secret in Livebook.Hubs.get_secrets(hub) end @@ -174,11 +167,8 @@ defmodule LivebookWeb.Integration.Hub.EditLiveTest do render_confirm(view) assert_receive {:secret_deleted, ^secret} - - %{"success" => "Secret TEAM_DELETE_SECRET deleted successfully"} = - assert_redirect(view, "/hub/#{hub.id}") - - {:ok, view, _html} = live(conn, ~p"/hub/#{hub.id}") + assert_patch(view, "/hub/#{hub.id}") + assert render(view) =~ "Secret TEAM_DELETE_SECRET deleted successfully" refute render(element(view, "#hub-secrets-list")) =~ secret.name refute secret in Livebook.Hubs.get_secrets(hub) end @@ -221,12 +211,8 @@ defmodule LivebookWeb.Integration.Hub.EditLiveTest do |> render_submit(attrs) assert_receive {:file_system_created, %{id: ^id} = file_system} - - %{"success" => "File storage added successfully"} = - assert_redirect(view, "/hub/#{hub.id}") - - {:ok, view, _html} = live(conn, ~p"/hub/#{hub.id}") - + assert_patch(view, "/hub/#{hub.id}") + assert render(view) =~ "File storage added successfully" assert render(element(view, "#hub-file-systems-list")) =~ file_system.bucket_url assert file_system in Livebook.Hubs.get_file_systems(hub) end @@ -265,13 +251,10 @@ defmodule LivebookWeb.Integration.Hub.EditLiveTest do |> render_submit(put_in(attrs.file_system.access_key_id, "new key")) updated_file_system = %{file_system | access_key_id: "new key"} + assert_receive {:file_system_updated, ^updated_file_system} - - %{"success" => "File storage updated successfully"} = - assert_redirect(view, "/hub/#{hub.id}") - - {:ok, view, _html} = live(conn, ~p"/hub/#{hub.id}") - + assert_patch(view, "/hub/#{hub.id}") + assert render(view) =~ "File storage updated successfully" assert render(element(view, "#hub-file-systems-list")) =~ file_system.bucket_url assert updated_file_system in Livebook.Hubs.get_file_systems(hub) end @@ -297,12 +280,8 @@ defmodule LivebookWeb.Integration.Hub.EditLiveTest do render_confirm(view) assert_receive {:file_system_deleted, ^file_system} - - %{"success" => "File storage deleted successfully"} = - assert_redirect(view, "/hub/#{hub.id}") - - {:ok, view, _html} = live(conn, ~p"/hub/#{hub.id}") - + assert_patch(view, "/hub/#{hub.id}") + assert render(view) =~ "File storage deleted successfully" refute render(element(view, "#hub-file-systems-list")) =~ file_system.bucket_url refute file_system in Livebook.Hubs.get_file_systems(hub) end @@ -347,14 +326,11 @@ defmodule LivebookWeb.Integration.Hub.EditLiveTest do |> render_submit(attrs) assert_receive {:deployment_group_created, - %DeploymentGroup{name: "TEAM_ADD_DEPLOYMENT_GROUP"} = deployment_group} + %DeploymentGroup{id: id, name: "TEAM_ADD_DEPLOYMENT_GROUP"} = + deployment_group} - %{"success" => "Deployment group TEAM_ADD_DEPLOYMENT_GROUP added successfully"} = - assert_redirect(view, "/hub/#{hub.id}/deployment-groups/edit/#{deployment_group.id}") - - {:ok, view, _html} = live(conn, ~p"/hub/#{hub.id}") - - assert render(element(view, "#hub-deployment-groups-list")) =~ deployment_group.name + assert_patch(view, "/hub/#{hub.id}/deployment-groups/edit/#{id}") + assert render(view) =~ "Deployment group TEAM_ADD_DEPLOYMENT_GROUP added successfully" assert deployment_group in Livebook.Teams.get_deployment_groups(hub) end @@ -408,13 +384,8 @@ defmodule LivebookWeb.Integration.Hub.EditLiveTest do updated_deployment_group = %{deployment_group | mode: new_mode} assert_receive {:deployment_group_updated, ^updated_deployment_group} - - %{"success" => "Deployment group TEAM_EDIT_DEPLOYMENT_GROUP updated successfully"} = - assert_redirect(view, "/hub/#{hub.id}/deployment-groups/edit/#{deployment_group.id}") - - {:ok, view, _html} = live(conn, ~p"/hub/#{hub.id}") - assert render(element(view, "#hub-deployment-groups-list")) =~ deployment_group.name - + assert_patch(view, "/hub/#{hub.id}/deployment-groups/edit/#{deployment_group.id}") + assert render(view) =~ "Deployment group TEAM_EDIT_DEPLOYMENT_GROUP updated successfully" assert updated_deployment_group in Livebook.Teams.get_deployment_groups(hub) end @@ -443,10 +414,8 @@ defmodule LivebookWeb.Integration.Hub.EditLiveTest do assert_receive {:deployment_group_deleted, %DeploymentGroup{name: "TEAM_DELETE_DEPLOYMENT_GROUP"}} - %{"success" => "Deployment group TEAM_DELETE_DEPLOYMENT_GROUP deleted successfully"} = - assert_redirect(view, "/hub/#{hub.id}") - - {:ok, view, _html} = live(conn, ~p"/hub/#{hub.id}") + assert_patch(view, "/hub/#{hub.id}") + assert render(view) =~ "Deployment group TEAM_DELETE_DEPLOYMENT_GROUP deleted successfully" refute render(element(view, "#hub-deployment-groups-list")) =~ deployment_group.name refute deployment_group in Livebook.Teams.get_deployment_groups(hub) end diff --git a/test/livebook_web/live/hub/edit_live_test.exs b/test/livebook_web/live/hub/edit_live_test.exs index 208baa718..ec8040615 100644 --- a/test/livebook_web/live/hub/edit_live_test.exs +++ b/test/livebook_web/live/hub/edit_live_test.exs @@ -81,12 +81,8 @@ defmodule LivebookWeb.Hub.EditLiveTest do |> render_submit(attrs) assert_receive {:secret_created, ^secret} - - %{"success" => "Secret PERSONAL_ADD_SECRET added successfully"} = - assert_redirect(view, "/hub/#{hub.id}") - - {:ok, view, _html} = live(conn, ~p"/hub/#{hub.id}") - + assert_patch(view, "/hub/#{hub.id}") + assert render(view) =~ "Secret PERSONAL_ADD_SECRET added successfully" assert render(element(view, "#hub-secrets-list")) =~ secret.name assert secret in Livebook.Hubs.get_secrets(hub) end @@ -128,11 +124,8 @@ defmodule LivebookWeb.Hub.EditLiveTest do updated_secret = %{secret | value: new_value} assert_receive {:secret_updated, ^updated_secret} - - %{"success" => "Secret PERSONAL_EDIT_SECRET updated successfully"} = - assert_redirect(view, "/hub/#{hub.id}") - - {:ok, view, _html} = live(conn, ~p"/hub/#{hub.id}") + assert_patch(view, "/hub/#{hub.id}") + assert render(view) =~ "Secret PERSONAL_EDIT_SECRET updated successfully" assert render(element(view, "#hub-secrets-list")) =~ secret.name assert updated_secret in Livebook.Hubs.get_secrets(hub) end @@ -153,11 +146,8 @@ defmodule LivebookWeb.Hub.EditLiveTest do render_confirm(view) assert_receive {:secret_deleted, ^secret} - - %{"success" => "Secret PERSONAL_DELETE_SECRET deleted successfully"} = - assert_redirect(view, "/hub/#{hub.id}") - - {:ok, view, _html} = live(conn, ~p"/hub/#{hub.id}") + assert_patch(view, "/hub/#{hub.id}") + assert render(view) =~ "Secret PERSONAL_DELETE_SECRET deleted successfully" refute render(element(view, "#hub-secrets-list")) =~ secret.name refute secret in Livebook.Hubs.get_secrets(hub) end @@ -194,12 +184,8 @@ defmodule LivebookWeb.Hub.EditLiveTest do |> render_submit(attrs) assert_receive {:file_system_created, ^file_system} - - %{"success" => "File storage added successfully"} = - assert_redirect(view, "/hub/#{hub.id}") - - {:ok, view, _html} = live(conn, ~p"/hub/#{hub.id}") - + assert_patch(view, "/hub/#{hub.id}") + assert render(view) =~ "File storage added successfully" assert render(element(view, "#hub-file-systems-list")) =~ file_system.bucket_url assert file_system in Livebook.Hubs.get_file_systems(hub) end @@ -235,13 +221,10 @@ defmodule LivebookWeb.Hub.EditLiveTest do |> render_submit(put_in(attrs.file_system.access_key_id, "new key")) updated_file_system = %{file_system | access_key_id: "new key"} + assert_receive {:file_system_updated, ^updated_file_system} - - %{"success" => "File storage updated successfully"} = - assert_redirect(view, "/hub/#{hub.id}") - - {:ok, view, _html} = live(conn, ~p"/hub/#{hub.id}") - + assert_patch(view, "/hub/#{hub.id}") + assert render(view) =~ "File storage updated successfully" assert render(element(view, "#hub-file-systems-list")) =~ file_system.bucket_url assert updated_file_system in Livebook.Hubs.get_file_systems(hub) end @@ -265,11 +248,8 @@ defmodule LivebookWeb.Hub.EditLiveTest do assert_receive {:file_system_deleted, ^file_system} - %{"success" => "File storage deleted successfully"} = - assert_redirect(view, "/hub/#{hub.id}") - - {:ok, view, _html} = live(conn, ~p"/hub/#{hub.id}") - + assert_patch(view, "/hub/#{hub.id}") + assert render(view) =~ "File storage deleted successfully" refute render(element(view, "#hub-file-systems-list")) =~ file_system.bucket_url refute file_system in Livebook.Hubs.get_file_systems(hub) end