From 52f7d7419b07a411e2c11df359e59d6511d82fb6 Mon Sep 17 00:00:00 2001 From: Cristine Guadelupe Date: Sun, 18 Sep 2022 18:40:09 -0300 Subject: [PATCH] Changes secrets wording form label to name (#1419) --- assets/js/hooks/js_view.js | 2 +- assets/js/hooks/js_view/iframe.js | 2 +- assets/js/hooks/session.js | 8 ++-- iframe/priv/static/iframe/v4.html | 2 +- .../runtime/evaluator/default_formatter.ex | 4 +- lib/livebook/session.ex | 2 +- lib/livebook/session/data.ex | 2 +- lib/livebook_web/live/output.ex | 8 ++-- lib/livebook_web/live/session_live.ex | 6 +-- .../live/session_live/secrets_component.ex | 38 +++++++++---------- test/livebook_web/live/session_live_test.exs | 4 +- 11 files changed, 39 insertions(+), 39 deletions(-) diff --git a/assets/js/hooks/js_view.js b/assets/js/hooks/js_view.js index 041667cf5..4fec1ad8c 100644 --- a/assets/js/hooks/js_view.js +++ b/assets/js/hooks/js_view.js @@ -417,7 +417,7 @@ const JSView = { } else if (event.type == "secretSelected") { this.postMessage({ type: "secretSelected", - secretLabel: event.secretLabel, + secretName: event.secretName, }); } }, diff --git a/assets/js/hooks/js_view/iframe.js b/assets/js/hooks/js_view/iframe.js index 746dfd2e0..0efa77e96 100644 --- a/assets/js/hooks/js_view/iframe.js +++ b/assets/js/hooks/js_view/iframe.js @@ -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); diff --git a/assets/js/hooks/session.js b/assets/js/hooks/session.js index aeb7902c0..7f6098baa 100644 --- a/assets/js/hooks/session.js +++ b/assets/js/hooks/session.js @@ -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, }); }, diff --git a/iframe/priv/static/iframe/v4.html b/iframe/priv/static/iframe/v4.html index 9917758cf..b6edddae4 100644 --- a/iframe/priv/static/iframe/v4.html +++ b/iframe/priv/static/iframe/v4.html @@ -146,7 +146,7 @@ } ); } else if (message.type === "secretSelected") { - state.secretHandler && state.secretHandler(message.secretLabel); + state.secretHandler && state.secretHandler(message.secretName); } } diff --git a/lib/livebook/runtime/evaluator/default_formatter.ex b/lib/livebook/runtime/evaluator/default_formatter.ex index 9a7291c39..fa4266964 100644 --- a/lib/livebook/runtime/evaluator/default_formatter.ex +++ b/lib/livebook/runtime/evaluator/default_formatter.ex @@ -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 diff --git a/lib/livebook/session.ex b/lib/livebook/session.ex index c9ef8fd66..edd26dd7c 100644 --- a/lib/livebook/session.ex +++ b/lib/livebook/session.ex @@ -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 diff --git a/lib/livebook/session/data.ex b/lib/livebook/session/data.ex index e69665b5e..1439d23d2 100644 --- a/lib/livebook/session/data.ex +++ b/lib/livebook/session/data.ex @@ -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 diff --git a/lib/livebook_web/live/output.ex b/lib/livebook_web/live/output.ex index 5fb26b4b8..9fdcf5f4f 100644 --- a/lib/livebook_web/live/output.ex +++ b/lib/livebook_web/live/output.ex @@ -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"""
@@ -249,9 +249,9 @@ defmodule LivebookWeb.Output do >
<.remix_icon icon="close-circle-line" /> - Missing secret <%= inspect(@secret_label) %> + Missing secret <%= inspect(@secret_name) %>
- <%= 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 %> diff --git a/lib/livebook_web/live/session_live.ex b/lib/livebook_web/live/session_live.ex index 09a155155..eeb3a234a 100644 --- a/lib/livebook_web/live/session_live.ex +++ b/lib/livebook_web/live/session_live.ex @@ -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 %>
- <%= secret.label %> + <%= secret.name %> 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) )} diff --git a/lib/livebook_web/live/session_live/secrets_component.ex b/lib/livebook_web/live/session_live/secrets_component.ex index c1af1a80a..b7e59f759 100644 --- a/lib/livebook_web/live/session_live/secrets_component.ex +++ b/lib/livebook_web/live/session_live/secrets_component.ex @@ -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)} >
- <.input_wrapper form={f} field={:label}> + <.input_wrapper form={f} field={:name}>
- Label (alphanumeric and underscore) + Name (alphanumeric and underscore)
- <%= 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" ) %> @@ -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" ) %> @@ -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 diff --git a/test/livebook_web/live/session_live_test.exs b/test/livebook_web/live/session_live_test.exs index 5b5239c57..4b089c9f4 100644 --- a/test/livebook_web/live/session_live_test.exs +++ b/test/livebook_web/live/session_live_test.exs @@ -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