defmodule LivebookWeb.SessionLive.CellSettingsComponent do
use LivebookWeb, :live_component
alias Livebook.Session
@impl true
def update(assigns, socket) do
metadata = assigns.cell.metadata
assigns =
Map.merge(assigns, %{disable_formatting: Map.get(metadata, "disable_formatting", false)})
{:ok, assign(socket, assigns)}
end
@impl true
def render(assigns) do
~L"""
"""
end
@impl true
def handle_event("save", params, socket) do
metadata = update_metadata(socket.assigns.cell.metadata, params)
Session.set_cell_metadata(socket.assigns.session_id, socket.assigns.cell.id, metadata)
{:noreply, push_patch(socket, to: socket.assigns.return_to)}
end
defp update_metadata(metadata, form_data) do
if Map.has_key?(form_data, "disable_formatting") do
Map.put(metadata, "disable_formatting", true)
else
Map.delete(metadata, "disable_formatting")
end
end
end