2021-04-02 20:00:49 +08:00
|
|
|
defmodule LivebookWeb.SessionLive.SectionComponent do
|
2021-03-04 05:56:28 +08:00
|
|
|
use LivebookWeb, :live_component
|
2021-02-11 23:35:32 +08:00
|
|
|
|
|
|
|
def render(assigns) do
|
2021-07-07 20:32:49 +08:00
|
|
|
~H"""
|
2021-11-17 04:57:10 +08:00
|
|
|
<section data-element="section" data-section-id={@section_view.id}>
|
|
|
|
<div class="flex space-x-4 items-center"
|
|
|
|
data-element="section-headline"
|
|
|
|
id={@section_view.id}
|
|
|
|
data-focusable-id={@section_view.id}
|
|
|
|
phx-hook="Headline"
|
|
|
|
data-on-value-change="set_section_name"
|
|
|
|
data-metadata={@section_view.id}>
|
2021-12-30 05:06:19 +08:00
|
|
|
<h2 class="grow text-gray-800 font-semibold text-2xl px-1 -ml-1 rounded-lg border border-transparent whitespace-pre-wrap cursor-text"
|
2021-11-17 04:57:10 +08:00
|
|
|
tabindex="0"
|
2021-07-07 20:32:49 +08:00
|
|
|
id={@section_view.html_id}
|
2021-11-17 04:57:10 +08:00
|
|
|
data-element="heading"
|
|
|
|
spellcheck="false"><%= @section_view.name %></h2>
|
|
|
|
<div class="flex space-x-2 items-center" data-element="section-actions"
|
|
|
|
role="toolbar"
|
|
|
|
aria-label="section actions">
|
2021-11-02 01:20:56 +08:00
|
|
|
<span class="tooltip top" data-tooltip="Link">
|
|
|
|
<a href={"##{@section_view.html_id}"} class="icon-button" aria-label="link to section">
|
2021-07-07 20:32:49 +08:00
|
|
|
<.remix_icon icon="link" class="text-xl" />
|
2021-04-26 21:24:43 +08:00
|
|
|
</a>
|
|
|
|
</span>
|
2021-07-16 00:19:36 +08:00
|
|
|
<%= if @section_view.valid_parents != [] and not @section_view.has_children? do %>
|
2021-11-11 02:28:09 +08:00
|
|
|
<.menu id={"section-#{@section_view.id}-branch-menu"}>
|
|
|
|
<:toggle>
|
|
|
|
<span class="tooltip top" data-tooltip="Branch out from">
|
2021-11-17 04:57:10 +08:00
|
|
|
<button class="icon-button" aria-label="branch out from other section">
|
2021-11-11 02:28:09 +08:00
|
|
|
<.remix_icon icon="git-branch-line" class="text-xl flip-horizontally" />
|
|
|
|
</button>
|
|
|
|
</span>
|
|
|
|
</:toggle>
|
|
|
|
<:content>
|
2021-07-16 00:19:36 +08:00
|
|
|
<%= for parent <- @section_view.valid_parents do %>
|
|
|
|
<%= if @section_view.parent && @section_view.parent.id == parent.id do %>
|
2021-11-11 02:28:09 +08:00
|
|
|
<button class="menu-item text-gray-900"
|
2021-07-16 00:19:36 +08:00
|
|
|
phx-click="unset_section_parent"
|
|
|
|
phx-value-section_id={@section_view.id}>
|
|
|
|
<.remix_icon icon="arrow-right-s-line" />
|
|
|
|
<span class="font-medium"><%= parent.name %></span>
|
|
|
|
</button>
|
|
|
|
<% else %>
|
2022-01-18 22:12:09 +08:00
|
|
|
<button class="menu-item text-gray-500 bg-gray-50"
|
2021-07-16 00:19:36 +08:00
|
|
|
phx-click="set_section_parent"
|
|
|
|
phx-value-section_id={@section_view.id}
|
|
|
|
phx-value-parent_id={parent.id}>
|
2022-01-18 22:12:09 +08:00
|
|
|
<%= if @section_view.parent && @section_view.parent.id do %>
|
|
|
|
<.remix_icon icon="arrow-right-s-line" class="invisible" />
|
|
|
|
<% end %>
|
2021-07-16 00:19:36 +08:00
|
|
|
<span class="font-medium"><%= parent.name %></span>
|
|
|
|
</button>
|
|
|
|
<% end %>
|
|
|
|
<% end %>
|
2021-11-11 02:28:09 +08:00
|
|
|
</:content>
|
|
|
|
</.menu>
|
2021-07-16 00:19:36 +08:00
|
|
|
<% end %>
|
2021-11-02 01:20:56 +08:00
|
|
|
<span class="tooltip top" data-tooltip="Move up">
|
2021-04-20 18:12:29 +08:00
|
|
|
<button class="icon-button"
|
2021-11-02 01:20:56 +08:00
|
|
|
aria-label="move section up"
|
2021-04-20 18:12:29 +08:00
|
|
|
phx-click="move_section"
|
2021-07-07 20:32:49 +08:00
|
|
|
phx-value-section_id={@section_view.id}
|
2021-04-20 18:12:29 +08:00
|
|
|
phx-value-offset="-1">
|
2021-07-07 20:32:49 +08:00
|
|
|
<.remix_icon icon="arrow-up-s-line" class="text-xl" />
|
2021-04-20 18:12:29 +08:00
|
|
|
</button>
|
|
|
|
</span>
|
2021-11-02 01:20:56 +08:00
|
|
|
<span class="tooltip top" data-tooltip="Move down">
|
2021-04-20 18:12:29 +08:00
|
|
|
<button class="icon-button"
|
2021-11-02 01:20:56 +08:00
|
|
|
aria-label="move section down"
|
2021-04-20 18:12:29 +08:00
|
|
|
phx-click="move_section"
|
2021-07-07 20:32:49 +08:00
|
|
|
phx-value-section_id={@section_view.id}
|
2021-04-20 18:12:29 +08:00
|
|
|
phx-value-offset="1">
|
2021-07-07 20:32:49 +08:00
|
|
|
<.remix_icon icon="arrow-down-s-line" class="text-xl" />
|
2021-04-20 18:12:29 +08:00
|
|
|
</button>
|
|
|
|
</span>
|
2021-11-17 04:57:10 +08:00
|
|
|
<span
|
|
|
|
{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"]}>
|
2021-12-28 01:42:27 +08:00
|
|
|
<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}>
|
2021-10-21 00:10:11 +08:00
|
|
|
<.remix_icon icon="delete-bin-6-line" class="text-xl" />
|
2021-12-28 01:42:27 +08:00
|
|
|
</button>
|
2021-10-21 00:10:11 +08:00
|
|
|
</span>
|
2021-02-11 23:35:32 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-07-16 00:19:36 +08:00
|
|
|
<%= if @section_view.parent do %>
|
|
|
|
<h3 class="mt-1 flex items-end space-x-1 text-sm font-semibold text-gray-800">
|
2021-11-02 01:20:56 +08:00
|
|
|
<span class="tooltip bottom" data-tooltip={"This section branches out from the main flow\nand can be evaluated in parallel"}>
|
2021-07-16 00:19:36 +08:00
|
|
|
<.remix_icon icon="git-branch-line" class="text-lg font-normal flip-horizontally leading-none" />
|
|
|
|
</span>
|
|
|
|
<span class="leading-none">from ”<%= @section_view.parent.name %>”</span>
|
|
|
|
</h3>
|
|
|
|
<% end %>
|
2021-03-30 18:35:11 +08:00
|
|
|
<div class="container">
|
2021-03-20 21:10:15 +08:00
|
|
|
<div class="flex flex-col space-y-1">
|
2021-11-17 04:57:10 +08:00
|
|
|
<.live_component module={LivebookWeb.SessionLive.InsertButtonsComponent}
|
|
|
|
id={"#{@section_view.id}:first"}
|
|
|
|
persistent={@section_view.cell_views == []}
|
|
|
|
section_id={@section_view.id}
|
|
|
|
cell_id={nil} />
|
2021-03-26 06:29:22 +08:00
|
|
|
<%= for {cell_view, index} <- Enum.with_index(@section_view.cell_views) do %>
|
2021-11-02 02:33:43 +08:00
|
|
|
<.live_component module={LivebookWeb.SessionLive.CellComponent}
|
|
|
|
id={cell_view.id}
|
|
|
|
session_id={@session_id}
|
|
|
|
runtime={@runtime}
|
|
|
|
cell_view={cell_view} />
|
2021-11-17 04:57:10 +08:00
|
|
|
<.live_component module={LivebookWeb.SessionLive.InsertButtonsComponent}
|
|
|
|
id={"#{@section_view.id}:#{index}"}
|
|
|
|
persistent={false}
|
|
|
|
section_id={@section_view.id}
|
|
|
|
cell_id={cell_view.id} />
|
2021-03-25 01:37:50 +08:00
|
|
|
<% end %>
|
2021-02-11 23:35:32 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-11-17 04:57:10 +08:00
|
|
|
</section>
|
2021-02-11 23:35:32 +08:00
|
|
|
"""
|
|
|
|
end
|
|
|
|
end
|