mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-07 20:16:31 +08:00
Showing app configuration when clicking Launch Preview (#2507)
This commit is contained in:
parent
dc8c3f4efc
commit
9ec411fb3a
5 changed files with 61 additions and 45 deletions
|
@ -573,29 +573,21 @@ defmodule LivebookWeb.SessionLive do
|
||||||
{:noreply, socket}
|
{:noreply, socket}
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_event("deploy_app", %{}, socket) do
|
def handle_event("deploy_app", _, socket) do
|
||||||
on_confirm = fn socket ->
|
|
||||||
Livebook.Session.deploy_app(socket.assigns.session.pid)
|
|
||||||
socket
|
|
||||||
end
|
|
||||||
|
|
||||||
data = socket.private.data
|
data = socket.private.data
|
||||||
slug = data.notebook.app_settings.slug
|
app_settings = data.notebook.app_settings
|
||||||
slug_taken? = slug != data.deployed_app_slug and Livebook.Apps.exists?(slug)
|
|
||||||
|
|
||||||
socket =
|
if Livebook.Notebook.AppSettings.valid?(app_settings) do
|
||||||
if slug_taken? do
|
{:noreply,
|
||||||
confirm(socket, on_confirm,
|
LivebookWeb.SessionLive.AppSettingsComponent.deploy_app(
|
||||||
title: "Deploy app",
|
socket,
|
||||||
description:
|
app_settings,
|
||||||
"An app with this slug already exists, do you want to deploy a new version?",
|
data.deployed_app_slug
|
||||||
confirm_text: "Replace"
|
)}
|
||||||
)
|
else
|
||||||
else
|
{:noreply,
|
||||||
on_confirm.(socket)
|
push_patch(socket, to: ~p"/sessions/#{socket.assigns.session.id}/settings/launch-app")}
|
||||||
end
|
end
|
||||||
|
|
||||||
{:noreply, socket}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_event("intellisense_request", %{"cell_id" => cell_id} = params, socket) do
|
def handle_event("intellisense_request", %{"cell_id" => cell_id} = params, socket) do
|
||||||
|
|
|
@ -98,28 +98,13 @@ defmodule LivebookWeb.SessionLive.AppInfoComponent do
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class={["grid gap-2", @app && "grid-cols-2"]}>
|
<div class={["grid gap-2", @app && "grid-cols-2"]}>
|
||||||
<span
|
<span class="flex flex-col">
|
||||||
class={[
|
|
||||||
"flex flex-col",
|
|
||||||
not Livebook.Notebook.AppSettings.valid?(@settings) && "tooltip top"
|
|
||||||
]}
|
|
||||||
data-tooltip="You must configure the app to preview it"
|
|
||||||
>
|
|
||||||
<%= if @app do %>
|
<%= if @app do %>
|
||||||
<.button
|
<.button color="gray" outlined phx-click="deploy_app">
|
||||||
color="gray"
|
|
||||||
outlined
|
|
||||||
phx-click="deploy_app"
|
|
||||||
disabled={not Livebook.Notebook.AppSettings.valid?(@settings)}
|
|
||||||
>
|
|
||||||
<.remix_icon icon="slideshow-4-line" /> Relaunch
|
<.remix_icon icon="slideshow-4-line" /> Relaunch
|
||||||
</.button>
|
</.button>
|
||||||
<% else %>
|
<% else %>
|
||||||
<.button
|
<.button color="blue" phx-click="deploy_app">
|
||||||
color="blue"
|
|
||||||
phx-click="deploy_app"
|
|
||||||
disabled={not Livebook.Notebook.AppSettings.valid?(@settings)}
|
|
||||||
>
|
|
||||||
<.remix_icon icon="slideshow-4-line" /> Launch preview
|
<.remix_icon icon="slideshow-4-line" /> Launch preview
|
||||||
</.button>
|
</.button>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -2,6 +2,7 @@ defmodule LivebookWeb.SessionLive.AppSettingsComponent do
|
||||||
use LivebookWeb, :live_component
|
use LivebookWeb, :live_component
|
||||||
|
|
||||||
alias Livebook.Notebook.AppSettings
|
alias Livebook.Notebook.AppSettings
|
||||||
|
import LivebookWeb.Confirm
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def update(assigns, socket) do
|
def update(assigns, socket) do
|
||||||
|
@ -24,6 +25,11 @@ defmodule LivebookWeb.SessionLive.AppSettingsComponent do
|
||||||
<h3 class="text-2xl font-semibold text-gray-800">
|
<h3 class="text-2xl font-semibold text-gray-800">
|
||||||
App settings
|
App settings
|
||||||
</h3>
|
</h3>
|
||||||
|
<%= if @live_action == :app_settings_and_launch do %>
|
||||||
|
<.message_box kind={:info}>
|
||||||
|
You must configure your app before launch it.
|
||||||
|
</.message_box>
|
||||||
|
<% end %>
|
||||||
<.form
|
<.form
|
||||||
:let={f}
|
:let={f}
|
||||||
for={@changeset}
|
for={@changeset}
|
||||||
|
@ -125,9 +131,12 @@ defmodule LivebookWeb.SessionLive.AppSettingsComponent do
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-8 flex space-x-2">
|
<div class="mt-8 flex space-x-2">
|
||||||
<.button type="submit" disabled={not @changeset.valid?}>
|
<%= if @live_action == :app_settings do %>
|
||||||
<span>Save</span>
|
<.button type="submit" disabled={not @changeset.valid?}>Save</.button>
|
||||||
</.button>
|
<% end %>
|
||||||
|
<%= if @live_action == :app_settings_and_launch do %>
|
||||||
|
<.button disabled={not @changeset.valid?}>Launch</.button>
|
||||||
|
<% end %>
|
||||||
<.button color="gray" outlined type="reset" name="reset">
|
<.button color="gray" outlined type="reset" name="reset">
|
||||||
Reset
|
Reset
|
||||||
</.button>
|
</.button>
|
||||||
|
@ -154,10 +163,37 @@ defmodule LivebookWeb.SessionLive.AppSettingsComponent do
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_event("save", %{"app_settings" => params}, socket) do
|
def handle_event("save", %{"app_settings" => params}, socket) do
|
||||||
with {:ok, settings} <- AppSettings.update(socket.assigns.settings, params) do
|
app_settings = socket.assigns.settings
|
||||||
|
deployed_app_slug = socket.assigns.deployed_app_slug
|
||||||
|
|
||||||
|
with {:ok, settings} <- AppSettings.update(app_settings, params) do
|
||||||
Livebook.Session.set_app_settings(socket.assigns.session.pid, settings)
|
Livebook.Session.set_app_settings(socket.assigns.session.pid, settings)
|
||||||
end
|
end
|
||||||
|
|
||||||
{:noreply, push_patch(socket, to: ~p"/sessions/#{socket.assigns.session.id}")}
|
if socket.assigns.live_action == :app_settings_and_launch do
|
||||||
|
{:noreply, deploy_app(socket, app_settings, deployed_app_slug)}
|
||||||
|
else
|
||||||
|
{:noreply, push_patch(socket, to: ~p"/sessions/#{socket.assigns.session.id}")}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def deploy_app(socket, app_settings, deployed_app_slug) do
|
||||||
|
on_confirm = fn socket ->
|
||||||
|
Livebook.Session.deploy_app(socket.assigns.session.pid)
|
||||||
|
push_patch(socket, to: ~p"/sessions/#{socket.assigns.session.id}")
|
||||||
|
end
|
||||||
|
|
||||||
|
slug = app_settings.slug
|
||||||
|
slug_taken? = slug != deployed_app_slug and Livebook.Apps.exists?(slug)
|
||||||
|
|
||||||
|
if slug_taken? do
|
||||||
|
confirm(socket, on_confirm,
|
||||||
|
title: "Deploy app",
|
||||||
|
description: "An app with this slug already exists, do you want to deploy a new version?",
|
||||||
|
confirm_text: "Replace"
|
||||||
|
)
|
||||||
|
else
|
||||||
|
on_confirm.(socket)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -78,7 +78,7 @@ defmodule LivebookWeb.SessionLive.Render do
|
||||||
</.modal>
|
</.modal>
|
||||||
|
|
||||||
<.modal
|
<.modal
|
||||||
:if={@live_action == :app_settings}
|
:if={@live_action in [:app_settings, :app_settings_and_launch]}
|
||||||
id="app-settings-modal"
|
id="app-settings-modal"
|
||||||
show
|
show
|
||||||
width={:medium}
|
width={:medium}
|
||||||
|
@ -89,6 +89,8 @@ defmodule LivebookWeb.SessionLive.Render do
|
||||||
id="app-settings"
|
id="app-settings"
|
||||||
session={@session}
|
session={@session}
|
||||||
settings={@data_view.app_settings}
|
settings={@data_view.app_settings}
|
||||||
|
live_action={@live_action}
|
||||||
|
deployed_app_slug={@data_view.deployed_app_slug}
|
||||||
/>
|
/>
|
||||||
</.modal>
|
</.modal>
|
||||||
|
|
||||||
|
|
|
@ -108,6 +108,7 @@ defmodule LivebookWeb.Router do
|
||||||
live "/sessions/:id/settings/runtime", SessionLive, :runtime_settings
|
live "/sessions/:id/settings/runtime", SessionLive, :runtime_settings
|
||||||
live "/sessions/:id/settings/file", SessionLive, :file_settings
|
live "/sessions/:id/settings/file", SessionLive, :file_settings
|
||||||
live "/sessions/:id/settings/app", SessionLive, :app_settings
|
live "/sessions/:id/settings/app", SessionLive, :app_settings
|
||||||
|
live "/sessions/:id/settings/launch-app", SessionLive, :app_settings_and_launch
|
||||||
live "/sessions/:id/app-docker", SessionLive, :app_docker
|
live "/sessions/:id/app-docker", SessionLive, :app_docker
|
||||||
live "/sessions/:id/add-file/:tab", SessionLive, :add_file_entry
|
live "/sessions/:id/add-file/:tab", SessionLive, :add_file_entry
|
||||||
live "/sessions/:id/rename-file/:name", SessionLive, :rename_file_entry
|
live "/sessions/:id/rename-file/:name", SessionLive, :rename_file_entry
|
||||||
|
|
Loading…
Add table
Reference in a new issue