Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warning on export page if there are stale output #2420

Merged
merged 4 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/livebook_web/live/session_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ defmodule LivebookWeb.SessionLive do
id="export"
session={@session}
tab={@tab}
any_stale_cell?={@any_stale_cell?}
/>
</.modal>

Expand Down Expand Up @@ -1059,7 +1060,8 @@ defmodule LivebookWeb.SessionLive do
end

def handle_params(%{"tab" => tab}, _url, socket) when socket.assigns.live_action == :export do
{:noreply, assign(socket, tab: tab)}
any_stale_cell? = any_stale_cell?(socket.private.data)
{:noreply, assign(socket, tab: tab, any_stale_cell?: any_stale_cell?)}
end

def handle_params(%{"tab" => tab} = params, _url, socket)
Expand Down Expand Up @@ -2964,4 +2966,12 @@ defmodule LivebookWeb.SessionLive do

defp intellisense_node(%Cell.Smart{editor_intellisense_node: node_cookie}), do: node_cookie
defp intellisense_node(_), do: nil

defp any_stale_cell?(data) do
data.notebook
|> Notebook.evaluable_cells_with_section()
|> Enum.any?(fn {cell, _section} ->
data.cell_infos[cell.id].eval.validity == :stale
end)
end
end
19 changes: 8 additions & 11 deletions lib/livebook_web/live/session_live/export_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,15 @@ defmodule LivebookWeb.SessionLive.ExportComponent do

@impl true
def update(assigns, socket) do
{any_stale_cell?, assigns} = Map.pop!(assigns, :any_stale_cell?)
socket = assign(socket, assigns)
ByeongUkChoi marked this conversation as resolved.
Show resolved Hide resolved

socket =
if socket.assigns[:notebook] do
socket
else
# Note: we need to load the notebook, because the local data
# has cell contents stripped out
notebook = Session.get_notebook(socket.assigns.session.pid)
assign(socket, :notebook, notebook)
end

{:ok, socket}
{:ok,
socket
# Note: we need to load the notebook, because the local data
# has cell contents stripped out
|> assign_new(:notebook, fn -> Session.get_notebook(socket.assigns.session.pid) end)
|> assign_new(:any_stale_cell?, fn -> any_stale_cell? end)}
end
ByeongUkChoi marked this conversation as resolved.
Show resolved Hide resolved

@impl true
Expand Down Expand Up @@ -55,6 +51,7 @@ defmodule LivebookWeb.SessionLive.ExportComponent do
id={"export-notebook-#{@tab}"}
session={@session}
notebook={@notebook}
any_stale_cell?={@any_stale_cell?}
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ defmodule LivebookWeb.SessionLive.ExportLiveMarkdownComponent do
<.switch_field name="include_outputs" label="Include outputs" value={@include_outputs} />
</form>
</div>
<.message_box
:if={@include_outputs and @any_stale_cell?}
kind={:warning}
message="There are stale cells, some outputs may be inaccurate."
jonatanklosko marked this conversation as resolved.
Show resolved Hide resolved
/>
<div class="flex flex-col space-y-1">
<div class="flex justify-between items-center">
<span class="text-sm text-gray-700 font-semibold">
Expand Down
Loading