mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-01-11 01:18:12 +08:00
Fix frame rendering (#735)
* Fix frame rendering * Add test for the dynamic frame
This commit is contained in:
parent
6de1dd84c2
commit
ac6b423e79
5 changed files with 61 additions and 7 deletions
|
@ -642,8 +642,8 @@ defmodule Livebook.Session do
|
|||
{:noreply, state}
|
||||
end
|
||||
|
||||
def handle_info({:evaluation_output, cell_id, string}, state) do
|
||||
operation = {:add_cell_evaluation_output, self(), cell_id, string}
|
||||
def handle_info({:evaluation_output, cell_id, output}, state) do
|
||||
operation = {:add_cell_evaluation_output, self(), cell_id, output}
|
||||
{:noreply, handle_operation(state, operation)}
|
||||
end
|
||||
|
||||
|
|
|
@ -99,10 +99,20 @@ defmodule LivebookWeb.Output do
|
|||
)
|
||||
end
|
||||
|
||||
defp render_output({:frame_dynamic, pid}, %{id: id, socket: socket, input_values: input_values}) do
|
||||
defp render_output({:frame_dynamic, pid}, %{
|
||||
id: id,
|
||||
socket: socket,
|
||||
input_values: input_values,
|
||||
cell_validity_status: cell_validity_status
|
||||
}) do
|
||||
live_render(socket, LivebookWeb.Output.FrameDynamicLive,
|
||||
id: id,
|
||||
session: %{"id" => id, "pid" => pid, "input_values" => input_values}
|
||||
session: %{
|
||||
"id" => id,
|
||||
"pid" => pid,
|
||||
"input_values" => input_values,
|
||||
"cell_validity_status" => cell_validity_status
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -2,12 +2,27 @@ defmodule LivebookWeb.Output.FrameDynamicLive do
|
|||
use LivebookWeb, :live_view
|
||||
|
||||
@impl true
|
||||
def mount(_params, %{"pid" => pid, "id" => id, "input_values" => input_values}, socket) do
|
||||
def mount(
|
||||
_params,
|
||||
%{
|
||||
"pid" => pid,
|
||||
"id" => id,
|
||||
"input_values" => input_values,
|
||||
"cell_validity_status" => cell_validity_status
|
||||
},
|
||||
socket
|
||||
) do
|
||||
if connected?(socket) do
|
||||
send(pid, {:connect, self()})
|
||||
end
|
||||
|
||||
{:ok, assign(socket, id: id, output: nil, input_values: input_values)}
|
||||
{:ok,
|
||||
assign(socket,
|
||||
id: id,
|
||||
output: nil,
|
||||
input_values: input_values,
|
||||
cell_validity_status: cell_validity_status
|
||||
)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
|
@ -20,7 +35,8 @@ defmodule LivebookWeb.Output.FrameDynamicLive do
|
|||
id={"#{@id}-frame"}
|
||||
socket={@socket}
|
||||
runtime={nil}
|
||||
input_values={@input_values} />
|
||||
input_values={@input_values}
|
||||
cell_validity_status={@cell_validity_status} />
|
||||
<% else %>
|
||||
<div class="text-gray-300">
|
||||
Empty output frame
|
||||
|
|
|
@ -115,6 +115,7 @@ defmodule LivebookWeb.SessionLive.CellComponent do
|
|||
|
||||
<%= if @cell_view.outputs != [] do %>
|
||||
<div class="mt-2" data-element="outputs-container">
|
||||
<%# There is an akin render in LivebookWeb.Output.FrameDynamicLive %>
|
||||
<LivebookWeb.Output.outputs
|
||||
outputs={@cell_view.outputs}
|
||||
id={"cell-#{@cell_view.id}-evaluation#{evaluation_number(@cell_view.evaluation_status, @cell_view.number_of_evaluations)}-outputs"}
|
||||
|
|
|
@ -214,6 +214,33 @@ defmodule LivebookWeb.SessionLiveTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "outputs" do
|
||||
test "dynamic frame output renders output sent from the frame server",
|
||||
%{conn: conn, session: session} do
|
||||
frame_pid =
|
||||
spawn(fn ->
|
||||
output = {:text, "Dynamic output in frame"}
|
||||
|
||||
receive do
|
||||
{:connect, pid} -> send(pid, {:connect_reply, %{output: output}})
|
||||
end
|
||||
end)
|
||||
|
||||
frame_output = {:frame_dynamic, frame_pid}
|
||||
|
||||
section_id = insert_section(session.pid)
|
||||
cell_id = insert_text_cell(session.pid, section_id, :elixir)
|
||||
# Evaluate the cell
|
||||
Session.queue_cell_evaluation(session.pid, cell_id)
|
||||
# Send an additional output
|
||||
send(session.pid, {:evaluation_output, cell_id, frame_output})
|
||||
|
||||
{:ok, view, _} = live(conn, "/sessions/#{session.id}")
|
||||
|
||||
assert render(view) =~ "Dynamic output in frame"
|
||||
end
|
||||
end
|
||||
|
||||
describe "runtime settings" do
|
||||
test "connecting to elixir standalone updates connect button to reconnect",
|
||||
%{conn: conn, session: session} do
|
||||
|
|
Loading…
Reference in a new issue