livebook/lib/livebook_web/live/session_live/delete_section_component.ex

51 lines
1.6 KiB
Elixir
Raw Normal View History

defmodule LivebookWeb.SessionLive.DeleteSectionComponent do
use LivebookWeb, :live_component
@impl true
def render(assigns) do
~H"""
<div class="p-6 flex flex-col space-y-8">
<h3 class="text-2xl font-semibold text-gray-800">
Delete section
</h3>
<p class="text-gray-700">
2022-08-02 21:51:02 +08:00
Are you sure you want to delete this section - <span class="font-semibold"><%= @section.name %></span>?
</p>
<form phx-submit="delete" phx-target={@myself}>
<h3 class="mb-1 text-lg font-semibold text-gray-800">
Options
</h3>
2022-08-02 21:51:02 +08:00
<% # If there is no previous section, all cells need to be deleted %>
2023-02-23 02:34:54 +08:00
<.switch_field
name="delete_cells"
label="Delete all cells in this section"
2023-02-23 02:34:54 +08:00
value={@is_first}
2022-08-02 21:51:02 +08:00
disabled={@is_first}
/>
<div class="mt-8 flex justify-end space-x-2">
<button type="submit" class="button-base button-red">
2022-08-02 21:51:02 +08:00
<.remix_icon icon="delete-bin-6-line" class="align-middle mr-1" /> Delete
</button>
2023-02-23 02:34:54 +08:00
<.link patch={@return_to} class="button-base button-outlined-gray">
Cancel
</.link>
</div>
</form>
</div>
"""
end
@impl true
def handle_event("delete", %{"delete_cells" => delete_cells}, socket) do
delete_cells? = delete_cells == "true"
Livebook.Session.delete_section(
socket.assigns.session.pid,
socket.assigns.section.id,
delete_cells?
)
{:noreply, push_patch(socket, to: socket.assigns.return_to, replace: true)}
end
end