Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable copy button for error output #2435

Merged
merged 4 commits into from
Jan 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 33 additions & 16 deletions lib/livebook_web/live/output.ex
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ defmodule LivebookWeb.Output do

defp render_output(
%{type: :error, context: {:missing_secret, secret_name}} = output,
%{session_id: session_id}
%{session_id: session_id, id: id}
) do
assigns = %{message: output.message, secret_name: secret_name, session_id: session_id}
assigns = %{message: output.message, secret_name: secret_name, session_id: session_id, id: id}

~H"""
<div class="-m-4 space-x-4 py-4">
Expand All @@ -278,16 +278,21 @@ defmodule LivebookWeb.Output do
Add secret
</.link>
</div>
<%= render_formatted_error_message(@message) %>
<%= render_formatted_error_message(@id, @message) %>
</div>
"""
end

defp render_output(
%{type: :error, context: {:file_entry_forbidden, file_entry_name}} = output,
%{session_id: session_id}
%{session_id: session_id, id: id}
) do
assigns = %{message: output.message, file_entry_name: file_entry_name, session_id: session_id}
assigns = %{
message: output.message,
file_entry_name: file_entry_name,
session_id: session_id,
id: id
}

~H"""
<div class="-m-4 space-x-4 py-4">
Expand All @@ -306,7 +311,7 @@ defmodule LivebookWeb.Output do
Review access
</button>
</div>
<%= render_formatted_error_message(@message) %>
<%= render_formatted_error_message(@id, @message) %>
</div>
"""
end
Expand Down Expand Up @@ -346,8 +351,8 @@ defmodule LivebookWeb.Output do
"""
end

defp render_output(%{type: :error, message: message}, %{}) do
render_formatted_error_message(message)
defp render_output(%{type: :error, message: message}, %{id: id}) do
render_formatted_error_message(id, message)
end

defp render_output(output, %{}) do
Expand All @@ -373,16 +378,28 @@ defmodule LivebookWeb.Output do
"""
end

defp render_formatted_error_message(formatted) do
assigns = %{message: formatted}
defp render_formatted_error_message(id, message) do
assigns = %{id: id, message: message}

~H"""
<div
class="whitespace-pre-wrap break-words font-editor text-gray-500"
role="complementary"
aria-label="error"
phx-no-format
><%= ansi_string_to_html(@message) %></div>
<div id={@id} class="relative group/error">
<div
id={"#{@id}-message"}
class="whitespace-pre-wrap break-words font-editor text-gray-500"
role="complementary"
aria-label="error"
phx-no-format
><%= ansi_string_to_html(@message) %></div>
<div class="absolute right-2 top-0 z-10 invisible group-hover/error:visible">
<button
class="icon-button bg-gray-100"
data-el-clipcopy
phx-click={JS.dispatch("lb:clipcopy", to: "##{@id}-message")}
>
<.remix_icon icon="clipboard-line" class="text-lg" />
</button>
</div>
</div>
"""
end
end
Loading