Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove delete prompt for empty sections #829

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions lib/livebook_web/live/session_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,32 @@ 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, section} ->
if section.cells == [] do
jonatanklosko marked this conversation as resolved.
Show resolved Hide resolved
Session.delete_section(socket.assigns.session.pid, section_id, true)
socket
else
push_patch(socket,
to:
Routes.session_path(
socket,
:delete_section,
socket.assigns.session.id,
section.id
)
)
end

: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)

Expand Down
10 changes: 5 additions & 5 deletions lib/livebook_web/live/session_live/section_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
<button class={"icon-button #{if @section_view.has_children?, do: "disabled"}"}
aria-label="delete section"
phx-click="delete_section"
phx-value-section_id={@section_view.id}>
<.remix_icon icon="delete-bin-6-line" class="text-xl" />
<% end %>
</button>
</span>
</div>
</div>
Expand Down