mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-09 21:16:26 +08:00
Secrets modal title from options (#1443)
* Secrets modal title from options * Applying suggestions
This commit is contained in:
parent
83b21dfd1e
commit
d494e58c6a
3 changed files with 24 additions and 5 deletions
|
@ -335,6 +335,7 @@ const JSView = {
|
||||||
this.pushEvent("select_secret", {
|
this.pushEvent("select_secret", {
|
||||||
js_view_ref: this.props.ref,
|
js_view_ref: this.props.ref,
|
||||||
preselect_name: message.preselectName,
|
preselect_name: message.preselectName,
|
||||||
|
options: message.options,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -408,6 +408,7 @@ defmodule LivebookWeb.SessionLive do
|
||||||
prefill_secret_name={@prefill_secret_name}
|
prefill_secret_name={@prefill_secret_name}
|
||||||
select_secret_ref={@select_secret_ref}
|
select_secret_ref={@select_secret_ref}
|
||||||
preselect_name={@preselect_name}
|
preselect_name={@preselect_name}
|
||||||
|
select_secret_options={@select_secret_options}
|
||||||
return_to={@self_path}
|
return_to={@self_path}
|
||||||
/>
|
/>
|
||||||
</.modal>
|
</.modal>
|
||||||
|
@ -759,7 +760,9 @@ defmodule LivebookWeb.SessionLive do
|
||||||
assign(socket,
|
assign(socket,
|
||||||
prefill_secret_name: params["secret_name"],
|
prefill_secret_name: params["secret_name"],
|
||||||
preselect_name: params["preselect_name"],
|
preselect_name: params["preselect_name"],
|
||||||
select_secret_ref: if(params["preselect_name"], do: socket.assigns.select_secret_ref)
|
select_secret_ref: if(params["preselect_name"], do: socket.assigns.select_secret_ref),
|
||||||
|
select_secret_options:
|
||||||
|
if(params["preselect_name"], do: socket.assigns.select_secret_options)
|
||||||
)}
|
)}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1122,10 +1125,18 @@ defmodule LivebookWeb.SessionLive do
|
||||||
|
|
||||||
def handle_event(
|
def handle_event(
|
||||||
"select_secret",
|
"select_secret",
|
||||||
%{"js_view_ref" => select_secret_ref, "preselect_name" => preselect_name},
|
%{
|
||||||
|
"js_view_ref" => select_secret_ref,
|
||||||
|
"preselect_name" => preselect_name,
|
||||||
|
"options" => select_secret_options
|
||||||
|
},
|
||||||
socket
|
socket
|
||||||
) do
|
) do
|
||||||
socket = assign(socket, select_secret_ref: select_secret_ref)
|
socket =
|
||||||
|
assign(socket,
|
||||||
|
select_secret_ref: select_secret_ref,
|
||||||
|
select_secret_options: select_secret_options
|
||||||
|
)
|
||||||
|
|
||||||
{:noreply,
|
{:noreply,
|
||||||
push_patch(socket,
|
push_patch(socket,
|
||||||
|
|
|
@ -9,7 +9,10 @@ defmodule LivebookWeb.SessionLive.SecretsComponent do
|
||||||
if socket.assigns[:data] do
|
if socket.assigns[:data] do
|
||||||
socket
|
socket
|
||||||
else
|
else
|
||||||
assign(socket, data: %{"name" => prefill_secret_name(socket), "value" => ""})
|
assign(socket,
|
||||||
|
data: %{"name" => prefill_secret_name(socket), "value" => ""},
|
||||||
|
title: title(socket)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
{:ok, socket}
|
{:ok, socket}
|
||||||
|
@ -20,7 +23,7 @@ defmodule LivebookWeb.SessionLive.SecretsComponent do
|
||||||
~H"""
|
~H"""
|
||||||
<div class="p-6 max-w-4xl flex flex-col space-y-5">
|
<div class="p-6 max-w-4xl flex flex-col space-y-5">
|
||||||
<h3 class="text-2xl font-semibold text-gray-800">
|
<h3 class="text-2xl font-semibold text-gray-800">
|
||||||
Add secret
|
<%= @title %>
|
||||||
</h3>
|
</h3>
|
||||||
<div class="flex flex-columns gap-4">
|
<div class="flex flex-columns gap-4">
|
||||||
<%= if @select_secret_ref do %>
|
<%= if @select_secret_ref do %>
|
||||||
|
@ -176,4 +179,8 @@ defmodule LivebookWeb.SessionLive.SecretsComponent do
|
||||||
defp unavailable_secret?(preselect_name, secrets) do
|
defp unavailable_secret?(preselect_name, secrets) do
|
||||||
preselect_name not in Enum.map(secrets, & &1.name)
|
preselect_name not in Enum.map(secrets, & &1.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp title(%{assigns: %{select_secret_ref: nil}}), do: "Add secret"
|
||||||
|
defp title(%{assigns: %{select_secret_options: %{"title" => title}}}), do: title
|
||||||
|
defp title(_), do: "Select secret"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue