From 90278d37325ceac16d59666a69977e2e4282d27a Mon Sep 17 00:00:00 2001 From: bu Date: Mon, 1 Jan 2024 11:30:22 +0900 Subject: [PATCH 1/4] Add warning on export page if there are stale output --- lib/livebook_web/live/session_live.ex | 8 +++++++- lib/livebook_web/live/session_live/export_component.ex | 10 ++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/livebook_web/live/session_live.ex b/lib/livebook_web/live/session_live.ex index 8e2f32a97fa..77bf610b504 100644 --- a/lib/livebook_web/live/session_live.ex +++ b/lib/livebook_web/live/session_live.ex @@ -614,6 +614,7 @@ defmodule LivebookWeb.SessionLive do id="export" session={@session} tab={@tab} + has_stale_cell?={@has_stale_cell?} /> @@ -1059,7 +1060,12 @@ defmodule LivebookWeb.SessionLive do end def handle_params(%{"tab" => tab}, _url, socket) when socket.assigns.live_action == :export do - {:noreply, assign(socket, tab: tab)} + has_stale_cell? = + socket.assigns.data_view.section_views + |> Enum.flat_map(& &1.cell_views) + |> Enum.any?(&(&1.eval.validity == :stale)) + + {:noreply, assign(socket, tab: tab, has_stale_cell?: has_stale_cell?)} end def handle_params(%{"tab" => tab} = params, _url, socket) diff --git a/lib/livebook_web/live/session_live/export_component.ex b/lib/livebook_web/live/session_live/export_component.ex index 3a2830836a6..54888183dc1 100644 --- a/lib/livebook_web/live/session_live/export_component.ex +++ b/lib/livebook_web/live/session_live/export_component.ex @@ -31,6 +31,16 @@ defmodule LivebookWeb.SessionLive.ExportComponent do

Here you can preview and directly export the notebook source.

+
+
+ <.remix_icon icon="close-circle-line" /> +

There are stale section(s)

+
+
<.link patch={~p"/sessions/#{@session.id}/export/livemd"} From aca19fece1ca9a79deac53e71678e6d7cf2f718a Mon Sep 17 00:00:00 2001 From: bu Date: Tue, 2 Jan 2024 21:40:16 +0900 Subject: [PATCH 2/4] apply feedback --- lib/livebook_web/live/session_live.ex | 18 +++++++++++------- .../live/session_live/export_component.ex | 19 +++++++------------ .../export_live_markdown_component.ex | 5 +++++ 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/lib/livebook_web/live/session_live.ex b/lib/livebook_web/live/session_live.ex index 77bf610b504..5aff274a81b 100644 --- a/lib/livebook_web/live/session_live.ex +++ b/lib/livebook_web/live/session_live.ex @@ -614,7 +614,7 @@ defmodule LivebookWeb.SessionLive do id="export" session={@session} tab={@tab} - has_stale_cell?={@has_stale_cell?} + any_stale_cell?={@any_stale_cell?} /> @@ -1060,12 +1060,8 @@ defmodule LivebookWeb.SessionLive do end def handle_params(%{"tab" => tab}, _url, socket) when socket.assigns.live_action == :export do - has_stale_cell? = - socket.assigns.data_view.section_views - |> Enum.flat_map(& &1.cell_views) - |> Enum.any?(&(&1.eval.validity == :stale)) - - {:noreply, assign(socket, tab: tab, has_stale_cell?: has_stale_cell?)} + 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) @@ -2970,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 diff --git a/lib/livebook_web/live/session_live/export_component.ex b/lib/livebook_web/live/session_live/export_component.ex index 54888183dc1..da4faf0e7ee 100644 --- a/lib/livebook_web/live/session_live/export_component.ex +++ b/lib/livebook_web/live/session_live/export_component.ex @@ -7,17 +7,11 @@ defmodule LivebookWeb.SessionLive.ExportComponent do def update(assigns, socket) do 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)} end @impl true @@ -32,7 +26,7 @@ defmodule LivebookWeb.SessionLive.ExportComponent do Here you can preview and directly export the notebook source.

@@ -65,6 +59,7 @@ defmodule LivebookWeb.SessionLive.ExportComponent do id={"export-notebook-#{@tab}"} session={@session} notebook={@notebook} + any_stale_cell?={@any_stale_cell?} />
diff --git a/lib/livebook_web/live/session_live/export_live_markdown_component.ex b/lib/livebook_web/live/session_live/export_live_markdown_component.ex index 1aa1d20f432..7b36db6ee2d 100644 --- a/lib/livebook_web/live/session_live/export_live_markdown_component.ex +++ b/lib/livebook_web/live/session_live/export_live_markdown_component.ex @@ -31,6 +31,11 @@ defmodule LivebookWeb.SessionLive.ExportLiveMarkdownComponent do <.switch_field name="include_outputs" label="Include outputs" value={@include_outputs} /> + <.message_box + :if={@include_outputs and @any_stale_cell?} + kind={:warning} + message="There are stale cells, some outputs may be inaccurate." + />
From e56a379750cb52bc6a475e31e6ad632e72ab2856 Mon Sep 17 00:00:00 2001 From: bu Date: Tue, 2 Jan 2024 22:15:54 +0900 Subject: [PATCH 3/4] apply suggestions --- .../live/session_live/export_component.ex | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/lib/livebook_web/live/session_live/export_component.ex b/lib/livebook_web/live/session_live/export_component.ex index da4faf0e7ee..4c4f0da4099 100644 --- a/lib/livebook_web/live/session_live/export_component.ex +++ b/lib/livebook_web/live/session_live/export_component.ex @@ -5,13 +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) {: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(:notebook, fn -> Session.get_notebook(socket.assigns.session.pid) end) + |> assign_new(:any_stale_cell?, fn -> any_stale_cell? end)} end @impl true @@ -25,16 +27,6 @@ defmodule LivebookWeb.SessionLive.ExportComponent do

Here you can preview and directly export the notebook source.

-
-
- <.remix_icon icon="close-circle-line" /> -

There are stale section(s)

-
-
<.link patch={~p"/sessions/#{@session.id}/export/livemd"} From 85dd420b3ec34b4eb5529b8c1c9b32d9f025d334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Tue, 2 Jan 2024 15:22:27 +0100 Subject: [PATCH 4/4] Update lib/livebook_web/live/session_live/export_live_markdown_component.ex --- .../live/session_live/export_live_markdown_component.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/livebook_web/live/session_live/export_live_markdown_component.ex b/lib/livebook_web/live/session_live/export_live_markdown_component.ex index 7b36db6ee2d..24adee8cc17 100644 --- a/lib/livebook_web/live/session_live/export_live_markdown_component.ex +++ b/lib/livebook_web/live/session_live/export_live_markdown_component.ex @@ -34,7 +34,7 @@ defmodule LivebookWeb.SessionLive.ExportLiveMarkdownComponent do <.message_box :if={@include_outputs and @any_stale_cell?} kind={:warning} - message="There are stale cells, some outputs may be inaccurate." + 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." />