mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-09-11 23:44:23 +08:00
Implements delete hub button (#1705)
This commit is contained in:
parent
8c9c3ce94d
commit
d0e83dc288
4 changed files with 55 additions and 3 deletions
|
@ -88,7 +88,10 @@ defmodule Livebook.Hubs do
|
||||||
struct
|
struct
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc false
|
@doc """
|
||||||
|
Deletes a hub with the given id.
|
||||||
|
"""
|
||||||
|
@spec delete_hub(String.t()) :: :ok
|
||||||
def delete_hub(id) do
|
def delete_hub(id) do
|
||||||
with {:ok, hub} <- get_hub(id) do
|
with {:ok, hub} <- get_hub(id) do
|
||||||
:ok = Broadcasts.hub_changed()
|
:ok = Broadcasts.hub_changed()
|
||||||
|
|
|
@ -44,8 +44,23 @@ defmodule LivebookWeb.Hub.EditLive do
|
||||||
saved_hubs={@saved_hubs}
|
saved_hubs={@saved_hubs}
|
||||||
>
|
>
|
||||||
<div class="p-4 md:px-12 md:py-7 max-w-screen-md mx-auto space-y-8">
|
<div class="p-4 md:px-12 md:py-7 max-w-screen-md mx-auto space-y-8">
|
||||||
<div>
|
<div class="flex relative">
|
||||||
<PageHelpers.title text="Edit Hub" socket={@socket} />
|
<PageHelpers.title text="Edit Hub" socket={@socket} />
|
||||||
|
|
||||||
|
<button
|
||||||
|
phx-click={
|
||||||
|
with_confirm(
|
||||||
|
JS.push("delete_hub", value: %{id: @hub.id}),
|
||||||
|
title: "Delete hub",
|
||||||
|
description: "Are you sure you want to delete this hub?",
|
||||||
|
confirm_text: "Delete",
|
||||||
|
confirm_icon: "close-circle-line"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
class="absolute right-0 button-base bg-red-500"
|
||||||
|
>
|
||||||
|
Delete hub
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= if @type == "fly" do %>
|
<%= if @type == "fly" do %>
|
||||||
|
@ -69,4 +84,14 @@ defmodule LivebookWeb.Hub.EditLive do
|
||||||
</LayoutHelpers.layout>
|
</LayoutHelpers.layout>
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def handle_event("delete_hub", %{"id" => id}, socket) do
|
||||||
|
Hubs.delete_hub(id)
|
||||||
|
|
||||||
|
{:noreply,
|
||||||
|
socket
|
||||||
|
|> put_flash(:success, "Hub deleted successfully")
|
||||||
|
|> push_redirect(to: "/")}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -264,7 +264,7 @@ defmodule LivebookWeb.LayoutHelpers do
|
||||||
"h-7 flex items-center hover:text-white #{text_color} border-l-4 #{border_color} hover:border-white"
|
"h-7 flex items-center hover:text-white #{text_color} border-l-4 #{border_color} hover:border-white"
|
||||||
|
|
||||||
if tooltip = Provider.connection_error(hub) do
|
if tooltip = Provider.connection_error(hub) do
|
||||||
[to: to, data_tooltip: tooltip, class: "tooltip top " <> class]
|
[to: to, data_tooltip: tooltip, class: "tooltip right " <> class]
|
||||||
else
|
else
|
||||||
[to: to, class: class]
|
[to: to, class: class]
|
||||||
end
|
end
|
||||||
|
|
|
@ -63,6 +63,30 @@ defmodule LivebookWeb.Hub.EditLiveTest do
|
||||||
refute Hubs.fetch_hub!(hub.id) == hub
|
refute Hubs.fetch_hub!(hub.id) == hub
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "deletes hub", %{conn: conn, bypass: bypass} do
|
||||||
|
{:ok, pid} = Agent.start(fn -> %{fun: &fetch_app_response/2, type: :mount} end)
|
||||||
|
app_id = Livebook.Utils.random_short_id()
|
||||||
|
hub_id = "fly-#{app_id}"
|
||||||
|
|
||||||
|
hub = insert_hub(:fly, id: hub_id, application_id: app_id)
|
||||||
|
fly_bypass(bypass, app_id, pid)
|
||||||
|
|
||||||
|
{:ok, view, html} = live(conn, Routes.hub_path(conn, :edit, hub.id))
|
||||||
|
|
||||||
|
assert {:ok, view, _html} =
|
||||||
|
view
|
||||||
|
|> render_click("delete_hub", %{"id" => hub_id})
|
||||||
|
|> follow_redirect(conn)
|
||||||
|
|
||||||
|
hubs_html = view |> element("#hubs") |> render()
|
||||||
|
|
||||||
|
refute hubs_html =~ hub.hub_emoji
|
||||||
|
refute hubs_html =~ Routes.hub_path(conn, :edit, hub.id)
|
||||||
|
refute hubs_html =~ hub.hub_name
|
||||||
|
|
||||||
|
assert Hubs.get_hub(hub_id) == :error
|
||||||
|
end
|
||||||
|
|
||||||
test "add env var", %{conn: conn, bypass: bypass} do
|
test "add env var", %{conn: conn, bypass: bypass} do
|
||||||
{:ok, pid} = Agent.start(fn -> %{fun: &fetch_app_response/2, type: :mount} end)
|
{:ok, pid} = Agent.start(fn -> %{fun: &fetch_app_response/2, type: :mount} end)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue