Skip to content

Commit

Permalink
Fix updateNodeInfo call from secret component (#350)
Browse files Browse the repository at this point in the history
Co-authored-by: José Valim <[email protected]>
  • Loading branch information
cristineguadelupe and josevalim authored Oct 4, 2023
1 parent 2c9f47b commit bac75f0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
8 changes: 6 additions & 2 deletions lib/assets/remote_execution_cell/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ export function init(ctx, payload) {
value: secretName,
});
this.$emit("update:secretInputValue", secretName);
updateNodeInfo();
},
preselectName,
{ title: this.modalTitle }
Expand Down Expand Up @@ -226,7 +225,7 @@ export function init(ctx, payload) {
updateNodeInfo() {
const node = this.fields["node"];
const cookie = this.fields["use_cookie_secret"]
? this.fields["cookie_secret"]
? this.fields["cookie_secret_value"]
: this.fields["cookie"];
ctx.setSmartCellEditorIntellisenseNode(node, cookie);
},
Expand All @@ -241,6 +240,11 @@ export function init(ctx, payload) {
setFields(fields);
});

ctx.handleEvent("update_node_info", (cookie_secret_value) => {
const node = app.fields["node"];
ctx.setSmartCellEditorIntellisenseNode(node, cookie_secret_value);
});

function setFields(fields) {
for (const field in fields) {
app.fields[field] = fields[field];
Expand Down
29 changes: 23 additions & 6 deletions lib/kino/remote_execution_cell.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ defmodule Kino.RemoteExecutionCell do
{shared_cookie, shared_cookie_secret} =
AttributeStore.get_attribute({@global_key, :cookie}, {nil, nil})

node = attrs["node"] || AttributeStore.get_attribute({@global_key, :node})
node = attrs["node"] || AttributeStore.get_attribute({@global_key, :node}) || ""
cookie_secret = attrs["cookie_secret"] || shared_cookie_secret
cookie_secret_value = cookie_secret && System.get_env("LB_#{cookie_secret}")

fields = %{
"assign_to" => attrs["assign_to"] || "",
"node" => node || "",
"node" => node,
"cookie" => attrs["cookie"] || shared_cookie || "",
"cookie_secret" => attrs["cookie_secret"] || shared_cookie_secret || "",
"cookie_secret" => cookie_secret || "",
"use_cookie_secret" =>
if(shared_cookie, do: false, else: Map.get(attrs, "use_cookie_secret", true))
if(shared_cookie, do: false, else: Map.get(attrs, "use_cookie_secret", true)),
"cookie_secret_value" => cookie_secret_value
}

ctx = assign(ctx, fields: fields)
Expand All @@ -42,14 +45,19 @@ defmodule Kino.RemoteExecutionCell do
def handle_event("update_field", %{"field" => field, "value" => value}, ctx) do
ctx = update(ctx, :fields, &Map.put(&1, field, value))
if field in @global_attrs, do: put_shared_attr(field, value)
broadcast_event(ctx, "update_field", %{"fields" => %{field => value}})
fields = update_fields(field, value)

if field == "cookie_secret",
do: send_event(ctx, ctx.origin, "update_node_info", fields["cookie_secret_value"])

broadcast_event(ctx, "update_field", %{"fields" => fields})

{:noreply, ctx}
end

@impl true
def to_attrs(ctx) do
ctx.assigns.fields
Map.delete(ctx.assigns.fields, "cookie_secret_value")
end

@impl true
Expand Down Expand Up @@ -118,4 +126,13 @@ defmodule Kino.RemoteExecutionCell do
defp put_shared_attr(field, value) do
AttributeStore.put_attribute({@global_key, String.to_atom(field)}, value)
end

defp update_fields("cookie_secret", cookie_secret) do
%{
"cookie_secret" => cookie_secret,
"cookie_secret_value" => System.get_env("LB_#{cookie_secret}")
}
end

defp update_fields(field, value), do: %{field => value}
end

0 comments on commit bac75f0

Please sign in to comment.