Handle missing debounce only from old output (#2261)

This commit is contained in:
José Valim 2023-10-06 22:56:12 +03:00 committed by GitHub
parent f0ca13c88a
commit 1bb0005f20
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 29 deletions

View file

@ -2889,34 +2889,22 @@ defmodule Livebook.Session do
# attributes that are missing.
defp normalize_runtime_output(output)
defp normalize_runtime_output(%{type: :input, attrs: attrs} = output)
when attrs.type in [:text, :textarea, :password, :number, :url, :range, :color] and
not is_map_key(attrs, :debounce) do
default =
case attrs.type do
:range -> 250
_other -> :blur
end
put_in(output.attrs[:debounce], default)
|> normalize_runtime_output()
end
# Traverse composite outputs
defp normalize_runtime_output(output) when output.type in [:frame, :tabs, :grid] do
outputs = Enum.map(output.outputs, &normalize_runtime_output/1)
%{output | outputs: outputs}
end
# defp normalize_runtime_output(output) when output.type in [:frame, :tabs, :grid] do
# outputs = Enum.map(output.outputs, &normalize_runtime_output/1)
# %{output | outputs: outputs}
# end
defp normalize_runtime_output(%{type: :frame_update} = output) do
{update_type, new_outputs} = output.update
new_outputs = Enum.map(new_outputs, &normalize_runtime_output/1)
%{output | update: {update_type, new_outputs}}
end
# defp normalize_runtime_output(%{type: :frame_update} = output) do
# {update_type, new_outputs} = output.update
# new_outputs = Enum.map(new_outputs, &normalize_runtime_output/1)
# %{output | update: {update_type, new_outputs}}
# end
defp normalize_runtime_output(output) when is_map(output), do: output
# TODO: Remove this when Kino v0.10.0 is a long time in the past.
# Rewrite tuples to maps for backward compatibility with Kino <= 0.10.0
defp normalize_runtime_output(:ignored) do
@ -3000,12 +2988,23 @@ defmodule Livebook.Session do
end
defp normalize_runtime_output({:input, attrs}) do
{fields, attrs} = Map.split(attrs, [:ref, :id, :destination])
{fields, %{type: type} = attrs} = Map.split(attrs, [:ref, :id, :destination])
attrs =
case attrs.type do
:textarea -> Map.put_new(attrs, :monospace, false)
_other -> attrs
cond do
type in [:textarea] ->
attrs
|> Map.put_new(:monospace, false)
|> Map.put_new(:debounce, :blur)
type in [:text, :password, :number, :url, :color] ->
Map.put_new(attrs, :debounce, :blur)
type in [:range] ->
Map.put_new(attrs, :debounce, 250)
true ->
attrs
end
Map.merge(fields, %{type: :input, attrs: attrs})

View file

@ -189,7 +189,7 @@ defmodule LivebookWeb.AppSessionLiveTest do
ref: "ref1",
id: "input1",
destination: test,
attrs: %{type: :number, default: 1, label: "Name"}
attrs: %{type: :number, default: 1, label: "Name", debounce: :blur}
}
notebook = %{

View file

@ -490,7 +490,7 @@ defmodule LivebookWeb.SessionLiveTest do
ref: "ref1",
id: "input1",
destination: test,
attrs: %{type: :number, default: 1, label: "Name"}
attrs: %{type: :number, default: 1, label: "Name", debounce: :blur}
}
Session.subscribe(session.id)
@ -746,7 +746,7 @@ defmodule LivebookWeb.SessionLiveTest do
ref: "ref1",
id: "input1",
destination: test,
attrs: %{type: :number, default: 1, label: "Name"}
attrs: %{type: :number, default: 1, label: "Name", debounce: :blur}
}
Session.subscribe(session.id)