mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-11 14:06:20 +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
3 changed files with 24 additions and 12 deletions
|
@ -614,6 +614,7 @@ defmodule LivebookWeb.SessionLive do
|
||||||
id="export"
|
id="export"
|
||||||
session={@session}
|
session={@session}
|
||||||
tab={@tab}
|
tab={@tab}
|
||||||
|
any_stale_cell?={@any_stale_cell?}
|
||||||
/>
|
/>
|
||||||
</.modal>
|
</.modal>
|
||||||
|
|
||||||
|
@ -1059,7 +1060,8 @@ defmodule LivebookWeb.SessionLive do
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_params(%{"tab" => tab}, _url, socket) when socket.assigns.live_action == :export do
|
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
|
end
|
||||||
|
|
||||||
def handle_params(%{"tab" => tab} = params, _url, socket)
|
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(%Cell.Smart{editor_intellisense_node: node_cookie}), do: node_cookie
|
||||||
defp intellisense_node(_), do: nil
|
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
|
end
|
||||||
|
|
|
@ -5,19 +5,15 @@ defmodule LivebookWeb.SessionLive.ExportComponent do
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def update(assigns, socket) do
|
def update(assigns, socket) do
|
||||||
|
{any_stale_cell?, assigns} = Map.pop!(assigns, :any_stale_cell?)
|
||||||
socket = assign(socket, assigns)
|
socket = assign(socket, assigns)
|
||||||
|
|
||||||
socket =
|
{:ok,
|
||||||
if socket.assigns[:notebook] do
|
socket
|
||||||
socket
|
# Note: we need to load the notebook, because the local data
|
||||||
else
|
# has cell contents stripped out
|
||||||
# Note: we need to load the notebook, because the local data
|
|> assign_new(:notebook, fn -> Session.get_notebook(socket.assigns.session.pid) end)
|
||||||
# has cell contents stripped out
|
|> assign_new(:any_stale_cell?, fn -> any_stale_cell? end)}
|
||||||
notebook = Session.get_notebook(socket.assigns.session.pid)
|
|
||||||
assign(socket, :notebook, notebook)
|
|
||||||
end
|
|
||||||
|
|
||||||
{:ok, socket}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
|
@ -55,6 +51,7 @@ defmodule LivebookWeb.SessionLive.ExportComponent do
|
||||||
id={"export-notebook-#{@tab}"}
|
id={"export-notebook-#{@tab}"}
|
||||||
session={@session}
|
session={@session}
|
||||||
notebook={@notebook}
|
notebook={@notebook}
|
||||||
|
any_stale_cell?={@any_stale_cell?}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -31,6 +31,11 @@ defmodule LivebookWeb.SessionLive.ExportLiveMarkdownComponent do
|
||||||
<.switch_field name="include_outputs" label="Include outputs" value={@include_outputs} />
|
<.switch_field name="include_outputs" label="Include outputs" value={@include_outputs} />
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</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 flex-col space-y-1">
|
||||||
<div class="flex justify-between items-center">
|
<div class="flex justify-between items-center">
|
||||||
<span class="text-sm text-gray-700 font-semibold">
|
<span class="text-sm text-gray-700 font-semibold">
|
||||||
|
|
Loading…
Add table
Reference in a new issue