Changes secrets wording form label to name (#1419)

This commit is contained in:
Cristine Guadelupe 2022-09-18 18:40:09 -03:00 committed by GitHub
parent 2766cf3256
commit 52f7d7419b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 39 additions and 39 deletions

View file

@ -417,7 +417,7 @@ const JSView = {
} else if (event.type == "secretSelected") {
this.postMessage({
type: "secretSelected",
secretLabel: event.secretLabel,
secretName: event.secretName,
});
}
},

View file

@ -26,7 +26,7 @@ import { sha256Base64 } from "../../lib/utils";
// (2): https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-sandbox
// (3): https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts
const IFRAME_SHA256 = "6aUFRKEwZbbohB7OpFdKqnJJVRhccJxHGV+tArREQ+I=";
const IFRAME_SHA256 = "Ogec/87xIEbz3xVctg9QCMqCPCTCf6vyL88bl41PR3I=";
export function initializeIframeSource(iframe, iframePort, iframeUrl) {
const url = getIframeUrl(iframePort, iframeUrl);

View file

@ -207,8 +207,8 @@ const Session = {
this.handleEvent(
"secret_selected",
({ select_secret_ref, secret_label }) => {
this.handleSecretSelected(select_secret_ref, secret_label);
({ select_secret_ref, secret_name }) => {
this.handleSecretSelected(select_secret_ref, secret_name);
}
);
@ -1041,10 +1041,10 @@ const Session = {
});
},
handleSecretSelected(select_secret_ref, secretLabel) {
handleSecretSelected(select_secret_ref, secretName) {
globalPubSub.broadcast(`js_views:${select_secret_ref}`, {
type: "secretSelected",
secretLabel,
secretName,
});
},

View file

@ -146,7 +146,7 @@
}
);
} else if (message.type === "secretSelected") {
state.secretHandler && state.secretHandler(message.secretLabel);
state.secretHandler && state.secretHandler(message.secretName);
}
}

View file

@ -129,8 +129,8 @@ defmodule Livebook.Runtime.Evaluator.DefaultFormatter do
IO.ANSI.format([:red, string], true)
end
defp error_type(%System.EnvError{env: "LB_" <> secret_label}),
do: {:missing_secret, secret_label}
defp error_type(%System.EnvError{env: "LB_" <> secret_name}),
do: {:missing_secret, secret_name}
defp error_type(_), do: :other
end

View file

@ -1571,7 +1571,7 @@ defmodule Livebook.Session do
end
defp set_runtime_secrets(state, secrets) do
secrets = Enum.map(secrets, &{"LB_#{&1.label}", &1.value})
secrets = Enum.map(secrets, &{"LB_#{&1.name}", &1.value})
Runtime.put_system_envs(state.data.runtime, secrets)
end

View file

@ -1508,7 +1508,7 @@ defmodule Livebook.Session.Data do
end
defp put_secret({data, _} = data_actions, secret) do
idx = Enum.find_index(data.secrets, &(&1.label == secret.label))
idx = Enum.find_index(data.secrets, &(&1.name == secret.name))
secrets =
if idx do

View file

