diff --git a/lib/livebook_web/live/session_live/secrets_component.ex b/lib/livebook_web/live/session_live/secrets_component.ex index b7e59f759..60e087c17 100644 --- a/lib/livebook_web/live/session_live/secrets_component.ex +++ b/lib/livebook_web/live/session_live/secrets_component.ex @@ -22,61 +22,87 @@ defmodule LivebookWeb.SessionLive.SecretsComponent do

Add secret

-

- Enter the secret name and its value. -

- <.form - let={f} - for={:data} - phx-submit="save" - phx-change="validate" - autocomplete="off" - phx-target={@myself} - errors={data_errors(@data)} - > -
- <.input_wrapper form={f} field={:name}> -
- Name (alphanumeric and underscore) +
+ <%= if @select_secret_ref do %> +
+
+

+ Choose a secret +

+
+ <%= for secret <- @secrets do %> + <.choice_button + active={secret.name == @preselect_name} + value={secret.name} + phx-target={@myself} + phx-click="select_secret" + class={ + if secret.name == @preselect_name, + do: "text-xs rounded-full", + else: "text-xs rounded-full text-gray-700 hover:bg-gray-200" + } + > + <%= secret.name %> + + <% end %> + <%= if @secrets == [] do %> +
+ <.remix_icon icon="folder-lock-line" class="align-middle text-2xl" /> + + Secrets not found.
Add to see them here. +
+
+ <% end %> +
- <%= text_input(f, :name, - value: @data["name"], - class: "input", - autofocus: !@prefill_secret_name, - spellcheck: "false" - ) %> - - <.input_wrapper form={f} field={:value}> -
Value
- <%= text_input(f, :value, - value: @data["value"], - class: "input", - autofocus: !!@prefill_secret_name || unavailable_secret?(@preselect_name, @secrets), - spellcheck: "false" - ) %> - -
- - <%= live_patch("Cancel", to: @return_to, class: "button-base button-outlined-gray") %>
-
- - <%= if @select_secret_ref do %> -

- Select secret -

+ <% end %> <.form - let={_} - for={:secrets} - phx-submit="save_secret" - phx-change="select_secret" + let={f} + for={:data} + phx-submit="save" + phx-change="validate" + autocomplete="off" phx-target={@myself} + errors={data_errors(@data)} + class="basis-1/2 grow" > - <.select name="secret" selected={@preselect_name} options={secret_options(@secrets)} /> +
+ <%= if @select_secret_ref do %> +

+ Add new secret +

+ <% end %> + <.input_wrapper form={f} field={:name}> +
+ Name (alphanumeric and underscore) +
+ <%= text_input(f, :name, + value: @data["name"], + class: "input", + autofocus: !@prefill_secret_name, + spellcheck: "false" + ) %> + + <.input_wrapper form={f} field={:value}> +
Value
+ <%= text_input(f, :value, + value: @data["value"], + class: "input", + autofocus: !!@prefill_secret_name || unavailable_secret?(@preselect_name, @secrets), + spellcheck: "false" + ) %> + +
+ + <%= live_patch("Cancel", to: @return_to, class: "button-base button-outlined-gray") %> +
+
- <% end %> +
""" end @@ -96,7 +122,7 @@ defmodule LivebookWeb.SessionLive.SecretsComponent do end end - def handle_event("select_secret", %{"secret" => secret_name}, socket) do + def handle_event("select_secret", %{"value" => secret_name}, socket) do {:noreply, socket |> push_patch(to: socket.assigns.return_to) |> push_secret_selected(secret_name)} end @@ -126,8 +152,6 @@ defmodule LivebookWeb.SessionLive.SecretsComponent do defp data_error("value", ""), do: "can't be blank" defp data_error(_key, _value), do: nil - defp secret_options(secrets), do: [{"", ""} | Enum.map(secrets, &{&1.name, &1.name})] - defp push_secret_selected(%{assigns: %{select_secret_ref: nil}} = socket, _), do: socket defp push_secret_selected(%{assigns: %{select_secret_ref: ref}} = socket, secret_name) do