Allow downloading source from sessions list (#980)

* Support downloading source on a per session basis

* Update session_list_component.ex

* Add test

* Update lib/livebook_web/live/home_live/session_list_component.ex

* Update test/livebook_web/live/home_live_test.exs

Co-authored-by: José Valim <jose.valim@gmail.com>
Co-authored-by: Jonatan Kłosko <jonatanklosko@gmail.com>
This commit is contained in:
Benjamin Philip 2022-02-04 16:06:09 +05:30 committed by GitHub
parent a308a63994
commit 1a0b9e0f7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View file

@ -136,6 +136,13 @@ defmodule LivebookWeb.HomeLive.SessionListComponent do
</button>
</:toggle>
<:content>
<a class="menu-item text-gray-500"
role="menuitem"
href={Routes.session_path(@socket, :download_source, session.id, "livemd", include_outputs: false)}
download>
<.remix_icon icon="download-2-line" class="text-lg"/>
<span class="font-medium">Download source</span>
</a>
<button class="menu-item text-gray-500"
type="button"
role="menuitem"

View file

@ -136,6 +136,23 @@ defmodule LivebookWeb.HomeLiveTest do
refute render(view) =~ id
end
test "allows download the source of an existing session", %{conn: conn} do
{:ok, session} = Sessions.create_session()
Session.set_notebook_name(session.pid, "My notebook")
{:ok, view, _} = live(conn, "/")
{:error, {:redirect, %{to: to}}} =
view
|> element(~s{[data-test-session-id="#{session.id}"] a}, "Download source")
|> render_click
assert to ==
Routes.session_path(conn, :download_source, session.id, "livemd",
include_outputs: false
)
end
test "allows forking existing session", %{conn: conn} do
{:ok, session} = Sessions.create_session()
Session.set_notebook_name(session.pid, "My notebook")