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

Show Run#metadata in the web UI #903

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
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
24 changes: 3 additions & 21 deletions app/views/maintenance_tasks/runs/_arguments.html.erb
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
<% if run.arguments.present? %>
<div class="table-container">
<h6 class="title is-6">Arguments:</h6>
<table class="table">
<tbody>
<% run.arguments.transform_values(&:to_s).each do |key, value| %>
<tr>
<td class="is-family-monospace"><%= key %></td>
<td>
<% next if value.empty? %>
<% if value.include?("\n") %>
<pre><%= value %></pre>
<% else %>
<code><%= value %></code>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
<% if arguments.present? %>
<h6 class="title is-6">Arguments:</h6>
<%= render "maintenance_tasks/runs/serializable", serializable: arguments %>
<% end %>
4 changes: 4 additions & 0 deletions app/views/maintenance_tasks/runs/_metadata.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<% if metadata.present? %>
<h6 class="title is-6">Metadata:</h6>
<%= render "maintenance_tasks/runs/serializable", serializable: metadata %>
<% end %>
4 changes: 3 additions & 1 deletion app/views/maintenance_tasks/runs/_run.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

<%= render "maintenance_tasks/runs/csv", run: run %>
<%= tag.hr if run.csv_file.present? && run.arguments.present? %>
<%= render "maintenance_tasks/runs/arguments", run: run %>
<%= render "maintenance_tasks/runs/arguments", arguments: run.arguments %>
<%= tag.hr if run.csv_file.present? || run.arguments.present? && run.metadata.present? %>
<%= render "maintenance_tasks/runs/metadata", metadata: run.metadata %>

<div class="buttons">
<% if run.paused? %>
Expand Down
26 changes: 26 additions & 0 deletions app/views/maintenance_tasks/runs/_serializable.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<% if serializable.present? %>
<% case serializable %>
<% when Hash %>
<div class="table-container">
<table class="table">
<tbody>
<% serializable.transform_values(&:to_s).each do |key, value| %>
<tr>
<td class="is-family-monospace"><%= key %></td>
<td>
<% next if value.empty? %>
<% if value.include?("\n") %>
<pre><%= value %></pre>
<% else %>
<code><%= value %></code>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
<% else %>
<code><%= serializable.inspect %></code>
<% end %>
<% end %>
4 changes: 3 additions & 1 deletion app/views/maintenance_tasks/tasks/_task.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

<%= render "maintenance_tasks/runs/csv", run: run %>
<%= tag.hr if run.csv_file.present? && run.arguments.present? %>
<%= render "maintenance_tasks/runs/arguments", run: run %>
<%= render "maintenance_tasks/runs/arguments", arguments: run.arguments %>
<%= tag.hr if run.csv_file.present? || run.arguments.present? && run.metadata.present? %>
<%= render "maintenance_tasks/runs/metadata", metadata: run.metadata %>
<% end %>
</div>
19 changes: 19 additions & 0 deletions test/system/maintenance_tasks/runs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class RunsTest < ApplicationSystemTestCase
assert_title("Maintenance::UpdatePostsTask")
assert_text("Enqueued")
assert_text("Waiting to start.")
assert_text("Metadata")
assert_table do |table|
table.assert_text("user_email")
table.assert_text("michael.elfassy@shopify.com")
end
end
run = Run.last
assert_equal("michael.elfassy@shopify.com", run.metadata["user_email"])
Expand All @@ -41,6 +46,20 @@ class RunsTest < ApplicationSystemTestCase
MaintenanceTasks.metadata = nil
end

test "metadata can be non-hash" do
MaintenanceTasks.metadata = -> { "hello metadata" }
visit(maintenance_tasks_path)

assert_difference("Run.count") do
click_on("Maintenance::UpdatePostsTask")
click_on("Run")

assert_text("hello metadata")
end
ensure
MaintenanceTasks.metadata = nil
end

test "run a CSV Task" do
visit maintenance_tasks_path

Expand Down