2021-06-29 05:46:50 +08:00
|
|
|
defmodule LivebookWeb.SessionLive.DeleteSectionComponent do
|
|
|
|
use LivebookWeb, :live_component
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def render(assigns) do
|
2021-07-07 20:32:49 +08:00
|
|
|
~H"""
|
2022-09-01 05:53:23 +08:00
|
|
|
<div class="p-6 flex flex-col space-y-8">
|
2021-06-29 05:46:50 +08:00
|
|
|
<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>?
|
2021-06-29 05:46:50 +08:00
|
|
|
</p>
|
2021-07-07 20:32:49 +08:00
|
|
|
<form phx-submit="delete" phx-target={@myself}>
|
2021-06-29 05:46:50 +08:00
|
|
|
<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 %>
|
2021-07-07 20:32:49 +08:00
|
|
|
<.switch_checkbox
|
|
|
|
name="delete_cells"
|
|
|
|
label="Delete all cells in this section"
|
|
|
|
checked={@is_first}
|
2022-08-02 21:51:02 +08:00
|
|
|
disabled={@is_first}
|
|
|
|
/>
|
2021-06-29 05:46:50 +08:00
|
|
|
<div class="mt-8 flex justify-end space-x-2">
|
2021-12-04 04:57:21 +08:00
|
|
|
<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
|
2021-06-29 05:46:50 +08:00
|
|
|
</button>
|
2022-08-02 21:51:02 +08:00
|
|
|
<%= live_patch("Cancel", to: @return_to, class: "button-base button-outlined-gray") %>
|
2021-06-29 05:46:50 +08:00
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
|
|
|
@impl true
|
2021-07-27 01:59:52 +08:00
|
|
|
def handle_event("delete", %{"delete_cells" => delete_cells}, socket) do
|
|
|
|
delete_cells? = delete_cells == "true"
|
2021-06-29 05:46:50 +08:00
|
|
|
|
|
|
|
Livebook.Session.delete_section(
|
2021-09-05 01:16:01 +08:00
|
|
|
socket.assigns.session.pid,
|
2021-06-29 05:46:50 +08:00
|
|
|
socket.assigns.section.id,
|
|
|
|
delete_cells?
|
|
|
|
)
|
|
|
|
|
2021-12-08 20:17:50 +08:00
|
|
|
{:noreply, push_patch(socket, to: socket.assigns.return_to, replace: true)}
|
2021-06-29 05:46:50 +08:00
|
|
|
end
|
|
|
|
end
|