Secrets modal title from options (#1443)

* Secrets modal title from options

* Applying suggestions
This commit is contained in:
Cristine Guadelupe 2022-09-27 23:25:07 -03:00 committed by GitHub
parent 83b21dfd1e
commit d494e58c6a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 5 deletions

View file

@ -335,6 +335,7 @@ const JSView = {
this.pushEvent("select_secret", {
js_view_ref: this.props.ref,
preselect_name: message.preselectName,
options: message.options,
});
}
}

View file

@ -408,6 +408,7 @@ defmodule LivebookWeb.SessionLive do
prefill_secret_name={@prefill_secret_name}
select_secret_ref={@select_secret_ref}
preselect_name={@preselect_name}
select_secret_options={@select_secret_options}
return_to={@self_path}
/>
</.modal>
@ -759,7 +760,9 @@ defmodule LivebookWeb.SessionLive do
assign(socket,
prefill_secret_name: params["secret_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
@ -1122,10 +1125,18 @@ defmodule LivebookWeb.SessionLive do
def handle_event(
"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
) 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,
push_patch(socket,

View file

@ -9,7 +9,10 @@ defmodule LivebookWeb.SessionLive.SecretsComponent do
if socket.assigns[:data] do
socket
else
assign(socket, data: %{"name" => prefill_secret_name(socket), "value" => ""})
assign(socket,
data: %{"name" => prefill_secret_name(socket), "value" => ""},
title: title(socket)
)
end
{:ok, socket}
@ -20,7 +23,7 @@ defmodule LivebookWeb.SessionLive.SecretsComponent do
~H"""
<div class="p-6 max-w-4xl flex flex-col space-y-5">
<h3 class="text-2xl font-semibold text-gray-800">
Add secret
<%= @title %>
</h3>
<div class="flex flex-columns gap-4">
<%= if @select_secret_ref do %>
@ -176,4 +179,8 @@ defmodule LivebookWeb.SessionLive.SecretsComponent do
defp unavailable_secret?(preselect_name, secrets) do
preselect_name not in Enum.map(secrets, & &1.name)
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