@ -235,11 +235,11 @@ defmodule LivebookWeb.Output do
)
end
defp render_output({:error, formatted, {:missing_secret, secret_label}}, %{
defp render_output({:error, formatted, {:missing_secret, secret_name}}, %{
socket: socket,
session_id: session_id
}) do
assigns = %{message: formatted, secret_label: secret_label}
assigns = %{message: formatted, secret_name: secret_name}
~H"""
<div class="-m-4 space-x-4 py-4">
@ -249,9 +249,9 @@ defmodule LivebookWeb.Output do
>
<div class="flex space-x-2 font-editor">
<.remix_icon icon="close-circle-line" />
<span>Missing secret <%= inspect(@secret_label) %></span>
<span>Missing secret <%= inspect(@secret_name) %></span>
</div>
<%= live_patch to: Routes.session_path(socket, :secrets, session_id, secret_label: secret_label),
<%= live_patch to: Routes.session_path(socket, :secrets, session_id, secret_name: secret_name),
class: "button-base button-gray",
aria_label: "add secret",
role: "button" do %>

View file

@ -405,7 +405,7 @@ defmodule LivebookWeb.SessionLive do
id="secrets"
session={@session}
secrets={@data_view.secrets}
prefill_secret_label={@prefill_secret_label}
prefill_secret_name={@prefill_secret_name}
select_secret_ref={@select_secret_ref}
preselect_name={@preselect_name}
return_to={@self_path}
@ -556,7 +556,7 @@ defmodule LivebookWeb.SessionLive do
<%= for secret <- @data_view.secrets do %>
<div class="flex justify-between items-center text-gray-500">
<span class="break-all">
<%= secret.label %>
<%= secret.name %>
</span>
<span class="rounded-full bg-gray-200 px-2 text-xs text-gray-600">
Session
@ -757,7 +757,7 @@ defmodule LivebookWeb.SessionLive do
when socket.assigns.live_action == :secrets do
{:noreply,
assign(socket,
prefill_secret_label: params["secret_label"],
prefill_secret_name: params["secret_name"],
preselect_name: params["preselect_name"],
select_secret_ref: if(params["preselect_name"], do: socket.assigns.select_secret_ref)
)}

View file

@ -9,7 +9,7 @@ defmodule LivebookWeb.SessionLive.SecretsComponent do
if socket.assigns[:data] do
socket
else
assign(socket, data: %{"label" => prefill_secret_label(socket), "value" => ""})
assign(socket, data: %{"name" => prefill_secret_name(socket), "value" => ""})
end
{:ok, socket}
@ -35,14 +35,14 @@ defmodule LivebookWeb.SessionLive.SecretsComponent do
errors={data_errors(@data)}
>
<div class="flex flex-col space-y-4">
<.input_wrapper form={f} field={:label}>
<.input_wrapper form={f} field={:name}>
<div class="input-label">
Label <span class="text-xs text-gray-500">(alphanumeric and underscore)</span>
Name <span class="text-xs text-gray-500">(alphanumeric and underscore)</span>
</div>
<%= text_input(f, :label,
value: @data["label"],
<%= text_input(f, :name,
value: @data["name"],
class: "input",
autofocus: !@prefill_secret_label,
autofocus: !@prefill_secret_name,
spellcheck: "false"
) %>
</.input_wrapper>
@ -51,7 +51,7 @@ defmodule LivebookWeb.SessionLive.SecretsComponent do
<%= text_input(f, :value,
value: @data["value"],
class: "input",
autofocus: !!@prefill_secret_label || unavailable_secret?(@preselect_name, @secrets),
autofocus: !!@prefill_secret_name || unavailable_secret?(@preselect_name, @secrets),
spellcheck: "false"
) %>
</.input_wrapper>
@ -83,22 +83,22 @@ defmodule LivebookWeb.SessionLive.SecretsComponent do
@impl true
def handle_event("save", %{"data" => data}, socket) do
secret_label = String.upcase(data["label"])
secret_name = String.upcase(data["name"])
if data_errors(data) == [] do
secret = %{label: secret_label, value: data["value"]}
secret = %{name: secret_name, value: data["value"]}
Livebook.Session.put_secret(socket.assigns.session.pid, secret)
{:noreply,
socket |> push_patch(to: socket.assigns.return_to) |> push_secret_selected(secret_label)}
socket |> push_patch(to: socket.assigns.return_to) |> push_secret_selected(secret_name)}
else
{:noreply, assign(socket, data: data)}
end
end
def handle_event("select_secret", %{"secret" => secret_label}, socket) do
def handle_event("select_secret", %{"secret" => secret_name}, socket) do
{:noreply,
socket |> push_patch(to: socket.assigns.return_to) |> push_secret_selected(secret_label)}
socket |> push_patch(to: socket.assigns.return_to) |> push_secret_selected(secret_name)}
end
def handle_event("validate", %{"data" => data}, socket) do
@ -115,7 +115,7 @@ defmodule LivebookWeb.SessionLive.SecretsComponent do
end)
end
defp data_error("label", value) do
defp data_error("name", value) do
cond do
String.match?(value, ~r/^\w+$/) -> nil
value == "" -> "can't be blank"
@ -126,16 +126,16 @@ 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.label, &1.label})]
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_label) do
push_event(socket, "secret_selected", %{select_secret_ref: ref, secret_label: secret_label})
defp push_secret_selected(%{assigns: %{select_secret_ref: ref}} = socket, secret_name) do
push_event(socket, "secret_selected", %{select_secret_ref: ref, secret_name: secret_name})
end
defp prefill_secret_label(socket) do
case socket.assigns.prefill_secret_label do
defp prefill_secret_name(socket) do
case socket.assigns.prefill_secret_name do
nil ->
if unavailable_secret?(socket.assigns.preselect_name, socket.assigns.secrets),
do: socket.assigns.preselect_name,
@ -150,6 +150,6 @@ defmodule LivebookWeb.SessionLive.SecretsComponent do
defp unavailable_secret?("", _), do: false
defp unavailable_secret?(preselect_name, secrets) do
preselect_name not in Enum.map(secrets, & &1.label)
preselect_name not in Enum.map(secrets, & &1.name)
end
end

View file

@ -921,9 +921,9 @@ defmodule LivebookWeb.SessionLiveTest do
view
|> element(~s{form[phx-submit="save"]})
|> render_submit(%{data: %{label: "foo", value: "123"}})
|> render_submit(%{data: %{name: "foo", value: "123"}})
assert %{secrets: [%{label: "FOO", value: "123"}]} = Session.get_data(session.pid)
assert %{secrets: [%{name: "FOO", value: "123"}]} = Session.get_data(session.pid)
end
test "shows the 'Add secret' button for unavailable secrets", %{conn: conn, session: session} do