diff --git a/lib/livebook_web/live/session_live.ex b/lib/livebook_web/live/session_live.ex index 09f1daa8ecb..62325aad803 100644 --- a/lib/livebook_web/live/session_live.ex +++ b/lib/livebook_web/live/session_live.ex @@ -664,6 +664,31 @@ defmodule LivebookWeb.SessionLive do {:noreply, socket} end + def handle_event("delete_section", %{"section_id" => section_id}, socket) do + socket = + case Notebook.fetch_section(socket.private.data.notebook, section_id) do + {:ok, %{cells: []} = section} -> + Session.delete_section(socket.assigns.session.pid, section.id, true) + socket + + {:ok, section} -> + push_patch(socket, + to: + Routes.session_path( + socket, + :delete_section, + socket.assigns.session.id, + section.id + ) + ) + + :error -> + socket + end + + {:noreply, socket} + end + def handle_event("queue_cell_evaluation", %{"cell_id" => cell_id}, socket) do Session.queue_cell_evaluation(socket.assigns.session.pid, cell_id) diff --git a/lib/livebook_web/live/session_live/section_component.ex b/lib/livebook_web/live/session_live/section_component.ex index b0ee4220913..ec1dfe088ab 100644 --- a/lib/livebook_web/live/session_live/section_component.ex +++ b/lib/livebook_web/live/session_live/section_component.ex @@ -77,12 +77,12 @@ defmodule LivebookWeb.SessionLive.SectionComponent do {if @section_view.has_children?, do: [class: "tooltip left", data_tooltip: "Cannot delete this section because\nother sections branch from it"], else: [class: "tooltip top", data_tooltip: "Delete"]}> - <%= live_patch to: Routes.session_path(@socket, :delete_section, @session_id, @section_view.id), - class: "icon-button #{if @section_view.has_children?, do: "disabled"}", - aria_label: "delete section", - role: "button" do %> +