mirror of
https://github.com/livebook-dev/livebook.git
synced 2024-09-20 18:15:56 +08:00
Add warning on export page if there are stale output (#2420)
Co-authored-by: Jonatan Kłosko <jonatanklosko@gmail.com>
This commit is contained in:
parent
469c53a4df
commit
bc099bf03e
|
@ -614,6 +614,7 @@ defmodule LivebookWeb.SessionLive do
|
|||
id="export"
|
||||
session={@session}
|
||||
tab={@tab}
|
||||
any_stale_cell?={@any_stale_cell?}
|
||||
/>
|
||||
</.modal>
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
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
|
||||
|
||||
@impl true
|
||||
|
@ -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>
|
||||
|
|
|
@ -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. You may want to reevaluate the notebook to make sure the outputs are up to date."
|
||||
/>
|
||||
<div class="flex flex-col space-y-1">
|
||||
<div class="flex justify-between items-center">
|
||||
<span class="text-sm text-gray-700 font-semibold">
|
||||
|
|
Loading…
Reference in a new issue