defmodule LivebookWeb.SessionLive.InsertButtonsComponent do use LivebookWeb, :live_component def render(assigns) do ~H""" """ end defp smart_cell_insert_button(%{definition: %{requirement: %{variants: [_, _ | _]}}} = assigns) do ~H""" <.submenu> <:content> <%= for {variant, idx} <- Enum.with_index(@definition.requirement.variants) do %> <% end %> """ end defp smart_cell_insert_button(assigns) do ~H""" """ end defp on_smart_cell_click(%{requirement: nil} = definition, _variant_idx, section_id, cell_id) do insert_smart_cell(definition, section_id, cell_id) end defp on_smart_cell_click(%{requirement: %{}} = definition, variant_idx, section_id, cell_id) do variant = Enum.fetch!(definition.requirement.variants, variant_idx) with_confirm( JS.push("add_smart_cell_dependencies", value: %{kind: definition.kind, variant_idx: variant_idx} ) |> insert_smart_cell(definition, section_id, cell_id) |> JS.push("queue_cells_reevaluation"), title: "Add packages", description: case variant.packages do [%{name: name}] -> ~s''' The “#{definition.name}“ smart cell requires the #{code_tag(name)} package. Do you want to add it as a dependency and restart? ''' packages -> ~s''' The “#{definition.name}“ smart cell requires the #{packages |> Enum.map(&code_tag(&1.name)) |> format_items()} packages. Do you want to add them as dependencies and restart? ''' end, confirm_text: "Add and restart", confirm_icon: "add-line", danger: false, html: true ) end defp code_tag(text), do: "#{text}" defp insert_smart_cell(js \\ %JS{}, definition, section_id, cell_id) do JS.push(js, "insert_cell_below", value: %{ type: "smart", kind: definition.kind, section_id: section_id, cell_id: cell_id } ) end end