defmodule LivebookWeb.SessionLive.InputCellSettingsComponent do use LivebookWeb, :live_component alias Livebook.Session @impl true def update(assigns, socket) do cell = assigns.cell socket = socket |> assign(assigns) |> assign_new(:name, fn -> cell.name end) |> assign_new(:type, fn -> cell.type end) {:ok, socket} end @impl true def render(assigns) do ~L"""

Cell settings

Name
<%= render_radios("type", [text: "Text", url: "URL", number: "Number", password: "Password"], @type) %>
<%= live_patch "Cancel", to: @return_to, class: "button button-outlined-gray" %> <%= content_tag :button, "Save", type: :submit, class: "button button-blue", disabled: @name == "" %>
""" end @impl true def handle_event("validate", %{"name" => name, "type" => type}, socket) do type = String.to_existing_atom(type) {:noreply, assign(socket, name: name, type: type)} end def handle_event("save", %{"name" => name, "type" => type}, socket) do type = String.to_existing_atom(type) attrs = %{name: name, type: type} Session.set_cell_attributes(socket.assigns.session_id, socket.assigns.cell.id, attrs) {:noreply, push_patch(socket, to: socket.assigns.return_to)} end end