defmodule LivebookWeb.SessionLive.CodeCellSettingsComponent do use LivebookWeb, :live_component alias Livebook.Session @impl true def update(assigns, socket) do cell = assigns.cell socket = socket |> assign(assigns) |> assign_new(:output_size, fn -> cell.output_size end) |> assign_new(:output_size_options, fn -> for %{name: label, size: value} <- Livebook.Notebook.Cell.output_sizes() do {label, value} end end) |> assign_new(:reevaluate_automatically, fn -> cell.reevaluate_automatically end) |> assign_new(:continue_on_error, fn -> cell.continue_on_error end) {:ok, socket} end @impl true def render(assigns) do ~H"""

Cell settings

<.switch_field name="reevaluate_automatically" label="Reevaluate automatically" value={@reevaluate_automatically} /> <.switch_field name="continue_on_error" label="Continue on error" value={@continue_on_error} />
Cell output size <.select_field id="cell-output-size" name="output_size" aria-label="cell output size" value={@output_size} options={@output_size_options} />
<.button type="submit"> Save <.button color="gray" outlined patch={@return_to}> Cancel
""" end @impl true def handle_event( "save", %{ "output_size" => output_size, "reevaluate_automatically" => reevaluate_automatically, "continue_on_error" => continue_on_error }, socket ) do reevaluate_automatically = reevaluate_automatically == "true" continue_on_error = continue_on_error == "true" output_size = case output_size do "default" -> :default "wide" -> :wide "full" -> :full end Session.set_cell_attributes(socket.assigns.session.pid, socket.assigns.cell.id, %{ output_size: output_size, reevaluate_automatically: reevaluate_automatically, continue_on_error: continue_on_error }) {:noreply, push_patch(socket, to: socket.assigns.return_to)} end end